perplex_runtime

Trait Parser

Source
pub trait Parser {
    type Terminal;
    type Nonterminal;

    // Required methods
    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);
}
Expand description

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.

Required Associated Types§

Source

type Terminal

The type of terminals the parser emits.

Source

type Nonterminal

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

Required Methods§

Source

fn peek(&mut self) -> &Self::Terminal

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

Source

fn shift( &mut self, state_fn: fn(_: &mut Self), goto_fn: fn(_: &mut Self, _: Self::Nonterminal), )

Push the next terminal onto the stack.

This function is called by shift actions in the parser.

Source

fn goto( &mut self, nonterminal: Self::Nonterminal, state_fn: fn(_: &mut Self), goto_fn: fn(_: &mut Self, _: Self::Nonterminal), )

Push a nonterminal onto the stack.

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

Source

fn reduce<F: Fn(Vec<Symbol<Self::Terminal, Self::Nonterminal>>) -> Self::Nonterminal>( &mut self, length: usize, f: F, )

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.

Source

fn accept(&mut self)

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

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

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§