cfgrammar::yacc::firsts

Struct 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>,

source

pub fn new(grm: &YaccGrammar<StorageT>) -> Self

Generates and returns the firsts set for the given grammar.

source

pub fn firsts(&self, ridx: RIdx<StorageT>) -> &Vob

Return all the firsts for rule ridx.

source

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.

source

pub fn is_epsilon_set(&self, ridx: RIdx<StorageT>) -> bool

Returns true if the rule ridx has epsilon in its first set.

source

pub fn set(&mut self, ridx: RIdx<StorageT>, tidx: TIdx<StorageT>) -> bool

Ensures that the firsts bit for token tidx rule ridx is set. Returns true if it was already set, or false otherwise.

Trait Implementations§

source§

impl<StorageT: Debug> Debug for YaccFirsts<StorageT>

source§

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

Formats the value using the given formatter. Read more

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> 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.