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