Grammatica
|
A character stream tokenizer. More...
Public Member Functions | |
Tokenizer (TextReader input) | |
Creates a new case-sensitive tokenizer for the specified input stream. More... | |
Tokenizer (TextReader input, bool ignoreCase) | |
Creates a new tokenizer for the specified input stream. More... | |
bool | GetUseTokenList () |
Checks if the token list feature is used. More... | |
void | SetUseTokenList (bool useTokenList) |
Sets the token list feature flag. More... | |
string | GetPatternDescription (int id) |
Returns a description of the token pattern with the specified id. More... | |
int | GetCurrentLine () |
Returns the current line number. More... | |
int | GetCurrentColumn () |
Returns the current column number. More... | |
void | AddPattern (TokenPattern pattern) |
Adds a new token pattern to the tokenizer. More... | |
void | Reset (TextReader input) |
Resets this tokenizer for usage with another input stream. More... | |
Token | Next () |
Finds the next token on the stream. More... | |
override string | ToString () |
Returns a string representation of this object. More... | |
Protected Member Functions | |
virtual Token | NewToken (TokenPattern pattern, string image, int line, int column) |
Factory method for creating a new token. More... | |
Properties | |
bool | UseTokenList [get, set] |
The token list flag property. More... | |
A character stream tokenizer.
This class groups the characters read from the stream together into tokens ("words"). The grouping is controlled by token patterns that contain either a fixed string to search for, or a regular expression. If the stream of characters don't match any of the token patterns, a parse exception is thrown.
|
inline |
Creates a new case-sensitive tokenizer for the specified input stream.
input | the input stream to read |
|
inline |
Creates a new tokenizer for the specified input stream.
The tokenizer can be set to process tokens either in case-sensitive or case-insensitive mode.
input | the input stream to read |
ignoreCase | the character case ignore flag |
|
inline |
Adds a new token pattern to the tokenizer.
The pattern will be added last in the list, choosing a previous token pattern in case two matches the same string.
pattern | the pattern to add |
ParserCreationException | if the pattern couldn't be added to the tokenizer |
|
inline |
Returns the current column number.
This number will be the column number of the next token returned.
|
inline |
Returns the current line number.
This number will be the line number of the next token returned.
|
inline |
Returns a description of the token pattern with the specified id.
id | the token pattern id |
|
inline |
Checks if the token list feature is used.
The token list feature makes all tokens (including ignored tokens) link to each other in a linked list. By default the token list feature is not used.
|
inlineprotectedvirtual |
Factory method for creating a new token.
This method can be overridden to provide other token implementations than the default one.
pattern | the token pattern |
image | the token image (i.e. characters) |
line | the line number of the first character |
column | the column number of the first character |
|
inline |
Finds the next token on the stream.
This method will return null when end of file has been reached. It will return a parse exception if no token matched the input stream, or if a token pattern with the error flag set matched. Any tokens matching a token pattern with the ignore flag set will be silently ignored and the next token will be returned.
ParseException | if the input stream couldn't be read or parsed correctly |
|
inline |
Resets this tokenizer for usage with another input stream.
This method will clear all the internal state in the tokenizer as well as close the previous input stream. It is normally called in order to reuse a parser and tokenizer pair with multiple input streams, thereby avoiding the cost of re-analyzing the grammar structures.
input | the new input stream to read |
|
inline |
Sets the token list feature flag.
The token list feature makes all tokens (including ignored tokens) link to each other in a linked list when active. By default the token list feature is not used.
useTokenList | the token list feature flag |
|
inline |
Returns a string representation of this object.
The returned string will contain the details of all the token patterns contained in this tokenizer.
|
getset |
The token list flag property.
If the token list flag is set, all tokens (including ignored tokens) link to each other in a double-linked list. By default the token list flag is set to false.