Class ParserStateContext<TChar>
Manages the lifetime of a parsing operation on streaming input.
public abstract class ParserStateContext<TChar> : IParserStateBox, IBufferWriter<TChar>
Type Parameters
TChar
The type of characters that are parsed. Usually it is char or byte (not supported by Farkle's built-in parsers).
- Inheritance
-
ParserStateContext<TChar>
- Implements
-
IBufferWriter<TChar>
- Derived
-
ParserStateContext<TChar, T>
Remarks
Parser state contexts are the intermediate-level Parser API of Farkle, sitting on top of IParser<TChar, T>. They contain the logic to parse text, to keep the parsing operation's ParserState, to manage the character buffer, and bring them all together.
Parser state contexts implement the IBufferWriter<T> interface to allow writing characters in an efficient fashion. The parsing logic is automatically invoked when new characters are submitted through the Advance(int) method, or when input ends with the CompleteInput() method.
This class cannot be inherited by user code.
Properties
IsCompleted
Whether the parsing operation has completed.
public abstract bool IsCompleted { get; }
Property Value
State
The parsing operation's state.
public ref ParserState State { get; }
Property Value
Remarks
Methods
Advance(int)
Notifies the IBufferWriter<T> that count
data items were written to the output Span<T> or Memory<T>.
public void Advance(int count)
Parameters
CompleteInput()
Signals to the ParserStateContext<TChar> that no more input will be supplied.
public void CompleteInput()
GetMemory(int)
Returns a Memory<T> to write to that is at least the requested size (specified by sizeHint
).
public Memory<TChar> GetMemory(int sizeHint = 0)
Parameters
Returns
- Memory<TChar>
A Memory<T> of at least the size
sizeHint
. IfsizeHint
is 0, returns a non-empty buffer.
Exceptions
- OutOfMemoryException
The requested buffer size is not available.
GetSpan(int)
Returns a Span<T> to write to that is at least the requested size (specified by sizeHint
).
public Span<TChar> GetSpan(int sizeHint = 0)
Parameters
Returns
Reset()
Resets the ParserStateContext<TChar>, allowing it to be reused for another parsing operation.
public virtual void Reset()
Remarks
This method cannot be overridden by user code. To provide custom resetting logic override OnReset() instead.