Trait parsimonious::Committed
[−]
[src]
pub trait Committed<S>: Parser { type Output; type State: Stateful<S, Output = Self::Output>; fn init(&self) -> Self::State; fn iter(self, data: S) -> IterParser<Self, Self::State, S>
where
Self: Sized + Copy, { ... } }
A trait for committed parsers.
A parser is committed if it is guaranteed not to backtrack. Committed parsers are typically constructed by calling the methods of the library, for example:
let parser = character(char::is_alphanumeric).star(String::new);
Here, parser
is a Committed<&str,Output=String>
.
The reason for distinguishing between committed and uncommitted parsers
is that the library is designed for LL(1) grammars, that only use one token
of lookahead. This means that the sequence of two parsers
p.and_then(q)
is only well-defined when q
is committed,
since if p
commits, then q
cannot backtrack.
Semantically, a parser with input S and output T is a partial function S* → T whose domain is prefix-closed (that is, if s·t is in the domain, then s is in the domain) and non-empty.
Associated Types
type Output
The type of the data being produced by the parser.
type State: Stateful<S, Output = Self::Output>
The type of the parser state.
Required Methods
Provided Methods
fn iter(self, data: S) -> IterParser<Self, Self::State, S> where
Self: Sized + Copy,
Self: Sized + Copy,
Build an iterator from a parser and some data.
Implementors
impl<P, F, S> Committed<S> for MapParser<P, F> where
P: Committed<S>,
F: Copy + Function<P::Output>,impl<P, Q, S> Committed<S> for AndThenParser<P, Q> where
P: Committed<S>,
Q: Committed<S>,impl<P, F, S> Committed<S> for OrEmitParser<P, F> where
P: Clone + Uncommitted<S>,
F: Copy + Factory<Output = P::Output>,impl<P, F, S> Committed<S> for StarParser<P, F> where
P: Copy + Uncommitted<S>,
F: Factory,
F::Output: Consumer<P::Output>,impl<P, Q, S> Committed<S> for PipeParser<P, Q> where
P: Copy + Committed<S>,
Q: Committed<Peekable<IterParser<P, P::State, S>>>,