[−][src]Struct cfgrammar::yacc::grammar::YaccGrammar
Representation of a YaccGrammar
. See the top-level documentation for the
guarantees this struct makes about rules, tokens, productions, and symbols.
Methods
impl YaccGrammar<u32>
[src]
impl<StorageT: 'static + PrimInt + Unsigned> YaccGrammar<StorageT> where
usize: AsPrimitive<StorageT>,
[src]
usize: AsPrimitive<StorageT>,
pub fn new_with_storaget(
yacc_kind: YaccKind,
s: &str
) -> Result<Self, YaccGrammarError>
[src]
yacc_kind: YaccKind,
s: &str
) -> Result<Self, YaccGrammarError>
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.
pub fn prods_len(&self) -> PIdx<StorageT>
[src]
How many productions does this grammar have?
pub fn iter_pidxs(&self) -> impl Iterator<Item = PIdx<StorageT>>
[src]
Return an iterator which produces (in order from 0..self.prods_len()
) all this
grammar's valid PIdx
s.
pub fn prod(&self, pidx: PIdx<StorageT>) -> &[Symbol<StorageT>]
[src]
Get the sequence of symbols for production pidx
. Panics if pidx
doesn't exist.
pub fn prod_len(&self, pidx: PIdx<StorageT>) -> SIdx<StorageT>
[src]
How many symbols does production pidx
have? Panics if pidx
doesn't exist.
pub fn prod_to_rule(&self, pidx: PIdx<StorageT>) -> RIdx<StorageT>
[src]
Return the rule index of the production pidx
. Panics if pidx
doesn't exist.
pub fn prod_precedence(&self, pidx: PIdx<StorageT>) -> Option<Precedence>
[src]
Return the precedence of production pidx
(where None
indicates "no precedence specified").
Panics if pidx
doesn't exist.
pub fn start_prod(&self) -> PIdx<StorageT>
[src]
Return the production index of the start rule's sole production (for Yacc grammars the start rule is defined to have precisely one production).
pub fn rules_len(&self) -> RIdx<StorageT>
[src]
How many rules does this grammar have?
pub fn iter_rules(&self) -> impl Iterator<Item = RIdx<StorageT>>
[src]
Return an iterator which produces (in order from 0..self.rules_len()
) all this
grammar's valid RIdx
s.
pub fn rule_to_prods(&self, ridx: RIdx<StorageT>) -> &[PIdx<StorageT>]
[src]
Return the productions for rule ridx
. Panics if ridx
doesn't exist.
pub fn rule_name(&self, ridx: RIdx<StorageT>) -> &str
[src]
Return the name of rule ridx
. Panics if ridx
doesn't exist.
pub fn implicit_rule(&self) -> Option<RIdx<StorageT>>
[src]
Return the RIdx
of the implict rule if it exists, or None
otherwise.
pub fn rule_idx(&self, n: &str) -> Option<RIdx<StorageT>>
[src]
Return the index of the rule named n
or None
if it doesn't exist.
pub fn start_rule_idx(&self) -> RIdx<StorageT>
[src]
What is the index of the start rule? Note that cfgrammar will have inserted at least one rule "above" the user's start rule.
pub fn tokens_len(&self) -> TIdx<StorageT>
[src]
How many tokens does this grammar have?
pub fn iter_tidxs(&self) -> impl Iterator<Item = TIdx<StorageT>>
[src]
Return an iterator which produces (in order from 0..self.tokens_len()
) all this
grammar's valid TIdx
s.
pub fn eof_token_idx(&self) -> TIdx<StorageT>
[src]
Return the index of the end token.
pub fn token_name(&self, tidx: TIdx<StorageT>) -> Option<&str>
[src]
Return the name of token tidx
(where None
indicates "the rule has no name"). Panics if
tidx
doesn't exist.
pub fn token_precedence(&self, tidx: TIdx<StorageT>) -> Option<Precedence>
[src]
Return the precedence of token tidx
(where None
indicates "no precedence specified").
Panics if tidx
doesn't exist.
pub fn token_epp(&self, tidx: TIdx<StorageT>) -> Option<&str>
[src]
Return the %epp entry for token tidx
(where None
indicates "the token has no
pretty-printed value"). Panics if tidx
doesn't exist.
pub fn action(&self, pidx: PIdx<StorageT>) -> &Option<String>
[src]
Get the action for production pidx
. Panics if pidx
doesn't exist.
pub fn actiontype(&self, ridx: RIdx<StorageT>) -> &Option<String>
[src]
pub fn programs(&self) -> &Option<String>
[src]
Get the programs part of the grammar
pub fn tokens_map(&self) -> HashMap<&str, TIdx<StorageT>>
[src]
Returns a map from names to TIdx
s of all tokens that a lexer will need to generate valid
inputs from this grammar.
pub fn token_idx(&self, n: &str) -> Option<TIdx<StorageT>>
[src]
Return the index of the token named n
or None
if it doesn't exist.
pub fn avoid_insert(&self, tidx: TIdx<StorageT>) -> bool
[src]
Is the token tidx
marked as %avoid_insert
?
pub fn has_path(&self, from: RIdx<StorageT>, to: RIdx<StorageT>) -> bool
[src]
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.
pub fn pp_prod(&self, pidx: PIdx<StorageT>) -> String
[src]
Returns the string representation of a given production pidx
.
pub fn sentence_generator<F>(
&self,
token_cost: F
) -> SentenceGenerator<StorageT> where
F: Fn(TIdx<StorageT>) -> u8,
[src]
&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
.
pub fn firsts(&self) -> YaccFirsts<StorageT>
[src]
Return a YaccFirsts
struct for this grammar.
pub fn follows(&self) -> YaccFollows<StorageT>
[src]
Return a YaccFirsts
struct for this grammar.
Auto Trait Implementations
impl<StorageT> RefUnwindSafe for YaccGrammar<StorageT> where
StorageT: RefUnwindSafe,
StorageT: RefUnwindSafe,
impl<StorageT> Send for YaccGrammar<StorageT> where
StorageT: Send,
StorageT: Send,
impl<StorageT> Sync for YaccGrammar<StorageT> where
StorageT: Sync,
StorageT: Sync,
impl<StorageT> Unpin for YaccGrammar<StorageT> where
StorageT: Unpin,
StorageT: Unpin,
impl<StorageT> UnwindSafe for YaccGrammar<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>,