mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-30 23:11:04 +00:00
distinguish lifetimes of the state table from the underlying grammar
This commit is contained in:
parent
a661d9ee94
commit
5c71e53c6b
@ -11,22 +11,21 @@ pub enum ParseTree {
|
|||||||
Terminal(TerminalString),
|
Terminal(TerminalString),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn interpret<'g,TOKENS>(states: &'g [State<'g>], tokens: TOKENS)
|
pub fn interpret<TOKENS>(states: &[State], tokens: TOKENS) -> Result<ParseTree, ()>
|
||||||
-> Result<ParseTree, ()>
|
|
||||||
where TOKENS: Iterator<Item=TerminalString>
|
where TOKENS: Iterator<Item=TerminalString>
|
||||||
{
|
{
|
||||||
let mut m = Machine::new(states);
|
let mut m = Machine::new(states);
|
||||||
m.execute(tokens)
|
m.execute(tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Machine<'grammar> {
|
struct Machine<'states, 'grammar:'states> {
|
||||||
states: &'grammar [State<'grammar>],
|
states: &'states [State<'grammar>],
|
||||||
state_stack: Vec<&'grammar State<'grammar>>,
|
state_stack: Vec<&'states State<'grammar>>,
|
||||||
data_stack: Vec<ParseTree>,
|
data_stack: Vec<ParseTree>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'grammar> Machine<'grammar> {
|
impl<'states, 'grammar> Machine<'states, 'grammar> {
|
||||||
fn new(states: &'grammar [State<'grammar>]) -> Machine<'grammar> {
|
fn new(states: &'states [State<'grammar>]) -> Machine<'states,'grammar> {
|
||||||
Machine { states: states,
|
Machine { states: states,
|
||||||
state_stack: vec![],
|
state_stack: vec![],
|
||||||
data_stack: vec![] }
|
data_stack: vec![] }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user