pub trait Parser {
type Terminal;
type Nonterminal;
// Required methods
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);
}
Expand description
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.
Required Associated Types§
Sourcetype Nonterminal
type Nonterminal
The type of nonterminals the parser emits. This is likely an enum over all nonterminals generated automatically.
Required Methods§
Sourcefn peek(&mut self) -> &Self::Terminal
fn peek(&mut self) -> &Self::Terminal
Peek at the next terminal in the sequence without shifting it.
Sourcefn shift(
&mut self,
state_fn: fn(_: &mut Self),
goto_fn: fn(_: &mut Self, _: Self::Nonterminal),
)
fn shift( &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.
Sourcefn goto(
&mut self,
nonterminal: Self::Nonterminal,
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), )
Push a nonterminal onto the stack.
This function is called after a reduce action in the parser.
Sourcefn reduce<F: Fn(Vec<Symbol<Self::Terminal, Self::Nonterminal>>) -> Self::Nonterminal>(
&mut self,
length: usize,
f: F,
)
fn reduce<F: Fn(Vec<Symbol<Self::Terminal, Self::Nonterminal>>) -> Self::Nonterminal>( &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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.