Class ParserInputReaderTokenizerExtensions
- Namespace
- Farkle.Parser.Tokenizers
- Assembly
- Farkle.dll
Provides extension methods on ParserInputReader<TChar> specific to tokenizers.
public static class ParserInputReaderTokenizerExtensions
- Inheritance
-
ParserInputReaderTokenizerExtensions
Remarks
Calling these methods outside of a tokenizer is undefined behavior.
Methods
IsSingleTokenizerInChain<TChar>(in ParserInputReader<TChar>)
Returns whether the tokenizer chain in a parsing operation consists of only one tokenizer.
public static bool IsSingleTokenizerInChain<TChar>(this in ParserInputReader<TChar> input)
Parameters
inputParserInputReader<TChar>The state of the parsing operation.
Returns
Type Parameters
TCharThe type of characters the tokenizer processes.
Remarks
If this property is true, tokenizers can avoid exiting when they encounter a noise symbol, and instead continue tokenizing. Checking for this property is optional and provides a performance improvement.
SuspendTokenizer<TChar>(ref ParserInputReader<TChar>, Tokenizer<TChar>)
Suspends the tokenization process and sets it to resume at the specified Tokenizer<TChar>.
public static void SuspendTokenizer<TChar>(this ref ParserInputReader<TChar> input, Tokenizer<TChar> tokenizer)
Parameters
inputParserInputReader<TChar>The state of the parsing operation.
tokenizerTokenizer<TChar>The tokenizer to resume at.
Type Parameters
TCharThe type of characters the tokenizer processes.
Remarks
This method is intended to be called by tokenizers that want to keep running when they return. The reasons they want that can be to ask for more characters or to produce many tokens consecutively.
- If the tokenizer is part of a chain and does not return a result, subsequent components of the chain will not be invoked. Instead the parent tokenizer will return without a result, causing the parser to return and request more input.
-
When the parent tokenizer gets invoked again, it will first invoke
tokenizerand if needed, continue the chain at the tokenizer after the tokenizer that initially suspended.
Because suspending tokenizers more than once is not allowed, tokenizers should return right after they call this method.
Exceptions
- ArgumentNullException
tokenizeris null.- InvalidOperationException
The tokenizer is already suspended.
SuspendTokenizer<TChar, TArg>(ref ParserInputReader<TChar>, ITokenizerResumptionPoint<TChar, TArg>, TArg)
Suspends the tokenization process and sets it to resume at the specified ITokenizerResumptionPoint<TChar, TArg>.
public static void SuspendTokenizer<TChar, TArg>(this ref ParserInputReader<TChar> input, ITokenizerResumptionPoint<TChar, TArg> resumptionPoint, TArg arg)
Parameters
inputParserInputReader<TChar>The state of the parsing operation.
resumptionPointITokenizerResumptionPoint<TChar, TArg>The resumption point to resume at.
argTArgAn argument to pass to
resumptionPointwhen it gets invoked.
Type Parameters
TCharThe type of characters the tokenizer processes.
TArgThe type of
arg.
Remarks
This method is intended to be called by tokenizers that want to keep running when they return. The reasons they want that can be to ask for more characters or to produce many tokens consecutively.
- If the tokenizer is part of a chain and does not return a result, subsequent components of the chain will not be invoked. Instead the parent tokenizer will return without a result, causing the parser to return and request more input.
-
When the parent tokenizer gets invoked again, it will first invoke
resumptionPointand if needed, continue the chain at the tokenizer after the tokenizer that initially suspended.
Because suspending tokenizers more than once is not allowed, tokenizers should return right after they call this method.
Exceptions
- ArgumentNullException
resumptionPointis null.- InvalidOperationException
The tokenizer is already suspended.