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//
4444namespace 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.
0 commit comments