Skip to main content

Recognizer

Struct Recognizer 

Source
pub struct Recognizer<'g, F = NullForest>
where F: Forest,
{ pub forest: F, pub grammar: &'g InternalGrammar, /* private fields */ }
Expand description

The recognizer implements the Earley algorithm. It parses the given input according to the grammar. The parse result is constructed inside the forest.

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

Fields§

§forest: F§grammar: &'g InternalGrammar

Implementations§

Source§

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

Source

pub fn trace(&self) -> Trace<'_, F::NodeRef> ⓘ

Source

pub fn events(&self) -> Events<'_, F::NodeRef> ⓘ

Source

pub fn minimal_distances(&self) -> Distances<'_, F::NodeRef> ⓘ

Source

pub fn expected_terminals(&self) -> ExpectedTerminals<'_, F::NodeRef> ⓘ

Source§

impl<'g, F> Recognizer<'g, F>
where F: MemoryUse<Arg = &'g InternalGrammar> + Forest,

Source

pub fn new_with_hint(grammar: &'g InternalGrammar, tokens: usize) -> Self

Source§

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

Source

pub fn new(grammar: &'g InternalGrammar, forest: F) -> Recognizer<'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.

Source

pub fn predict(&mut self, symbol: Symbol)

Makes the current Earley set predict a given symbol.

Source

pub fn begin_earleme(&mut self)

Source

pub 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.

Source

pub fn lookahead_hint(&mut self, lookahead: Option<Symbol>)

Source

pub fn end_earleme(&mut self) -> bool

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

Source

pub 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.

Source

pub fn is_exhausted(&self) -> bool

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

Source

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

Complete items.

Source

pub fn reset(&mut self)

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

Source

pub fn is_finished(&self) -> bool

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

Source

pub fn finished_node(&self) -> Option<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.

Source

pub fn predicted_symbols(&self) -> PredictedSymbols<'_> ⓘ

Accesses predicted symbols.

Source

pub fn medial_items(&self) -> MedialItems<'_, F::NodeRef> ⓘ

Accesses medial items.

Source

pub fn earleme(&self) -> usize

Returns the current location number.

Source

pub fn complete_all_sums_entirely(&mut self)

Performs the completion pass.

Source

pub fn next_sum<'r>(&'r mut self) -> Option<CompleteSum<'g, 'r, F>>

Allows iteration through groups of completions that have unique symbol and origin.

Source§

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

Source

pub fn heap_peek(&self) -> Option<CompletedItem<F::NodeRef>>

Returns the greatest item in the binary heap, or None if it is empty.

Source

pub fn heap_pop(&mut self) -> Option<CompletedItem<F::NodeRef>>

Removes the greatest item from the binary heap and returns it, or None if it is empty.

Source

pub fn heap_push(&mut self, item: CompletedItem<F::NodeRef>)

Pushes an item onto the binary heap.

Source

pub fn heap_push_linked(&mut self, item: CompletedItemLinked<F::NodeRef>)

Pushes an item onto the binary heap.

Trait Implementations§

Source§

impl<'g, F: Forest> Debug for Recognizer<'g, F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'g, F> MemoryUse for Recognizer<'g, F>
where F: MemoryUse<Arg = &'g InternalGrammar> + Forest,

Source§

type Arg = &'g InternalGrammar

Source§

fn memory_use(&self) -> usize

Source§

fn new_with_limit(grammar: &'g InternalGrammar, memory_limit: usize) -> Self

Source§

impl<'g> MemoryUse for Recognizer<'g, NullForest>

Source§

type Arg = &'g InternalGrammar

Source§

fn memory_use(&self) -> usize

Source§

fn new_with_limit(grammar: &'g InternalGrammar, memory_limit: usize) -> Self

Auto Trait Implementations§

§

impl<'g, F> Freeze for Recognizer<'g, F>

§

impl<'g, F> RefUnwindSafe for Recognizer<'g, F>

§

impl<'g, F> Send for Recognizer<'g, F>

§

impl<'g, F> Sync for Recognizer<'g, F>

§

impl<'g, F> Unpin for Recognizer<'g, F>

§

impl<'g, F> UnsafeUnpin for Recognizer<'g, F>

§

impl<'g, F> UnwindSafe for Recognizer<'g, F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.