DataStack

Trait DataStack 

Source
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§

Source

type Term

Type for terminal symbols

Source

type NonTerm: NonTerminal

Type for non-terminal symbols - this must be enum type that was auto-generated by rusty_lr

Source

type UserData

Type for user data that is passed to the parser from the user.

Source

type ReduceActionError

Type for Err variant returned by reduce action

Source

type StartType

The value of the start symbol

Source

type Location: Location

Type for location of the token

Required Methods§

Source

fn pop_start(&mut self) -> Option<Self::StartType>

Source

fn pop(&mut self)

Source

fn push_terminal(&mut self, term: Self::Term)

Source

fn push_empty(&mut self)

Source

fn clear(&mut self)

Source

fn reserve(&mut self, additional: usize)

Source

fn split_off(&mut self, at: usize) -> Self

Source

fn append(&mut self, other: &mut Self)

Source

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§

Source

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.

Implementors§