pub struct ShiftReduceParser<K, T> { /* private fields */ }Expand description
The empty shift rule simply fails immediately with an error. The intention is that, starting from this rule, we can build up a complete shift rule.
Implementations§
Source§impl<K, T> ShiftReduceParser<K, T>
impl<K, T> ShiftReduceParser<K, T>
Trait Implementations§
Source§impl<K: PartialEq, T> ShiftReduceRule for ShiftReduceParser<K, T>
impl<K: PartialEq, T> ShiftReduceRule for ShiftReduceParser<K, T>
Source§fn shift(
&mut self,
_token: Token<K>,
_stack: &mut Vec<T>,
) -> Result<Option<T>, ()>
fn shift( &mut self, _token: Token<K>, _stack: &mut Vec<T>, ) -> Result<Option<T>, ()>
A shift rule reads the next token and decides what to do. For
example, it can return a completed term or it can begin a new
term.
Source§fn reduce(&self, _parent: T, _child: T) -> Result<T, ()>
fn reduce(&self, _parent: T, _child: T) -> Result<T, ()>
A _reduction rule combines a sub-term into its enclosing term.
For example, when parsing arithmetic expressions we might reduce
1 + 2*x with y to form 1 + 2*x + y.Source§fn apply<F: Fn(Self::Term, Self::Term) -> Result<Self::Term, ()>>(
self,
rule: F,
) -> ShiftApplyRule<Self::Kind, F, Self>
fn apply<F: Fn(Self::Term, Self::Term) -> Result<Self::Term, ()>>( self, rule: F, ) -> ShiftApplyRule<Self::Kind, F, Self>
Apply a given reduction as necessary when reducing terms.
fn first(self, term: Self::Term) -> ShiftFirstRule<Self::Kind, Self::Term, Self>
Source§fn terminate<F>(
self,
kind: Self::Kind,
rule: F,
) -> ShiftTerminalRule<Self::Kind, F, Self>
fn terminate<F>( self, kind: Self::Kind, rule: F, ) -> ShiftTerminalRule<Self::Kind, F, Self>
Handle a terminating token kind using a given parser. For
example, a token representing a number can be handled directly
using an appropriate parser (e.g.
usize::parse()).Source§fn skip(self, kind: Self::Kind) -> ShiftSkipRule<Self::Kind, Self::Term, Self>
fn skip(self, kind: Self::Kind) -> ShiftSkipRule<Self::Kind, Self::Term, Self>
Skip all occurrences of the given token. For example, if our
language supports
WhiteSpace tokens then we might want to
skip them and, likewise, for comments, etc.Source§fn open(
self,
kind: Self::Kind,
default: Self::Term,
) -> ShiftOpenRule<Self::Kind, Self::Term, Self>
fn open( self, kind: Self::Kind, default: Self::Term, ) -> ShiftOpenRule<Self::Kind, Self::Term, Self>
Begin parsing a new compound term when the given token is
encountered. The new term is initialised with a given default
value. For example, when parsing an S-expression (i.e. lisp),
then upon encountering a
( we start a new empty list.Source§fn close(
self,
kind: Self::Kind,
) -> ShiftCloseRule<Self::Kind, fn(Self::Term) -> Self::Term, Self>
fn close( self, kind: Self::Kind, ) -> ShiftCloseRule<Self::Kind, fn(Self::Term) -> Self::Term, Self>
Finish parsing a compound a compound term when the given token
is encountered. When this happens, the current stack element
is popped off the stack and either reduced into the element
below, or returned. For example, when parsing an S-expression
(i.e. lisp), the token
) signifies the end of a list.Source§fn close_with<F>(
self,
kind: Self::Kind,
rule: F,
) -> ShiftCloseRule<Self::Kind, F, Self>
fn close_with<F>( self, kind: Self::Kind, rule: F, ) -> ShiftCloseRule<Self::Kind, F, Self>
Finish parsing a compound a compound term when the given token
is encountered. When this happens, the current stack element
is popped off the stack and either reduced into the element
below, or returned. For example, when parsing an S-expression
(i.e. lisp), the token
) signifies the end of a list.Source§fn update<F: Fn(Self::Term) -> Self::Term>(
self,
kind: Self::Kind,
rule: F,
) -> ShiftUpdateRule<Self::Kind, F, Self>
fn update<F: Fn(Self::Term) -> Self::Term>( self, kind: Self::Kind, rule: F, ) -> ShiftUpdateRule<Self::Kind, F, Self>
Update the current state (i.e. topmost stack term) based on a
given token.
Source§fn update_with<F: Fn(Self::Term) -> Result<(bool, Self::Term), ()>>(
self,
kind: Self::Kind,
rule: F,
) -> ShiftUpdateWithRule<Self::Kind, F, Self>
fn update_with<F: Fn(Self::Term) -> Result<(bool, Self::Term), ()>>( self, kind: Self::Kind, rule: F, ) -> ShiftUpdateWithRule<Self::Kind, F, Self>
Update the current state (i.e. topmost stack item) based on a
given token. If the given rule returns
None, then no action
is taken. Otherwise, the topmost stack item is replaced with
that returned.Source§fn update_as<F: Fn(&mut Self::Term) -> Result<bool, ()>>(
self,
kind: Self::Kind,
rule: F,
) -> ShiftUpdateAsRule<Self::Kind, F, Self>
fn update_as<F: Fn(&mut Self::Term) -> Result<bool, ()>>( self, kind: Self::Kind, rule: F, ) -> ShiftUpdateAsRule<Self::Kind, F, Self>
Update the current state (i.e. topmost stack item) based on a
given token. If the given rule returns
false, then the rule
did not apply and other rules should be considered.Auto Trait Implementations§
impl<K, T> Freeze for ShiftReduceParser<K, T>
impl<K, T> RefUnwindSafe for ShiftReduceParser<K, T>where
K: RefUnwindSafe,
T: RefUnwindSafe,
impl<K, T> Send for ShiftReduceParser<K, T>
impl<K, T> Sync for ShiftReduceParser<K, T>
impl<K, T> Unpin for ShiftReduceParser<K, T>
impl<K, T> UnwindSafe for ShiftReduceParser<K, T>where
K: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more