pub struct Parser<'a> { /* private fields */ }
Expand description
Holds the state of the parser for the provided Grammar
Implementations
sourceimpl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcepub fn new(grammar: &'a mut Grammar<'_>) -> Result<Parser<'a>, GrammarError<'a>>
pub fn new(grammar: &'a mut Grammar<'_>) -> Result<Parser<'a>, GrammarError<'a>>
Creates a Parser
from the provided Grammar
ⓘ
let parser = match Parser::new(&mut grammar) {
Ok(p) => p,
Err(err) => panic!("Error: {:#?}", err),
};
sourcepub fn parse(&mut self, input: &'a str) -> Result<ParseTree<'a>, ParseError>
pub fn parse(&mut self, input: &'a str) -> Result<ParseTree<'a>, ParseError>
Parse the provided string
ⓘ
println!("Parse tree: {:#?}", parser.parse("a test string"));
sourcepub fn rollup(&mut self, non_terminals: Vec<NonTerminal<'a>>)
pub fn rollup(&mut self, non_terminals: Vec<NonTerminal<'a>>)
Specify any non-terminals that you want rolled up (see “Rolling Up the Parse Tree” section)
ⓘ
parser.rollup(vec![
"digit+",
"digit*",
]);
Trait Implementations
impl<'a> StructuralPartialEq for Parser<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Parser<'a>
impl<'a> Send for Parser<'a>
impl<'a> Sync for Parser<'a>
impl<'a> Unpin for Parser<'a>
impl<'a> UnwindSafe for Parser<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more