Struct Grammar

Source
pub struct Grammar {
    pub imports: Vec<ImportStm>,
    pub productions: ProdVec<Production>,
    pub terminals: TermVec<Terminal>,
    pub nonterminals: NonTermVec<NonTerminal>,
    pub nonterm_by_name: BTreeMap<String, SymbolIndex>,
    pub term_by_name: BTreeMap<String, SymbolIndex>,
    pub empty_index: SymbolIndex,
    pub stop_index: SymbolIndex,
    pub augmented_index: SymbolIndex,
    pub augmented_layout_index: Option<SymbolIndex>,
    pub start_index: SymbolIndex,
}

Fields§

§imports: Vec<ImportStm>§productions: ProdVec<Production>§terminals: TermVec<Terminal>§nonterminals: NonTermVec<NonTerminal>§nonterm_by_name: BTreeMap<String, SymbolIndex>§term_by_name: BTreeMap<String, SymbolIndex>§empty_index: SymbolIndex

Index of EMPTY symbol

§stop_index: SymbolIndex

Index of STOP symbol

§augmented_index: SymbolIndex

Index of grammar augmented symbol

§augmented_layout_index: Option<SymbolIndex>

Index of augmented symbol for Layout rule if given

§start_index: SymbolIndex

An index of the start symbol. First non-terminal or terminal of the grammar.

Implementations§

Source§

impl Grammar

Source

pub fn symbol_index(&self, name: &str) -> SymbolIndex

Source

pub fn symbol_name(&self, index: SymbolIndex) -> String

Source

pub fn symbol_has_content(&self, symbol: SymbolIndex) -> bool

If this symbol is either a non-terminal of a terminal with a content. I.e. not a constant match terminal (keyword, punctuation…)

Source

pub fn symbol_indexes(&self, names: &[&str]) -> SymbolVec<SymbolIndex>

Source

pub fn symbol_names<T>(&self, indexes: T) -> Vec<String>
where T: IntoIterator<Item = SymbolIndex>,

Source

pub fn term_to_symbol_index(&self, index: TermIndex) -> SymbolIndex

Source

pub fn symbol_to_term_index(&self, index: SymbolIndex) -> TermIndex

Convert symbol index to terminal index.

Source

pub fn symbol_to_term(&self, index: SymbolIndex) -> &Terminal

Convert symbol index to terminal

Source

pub fn term_by_name(&self, name: &str) -> &Terminal

Get Terminal by name.

Source

pub fn term_by_index(&self, index: TermIndex) -> &Terminal

Get Terminal by index.

Source

pub fn nonterm_to_symbol_index(&self, index: NonTermIndex) -> SymbolIndex

Source

pub fn symbol_to_nonterm_index(&self, index: SymbolIndex) -> NonTermIndex

Convert symbol index to non-terminal index. Panics if symbol index is a terminal index.

Source

pub fn symbol_to_nonterm(&self, index: SymbolIndex) -> &NonTerminal

Convert symbol index to non-terminal. Panics if symbol index is a terminal index.

Source

pub fn nonterm_by_name(&self, name: &str) -> &NonTerminal

Get NonTerminal by name.

Source

pub fn nonterm_by_index(&self, index: NonTermIndex) -> &NonTerminal

Get NonTerminal by index.

Source

pub fn is_nonterm(&self, index: SymbolIndex) -> bool

Source

pub fn is_term(&self, index: SymbolIndex) -> bool

Source

pub fn is_empty(&self, index: SymbolIndex) -> bool

Source

pub fn production_len(&self, prod: ProdIndex) -> usize

Source

pub fn production_rhs_symbols(&self, prod: ProdIndex) -> Vec<SymbolIndex>

Source

pub fn productions(&self) -> Vec<&Production>

Returns all productions except special AUG and AUGL.

Source

pub fn nonterminals(&self) -> Vec<&NonTerminal>

Returns all nonterminals except special EMPTY, AUG and AUGL.

Source

pub fn is_enum(&self, nonterminal: &NonTerminal) -> bool

Source

pub fn has_layout(&self) -> bool

Trait Implementations§

Source§

impl Debug for Grammar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Grammar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for Grammar

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.