1 use crate::error::Result;
2 use crate::parser_tables_generated::Term;
3 
4 /// This macro is pre-processed by the python grammar processor and generate
5 /// code out-side the current context.
6 #[macro_export]
7 macro_rules! grammar_extension {
8     ( $($_:tt)* ) => {};
9 }
10 
11 /// Aggregate a Value (= StackValue or ()) and a nonterminal/terminal as a stack
12 /// element. The term is currently used for replaying the parse table when
13 /// handling errors and non-optimized reduced actions with lookahead.
14 #[derive(Debug)]
15 pub struct TermValue<Value> {
16     pub term: Term,
17     pub value: Value,
18 }
19 
20 /// The parser trait is an abstraction to define the primitive of an LR Parser
21 /// with variable lookahead which can be replayed.
22 pub trait ParserTrait<'alloc, Value> {
shift(&mut self, tv: TermValue<Value>) -> Result<'alloc, bool>23     fn shift(&mut self, tv: TermValue<Value>) -> Result<'alloc, bool>;
shift_replayed(&mut self, state: usize)24     fn shift_replayed(&mut self, state: usize);
unshift(&mut self)25     fn unshift(&mut self);
rewind(&mut self, n: usize)26     fn rewind(&mut self, n: usize) {
27         for _ in 0..n {
28             self.unshift();
29         }
30     }
pop(&mut self) -> TermValue<Value>31     fn pop(&mut self) -> TermValue<Value>;
replay(&mut self, tv: TermValue<Value>)32     fn replay(&mut self, tv: TermValue<Value>);
epsilon(&mut self, state: usize)33     fn epsilon(&mut self, state: usize);
top_state(&self) -> usize34     fn top_state(&self) -> usize;
check_not_on_new_line(&mut self, peek: usize) -> Result<'alloc, bool>35     fn check_not_on_new_line(&mut self, peek: usize) -> Result<'alloc, bool>;
36 }
37