Skip to main content

Context

Struct Context 

Source
pub struct Context<P, Data, Start, StateIndex, const MAX_REDUCE_RULES: usize>
where P: Parser<Term = <Data as SemanticValue>::Term, NonTerm = <Data as SemanticValue>::NonTerm, StateIndex = StateIndex>, Data: SemanticValue, Start: StartExtractor<Data>,
{ /* 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<P, Data, Start, StateIndex, const MAX_REDUCE_RULES: usize> Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>
where P: Parser<Term = <Data as SemanticValue>::Term, NonTerm = <Data as SemanticValue>::NonTerm, StateIndex = StateIndex>, Data: SemanticValue, Start: StartExtractor<Data>, StateIndex: Index,

Source

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

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

Source

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

Source

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

Borrow the user data for the first active path.

In GLR mode, each forked branch owns an independently cloned user data value.

Source

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

Borrow the user data for every active path.

In GLR mode, each forked branch owns an independently cloned user data value.

Source

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

Mutably borrow the user data for the first active path.

In GLR mode, each forked branch owns an independently cloned user data value.

Source

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

Mutably borrow the user data for every active path.

In GLR mode, each forked branch owns an independently cloned user data value.

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( self, ) -> Result<(<Start as StartExtractor<Data>>::StartType, <Data as SemanticValue>::UserData), ParseError<<Data as SemanticValue>::Term, <Data as SemanticValue>::Location, <Data as SemanticValue>::ReduceActionError>>
where Data: Clone, <Data as SemanticValue>::UserData: Clone, <P as Parser>::Term: Clone, <P as Parser>::NonTerm: Debug,

End this context and return the first successful start symbol and user data pair.

Source

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

End this context and return iterator of the start value and user data from each successful path.

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,

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

Source

pub fn expected_token_str<'a>( &self, ) -> (impl Iterator<Item = &'static str> + use<P, Data, Start, StateIndex, MAX_REDUCE_RULES>, impl Iterator<Item = &'static str> + use<P, Data, Start, StateIndex, MAX_REDUCE_RULES>)
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 SemanticValue>::Term, ) -> Result<(), ParseError<<Data as SemanticValue>::Term, <Data as SemanticValue>::Location, <Data as SemanticValue>::ReduceActionError>>
where <P as Parser>::Term: Clone, <P as Parser>::NonTerm: Debug, Data: Clone, <Data as SemanticValue>::UserData: Clone, <Data as SemanticValue>::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 SemanticValue>::Location, ) -> Result<(), ParseError<<Data as SemanticValue>::Term, <Data as SemanticValue>::Location, <Data as SemanticValue>::ReduceActionError>>
where <P as Parser>::Term: Clone, <P as Parser>::NonTerm: Debug, Data: Clone, <Data as SemanticValue>::UserData: Clone,

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

Source

pub fn can_feed(&self, term: &<P as Parser>::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.

Source

pub fn can_accept(&self) -> bool

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

Trait Implementations§

Source§

impl<P, Data, Start, StateIndex, const MAX_REDUCE_RULES: usize> Clone for Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>
where P: Parser<Term = <Data as SemanticValue>::Term, NonTerm = <Data as SemanticValue>::NonTerm, StateIndex = StateIndex>, Data: SemanticValue, Start: StartExtractor<Data>, StateIndex: Index, Node<Data, StateIndex>: Clone, <Data as SemanticValue>::UserData: Clone,

Source§

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

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, Start, StateIndex, const MAX_REDUCE_RULES: usize> Debug for Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>
where P: Parser<Term = <Data as SemanticValue>::Term, NonTerm = <Data as SemanticValue>::NonTerm, StateIndex = StateIndex>, Data: SemanticValue + Debug, Start: StartExtractor<Data>, StateIndex: Index, <Data as SemanticValue>::UserData: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<P, Data, Start, StateIndex, const MAX_REDUCE_RULES: usize> Default for Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>
where P: Parser<Term = <Data as SemanticValue>::Term, NonTerm = <Data as SemanticValue>::NonTerm, StateIndex = StateIndex>, Data: SemanticValue, Start: StartExtractor<Data>, StateIndex: Index, <Data as SemanticValue>::UserData: Default,

Source§

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

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

Auto Trait Implementations§

§

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

§

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

§

impl<P, Data, Start, StateIndex, const MAX_REDUCE_RULES: usize> Send for Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>
where <P as Parser>::Tables: Sync, P: Send, Start: Send, <Data as SemanticValue>::UserData: Send, <Data as SemanticValue>::ReduceActionError: Send, StateIndex: Send, Data: Send, <Data as SemanticValue>::Location: Send,

§

impl<P, Data, Start, StateIndex, const MAX_REDUCE_RULES: usize> Sync for Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>
where <P as Parser>::Tables: Sync, P: Sync, Start: Sync, <Data as SemanticValue>::UserData: Sync, <Data as SemanticValue>::ReduceActionError: Sync, StateIndex: Sync, Data: Sync, <Data as SemanticValue>::Location: Sync,

§

impl<P, Data, Start, StateIndex, const MAX_REDUCE_RULES: usize> Unpin for Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>
where P: Unpin, Start: Unpin, <Data as SemanticValue>::UserData: Unpin, <Data as SemanticValue>::ReduceActionError: Unpin, StateIndex: Unpin, Data: Unpin, <Data as SemanticValue>::Location: Unpin,

§

impl<P, Data, Start, StateIndex, const MAX_REDUCE_RULES: usize> UnsafeUnpin for Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>

§

impl<P, Data, Start, StateIndex, const MAX_REDUCE_RULES: usize> UnwindSafe for Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>

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.