Table of Contents

Struct ParserState

Namespace
Farkle.Parser
Assembly
Farkle.dll

Contains all state of a parsing operation.

public struct ParserState
Inherited Members

Remarks

A ParserState contains things such as the parser's current position, and a key-value store of objects that can be used by the parser and its extensions to store arbitrary state (such as symbol tables for a programming language).

This is a mutable value type that must be passed around by reference.

Properties

Context

An implementation-specific object that can hold additional state without the allocation overhead of SetValue(object, object).

public object? Context { readonly get; init; }

Property Value

object

Remarks

The object held by this property is intended to be used by the main parser code and not user extensions to parser.

CurrentPosition

The position of the last character the parser has consumed.

public readonly TextPosition CurrentPosition { get; }

Property Value

TextPosition

Remarks

In transformers, this is the position of the first character of the token, analogous to the

ITransformerContext.TokenStartPosition
property of Farkle 6.
See Also

InputName

A user-provided identifier for the input being parsed.

public string? InputName { readonly get; set; }

Property Value

string

Remarks

When parsing a file this could be the file's path.

See Also

TotalCharactersConsumed

The number of characters the parser has consumed.

public readonly long TotalCharactersConsumed { get; }

Property Value

long
See Also

Methods

GetPositionAfter<T>(ReadOnlySpan<T>)

Gets the position of the last of the given characters, assuming they start at CurrentPosition.

public readonly TextPosition GetPositionAfter<T>(ReadOnlySpan<T> characters)

Parameters

characters ReadOnlySpan<T>

A ReadOnlySpan<T> of characters.

Returns

TextPosition

Type Parameters

T

The type of characters.

Remarks

The position's column number is incremented for each character. If T is char or byte, the line number is incremented and the column number is reset for each CR, LF or CRLF sequence.

CR characters at the end of characters do not change the line number.

RemoveValue(object)

Removes the value associated with the given key from the ParserState's key-value dictionary.

public bool RemoveValue(object key)

Parameters

key object

The key of a value to remove.

Returns

bool

Whether the key had existed in the dictionary.

Exceptions

ArgumentNullException

key is null.

SetValue(object, object)

Sets a value in the ParserState's key-value dictionary.

public void SetValue(object key, object value)

Parameters

key object

The key of the value to set.

value object

The value to associate with key.

Exceptions

ArgumentNullException

key or value is null.

TryGetValue(object, out object)

Returns the value associated with the given key in the ParserState's key-value dictionary, if it exists.

public readonly bool TryGetValue(object key, out object value)

Parameters

key object

The key of the value to get.

value object

Will be assigned the value corresponding to key, or null if such value does not exist.

Returns

bool

Whether the key exists in the dictionary.

Exceptions

ArgumentNullException

key is null.