Struct cfgrammar::yacc::grammar::YaccGrammar

source ·
pub struct YaccGrammar<StorageT = u32> { /* private fields */ }
Expand description

Representation of a YaccGrammar. See the top-level documentation for the guarantees this struct makes about rules, tokens, productions, and symbols.

Implementations§

source§

impl YaccGrammar<u32>

source

pub fn new(yacc_kind: YaccKind, s: &str) -> YaccGrammarResult<Self>

source§

impl<StorageT: 'static + PrimInt + Unsigned> YaccGrammar<StorageT>
where usize: AsPrimitive<StorageT>,

source

pub fn new_with_storaget( yacc_kind: YaccKind, s: &str, ) -> YaccGrammarResult<Self>

Takes as input a Yacc grammar of YaccKind as a String s and returns a YaccGrammar (or (YaccGrammarError on error).

As we’re compiling the YaccGrammar, we add a new start rule (which we’ll refer to as ^, though the actual name is a fresh name that is guaranteed to be unique) that references the user defined start rule.

source

pub fn new_from_ast_with_validity_info( yacc_kind: YaccKind, ast_validation: &ASTWithValidityInfo, ) -> YaccGrammarResult<Self>

source

pub fn prods_len(&self) -> PIdx<StorageT>

How many productions does this grammar have?

source

pub fn iter_pidxs(&self) -> impl Iterator<Item = PIdx<StorageT>>

Return an iterator which produces (in order from 0..self.prods_len()) all this grammar’s valid PIdxs.

source

pub fn prod(&self, pidx: PIdx<StorageT>) -> &[Symbol<StorageT>]

Get the sequence of symbols for production pidx. Panics if pidx doesn’t exist.

source

pub fn prod_len(&self, pidx: PIdx<StorageT>) -> SIdx<StorageT>

How many symbols does production pidx have? Panics if pidx doesn’t exist.

source

pub fn prod_to_rule(&self, pidx: PIdx<StorageT>) -> RIdx<StorageT>

Return the rule index of the production pidx. Panics if pidx doesn’t exist.

source

pub fn prod_precedence(&self, pidx: PIdx<StorageT>) -> Option<Precedence>

Return the precedence of production pidx (where None indicates “no precedence specified”). Panics if pidx doesn’t exist.

source

pub fn start_prod(&self) -> PIdx<StorageT>

Return the production index of the start rule’s sole production (for Yacc grammars the start rule is defined to have precisely one production).

source

pub fn rules_len(&self) -> RIdx<StorageT>

How many rules does this grammar have?

source

pub fn iter_rules(&self) -> impl Iterator<Item = RIdx<StorageT>>

Return an iterator which produces (in order from 0..self.rules_len()) all this grammar’s valid RIdxs.

source

pub fn rule_to_prods(&self, ridx: RIdx<StorageT>) -> &[PIdx<StorageT>]

Return the productions for rule ridx. Panics if ridx doesn’t exist.

source

pub fn rule_name(&self, ridx: RIdx<StorageT>) -> &str

👎Deprecated since 0.13.0: Please use rule_name_str instead

Return the name of rule ridx. Panics if ridx doesn’t exist.

source

pub fn rule_name_str(&self, ridx: RIdx<StorageT>) -> &str

Return the name of rule ridx. Panics if ridx doesn’t exist.

source

pub fn rule_name_span(&self, ridx: RIdx<StorageT>) -> Span

Return the span of rule ridx. Panics if ridx doesn’t exist.

source

pub fn implicit_rule(&self) -> Option<RIdx<StorageT>>

Return the RIdx of the implict rule if it exists, or None otherwise.

source

pub fn rule_idx(&self, n: &str) -> Option<RIdx<StorageT>>

Return the index of the rule named n or None if it doesn’t exist.

source

pub fn start_rule_idx(&self) -> RIdx<StorageT>

What is the index of the start rule? Note that cfgrammar will have inserted at least one rule “above” the user’s start rule.

source

pub fn tokens_len(&self) -> TIdx<StorageT>

How many tokens does this grammar have?

source

pub fn iter_tidxs(&self) -> impl Iterator<Item = TIdx<StorageT>>

Return an iterator which produces (in order from 0..self.tokens_len()) all this grammar’s valid TIdxs.

source

pub fn eof_token_idx(&self) -> TIdx<StorageT>

Return the index of the end token.

source

pub fn token_name(&self, tidx: TIdx<StorageT>) -> Option<&str>

Return the name of token tidx (where None indicates “the rule has no name”). Panics if tidx doesn’t exist.

source

pub fn token_precedence(&self, tidx: TIdx<StorageT>) -> Option<Precedence>

Return the precedence of token tidx (where None indicates “no precedence specified”). Panics if tidx doesn’t exist.

source

pub fn token_epp(&self, tidx: TIdx<StorageT>) -> Option<&str>

Return the %epp entry for token tidx (where None indicates “the token has no pretty-printed value”). Panics if tidx doesn’t exist.

source

pub fn token_span(&self, tidx: TIdx<StorageT>) -> Option<Span>

Return the span for token given by tidx if one exists. If None, the token is either implicit and not derived from a token in the source, otherwise the YaccGrammar itself may not derived from a textual source in which case the token may be explicit but still lack spans from its construction.

source

pub fn action(&self, pidx: PIdx<StorageT>) -> &Option<String>

Get the action for production pidx. Panics if pidx doesn’t exist.

source

pub fn actiontype(&self, ridx: RIdx<StorageT>) -> &Option<String>

source

pub fn parse_param(&self) -> &Option<(String, String)>

source

pub fn programs(&self) -> &Option<String>

Get the programs part of the grammar

source

pub fn tokens_map(&self) -> HashMap<&str, TIdx<StorageT>>

Returns a map from names to TIdxs of all tokens that a lexer will need to generate valid inputs from this grammar.

source

pub fn token_idx(&self, n: &str) -> Option<TIdx<StorageT>>

Return the index of the token named n or None if it doesn’t exist.

source

pub fn avoid_insert(&self, tidx: TIdx<StorageT>) -> bool

Is the token tidx marked as %avoid_insert?

source

pub fn expect(&self) -> Option<usize>

source

pub fn expectrr(&self) -> Option<usize>

source

pub fn has_path(&self, from: RIdx<StorageT>, to: RIdx<StorageT>) -> bool

Is there a path from the from rule to the to rule? Note that recursive rules return true for a path from themselves to themselves.

source

pub fn pp_prod(&self, pidx: PIdx<StorageT>) -> String

Returns the string representation of a given production pidx.

source

pub fn sentence_generator<F>( &self, token_cost: F, ) -> SentenceGenerator<'_, StorageT>
where F: Fn(TIdx<StorageT>) -> u8,

Return a SentenceGenerator which can then generate minimal sentences for any rule based on the user-defined token_cost function which gives the associated cost for generating each token (where the cost must be greater than 0). Note that multiple tokens can have the same score. The simplest cost function is thus |_| 1.

source

pub fn firsts(&self) -> YaccFirsts<StorageT>

Return a YaccFirsts struct for this grammar.

source

pub fn follows(&self) -> YaccFollows<StorageT>

Return a YaccFirsts struct for this grammar.

Trait Implementations§

source§

impl<'de, StorageT> Deserialize<'de> for YaccGrammar<StorageT>
where StorageT: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<StorageT> Serialize for YaccGrammar<StorageT>
where StorageT: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<StorageT> Freeze for YaccGrammar<StorageT>
where StorageT: Freeze,

§

impl<StorageT> RefUnwindSafe for YaccGrammar<StorageT>
where StorageT: RefUnwindSafe,

§

impl<StorageT> Send for YaccGrammar<StorageT>
where StorageT: Send,

§

impl<StorageT> Sync for YaccGrammar<StorageT>
where StorageT: Sync,

§

impl<StorageT> Unpin for YaccGrammar<StorageT>
where StorageT: Unpin,

§

impl<StorageT> UnwindSafe for YaccGrammar<StorageT>
where StorageT: UnwindSafe,

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, 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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,