-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the ParserTrait out of the generated code.
- Loading branch information
Showing
3 changed files
with
32 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
use crate::error::Result; | ||
use crate::parser_tables_generated::Term; | ||
|
||
/// This macro is pre-processed by the python grammar processor and generate | ||
/// code out-side the current context. | ||
#[macro_export] | ||
macro_rules! grammar_extension { | ||
( $($_:tt)* ) => {}; | ||
} | ||
|
||
/// Aggregate a Value (= StackValue or ()) and a nonterminal/terminal as a stack | ||
/// element. The term is currently used for replaying the parse table when | ||
/// handling errors and non-optimized reduced actions with lookahead. | ||
#[derive(Debug)] | ||
pub struct TermValue<Value> { | ||
pub term: Term, | ||
pub value: Value, | ||
} | ||
|
||
/// The parser trait is an abstraction to define the primitive of an LR Parser | ||
/// with variable lookahead which can be replayed. | ||
pub trait ParserTrait<'alloc, Value> { | ||
fn shift(&mut self, tv: TermValue<Value>) -> Result<'alloc, bool>; | ||
fn unshift(&mut self); | ||
fn rewind(&mut self, n: usize) { | ||
for _ in 0..n { | ||
self.unshift(); | ||
} | ||
} | ||
fn pop(&mut self) -> TermValue<Value>; | ||
fn replay(&mut self, tv: TermValue<Value>); | ||
fn epsilon(&mut self, state: usize); | ||
fn check_not_on_new_line(&mut self, peek: usize) -> Result<'alloc, bool>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters