pub trait DataStack: Sized + Default {
type Term;
type NonTerm: NonTerminal;
type UserData;
type ReduceActionError;
type StartType;
type Location: Location;
// Required methods
fn pop_start(&mut self) -> Option<Self::StartType>;
fn pop(&mut self);
fn push_terminal(&mut self, term: Self::Term);
fn push_empty(&mut self);
fn clear(&mut self);
fn reserve(&mut self, additional: usize);
fn split_off(&mut self, at: usize) -> Self;
fn append(&mut self, other: &mut Self);
fn reduce_action(
data_stack: &mut Self,
location_stack: &mut Vec<Self::Location>,
push_data: bool,
rule_index: usize,
shift: &mut bool,
lookahead: &TerminalSymbol<Self::Term>,
userdata: &mut Self::UserData,
location0: &mut Self::Location,
) -> Result<(), Self::ReduceActionError>;
// Provided method
fn with_capacity(capacity: usize) -> Self { ... }
}Expand description
A trait for data stack in the parser.
Since each non-terminal could have different ruletypes,
this effectively handles those rule types into separated Vec stack,
instead of using enum of rule types (since it would be costful at memory aspects if the size differs significantly).
For people who is curious about the implementation details,
you should see the actual generated DataStack structs, like GrammarDataStack in rusty_lr_parser/src/parser/parser_expanded.rs.
Required Associated Types§
Sourcetype NonTerm: NonTerminal
type NonTerm: NonTerminal
Type for non-terminal symbols - this must be enum type that was auto-generated by rusty_lr
Sourcetype ReduceActionError
type ReduceActionError
Type for Err variant returned by reduce action
Required Methods§
fn pop_start(&mut self) -> Option<Self::StartType>
fn pop(&mut self)
fn push_terminal(&mut self, term: Self::Term)
fn push_empty(&mut self)
fn clear(&mut self)
fn reserve(&mut self, additional: usize)
fn split_off(&mut self, at: usize) -> Self
fn append(&mut self, other: &mut Self)
Sourcefn reduce_action(
data_stack: &mut Self,
location_stack: &mut Vec<Self::Location>,
push_data: bool,
rule_index: usize,
shift: &mut bool,
lookahead: &TerminalSymbol<Self::Term>,
userdata: &mut Self::UserData,
location0: &mut Self::Location,
) -> Result<(), Self::ReduceActionError>
fn reduce_action( data_stack: &mut Self, location_stack: &mut Vec<Self::Location>, push_data: bool, rule_index: usize, shift: &mut bool, lookahead: &TerminalSymbol<Self::Term>, userdata: &mut Self::UserData, location0: &mut Self::Location, ) -> Result<(), Self::ReduceActionError>
Performs a reduce action with the given rule index. Returns false if the empty tag was pushed by this reduce action, true otherwise.
Provided Methods§
fn with_capacity(capacity: usize) -> Self
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.