pub struct LexerDef<StorageT> { /* fields omitted */ }
This struct represents, in essence, a .l file in memory. From it one can produce a Lexer
which actually lexes inputs.
Get the Rule
at index idx
.
Get the Rule
instance associated with a particular lexeme ID. Panics if no such rule
exists.
Get the Rule
instance associated with a particular name.
Set the id attribute on rules to the corresponding value in map
. This is typically used
to synchronise a parser's notion of lexeme IDs with the lexers. While doing this, it keeps
track of which lexemes:
- are defined in the lexer but not referenced by the parser
- and referenced by the parser but not defined in the lexer
and returns them as a tuple
(Option<HashSet<&str>>, Option<HashSet<&str>>)
in the order
(defined_in_lexer_missing_from_parser, referenced_in_parser_missing_from_lexer). Since
in most cases both sets are expected to be empty, None
is returned to avoid a HashSet
allocation.
Lexing and parsing can continue if either set is non-empty, so it is up to the caller as to
what action they take if either return set is non-empty. A non-empty set #1 is often
benign: some lexers deliberately define tokens which are not used (e.g. reserving future
keywords). A non-empty set #2 is more likely to be an error since there are parts of the
grammar where nothing the user can input will be parseable.
Returns an iterator over all rules in this AST.
Return a lexer for the String
s
that will lex relative to this LexerDef
.
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static