Struct gearley::recognizer::Recognizer [] [src]

pub struct Recognizer<'f, 'g, F = NullForest> where F: Forest<'f> + 'f {
    // some fields omitted
}

The recognizer implements the Earley algorithm. It parses the given input according to the grammar. The forest is used to construct a parse result.

To save memory, it only retains those parts of the Earley table that may be useful in the future.

Methods

impl<'f, 'g, F> Recognizer<'f, 'g, F> where F: Forest<'f> + 'f

fn trace(&self) -> Tracing<F::NodeRef>

fn events(&self) -> Events<F::NodeRef>

fn minimal_distances(&self) -> Distances<F::NodeRef>

fn expected_terminals(&self) -> ExpectedTerminals<F::NodeRef>

impl<'f, 'g, F> Recognizer<'f, 'g, F> where F: Forest<'f> + 'f

fn new(grammar: &'g InternalGrammar, forest: &'f F) -> Recognizer<'f, 'g, F>

Creates a new recognizer for a given grammar and forest. The recognizer has an initial Earley set that predicts the grammar's start symbol.

fn predict(&mut self, symbol: Symbol)

Makes the current Earley set predict a given symbol.

fn scan(&mut self, symbol: Symbol, value: F::LeafValue)

Reads a token. Creates a leaf bocage node with the given value. After reading one or more tokens, the parse can be advanced.

fn advance(&mut self) -> bool

Advances the parse. Calling this method may set the finished node, which can be accessed through the finished_node method.

fn advance_without_completion(&mut self)

Advances the parse. Omits the completion pass, which should be done through the completions method. Keep in mind that calling this method may not set the finished node, which should be tracked externally.

fn is_exhausted(&self) -> bool

Checks whether the recognizer is exhausted. The recognizer is exhausted when it can't accept more input.

fn completions<'r>(&'r mut self) -> Completions<'f, 'g, 'r, F>

Provides access to completions, which can be used to perform a completion pass.

fn complete(&mut self, set_id: Origin, sym: Symbol, rhs_link: F::NodeRef)

Complete items.

fn reset(&mut self)

Resets the recognizer to its initial state by removing all contents.

fn is_finished(&self) -> bool

Checks whether there is a valid parse that ends at the current position.

fn finished_node(&self) -> F::NodeRef

Retrieves the bocage node that represents the parse that has finished at the current location.

Panics

Panics when the parse has not finished at the current location.

fn raw_predicted_items(&self) -> RawPredictedItems

Accesses predicted items.

fn raw_medial_items(&self) -> RawMedialItems<F::NodeRef>

Accesses medial items.

fn earleme(&self) -> usize

Returns the current location number.

fn grammar(&self) -> &'g InternalGrammar

Returns a reference to the internal grammar.