Skip to main content

Context

Struct Context 

Source
pub struct Context<P, Data, StateIndex>
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm, StateIndex = StateIndex>, Data: DataStack,
{ pub state_stack: Vec<StateIndex>, /* private fields */ }
Expand description

A struct that maintains the current state and the values associated with each symbol.

Fields§

§state_stack: Vec<StateIndex>

stacks hold the values associated with each shifted symbol.

Implementations§

Source§

impl<P, Data, StateIndex> Context<P, Data, StateIndex>
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm, StateIndex = StateIndex>, Data: DataStack, StateIndex: Index + Copy,

Source

pub fn new( userdata: <Data as DataStack>::UserData, ) -> Context<P, Data, StateIndex>

Create a new context. state_stack is initialized with [0] (root state).

Source

pub fn with_default_userdata() -> Context<P, Data, StateIndex>
where <Data as DataStack>::UserData: Default,

Create a new context using Default::default() as user data.

Source

pub fn with_capacity( capacity: usize, userdata: <Data as DataStack>::UserData, ) -> Context<P, Data, StateIndex>

Create a new context with given capacity of state_stack and data_stack. state_stack is initialized with [0] (root state).

Source

pub fn with_capacity_and_default_userdata( capacity: usize, ) -> Context<P, Data, StateIndex>
where <Data as DataStack>::UserData: Default,

Create a new context with capacity using Default::default() as user data.

Source

pub fn userdata(&self) -> &<Data as DataStack>::UserData

Borrow the user data owned by this context.

Source

pub fn userdata_all( &self, ) -> impl Iterator<Item = &<Data as DataStack>::UserData>

Borrow the user data owned by this context as an iterator.

Source

pub fn userdata_mut(&mut self) -> &mut <Data as DataStack>::UserData

Mutably borrow the user data owned by this context.

Source

pub fn userdata_all_mut( &mut self, ) -> impl Iterator<Item = &mut <Data as DataStack>::UserData>

Mutably borrow the user data owned by this context as an iterator.

Source

pub fn accept( self, ) -> Result<(<Data as DataStack>::StartType, <Data as DataStack>::UserData), ParseError<<Data as DataStack>::Term, <Data as DataStack>::Location, <Data as DataStack>::ReduceActionError>>
where <Data as DataStack>::Term: Clone, <Data as DataStack>::NonTerm: Debug,

End this context and pop the value of the start symbol from the data stack.

Source

pub fn accept_all( self, ) -> Result<impl Iterator<Item = (<Data as DataStack>::StartType, <Data as DataStack>::UserData)>, ParseError<<Data as DataStack>::Term, <Data as DataStack>::Location, <Data as DataStack>::ReduceActionError>>
where <Data as DataStack>::Term: Clone, <Data as DataStack>::NonTerm: Debug,

End this context and return an iterator with the start symbol and final user data.

Source

pub fn can_accept(&self) -> bool

Source

pub fn state(&self) -> usize

Get current state index

Source

pub fn state_stack(&self) -> impl Iterator<Item = usize>

Get iterator of state stack

Source

pub fn expected_token( &self, ) -> (BTreeSet<<P as Parser>::TermClass>, BTreeSet<<P as Parser>::NonTerm>)
where <P as Parser>::TermClass: Ord, <P as Parser>::NonTerm: Ord,

Simulate parser and get next expected (terminals, non-terminals) for current context.

Source

pub fn expected_token_str<'a>( &self, ) -> (impl Iterator<Item = &'static str>, impl Iterator<Item = &'static str>)
where <P as Parser>::TermClass: Ord, <P as Parser>::NonTerm: Ord,

Same as expected_token(), but returns as printable type.

Source

pub fn feed( &mut self, term: <Data as DataStack>::Term, ) -> Result<(), ParseError<<Data as DataStack>::Term, <Data as DataStack>::Location, <Data as DataStack>::ReduceActionError>>
where <P as Parser>::Term: Clone, <P as Parser>::NonTerm: Debug, <Data as DataStack>::Location: Default,

Feed one terminal to parser, and update stacks. This will use Default::default() for location.

Source

pub fn feed_location( &mut self, term: <P as Parser>::Term, location: <Data as DataStack>::Location, ) -> Result<(), ParseError<<Data as DataStack>::Term, <Data as DataStack>::Location, <Data as DataStack>::ReduceActionError>>
where <P as Parser>::Term: Clone, <P as Parser>::NonTerm: Debug,

Feed one terminal with location to parser, and update stacks.

Source

pub fn can_feed(&self, term: &<Data as DataStack>::Term) -> bool

Check if term can be feeded to current state. This does not simulate for reduce action error, or panic mode. So this function will return false even if term can be shifted as error token, and will return true if Err variant is returned by reduce_action.

Source

pub fn can_panic(&self) -> bool

Check if current context can enter panic mode

Trait Implementations§

Source§

impl<P, Data, StateIndex> Clone for Context<P, Data, StateIndex>
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm, StateIndex = StateIndex>, Data: DataStack + Clone, StateIndex: Index + Copy, <Data as DataStack>::Term: Clone, <Data as DataStack>::NonTerm: Clone, <Data as DataStack>::UserData: Clone,

Source§

fn clone(&self) -> Context<P, Data, StateIndex>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P, Data, StateIndex> Default for Context<P, Data, StateIndex>
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm, StateIndex = StateIndex>, Data: DataStack, StateIndex: Index + Copy, <Data as DataStack>::UserData: Default,

Source§

fn default() -> Context<P, Data, StateIndex>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<P, Data, StateIndex> Freeze for Context<P, Data, StateIndex>
where Data: Freeze, <Data as DataStack>::UserData: Freeze,

§

impl<P, Data, StateIndex> RefUnwindSafe for Context<P, Data, StateIndex>

§

impl<P, Data, StateIndex> Send for Context<P, Data, StateIndex>
where Data: Send, <Data as DataStack>::UserData: Send, <P as Parser>::Tables: Sync, P: Send, StateIndex: Send, <Data as DataStack>::Location: Send,

§

impl<P, Data, StateIndex> Sync for Context<P, Data, StateIndex>
where Data: Sync, <Data as DataStack>::UserData: Sync, <P as Parser>::Tables: Sync, P: Sync, StateIndex: Sync, <Data as DataStack>::Location: Sync,

§

impl<P, Data, StateIndex> Unpin for Context<P, Data, StateIndex>
where Data: Unpin, <Data as DataStack>::UserData: Unpin, P: Unpin, StateIndex: Unpin, <Data as DataStack>::Location: Unpin,

§

impl<P, Data, StateIndex> UnsafeUnpin for Context<P, Data, StateIndex>
where Data: UnsafeUnpin, <Data as DataStack>::UserData: UnsafeUnpin,

§

impl<P, Data, StateIndex> UnwindSafe for Context<P, Data, StateIndex>
where Data: UnwindSafe, <Data as DataStack>::UserData: UnwindSafe, <P as Parser>::Tables: RefUnwindSafe, P: UnwindSafe, StateIndex: UnwindSafe, <Data as DataStack>::Location: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.