pub struct GrammarParser<'gram> { /* private fields */ }Expand description
A reusable parser built from a Grammar that validates all nonterminals are defined
at construction time.
§Example
use bnf::Grammar;
let grammar: Grammar = "<dna> ::= <base> | <base> <dna>
<base> ::= 'A' | 'C' | 'G' | 'T'"
.parse()
.unwrap();
let parser = grammar.build_parser()?;
let parse_trees: Vec<_> = parser.parse_input("GATTACA").collect();Implementations§
Source§impl<'gram> GrammarParser<'gram>
impl<'gram> GrammarParser<'gram>
Sourcepub fn new(grammar: &'gram Grammar) -> Result<Self, Error>
pub fn new(grammar: &'gram Grammar) -> Result<Self, Error>
Construct a new GrammarParser from a Grammar, validating that all
nonterminals referenced in productions have definitions.
§Errors
Returns Error::ValidationError if any nonterminal used in the RHS of
productions lacks a definition in the grammar.
Sourcepub fn parse_input<'p: 'gram>(
&'p self,
input: &'gram str,
) -> impl Iterator<Item = ParseTree<'gram>> + use<'p, 'gram>
pub fn parse_input<'p: 'gram>( &'p self, input: &'gram str, ) -> impl Iterator<Item = ParseTree<'gram>> + use<'p, 'gram>
Parse an input string using the grammar’s starting nonterminal.
Returns an iterator over all possible parse trees for the input.
Sourcepub fn parse_input_starting_with<'p: 'gram>(
&'p self,
input: &'gram str,
start: &'gram Term,
) -> impl Iterator<Item = ParseTree<'gram>> + use<'p, 'gram>
pub fn parse_input_starting_with<'p: 'gram>( &'p self, input: &'gram str, start: &'gram Term, ) -> impl Iterator<Item = ParseTree<'gram>> + use<'p, 'gram>
Parse an input string starting with the given term (nonterminal or terminal).
Returns an iterator over all possible parse trees for the input.
Trait Implementations§
Auto Trait Implementations§
impl<'gram> Freeze for GrammarParser<'gram>
impl<'gram> RefUnwindSafe for GrammarParser<'gram>
impl<'gram> !Send for GrammarParser<'gram>
impl<'gram> !Sync for GrammarParser<'gram>
impl<'gram> Unpin for GrammarParser<'gram>
impl<'gram> UnwindSafe for GrammarParser<'gram>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more