Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lex extensions

Flags can be specified at compile time through LexFlags or at .l file parse time using a %grmtools{ } section. At compile time these flags can be enabled using CTLexerBuilder methods.

Flags commonly affect the parsing of the lex file, the interpretation regular expressions, and set limits.

Boolean flags are specified by their name, and can be negated by prefixing with ! other flags should specify their value immediately after the flag name.

Example

%grmtools {
    allow_wholeline_comments,
    !octal,
    size_limit: 1024,
}
%%
. "rule"

List of flags:

FlagValueRequired
lrlex.lexerkindLexerKind
lrlex.posix_escapes1bool
lrlex.allow_wholeline_comments2bool
regex.case_insensitivebool
regex.dot_matches_new_linebool
regex.multi_linebool
regex.octalbool
regex.swap_greedbool
regex.ignore_whitespacebool
regex.unicodebool
regex.size_limitusize
regex.dfa_size_limitusize
regex.nest_limitu32

Flags affecting Posix compatibility

As discussed in Lex compatibility the default behaviors of grmtools and rust’s regex library have differed from that of posix lex.

The following flags can change the behavior to match posix lex more closely.

%grmtools {
    !dot_matches_new_line,
    posix_escapes
}
%%
...

  1. Enable compatibility with posix escape sequences.

  2. Enables rust style // comments at the start of lines. Which requires escaping of / when used in a regex.