rusty_lr_core 3.39.1

core library for rusty_lr
Documentation
/// A struct to hold information about non-terminal symbols
pub trait NonTerminal: Copy {
    /// Whether this non-terminal is auto-generated by rustylr.
    /// Some non-terminals could be auto-generated to handle regex patterns, character sets, etc.
    fn is_auto_generated(&self) -> bool {
        self.nonterm_type().is_some()
    }
    /// Augmented rule will be generated for entry point of the grammar.
    fn is_augmented(&self) -> bool {
        self.nonterm_type() == Some(NonTerminalType::Augmented)
    }
    /// whether this non-terminal is set as %trace
    fn is_trace(&self) -> bool;

    /// for internal use only;
    /// If this non-terminal is auto-generated, gets the pattern where this non-terminal was generated from.
    fn nonterm_type(&self) -> Option<NonTerminalType>;

    /// Gets the pretty name of this non-terminal.
    fn as_str(&self) -> &'static str;

    /// converts this non-terminal to a usize
    fn to_usize(&self) -> usize;
}

/// If the non-terminal is auto-generated,
/// the pattern where this non-terminal was generated from.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NonTerminalType {
    /// zero or more repetitions
    Star,
    /// one or more repetitions with left recursion
    PlusLeft,
    /// one or more repetitions with right recursion
    PlusRight,
    /// zero or one repetition
    Optional,
    /// Augmented rule
    Augmented,
    /// error recovery non-terminal
    Error,

    /// terminal set enclosed in brackets ( [a-zA-Z0-9] )
    TerminalSet,
    /// rule with explicit lookaheads
    Lookahead,

    /// sequence of tokens enclosed in parentheses ( a B c ... )
    Group,

    /// "abc" or b"abc"
    LiteralString,
}