[][src]Struct lrlex::LexerDef

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.

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]

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:

  1. are defined in the lexer but not referenced by the parser
  2. 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.

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

impl<StorageT> Sync for LexerDef<StorageT> where
    StorageT: Sync

impl<StorageT> Unpin for LexerDef<StorageT> where
    StorageT: Unpin

impl<StorageT> UnwindSafe for LexerDef<StorageT> where
    StorageT: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Err = <U as TryFrom<T>>::Err