Class Terminal
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
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 Farkle.Builder.Terminal.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 Farkle.Builder.Terminal.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 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
namestringThe name of the virtual terminal.
optionsTerminalOptionsOptions to configure the terminal. Optional.