In This Article

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:
MergeableTokenReader
Implements:
ITokenReader

Constructors

TokenReaderBase(ITextBufferReader)

Represents the abstract base class of an object that can provide tokens to a ILLParser in a forward-only direction.

protected TokenReaderBase(ITextBufferReader reader)
Parameter Type Description
reader ITextBufferReader

The ITextBufferReader to use for consuming text.

Properties

IsAtEnd

Indicates whether the current IToken is at the end of the text buffer.

public bool IsAtEnd { get; }

Property Value

bool:

true if the current IToken is at the end of the text buffer; otherwise, false.

IsParserInErrorState

Indicates 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

The IToken that is immediately after the current token.

public IToken LookAheadToken { get; }

Property Value

IToken

Offset

The current offset, which is offset after the last Token that was read.

public int Offset { get; }

Property Value

int

StackLevel

The current stack level from Push() calls without corresponding Pop() calls.

public int StackLevel { get; }

Property Value

int

Token

The current IToken.

public IToken? Token { get; }

Property Value

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

bool:

true if an IToken was found before the end of document; otherwise, false.

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

bool:

true if an IToken was found before the end of document; otherwise, false.

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

IToken:

The IToken that is the specified number of positions past the current token.

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

IToken

GetTokenText(IToken)

Returns an IToken's encapsulated text from the text buffer.

public string GetTokenText(IToken targetToken)
Parameter Type Description
targetToken IToken

The IToken to examine.

Returns

string:

The IToken's encapsulated text from the text buffer.

Initialize()

Initializes the token reader, which will be called by a ILLParser before the token reader is used.

public void Initialize()

OffsetToPosition(int)

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

Pop()

Pops the top token reader state from the stack and restores the token reader to that state.

public virtual bool Pop()

Returns

bool:

true if a pop occurred; otherwise, false.

Push()

Pushes the token reader state onto a stack for later restoration, generally to begin a multiple token look-ahead operation.

public virtual void Push()

Remarks

Any call to this method must have a corresponding Pop() call.

Inherited Members

Extension Methods