Struct cfgrammar::yacc::firsts::YaccFirsts
source · pub struct YaccFirsts<StorageT> { /* private fields */ }
Expand description
Firsts
stores all the first sets for a given grammar. For example, given this code and
grammar:
let grm = YaccGrammar::new(YaccKind::Original(YaccOriginalActionKind::GenericParseTree), "
S: A 'b';
A: 'a'
| ;").unwrap();
let firsts = Firsts::new(&grm);
then the following assertions (and only the following assertions) about the firsts set are correct:
assert!(firsts.is_set(grm.rule_idx("S").unwrap(), grm.token_idx("a").unwrap()));
assert!(firsts.is_set(grm.rule_idx("S").unwrap(), grm.token_idx("b").unwrap()));
assert!(firsts.is_set(grm.rule_idx("A").unwrap(), grm.token_idx("a").unwrap()));
assert!(firsts.is_epsilon_set(grm.rule_idx("A").unwrap()));
Implementations§
source§impl<StorageT: 'static + PrimInt + Unsigned> YaccFirsts<StorageT>where
usize: AsPrimitive<StorageT>,
impl<StorageT: 'static + PrimInt + Unsigned> YaccFirsts<StorageT>where
usize: AsPrimitive<StorageT>,
sourcepub fn new(grm: &YaccGrammar<StorageT>) -> Self
pub fn new(grm: &YaccGrammar<StorageT>) -> Self
Generates and returns the firsts set for the given grammar.
sourcepub fn is_set(&self, ridx: RIdx<StorageT>, tidx: TIdx<StorageT>) -> bool
pub fn is_set(&self, ridx: RIdx<StorageT>, tidx: TIdx<StorageT>) -> bool
Returns true if the token tidx
is in the first set for rule ridx
.
sourcepub fn is_epsilon_set(&self, ridx: RIdx<StorageT>) -> bool
pub fn is_epsilon_set(&self, ridx: RIdx<StorageT>) -> bool
Returns true if the rule ridx
has epsilon in its first set.
Trait Implementations§
Auto Trait Implementations§
impl<StorageT> Freeze for YaccFirsts<StorageT>
impl<StorageT> RefUnwindSafe for YaccFirsts<StorageT>where
StorageT: RefUnwindSafe,
impl<StorageT> Send for YaccFirsts<StorageT>where
StorageT: Send,
impl<StorageT> Sync for YaccFirsts<StorageT>where
StorageT: Sync,
impl<StorageT> Unpin for YaccFirsts<StorageT>where
StorageT: Unpin,
impl<StorageT> UnwindSafe for YaccFirsts<StorageT>where
StorageT: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more