Skip to content

Commit 76cf284

Browse files
committed
Merge branch 'TokenRedesign'
2 parents 4bff7bf + 4c50266 commit 76cf284

26 files changed

+335
-219
lines changed

Code Grapher/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

@@ -32,5 +32,7 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.2.22221.0")]
36-
[assembly: AssemblyFileVersion("1.2.22221.0")]
35+
[assembly: AssemblyVersion("1.3.31623.0")]
36+
[assembly: AssemblyFileVersion("1.3.31623.0")]
37+
38+
[assembly: AssemblyInformationalVersion("1.3.31623.0")]

Common/Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
<Reference Include="System.Xml" />
4949
</ItemGroup>
5050
<ItemGroup>
51-
<Compile Include="Grammar\SyntaxTokenFactory.cs" />
51+
<Compile Include="Grammar\DetailedTokenFactory.cs" />
5252
<Compile Include="Syntax\ISyntaxHighlightingGuide.cs" />
5353
<Compile Include="Extensions\TokenInterfaceExtensionMethods.cs" />
5454
<Compile Include="Grammar\Place.cs" />
55-
<Compile Include="Grammar\SyntaxToken.cs" />
55+
<Compile Include="Grammar\DetailedToken.cs" />
5656
<Compile Include="Properties\AssemblyInfo.cs" />
5757
</ItemGroup>
5858
<ItemGroup>
Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#region BSD 3-Clause License
2-
// <copyright file="SyntaxToken.cs" company="Edgerunner.org">
2+
// <copyright file="DetailedToken.cs" company="Edgerunner.org">
33
// Copyright 2020
44
// </copyright>
55
//
@@ -44,12 +44,11 @@
4444
namespace Org.Edgerunner.ANTLR4.Tools.Common.Grammar
4545
{
4646
/// <summary>
47-
/// Struct that represents a lightweight view model for IToken instances
47+
/// A more detailed implementation of IToken.
4848
/// </summary>
4949
/// <seealso cref="Antlr4.Runtime.IToken"/>
50-
public class SyntaxToken : CommonToken
50+
public class DetailedToken : CommonToken
5151
{
52-
private string _DisplayText;
5352
private string _TypeNameUpperCase;
5453
private int? _EndingLineNumber;
5554
private int? _EndingColumnPosition;
@@ -58,47 +57,77 @@ public class SyntaxToken : CommonToken
5857
private string _TypeName;
5958

6059
/// <summary>
61-
/// Initializes a new instance of the <see cref="SyntaxToken"/> class.
60+
/// Initializes a new instance of the <see cref="DetailedToken"/> class.
6261
/// </summary>
6362
/// <param name="source">The source.</param>
6463
/// <param name="type">The type.</param>
6564
/// <param name="channel">The channel.</param>
6665
/// <param name="start">The start.</param>
6766
/// <param name="stop">The stop.</param>
68-
public SyntaxToken([NotNull] Tuple<ITokenSource, ICharStream> source, int type, int channel, int start, int stop)
67+
// ReSharper disable once TooManyDependencies
68+
public DetailedToken([NotNull] Tuple<ITokenSource, ICharStream> source, int type, int channel, int start, int stop)
6969
: base(source, type, channel, start, stop)
7070
{
71-
ColumnPosition = charPositionInLine + 1;
71+
ColumnPosition = start + 1;
7272
Length = stop - start + 1;
73-
74-
//TypeName = parserToken.Type > -1 ? lexer.Vocabulary.GetDisplayName(parserToken.Type) : string.Empty;
75-
//TypeNameUpperCase = TypeName.ToUpperInvariant();
7673
}
7774

7875
/// <summary>
79-
/// Initializes a new instance of the <see cref="SyntaxToken"/> class.
76+
/// Initializes a new instance of the <see cref="DetailedToken"/> class.
8077
/// </summary>
8178
/// <param name="type">The type.</param>
8279
/// <param name="text">The text.</param>
83-
public SyntaxToken(int type, string text)
80+
public DetailedToken(int type, string text)
8481
: base(type, text)
8582
{
8683
}
8784

8885
/// <summary>
89-
/// Initializes a new instance of the <see cref="SyntaxToken"/> class.
86+
/// Initializes a new instance of the <see cref="DetailedToken"/> class.
9087
/// </summary>
9188
/// <param name="type">The type.</param>
92-
public SyntaxToken(int type)
89+
public DetailedToken(int type)
9390
: base(type)
9491
{
9592
}
9693

94+
/// <summary>Explicitly set the text for this token.</summary>
95+
/// <remarks>
96+
/// Explicitly set the text for this token. If {code text} is not
97+
/// <see langword="null" />
98+
/// , then
99+
/// <see cref="P:Antlr4.Runtime.CommonToken.Text" />
100+
/// will return this value rather than
101+
/// extracting the text from the input.
102+
/// </remarks>
103+
/// <value>
104+
/// The explicit text of the token, or
105+
/// <see langword="null" />
106+
/// if the text
107+
/// should be obtained from the input along with the start and stop indexes
108+
/// of the token.
109+
/// </value>
110+
public override string Text
111+
{
112+
get
113+
{
114+
if (!string.IsNullOrEmpty(text))
115+
return text;
116+
ICharStream inputStream = InputStream;
117+
if (inputStream == null)
118+
return null;
119+
int size = inputStream.Size;
120+
return start < size && stop < size ? inputStream.GetText(Interval.Of(start, stop)) : "<EOF>";
121+
}
122+
123+
set => text = value;
124+
}
125+
97126
/// <summary>
98127
/// Gets the token display text.
99128
/// </summary>
100129
/// <value>The token display text.</value>
101-
public string DisplayText => _DisplayText ?? (_DisplayText = FormatTokenText(Text));
130+
public string DisplayText => FormatTokenText(Text);
102131

103132
/// <summary>
104133
/// Gets or sets the token type.
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#region BSD 3-Clause License
2-
// <copyright file="SyntaxTokenFactory.cs" company="Edgerunner.org">
2+
// <copyright file="DetailedTokenFactory.cs" company="Edgerunner.org">
33
// Copyright 2022 Thaddeus Ryker
44
// </copyright>
55
//
@@ -43,16 +43,16 @@
4343
namespace Org.Edgerunner.ANTLR4.Tools.Common.Grammar
4444
{
4545
/// <summary>
46-
/// Class responsible for creating a <see cref="SyntaxToken"/>.
46+
/// Class responsible for creating a <see cref="DetailedToken"/>.
4747
/// Implements the <see cref="Antlr4.Runtime.ITokenFactory" />
4848
/// </summary>
4949
/// <seealso cref="Antlr4.Runtime.ITokenFactory" />
50-
public class SyntaxTokenFactory : ITokenFactory
50+
public class DetailedTokenFactory : ITokenFactory
5151
{
5252
/// <summary>
5353
/// The default static instance factory.
5454
/// </summary>
55-
public static readonly ITokenFactory Instance = new SyntaxTokenFactory();
55+
public static readonly ITokenFactory Instance = new DetailedTokenFactory();
5656

5757
IToken ITokenFactory.Create(Tuple<ITokenSource, ICharStream> source, int type, string text, int channel, int start, int stop, int line, int charPositionInLine)
5858
{
@@ -69,8 +69,8 @@ IToken ITokenFactory.Create(int type, string text)
6969
/// </summary>
7070
/// <param name="type">The type.</param>
7171
/// <param name="text">The text.</param>
72-
/// <returns>A new SyntaxToken.</returns>
73-
public virtual SyntaxToken Create(int type, string text) => new SyntaxToken(type, text);
72+
/// <returns>A new DetailedToken.</returns>
73+
public virtual DetailedToken Create(int type, string text) => new DetailedToken(type, text);
7474

7575
/// <summary>
7676
/// Creates the specified source.
@@ -83,15 +83,17 @@ IToken ITokenFactory.Create(int type, string text)
8383
/// <param name="stop">The token stop.</param>
8484
/// <param name="line">The token line.</param>
8585
/// <param name="charPositionInLine">The character position in line.</param>
86-
/// <returns>A new SyntaxToken instance.</returns>
87-
public SyntaxToken Create(Tuple<ITokenSource, ICharStream> source, int type, string text, int channel, int start, int stop, int line, int charPositionInLine)
86+
/// <returns>A new DetailedToken instance.</returns>
87+
public DetailedToken Create(Tuple<ITokenSource, ICharStream> source, int type, string text, int channel, int start, int stop, int line, int charPositionInLine)
8888
{
89-
SyntaxToken token =
90-
new SyntaxToken(source, type, channel, start, stop) { Line = line, Column = charPositionInLine };
89+
DetailedToken token =
90+
new DetailedToken(source, type, channel, start, stop) { Line = line, Column = charPositionInLine };
9191
if (text != null)
9292
token.Text = text;
9393
else if (source.Item2 != null)
9494
token.Text = source.Item2.GetText(Interval.Of(start, stop));
95+
if (source.Item1 is IRecognizer recognizer)
96+
token.TypeName = token.Type > -1 ? recognizer.Vocabulary.GetDisplayName(token.Type) : string.Empty;
9597
return token;
9698
}
9799
}

Common/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

@@ -32,5 +32,7 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.2.22221.0")]
36-
[assembly: AssemblyFileVersion("1.2.22221.0")]
35+
[assembly: AssemblyVersion("1.3.31623.0")]
36+
[assembly: AssemblyFileVersion("1.3.31623.0")]
37+
38+
[assembly: AssemblyInformationalVersion("1.3.31623.0")]

Common/Syntax/ISyntaxHighlightingGuide.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141

4242
namespace Org.Edgerunner.ANTLR4.Tools.Common.Syntax
4343
{
44+
/// <summary>
45+
/// Interface that represents a syntax highlighting guide
46+
/// </summary>
4447
public interface ISyntaxHighlightingGuide
4548
{
4649
/// <summary>
@@ -65,20 +68,20 @@ public interface ISyntaxHighlightingGuide
6568
/// </summary>
6669
/// <param name="token">The token.</param>
6770
/// <returns>The <see cref="Color"/> to use.</returns>
68-
Color GetTokenForegroundColor(SyntaxToken token);
71+
Color GetTokenForegroundColor(DetailedToken token);
6972

7073
/// <summary>
7174
/// Gets the background color to use for the token.
7275
/// </summary>
7376
/// <param name="token">The token.</param>
7477
/// <returns>The <see cref="Color"/> to use.</returns>
75-
Color GetTokenBackgroundColor(SyntaxToken token);
78+
Color GetTokenBackgroundColor(DetailedToken token);
7679

7780
/// <summary>
7881
/// Gets the FontStyle to use for the token.
7982
/// </summary>
8083
/// <param name="token">The token.</param>
8184
/// <returns>The <see cref="FontStyle"/> to use.</returns>
82-
FontStyle GetTokenFontStyle(SyntaxToken token);
85+
FontStyle GetTokenFontStyle(DetailedToken token);
8386
}
8487
}

Grun.Net.sln

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,23 @@ Global
6767
UpdateAssemblyVersion = True
6868
UpdateAssemblyFileVersion = True
6969
UpdateAssemblyInfoVersion = True
70-
AssemblyVersionSettings = None.None.DateStamp.IncrementWithResetOnIncrease
71-
AssemblyFileVersionSettings = None.None.DateStamp.IncrementWithResetOnIncrease
72-
AssemblyInfoVersionSettings = None.None.DateStamp.IncrementWithResetOnIncrease
70+
ShouldCreateLogs = True
71+
AdvancedSettingsExpanded = True
72+
AssemblyVersionSettings = None.None.None.None
73+
AssemblyFileVersionSettings = None.None.None.None
74+
AssemblyInfoVersionSettings = None.None.None.None
7375
UpdatePackageVersion = False
7476
AssemblyInfoVersionType = SettingsVersion
7577
InheritWinAppVersionFrom = None
78+
UpdateAssemblyVersion.Release|Any CPU = True
79+
UpdateAssemblyFileVersion.Release|Any CPU = True
80+
UpdateAssemblyInfoVersion.Release|Any CPU = True
81+
ShouldCreateLogs.Release|Any CPU = True
82+
AssemblyVersionSettings.Release|Any CPU = None.None.DateStamp.IncrementWithResetOnIncrease
83+
AssemblyFileVersionSettings.Release|Any CPU = None.None.DateStamp.IncrementWithResetOnIncrease
84+
AssemblyInfoVersionSettings.Release|Any CPU = None.None.DateStamp.IncrementWithResetOnIncrease
85+
UpdatePackageVersion.Release|Any CPU = False
86+
AssemblyInfoVersionType.Release|Any CPU = SettingsVersion
87+
InheritWinAppVersionFrom.Release|Any CPU = None
7688
EndGlobalSection
7789
EndGlobal

Grun/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ private static void HighlightSyntaxInConsole(int lineOffset, Analyzer analyzer,
309309

310310
var cursorRow = Console.CursorTop;
311311
var cursorColumn = Console.CursorLeft;
312-
foreach (var token in analyzer.SyntaxTokens)
312+
foreach (var token in analyzer.Tokens)
313313
{
314314
if (!_Cache.IsKnown(token))
315315
{
@@ -321,7 +321,7 @@ private static void HighlightSyntaxInConsole(int lineOffset, Analyzer analyzer,
321321
Console.SetCursorPosition(cursorColumn, cursorRow);
322322
}
323323

324-
private static void ColorToken(SyntaxToken token, int lineOffset, ISyntaxHighlightingGuide guide)
324+
private static void ColorToken(DetailedToken token, int lineOffset, ISyntaxHighlightingGuide guide)
325325
{
326326
if (token.Channel != 0)
327327
return;
@@ -423,7 +423,7 @@ private static void LoadApplicationSettings()
423423
_Settings.LoadDefaults();
424424
}
425425

426-
private static int MakeTokenKey(SyntaxToken token)
426+
private static int MakeTokenKey(DetailedToken token)
427427
{
428428
return $"{token.Line}-{token.ColumnPosition}-{token.DisplayText}".GetHashCode();
429429
}

Grun/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

@@ -32,5 +32,7 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.2.21216.2")]
36-
[assembly: AssemblyFileVersion("1.2.21216.2")]
35+
[assembly: AssemblyVersion("1.3.31623.0")]
36+
[assembly: AssemblyFileVersion("1.3.31623.0")]
37+
38+
[assembly: AssemblyInformationalVersion("1.3.31623.0")]

Grun/SyntaxHighlighting/ConsoleWrapperColor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static void SetSourceStart()
7272
_LineOffset = Console.CursorTop - 1;
7373
}
7474

75-
private static void HighlightTokens(IEnumerable<SyntaxToken> tokens, ISyntaxHighlightingGuide guide)
75+
private static void HighlightTokens(IEnumerable<DetailedToken> tokens, ISyntaxHighlightingGuide guide)
7676
{
7777
if (guide == null)
7878
return;
@@ -90,7 +90,7 @@ private static void HighlightTokens(IEnumerable<SyntaxToken> tokens, ISyntaxHigh
9090
Console.SetCursorPosition(cursorColumn, cursorRow);
9191
}
9292

93-
private static void HighlightToken(SyntaxToken token, ISyntaxHighlightingGuide guide)
93+
private static void HighlightToken(DetailedToken token, ISyntaxHighlightingGuide guide)
9494
{
9595
if (guide == null)
9696
return;
@@ -106,7 +106,7 @@ private static void HighlightToken(SyntaxToken token, ISyntaxHighlightingGuide g
106106
Console.SetCursorPosition(cursorColumn, cursorRow);
107107
}
108108

109-
private static void ColorToken(SyntaxToken token, int lineOffset, ISyntaxHighlightingGuide guide)
109+
private static void ColorToken(DetailedToken token, int lineOffset, ISyntaxHighlightingGuide guide)
110110
{
111111
if (token.Channel != 0)
112112
return;

0 commit comments

Comments
 (0)