Trait perplex_runtime::Parser[][src]

pub trait Parser {
    type Terminal;
    type Nonterminal;
    fn peek(&mut self) -> &Self::Terminal;
fn shift(
        &mut self,
        state_fn: fn(_: &mut Self),
        goto_fn: fn(_: &mut Self, _: Self::Nonterminal)
    );
fn goto(
        &mut self,
        nonterminal: Self::Nonterminal,
        state_fn: fn(_: &mut Self),
        goto_fn: fn(_: &mut Self, _: Self::Nonterminal)
    );
fn reduce<F: Fn(Vec<Symbol<Self::Terminal, Self::Nonterminal>>) -> Self::Nonterminal>(
        &mut self,
        length: usize,
        f: F
    );
fn accept(&mut self); }

A parser that can be passed to generated states.

The code generator emits a list of state and goto functions which are generic over the parser passed to them. This trait describes the minimal set of functionality that such a parser must support.

Associated Types

The type of terminals the parser emits.

The type of nonterminals the parser emits. This is likely an enum over all nonterminals generated automatically.

Required Methods

Peek at the next terminal in the sequence without shifting it.

Push the next terminal onto the stack.

This function is called by shift actions in the parser.

Push a nonterminal onto the stack.

This function is called after a reduce action in the parser.

Reduce the tail of the stack to a nonterminal.

The parser should split the last length symbols off the stack and call the given function f with them as argument. This function is called by the parser to initiate a reduction.

Accept the last symbol on the stack as the parse result.

Called by the parser when it has finished parsing the root rule.

Implementors