RLexer
class RLexer (View source)
Multistate lexer class.
Lexemes can be defined on the fly. If the particular lexer instance is meant to be used with Parle\RParser, the token IDs need to be taken from there. Otherwise, arbitrary token IDs can be supplied. Note, that Parle\Parser is not compatible with this lexer.
Constants
ICASE |
|
DOT_NOT_LF |
|
DOT_NOT_CRLF |
|
SKIP_WS |
|
MATCH_ZERO_LEN |
|
Properties
bool | $bol | ||
int | $flags | ||
int | $state | ||
int | $marker | ||
int | $cursor |
Methods
Processes the next rule and prepares the resulting token data.
Finalize the lexer rule set
Define token callback
Pass the data for processing
Dump the state machine
Add a lexer rule
Push a new start state This lexer type can have more than one state machine.
Reset lexer
Details
void
advance()
Processes the next rule and prepares the resulting token data.
void
build()
Finalize the lexer rule set
Rules, previously added with Parle\RLexer::push() are finalized. This method call has to be done after all the necessary rules was pushed. The rule set becomes read only. The lexing can begin.
void
callout(int $id, callable $callback)
Define token callback
Define a callback to be invoked once lexer encounters a particular token.
void
consume(string $data)
Pass the data for processing
Consume the data for lexing.
void
dump()
Dump the state machine
Dump the current state machine to stdout.
Token
getToken()
Retrieve the current token.
void
push(string $state, string $regex, string $newState)
Add a lexer rule
Push a pattern for lexeme recognition. A 'start state' and 'exit state' can be specified by using a suitable signature.
int
pushState(string $state)
Push a new start state This lexer type can have more than one state machine.
This allows you to lex different tokens depending on context, thus allowing simple parsing to take place. Once a state pushed, it can be used with a suitable Parle\RLexer::push() signature variant.
void
reset(int $pos)
Reset lexer
Reset lexing optionally supplying the desired offset.