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:
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

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.

public bool IsParserInErrorState { get; set; }

Property Value

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.

public 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.

public int Offset { get; }

Property Value

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.

public int StackLevel { get; }

Property Value

Int32:

The current stack level.

Token

Gets the current IToken.

public IToken Token { get; }

Property Value

IToken:

The current IToken.

Methods

Advance()

Advances to the next IToken.

public 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.

public bool AdvanceTo(int tokenId)
Parameter Type Description
tokenId Int32

The ID of IToken for which to search.

Returns

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.

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

The array of IToken IDs for which to search.

Returns

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.

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

The sequence of token IDs for which to search.

Returns

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.

public IToken GetLookAheadToken(int count)
Parameter Type Description
count 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.

GetNextToken()

Returns the next IToken that will be consumed by the token reader.

protected abstract IToken GetNextToken()

Returns

IToken:

The next IToken that will be consumed by the token reader.

GetTokenText(IToken)

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

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 using Newline for line ends.

Initialize()

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

public void Initialize()

OffsetToPosition(Int32)

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

public TextPosition OffsetToPosition(int offset)
Parameter Type Description
offset 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.

public virtual bool Pop()

Returns

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.

public virtual void Push()

Remarks

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

Inherited Members