Class Terminal
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
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
namestringThe name of the terminal.
regexRegexThe Regex that matches the terminal.
optionsTerminalOptionsOptions to configure the terminal. Optional.
Returns
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
namestringThe name of the terminal.
regexRegexThe Regex that matches the terminal.
transformerTransformer<char, T>The transformer to apply to the content of the terminal.
optionsTerminalOptionsOptions to configure the terminal. Optional.
Returns
Type Parameters
TThe type of values the terminal will produce.
Literal(string)
Creates a terminal that matches a literal string.
public static IGrammarSymbol Literal(string value)
Parameters
valuestringThe string matched by the terminal.
Returns
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
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
namestringThe name of the virtual terminal.
optionsTerminalOptionsOptions to configure the terminal. Optional.
Returns
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
namestringThe name of the virtual terminal.
transformerTransformer<char, T>The transformer that is associated with the virtual terminal.
optionsTerminalOptionsOptions to configure the terminal. Optional.
Returns
Type Parameters
TThe 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