LexEngine handles pattern parsing and state transformation.

This class is used by the Lexer and rarely has to be interacted with directly.

The static parse method transforms a single String to a Pattern. Multiple patterns can then be passed to the constructor to generate the state machine, which is obtainable from the firstState method.

Constructor

new (patterns:Array<Pattern>)

Creates a new LexEngine from patterns.

Each LexEngine maintains a state machine, whose initial state can be obtained from the firstState method. After this, this LexEngine can be discarded.

If patterns is null, the result is unspecified.

Methods

firstState ():State

Returns the entry state of the state machine generated by this LexEngine.

Static methods

staticparse (pattern:String):Pattern

Parses the pattern String and returns an instance of Pattern.

If pattern is not a valid pattern string, an exception of String is thrown.

The following meta characters are supported:

- `*`: zero or more
- `+`: one or more
- `?`: zero or one
- `|`: or
- `[`: begin char range
- `]`: end char range
- `(`: begin group
- `)`: end group
- `\`: escape next char

These characters must be escaped if they are part of the pattern, by using \\*, \\] etc.