Table of Contents

Class Terminal

Namespace
Farkle.Builder
Assembly
Farkle.dll

Provides factory methods to define terminals.

public static class Terminal
Inheritance
Terminal

Properties

NewLine

A special terminal that matches a new line.

public static IGrammarSymbol NewLine { get; }

Property Value

IGrammarSymbol

Remarks

This is different and better than a literal of newline characters. If used anywhere in the grammar, it indicates that the grammar is line-based, which means that newline characters are not noise. Newline characters are are considered the character sequences \r, \n, or \r\n.

Methods

Create(string, Regex, TerminalOptions)

Creates a terminal that does not produce a value.

public static IGrammarSymbol Create(string name, Regex regex, TerminalOptions options = TerminalOptions.None)

Parameters

name string

The name of the terminal.

regex Regex

The Regex that matches the terminal.

options TerminalOptions

Options to configure the terminal. Optional.

Returns

IGrammarSymbol

Create<T>(string, Regex, Transformer<char, T>, TerminalOptions)

Creates a terminal that produces a value.

public static IGrammarSymbol<T> Create<T>(string name, Regex regex, Transformer<char, T> transformer, TerminalOptions options = TerminalOptions.None)

Parameters

name string

The name of the terminal.

regex Regex

The Regex that matches the terminal.

transformer Transformer<char, T>

The transformer to apply to the content of the terminal.

options TerminalOptions

Options to configure the terminal. Optional.

Returns

IGrammarSymbol<T>

Type Parameters

T

The type of values the terminal will produce.

Literal(string)

Creates a terminal that matches a literal string.

public static IGrammarSymbol Literal(string value)

Parameters

value string

The string matched by the terminal.

Returns

IGrammarSymbol

Remarks

Multiple instances of literals with the same value resolve to the same terminal in a grammar, and will not cause conflicts when building it.

The equivalence of literals when building a grammar is affected by the grammar's case sensitivity option.

See Also
Append<T>(T, string)

Virtual(string, TerminalOptions)

Creates a virtual terminal with an associated transformer that produces a value.

public static IGrammarSymbol Virtual(string name, TerminalOptions options = TerminalOptions.None)

Parameters

name string

The name of the virtual terminal.

options TerminalOptions

Options to configure the terminal. Optional.

Returns

IGrammarSymbol

Remarks

Virtual terminals are never produced by Farkle's default tokenizer, and require a custom tokenizer to match them. You can do this by adding a special name to the terminal, and looking it from the IGrammarProvider that is passed to the tokenizer on construction.

See Also

Virtual<T>(string, Transformer<char, T>, TerminalOptions)

Creates a virtual terminal with an associated transformer that produces a value.

public static IGrammarSymbol<T> Virtual<T>(string name, Transformer<char, T> transformer, TerminalOptions options = TerminalOptions.None)

Parameters

name string

The name of the virtual terminal.

transformer Transformer<char, T>

The transformer that is associated with the virtual terminal.

options TerminalOptions

Options to configure the terminal. Optional.

Returns

IGrammarSymbol<T>

Type Parameters

T

The type of values the terminal will produce.

Remarks

Virtual terminals are never produced by Farkle's default tokenizer, and require a custom tokenizer to match them. You can do this by adding a special name to the terminal, and looking it from the IGrammarProvider that is passed to the tokenizer on construction.

In your custom tokenizer, invoking Transform(ref ParserState, TokenSymbolHandle, ReadOnlySpan<TChar>) with the virtual terminal's symbol will invoke transformer and return its result.

See Also