Table of Contents

Struct ParserInputReader<TChar>

Namespace
Farkle.Parser
Assembly
Farkle.dll

Provides an interface for a parser to read characters and alter its ParserState.

public ref struct ParserInputReader<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).

Inherited Members
Extension Methods

Remarks

This type is the replacement of the Farkle.IO.CharStream class of Farkle 6. Contrary to that, this is a mutable ref struct that must be passed around by reference and cannot be placed on the heap.

Constructors

ParserInputReader(IParserStateBox, ReadOnlySpan<TChar>, bool)

public ParserInputReader(IParserStateBox stateBox, ReadOnlySpan<TChar> characters, bool isFinal = true)

Parameters

stateBox IParserStateBox

An IParserStateBox containing a reference to the reader's ParserState.

characters ReadOnlySpan<TChar>

The value that will be assigned to RemainingCharacters.

isFinal bool

The value that will be assigned to IsFinalBlock.

Remarks

Callers should not assume that the stateBox instance will be kept alive by the garbage collector on all frameworks.

ParserInputReader(ref ParserState, ReadOnlySpan<TChar>, bool)

public ParserInputReader(ref ParserState state, ReadOnlySpan<TChar> characters, bool isFinal = true)

Parameters

state ParserState

A reference to the reader's ParserState.

characters ReadOnlySpan<TChar>

The value that will be assigned to RemainingCharacters.

isFinal bool

The value that will be assigned to IsFinalBlock.

Properties

IsEndOfInput

Whether input has ended. This happens when RemainingCharacters is empty and IsFinalBlock is true.

public readonly bool IsEndOfInput { get; }

Property Value

bool

IsFinalBlock

Whether there will be no other characters available after RemainingCharacters.

public readonly bool IsFinalBlock { get; }

Property Value

bool

RemainingCharacters

The remaining available characters.

public readonly ReadOnlySpan<TChar> RemainingCharacters { get; }

Property Value

ReadOnlySpan<TChar>

State

The parser's state.

public readonly ref ParserState State { get; }

Property Value

ParserState

Methods

Consume(int)

Consumes the first characters of RemainingCharacters and makes them unavailable for future reads.

public void Consume(int count)

Parameters

count int

The number of characters to consume.

Remarks

This method updates RemainingCharacters and the CurrentPosition and TotalCharactersConsumed properties of State.

Exceptions

ArgumentOutOfRangeException

count is negative or greater than the length of RemainingCharacters.

See Also

FailAtOffset(int, object)

Throws a ParserApplicationException indicating an error at the specified offset in the remaining characters.

public readonly void FailAtOffset(int offset, object message)

Parameters

offset int

The number of characters after CurrentPosition at which to throw the exception.

message object

The object to use as the exception's message.