Table of Contents

Class ParserStateContext<TChar>

Namespace
Farkle.Parser
Assembly
Farkle.dll

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
Derived

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

bool

State

The parsing operation's state.

public ref ParserState State { get; }

Property Value

ParserState

Remarks

The Context property will be equal to this object.

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

count int

The number of data items written to the Span<T> or Memory<T>.

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

sizeHint int

The minimum length of the returned Memory<T>. If 0, a non-empty buffer is returned.

Returns

Memory<TChar>

A Memory<T> of at least the size sizeHint. If sizeHint 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

sizeHint int

The minimum length of the returned Span<T>. If 0, a non-empty buffer is returned.

Returns

Span<TChar>

A Span<T> of at least the size sizeHint. If sizeHint is 0, returns a non-empty buffer.

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.

See Also