Trait parsell::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 { ... } fn init_parse(&self, data: S) -> ParseResult<Self::State, S> where Self: Sized { ... } fn init_done(&self) -> Self::Output where Self: Sized { ... } }
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
fn init(&self) -> Self::State
Create a stateful parser by initializing a stateless parser.
Provided Methods
fn iter(self, data: S) -> IterParser<Self, Self::State, S> where Self: Sized + Copy
Build an iterator from a parser and some data.
fn init_parse(&self, data: S) -> ParseResult<Self::State, S> where Self: Sized
Short hand for calling init then parse.
fn init_done(&self) -> Self::Output where Self: Sized
Short hand for calling init then done.
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, Q, S> Committed<S> for OrElseParser<P, Q> where P: Copy + Uncommitted<S>, Q: Committed<S, Output=P::Output>
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<'a> Committed<&'a str> for AnyCharacterParser
impl<I> Committed<I> for AnyTokenParser where I: Iterator
impl<'a, P> Committed<&'a str> for BufferedParser<P> where P: Committed<&'a str>
impl<P, Q, R, S, T> Committed<S> for PipeParser<P, Q> where P: Copy + Committed<S>, Q: for<'a> Committed<Peekable<&'a mut IterParser<P, P::State, S>>, State=R, Output=T>, R: for<'a> Stateful<Peekable<&'a mut IterParser<P, P::State, S>>, Output=T>