In This Article

ITokenReader Interface

Provides the base requirements for an object that can provide tokens to a ILLParser in a forward-only direction.

public interface ITokenReader

Properties

IsAtEnd

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

bool IsAtEnd { get; }

Property Value

System.Boolean:

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

IsParserInErrorState

Gets or sets whether the parser is currently recovering from an error state.

bool IsParserInErrorState { get; set; }

Property Value

System.Boolean:

true if the parser is currently recovering from an error state; otherwise, false.

LookAheadToken

Returns the IToken that is immediately after the current token.

IToken LookAheadToken { get; }

Property Value

IToken:

The IToken that is immediately after the current token.

Offset

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

int Offset { get; }

Property Value

System.Int32:

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

StackLevel

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

int StackLevel { get; }

Property Value

System.Int32:

The current stack level.

Token

Gets the current IToken.

IToken Token { get; }

Property Value

IToken:

The current IToken.

Methods

Advance()

Advances to the next IToken.

void Advance()

AdvanceTo(Int32)

Advances to the next IToken with the specified ID, such that the LookAheadToken property will be pointing to the matched token, if any.

bool AdvanceTo(int tokenId)
Parameter Type Description
tokenId System.Int32

The ID of IToken for which to search.

Returns

System.Boolean:

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(Int32[])

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.

bool AdvanceTo(params int[] tokenIds)
Parameter Type Description
tokenIds System.Int32[]

The array of IToken IDs for which to search.

Returns

System.Boolean:

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(Int32[])

Returns whether the next look-ahead tokens match the specified sequence of token IDs.

bool AreNext(params int[] tokenIds)
Parameter Type Description
tokenIds System.Int32[]

The sequence of token IDs for which to search.

Returns

System.Boolean:

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(Int32)

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

IToken GetLookAheadToken(int count)
Parameter Type Description
count System.Int32

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.

GetTokenText(IToken)

Returns an IToken's encapsulated text from the text buffer using Newline for line ends.

string GetTokenText(IToken targetToken)
Parameter Type Description
targetToken IToken

The IToken to examine.

Returns

System.String:

The IToken's encapsulated text from the text buffer using Newline for line ends.

Initialize()

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

void Initialize()

OffsetToPosition(Int32)

Returns the TextPosition that represents the specified offset within the text lines.

TextPosition OffsetToPosition(int offset)
Parameter Type Description
offset System.Int32

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.

bool Pop()

Returns

System.Boolean:

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.

void Push()

Remarks

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