Action code
Action code is normal Rust code with the addition of the following special variables:
-
$1...$nrefer to the respective symbol in the production, numbered from 1 (i.e.$1refers to the first symbol in the production). If the symbol references a ruleRthen an instance ofR's type will be stored in the$ivariable; if the symbol references a lexeme then anOption<Lexeme>instance is returned. -
$lexerallows access to the lexer and its various functions. The most commonly used of these is thelexeme_strfunction, which allows us to turnLexemes into&strs representing the corresponding portion of the user's input. -
$spanis 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.