Pidgin

Class ParseState<TToken>

Represents the state of a parsing process. Includes functionality managing and buffering the input stream, reporting errors, and computing source positions.

For efficiency, this object is implemented as a mutable struct and is intended to be passed by reference.

WARNING: This API is unstable and subject to change in future versions of the library.

Inheritance
Declaration
public sealed class ParseState<TToken> : ValueType
Type Parameters
Name Description

TToken

The type of tokens consumed by the parser.

Properties

Configuration

Gets the parser configuration

Declaration
public IConfiguration<TToken> Configuration { get; }
Property Value
Type Description

IConfiguration<TToken>

Current

Returns the current token.

Declaration
public TToken Current { get; }
Property Value
Type Description

TToken

HasCurrent

Returns true if the parser has not reached the end of the input.

Declaration
public bool HasCurrent { get; }
Property Value
Type Description

Boolean

Location

Returns the total number of tokens which have been consumed. In other words, the current absolute offset of the input stream.

Declaration
public int Location { get; }
Property Value
Type Description

Int32

Methods

Advance(Int32)

Advance the input stream by count tokens.

Declaration
public void Advance(int count = 1)
Parameters
Type Name Description

Int32

count

The number of tokens to advance.

Bookmark()

Start buffering the input

Declaration
public int Bookmark()
Returns
Type Description

Int32

DiscardBookmark(Int32)

Stop buffering the input

Declaration
public void DiscardBookmark(int bookmark)
Parameters
Type Name Description

Int32

bookmark

LookAhead(Int32)

Returns a Span<T> containing the next count tokens.

This method may return a span shorter than count, if the parser reaches the end of the input stream.

Declaration
public ReadOnlySpan<TToken> LookAhead(int count)
Parameters
Type Name Description

Int32

count

The number of tokens to advance.

Returns
Type Description

ReadOnlySpan<TToken>

Rewind(Int32)

Return to a bookmark previously obtained from Bookmark() and discard it

Declaration
public void Rewind(int bookmark)
Parameters
Type Name Description

Int32

bookmark

SetError(Maybe<TToken>, Boolean, Int32, String)

Sets the error. Call this when your parser fails

Declaration
public void SetError(Maybe<TToken> unexpected, bool eof, int errorLocation, string message)
Parameters
Type Name Description

Maybe<TToken>

unexpected

Boolean

eof

Int32

errorLocation

String

message