Struct ParserInputReader<TChar>
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)
Creates a ParserInputReader<TChar>.
public ParserInputReader(IParserStateBox stateBox, ReadOnlySpan<TChar> characters, bool isFinal = true)
Parameters
stateBox
IParserStateBoxAn IParserStateBox containing a reference to the reader's ParserState.
characters
ReadOnlySpan<TChar>The value that will be assigned to RemainingCharacters.
isFinal
boolThe 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)
Creates a ParserInputReader<TChar>.
public ParserInputReader(ref ParserState state, ReadOnlySpan<TChar> characters, bool isFinal = true)
Parameters
state
ParserStateA reference to the reader's ParserState.
characters
ReadOnlySpan<TChar>The value that will be assigned to RemainingCharacters.
isFinal
boolThe 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
IsFinalBlock
Whether there will be no other characters available after RemainingCharacters.
public readonly bool IsFinalBlock { get; }
Property Value
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
Methods
Consume(int)
Consumes the first characters of RemainingCharacters and makes them unavailable for future reads.
public void Consume(int count)
Parameters
count
intThe 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
-
GetPositionAfter<T>(ReadOnlySpan<T>)
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
intThe number of characters after CurrentPosition at which to throw the exception.
message
objectThe object to use as the exception's message.