[−][src]Struct lrlex::LexerDef
This struct represents, in essence, a .l file in memory. From it one can produce a Lexer
which actually lexes inputs.
Methods
impl<StorageT: Copy + Eq + Hash + PrimInt + Unsigned> LexerDef<StorageT>
[src]
pub fn new(rules: Vec<Rule<StorageT>>) -> LexerDef<StorageT>
[src]
pub fn get_rule(&self, idx: usize) -> Option<&Rule<StorageT>>
[src]
Get the Rule
at index idx
.
pub fn get_rule_by_id(&self, tok_id: StorageT) -> &Rule<StorageT>
[src]
Get the Rule
instance associated with a particular lexeme ID. Panics if no such rule
exists.
pub fn get_rule_by_name(&self, n: &str) -> Option<&Rule<StorageT>>
[src]
Get the Rule
instance associated with a particular name.
pub fn set_rule_ids<'a>(
&'a mut self,
rule_ids_map: &HashMap<&'a str, StorageT>
) -> (Option<HashSet<&'a str>>, Option<HashSet<&'a str>>)
[src]
&'a mut self,
rule_ids_map: &HashMap<&'a str, StorageT>
) -> (Option<HashSet<&'a str>>, Option<HashSet<&'a str>>)
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 aHashSet
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.
pub fn iter_rules(&self) -> Iter<Rule<StorageT>>
[src]
Returns an iterator over all rules in this AST.
pub fn lexer<'a>(&'a self, s: &'a str) -> impl Lexer<StorageT> + 'a
[src]
Return a lexer for the String
s
that will lex relative to this LexerDef
.
Auto Trait Implementations
impl<StorageT> !RefUnwindSafe for LexerDef<StorageT>
impl<StorageT> Send for LexerDef<StorageT> where
StorageT: Send,
StorageT: Send,
impl<StorageT> Sync for LexerDef<StorageT> where
StorageT: Sync,
StorageT: Sync,
impl<StorageT> Unpin for LexerDef<StorageT> where
StorageT: Unpin,
StorageT: Unpin,
impl<StorageT> UnwindSafe for LexerDef<StorageT> where
StorageT: UnwindSafe,
StorageT: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,