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,
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,
Sourcepub fn new(
userdata: <Data as SemanticValue>::UserData,
) -> Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>
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.
pub fn with_default_userdata() -> Context<P, Data, Start, StateIndex, MAX_REDUCE_RULES>
Sourcepub fn userdata(&self) -> &<Data as SemanticValue>::UserData
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.
Sourcepub fn userdata_all(
&self,
) -> impl Iterator<Item = &<Data as SemanticValue>::UserData>
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.
Sourcepub fn userdata_mut(&mut self) -> &mut <Data as SemanticValue>::UserData
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.
Sourcepub fn userdata_all_mut(
&mut self,
) -> impl Iterator<Item = &mut <Data as SemanticValue>::UserData>
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.
pub fn node(&self, node: usize) -> &Node<Data, StateIndex>
pub fn node_mut(&mut self, node: usize) -> &mut Node<Data, StateIndex>
Sourcepub fn debug_check(&self)
pub fn debug_check(&self)
for debugging; checks for memory leak, not freed nodes, etc.
Sourcepub fn states(&self) -> impl Iterator<Item = usize>
pub fn states(&self) -> impl Iterator<Item = usize>
Get current states in every diverged paths.
Sourcepub fn state_stacks(&self) -> impl Iterator<Item = impl Iterator<Item = usize>>
pub fn state_stacks(&self) -> impl Iterator<Item = impl Iterator<Item = usize>>
Get iterators of state stacks in all diverged paths.
Sourcepub 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>>
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>>
End this context and return the first successful start symbol and user data pair.
Sourcepub 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>>
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>>
End this context and return iterator of the start value and user data from each successful path.
Sourcepub fn expected_token(
&self,
) -> (BTreeSet<<P as Parser>::TermClass>, BTreeSet<<P as Parser>::NonTerm>)
pub fn expected_token( &self, ) -> (BTreeSet<<P as Parser>::TermClass>, BTreeSet<<P as Parser>::NonTerm>)
Get next expected (terminals, non-terminals) for current context.
Sourcepub 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>)
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>)
Same as expected_token(), but returns as printable type.
Sourcepub fn feed(
&mut self,
term: <Data as SemanticValue>::Term,
) -> Result<(), ParseError<<Data as SemanticValue>::Term, <Data as SemanticValue>::Location, <Data as SemanticValue>::ReduceActionError>>
pub fn feed( &mut self, term: <Data as SemanticValue>::Term, ) -> Result<(), ParseError<<Data as SemanticValue>::Term, <Data as SemanticValue>::Location, <Data as SemanticValue>::ReduceActionError>>
Feed one terminal to parser, and update stacks.
This will use Default::default() for location.
Sourcepub 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>>
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>>
Feed one terminal with location to parser, and update state stack.
Sourcepub fn can_feed(&self, term: &<P as Parser>::Term) -> bool
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.
Sourcepub fn can_accept(&self) -> bool
pub fn can_accept(&self) -> bool
Check if current context can be terminated and get the start value.