Table of Contents

Class Terminal

Namespace
Farkle.Builder
Assembly
Farkle.dll

Provides factory methods to define terminals.

public class Terminal : IGrammarSymbol, IGrammarBuilder
Inheritance
Terminal
Implements
Extension Methods

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 Farkle.Builder.Terminal.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 Farkle.Builder.Terminal.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 terminal that is never produced by Farkle's default tokenizer. Users will have to provide a custom tokenizer to match this terminal.

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