TokenReaderBase Class
Represents the abstract base class of an object that can provide tokens to a ILLParser in a forward-only direction.
public abstract class TokenReaderBase : ITokenReader
- Inheritance:
- object object
- Derived:
- MergableTokenReader
- Implements:
- ITokenReader
Constructors
TokenReaderBase(ITextBufferReader)
Initializes a new instance of the TokenReaderBase
class.
protected TokenReaderBase(ITextBufferReader reader)
Parameter | Type | Description |
---|---|---|
reader | ITextBufferReader | The ITextBufferReader to use for consuming text. |
Properties
IsAtEnd
Gets whether the current IToken is at the end of the text buffer.
public bool IsAtEnd { get; }
Property Value
IsParserInErrorState
Gets or sets whether the parser is currently recovering from an error state.
public bool IsParserInErrorState { get; set; }
Property Value
- bool:
true
if the parser is currently recovering from an error state; otherwise,false
.
LookAheadToken
Returns the IToken that is immediately after the current token.
public IToken LookAheadToken { get; }
Property Value
Offset
Gets the current offset, which is offset after the last Token that was read.
public int Offset { get; }
Property Value
StackLevel
Token
Gets the current IToken.
Methods
Advance()
Advances to the next IToken.
public void Advance()
AdvanceTo(int)
Advances to the next IToken with the specified ID, such that the LookAheadToken property will be pointing to the matched token, if any.
public bool AdvanceTo(int tokenId)
Parameter | Type | Description |
---|---|---|
tokenId | int | The ID of IToken for which to search. |
Returns
Remarks
If this method is successful, the LookAheadToken will be the IToken that was located.
AdvanceTo(params int[])
Advances to the next IToken with one of the specified IDs, such that the LookAheadToken property will be pointing to the matched token, if any.
public bool AdvanceTo(params int[] tokenIds)
Parameter | Type | Description |
---|---|---|
tokenIds | int[] | The array of IToken IDs for which to search. |
Returns
Remarks
If this method is successful, the LookAheadToken will be the IToken that was located.
AreNext(params int[])
Returns whether the next look-ahead tokens match the specified sequence of token IDs.
public bool AreNext(params int[] tokenIds)
Parameter | Type | Description |
---|---|---|
tokenIds | int[] | The sequence of token IDs for which to search. |
Returns
- bool:
true
if the next look-ahead tokens match the specified sequence of token IDs; otherwise,false
.
Remarks
This method is very useful within can-match callbacks that require two or more token look-aheads.
GetLookAheadToken(int)
Returns the IToken that is the specified number of positions past the current token.
public IToken GetLookAheadToken(int count)
Parameter | Type | Description |
---|---|---|
count | int | The number of positions past the current token to examine. |
Returns
Remarks
A parameter value of 1
will return the value of the LookAheadToken method without actually seeking past the next token.
GetNextToken()
Returns the next IToken that will be consumed by the token reader.
protected abstract IToken GetNextToken()
Returns
GetTokenText(IToken)
public string GetTokenText(IToken targetToken)
Parameter | Type | Description |
---|---|---|
targetToken | IToken | The IToken to examine. |
Returns
Initialize()
Initializes the token reader, which will be called by a ILLParser before the token reader is used.
public void Initialize()
OffsetToPosition(int)
Returns the TextPosition that represents the specified offset within the text lines.
public TextPosition OffsetToPosition(int offset)
Parameter | Type | Description |
---|---|---|
offset | int | The offset of a character within the snapshot. |
Returns
- TextPosition:
The TextPosition that represents the specified offset within the text lines.
Pop()
Pops the top token reader state from the stack and restores the token reader to that state.
Push()
Pushes the token reader state onto a stack for later restoration, generally to begin a multiple token look-ahead operation.