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
- Object
- ParseState<TToken>
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 |
---|---|
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 |
---|---|
Methods
Advance(Int32)
Advance the input stream by count
tokens.
Declaration
public void Advance(int count = 1)
Parameters
Type | Name | Description |
---|---|---|
count |
The number of tokens to advance. |
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 |
---|---|---|
count |
The number of tokens to advance. |
Returns
Type | Description |
---|---|
ReadOnlySpan<TToken> |
PopBookmark()
Stop buffering the input
Declaration
public void PopBookmark()
PushBookmark()
Start buffering the input
Declaration
public void PushBookmark()
Rewind()
Return to the last bookmark
Declaration
public void Rewind()
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 |
|
eof |
||
errorLocation |
||
message |