Trait perplex_runtime::Parser [−][src]
pub trait Parser { type Terminal; type Nonterminal; fn peek(&mut self) -> &Self::Terminal; fn shift(
&mut self,
state_fn: fn(_: &mut Self),
goto_fn: fn(_: &mut Self, _: Self::Nonterminal)
); fn goto(
&mut self,
nonterminal: Self::Nonterminal,
state_fn: fn(_: &mut Self),
goto_fn: fn(_: &mut Self, _: Self::Nonterminal)
); fn reduce<F: Fn(Vec<Symbol<Self::Terminal, Self::Nonterminal>>) -> Self::Nonterminal>(
&mut self,
length: usize,
f: F
); fn accept(&mut self); }
A parser that can be passed to generated states.
The code generator emits a list of state and goto functions which are generic over the parser passed to them. This trait describes the minimal set of functionality that such a parser must support.
Associated Types
type Terminal
The type of terminals the parser emits.
type Nonterminal
The type of nonterminals the parser emits. This is likely an enum over all nonterminals generated automatically.
Required Methods
fn peek(&mut self) -> &Self::Terminal
Peek at the next terminal in the sequence without shifting it.
fn shift(
&mut self,
state_fn: fn(_: &mut Self),
goto_fn: fn(_: &mut Self, _: Self::Nonterminal)
)
&mut self,
state_fn: fn(_: &mut Self),
goto_fn: fn(_: &mut Self, _: Self::Nonterminal)
)
Push the next terminal onto the stack.
This function is called by shift actions in the parser.
fn goto(
&mut self,
nonterminal: Self::Nonterminal,
state_fn: fn(_: &mut Self),
goto_fn: fn(_: &mut Self, _: Self::Nonterminal)
)
&mut self,
nonterminal: Self::Nonterminal,
state_fn: fn(_: &mut Self),
goto_fn: fn(_: &mut Self, _: Self::Nonterminal)
)
Push a nonterminal onto the stack.
This function is called after a reduce action in the parser.
fn reduce<F: Fn(Vec<Symbol<Self::Terminal, Self::Nonterminal>>) -> Self::Nonterminal>(
&mut self,
length: usize,
f: F
)
&mut self,
length: usize,
f: F
)
Reduce the tail of the stack to a nonterminal.
The parser should split the last length
symbols off the stack and call
the given function f
with them as argument. This function is called by
the parser to initiate a reduction.
fn accept(&mut self)
Accept the last symbol on the stack as the parse result.
Called by the parser when it has finished parsing the root rule.
Implementors
impl<I, S> Parser for ParserMachine<I, S> where
I: ParserInput<Item = S::Terminal>,
S: StateSpace, type Terminal = S::Terminal; type Nonterminal = S::Nonterminal;