pub struct YaccGrammar<StorageT = u32> { /* fields omitted */ }
Representation of a YaccGrammar
. See the top-level documentation for the
guarantees this struct makes about rules, tokens, productions, and symbols.
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.
How many productions does this grammar have?
Return an iterator which produces (in order from 0..self.prods_len()
) all this
grammar's valid PIdx
s.
Get the sequence of symbols for production pidx
. Panics if pidx
doesn't exist.
How many symbols does production pidx
have? Panics if pidx
doesn't exist.
Return the rule index of the production pidx
. Panics if pidx
doesn't exist.
Return the precedence of production pidx
(where None
indicates "no precedence specified").
Panics if pidx
doesn't exist.
Return the production index of the start rule's sole production (for Yacc grammars the
start rule is defined to have precisely one production).
How many rules does this grammar have?
Return an iterator which produces (in order from 0..self.rules_len()
) all this
grammar's valid RIdx
s.
Return the productions for rule ridx
. Panics if ridx
doesn't exist.
Return the name of rule ridx
. Panics if ridx
doesn't exist.
Return the RIdx
of the implict rule if it exists, or None
otherwise.
Return the index of the rule named n
or None
if it doesn't exist.
What is the index of the start rule? Note that cfgrammar will have inserted at least one
rule "above" the user's start rule.
How many tokens does this grammar have?
Return an iterator which produces (in order from 0..self.tokens_len()
) all this
grammar's valid TIdx
s.
Return the index of the end token.
Return the name of token tidx
(where None
indicates "the rule has no name"). Panics if
tidx
doesn't exist.
Return the precedence of token tidx
(where None
indicates "no precedence specified").
Panics if tidx
doesn't exist.
Return the %epp entry for token tidx
(where None
indicates "the token has no
pretty-printed value"). Panics if tidx
doesn't exist.
Get the action for production pidx
. Panics if pidx
doesn't exist.
Get the programs part of the grammar
Returns a map from names to TIdx
s of all tokens that a lexer will need to generate valid
inputs from this grammar.
Return the index of the token named n
or None
if it doesn't exist.
Is the token tidx
marked as %avoid_insert
?
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.
Returns the string representation of a given production pidx
.
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
.
Return a YaccFirsts
struct for this grammar.
Return a YaccFirsts
struct for this grammar.
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more