grmtools currently supports one common use of Lex, which is to produce a sequence of tokens. All Lex files require at least some porting to grmtools, though in many cases this is fairly trivial. Nevertheless, aspects such as the longest match rule are identical to Lex, and we assume familiarity with Lex syntax and its major features: the Lex manual is recommended reading.
There are several major differences between Lex and grmtools:
Lex has its own regular expression language whereas grmtools uses the well known Rust regex crate for regular expressions. These two regular expression languages are very similar, but complex regular expressions might not be supported under one or the other.
Lex files consist of a sequence of regular expressions and an action for each. grmtools lex files consists of a sequence of regular expressions and a token name. Actions are not currently supported (and, by extension, nor are special action expressions such as
Both Lex and grmtools lex files support start conditions as an optional prefix to regular expressions, listing necessary states for the input expression to be considered for matching against the input. Lex uses a special action expression
BEGIN(state)to switch to the named
state. grmtools lex files use a token name prefix.
Character sets, and changes to internal array sizes are not supported by grmtools.
In addition to escape sequences involved in the escaping of regular expressions. Lex and grmtools support the escape sequences
\x1234(hexadecimal) and ASCII escape sequences.
Lex also interprets the escape sequence
backspace. While regex treats
\bas a word boundary subsequently grmtools will too.
Additional escape sequences supported by regex:
\U12345678escape sequences for unicode characters, the
\Punicode character classes, as well as the
\Wperl character classes, and
Both Lex and grmtools support escaping arbitrary characters, for all other characters besides those listed above, when given an escaped character
\cit will be passed to the regex engine as the character
c. This is useful when a character is used within the lex format.
An example of this is when the character
<is used at the beginning of a regex. Both Lex and grmtools interpret this as the beginning of a start condition prefix. Which can be escaped with
\<to ensure it is treated as the start of a regular expression.
But the characters to which this behavior applies is impacted by the escape sequence differences listed above.