Action code
Action code is normal Rust code with the addition of the following special variables:
-
$1
...$n
refer to the respective symbol in the production, numbered from 1 (i.e.$1
refers to the first symbol in the production). If the symbol references a ruleR
then an instance ofR
's type will be stored in the$i
variable; if the symbol references a lexeme then anOption<Lexeme>
instance is returned. -
$lexer
allows access to the lexer and its various functions. The most commonly used of these is thelexeme_str
function, which allows us to turnLexeme
s into&str
s representing the corresponding portion of the user's input. -
$span
is a(start, end)
tuple (with both elements of typeusize
) which captures how much of the user's input the current production matched. This can be useful when storing debugging information. Note that this variable is not enabled by default: useCTParserBuilder::span_var(true)
to enable it.