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 InternalGrammarImplementations§
Source§impl<'g, F> Recognizer<'g, F>where
F: Forest,
impl<'g, F> Recognizer<'g, F>where
F: Forest,
Source§impl<'g, F> Recognizer<'g, F>
impl<'g, F> Recognizer<'g, F>
pub fn new_with_hint(grammar: &'g InternalGrammar, tokens: usize) -> Self
Source§impl<'g, F> Recognizer<'g, F>where
F: Forest,
impl<'g, F> Recognizer<'g, F>where
F: Forest,
Sourcepub fn new(grammar: &'g InternalGrammar, forest: F) -> Recognizer<'g, F>
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.
pub fn begin_earleme(&mut self)
Sourcepub fn scan(&mut self, symbol: Symbol, value: F::LeafValue)
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.
pub fn lookahead_hint(&mut self, lookahead: Option<Symbol>)
Sourcepub fn end_earleme(&mut self) -> bool
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.
Sourcepub fn advance_without_completion(&mut self)
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.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Checks whether the recognizer is exhausted. The recognizer is exhausted when it can’t accept more input.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Checks whether there is a valid parse that ends at the current position.
Sourcepub fn finished_node(&self) -> Option<F::NodeRef>
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.
Sourcepub fn predicted_symbols(&self) -> PredictedSymbols<'_> ⓘ
pub fn predicted_symbols(&self) -> PredictedSymbols<'_> ⓘ
Accesses predicted symbols.
Sourcepub fn medial_items(&self) -> MedialItems<'_, F::NodeRef> ⓘ
pub fn medial_items(&self) -> MedialItems<'_, F::NodeRef> ⓘ
Accesses medial items.
Sourcepub fn complete_all_sums_entirely(&mut self)
pub fn complete_all_sums_entirely(&mut self)
Performs the completion pass.
Sourcepub fn next_sum<'r>(&'r mut self) -> Option<CompleteSum<'g, 'r, F>>
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,
impl<'g, F> Recognizer<'g, F>where
F: Forest,
Sourcepub fn heap_peek(&self) -> Option<CompletedItem<F::NodeRef>>
pub fn heap_peek(&self) -> Option<CompletedItem<F::NodeRef>>
Returns the greatest item in the binary heap, or None if it is empty.
Sourcepub fn heap_pop(&mut self) -> Option<CompletedItem<F::NodeRef>>
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.
Sourcepub fn heap_push(&mut self, item: CompletedItem<F::NodeRef>)
pub fn heap_push(&mut self, item: CompletedItem<F::NodeRef>)
Pushes an item onto the binary heap.
Sourcepub fn heap_push_linked(&mut self, item: CompletedItemLinked<F::NodeRef>)
pub fn heap_push_linked(&mut self, item: CompletedItemLinked<F::NodeRef>)
Pushes an item onto the binary heap.