Context

Struct Context 

Source
pub struct Context<Data, StateIndex, const MAX_REDUCE_RULES: usize>
where Data: DataStack,
{ /* private fields */ }
Expand description

A struct that maintains the current state and the values associated with each symbol. This handles the divergence and merging of the parser.

Implementations§

Source§

impl<Data, StateIndex, const MAX_REDUCE_RULES: usize> Context<Data, StateIndex, MAX_REDUCE_RULES>
where Data: DataStack, StateIndex: Index,

Source

pub fn new() -> Context<Data, StateIndex, MAX_REDUCE_RULES>

Create a new context. current_nodes is initialized with a root node.

Source

pub fn node(&self, node: usize) -> &Node<Data, StateIndex>

Source

pub fn node_mut(&mut self, node: usize) -> &mut Node<Data, StateIndex>

Source

pub fn debug_check(&self)

for debugging; checks for memory leak, not freed nodes, etc.

Source

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

Get current states in every diverged paths.

Source

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

Get iterators of state stacks in all diverged paths.

Source

pub fn len_paths(&self) -> usize

Get number of diverged paths

Source

pub fn is_empty(&self) -> bool

Is there any path alive?

Source

pub fn accept<P>( self, parser: &P, userdata: &mut <Data as DataStack>::UserData, ) -> Result<impl Iterator<Item = <Data as DataStack>::StartType>, ParseError<<Data as DataStack>::Term, <Data as DataStack>::Location, <Data as DataStack>::ReduceActionError>>
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm>, Data: Clone, <P as Parser>::Term: Clone, <P as Parser>::NonTerm: Debug, <P as Parser>::State: State<StateIndex = StateIndex>,

End this context and return iterator of the start value from the data stack.

Source

pub fn trace<P>( &self, parser: &P, ) -> HashSet<<Data as DataStack>::NonTerm, FxBuildHasher>
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm>, <Data as DataStack>::NonTerm: Copy + Eq + Hash + NonTerminal,

Get set of %trace non-terminal symbols that current context is trying to parse.

The order of the returned set does not mean anything. If the current context is attempting to recognize following grammar:

Chunk -> Statement -> IfStatement -> ReturnStatement -> …

Then the returned set will be: [Chunk, Statement, IfStatement, ReturnStatement]

Source

pub fn backtraces<'a, P>( &'a self, parser: &'a P, ) -> impl Iterator<Item = Backtrace<<P as Parser>::TermClass, <P as Parser>::NonTerm>> + 'a
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm>, <Data as DataStack>::Term: Clone, <Data as DataStack>::NonTerm: Hash + Eq,

Get backtrace infos for all paths.

Source

pub fn expected_token<P>( &self, parser: &P, ) -> (BTreeSet<<P as Parser>::TermClass>, BTreeSet<<P as Parser>::NonTerm>)
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm>, <P as Parser>::TermClass: Ord, <P as Parser>::NonTerm: Ord, <P as Parser>::State: State<StateIndex = StateIndex>,

Get next expected (terminals, non-terminals) for current context.

Source

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

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

Source

pub fn feed<P>( &mut self, parser: &P, term: <Data as DataStack>::Term, userdata: &mut <Data as DataStack>::UserData, ) -> Result<(), ParseError<<Data as DataStack>::Term, <Data as DataStack>::Location, <Data as DataStack>::ReduceActionError>>
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm>, <P as Parser>::Term: Clone, <P as Parser>::NonTerm: Debug, <P as Parser>::State: State<StateIndex = StateIndex>, Data: Clone, <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<P>( &mut self, parser: &P, term: <P as Parser>::Term, userdata: &mut <Data as DataStack>::UserData, location: <Data as DataStack>::Location, ) -> Result<(), ParseError<<Data as DataStack>::Term, <Data as DataStack>::Location, <Data as DataStack>::ReduceActionError>>
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm>, <P as Parser>::Term: Clone, <P as Parser>::NonTerm: Debug, <P as Parser>::State: State<StateIndex = StateIndex>, Data: Clone,

Feed one terminal with location to parser, and update state stack.

Source

pub fn can_feed<P>(&self, parser: &P, term: &<P as Parser>::Term) -> bool
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm>, <P as Parser>::State: State<StateIndex = StateIndex>,

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<P>(&self, parser: &P) -> bool
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm>, <P as Parser>::State: State<StateIndex = StateIndex>,

Check if current context can enter panic mode.

Source

pub fn can_accept<P>(&self, parser: &P) -> bool
where P: Parser<Term = <Data as DataStack>::Term, NonTerm = <Data as DataStack>::NonTerm>, <P as Parser>::State: State<StateIndex = StateIndex>,

Check if current context can be terminated and get the start value.

Trait Implementations§

Source§

impl<Data, StateIndex, const MAX_REDUCE_RULES: usize> Clone for Context<Data, StateIndex, MAX_REDUCE_RULES>
where Data: DataStack, StateIndex: Index, Node<Data, StateIndex>: Clone,

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Data, StateIndex, const MAX_REDUCE_RULES: usize> Default for Context<Data, StateIndex, MAX_REDUCE_RULES>
where Data: DataStack, StateIndex: Index,

Source§

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

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

Auto Trait Implementations§

§

impl<Data, StateIndex, const MAX_REDUCE_RULES: usize> Freeze for Context<Data, StateIndex, MAX_REDUCE_RULES>

§

impl<Data, StateIndex, const MAX_REDUCE_RULES: usize> RefUnwindSafe for Context<Data, StateIndex, MAX_REDUCE_RULES>

§

impl<Data, StateIndex, const MAX_REDUCE_RULES: usize> Send for Context<Data, StateIndex, MAX_REDUCE_RULES>
where <Data as DataStack>::ReduceActionError: Send, Data: Send, StateIndex: Send, <Data as DataStack>::Location: Send,

§

impl<Data, StateIndex, const MAX_REDUCE_RULES: usize> Sync for Context<Data, StateIndex, MAX_REDUCE_RULES>
where <Data as DataStack>::ReduceActionError: Sync, Data: Sync, StateIndex: Sync, <Data as DataStack>::Location: Sync,

§

impl<Data, StateIndex, const MAX_REDUCE_RULES: usize> Unpin for Context<Data, StateIndex, MAX_REDUCE_RULES>
where <Data as DataStack>::ReduceActionError: Unpin, Data: Unpin, StateIndex: Unpin, <Data as DataStack>::Location: Unpin,

§

impl<Data, StateIndex, const MAX_REDUCE_RULES: usize> UnwindSafe for Context<Data, StateIndex, MAX_REDUCE_RULES>
where <Data as DataStack>::ReduceActionError: UnwindSafe, Data: 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.