class Lexer
package hxparse
Lexer matches a sequence of characters against a set of rule patterns.
An instance of Lexer is created once for each input and maintains state
for that input. Tokens can then be obtained by calling the token
method,
passing an instance of Ruleset
.
Rule sets can be created manually, or by calling the static buildRuleset
method.
Constructor
new (input:ByteData, ?sourceName:String)
Creates a new Lexer for input
.
If sourceName
is provided, it is used in error messages to denote
the position of an error.
If input
is null, the result is unspecified.
Variables
read onlycurrent:String
The String
that was matched by the most recent invocation of the
token
method.
Methods
token<T> (ruleset:Ruleset<T>):T
Returns the next token according to ruleset
.
This method starts with ruleset.state
and reads characters from this
input until no further state transitions are possible. It always returns
the longest match.
If a character is read which has no transition defined, an
UnexpectedChar
exception is thrown.
If the input is in the end of file state upon method invocation,
ruleset.eofFunction
is called with this
Lexer as argument. If
ruleset
defines no eofFunction
field, a haxe.io.Eof
exception
is thrown.
If ruleset
is null, the result is unspecified.
Static methods
staticbuildRuleset<Token> (rules:Array<{rule:String, func:Lexer ‑> Token}>, ?name:String):Ruleset<Token>
Builds a Ruleset
from the given rules
Array
.
For each element of rules
, its rule
String
is parsed into a
Pattern
using LexEngine.parse
.
If rules
is null, the result is unspecified.