Token definitions using regular expressions to match input.
More...
Token definitions using regular expressions to match input.
To get the Lexer to recognize tokens, they need to be defined. This is the task of the TokenDefinition class. Each TokenDefinition consists of a regular expression used to match the input string, a corresponding token type and an optional token value (making it possible to standarize the token value for synonyms, e.g. both ln and log can be tokenized into the same token with value 'log'.)
Example usage (excerpt from StdMathLexer):
MathParser\Lexing\TokenDefinition::__construct |
( |
|
$pattern, |
|
|
|
$tokenType, |
|
|
|
$value = null |
|
) |
| |
MathParser\Lexing\TokenDefinition::getTokenFromMatch |
( |
|
$match | ) |
|
|
private |
Convert matching string to an actual Token.
- Parameters
-
string | $match | Matching text. |
- Return values
-
Token | Corresponding token. |
MathParser\Lexing\TokenDefinition::match |
( |
|
$input | ) |
|
Try to match the given input to the current TokenDefinition.
- Parameters
-
- Return values
-
MathParser\Lexing\TokenDefinition::$pattern |
|
private |
string $pattern Regular expression defining the rule for matching a token.
MathParser\Lexing\TokenDefinition::$tokenType |
|
private |
inst $tokenType Type of token, as defined in TokenType class.
The documentation for this class was generated from the following file:
- src/MathParser/Lexing/TokenDefinition.php