Trait parsimonious::Parser [] [src]

pub trait Parser {
    fn or_else<P>(self, other: P) -> OrElseParser<Self, P>
    where
        Self: Sized
, { ... } fn or_emit<F>(self, factory: F) -> OrEmitParser<Self, F>
    where
        Self: Sized
, { ... } fn and_then<P>(self, other: P) -> AndThenParser<Self, P>
    where
        Self: Sized
, { ... } fn try_and_then<P>(
        self,
        other: P
    ) -> MapParser<AndThenParser<Self, P>, TryZip>
    where
        Self: Sized
, { ... } fn and_then_try<P>(
        self,
        other: P
    ) -> MapParser<AndThenParser<Self, P>, ZipTry>
    where
        Self: Sized
, { ... } fn try_and_then_try<P>(
        self,
        other: P
    ) -> MapParser<AndThenParser<Self, P>, TryZipTry>
    where
        Self: Sized
, { ... } fn plus<F>(self, factory: F) -> PlusParser<Self, F>
    where
        Self: Sized
, { ... } fn star<F>(self, factory: F) -> StarParser<Self, F>
    where
        Self: Sized
, { ... } fn map<F>(self, f: F) -> MapParser<Self, F>
    where
        Self: Sized
, { ... } fn map2<F>(self, f: F) -> MapParser<Self, Function2<F>>
    where
        Self: Sized
, { ... } fn map3<F>(self, f: F) -> MapParser<Self, Function3<F>>
    where
        Self: Sized
, { ... } fn map4<F>(self, f: F) -> MapParser<Self, Function4<F>>
    where
        Self: Sized
, { ... } fn map5<F>(self, f: F) -> MapParser<Self, Function5<F>>
    where
        Self: Sized
, { ... } fn try_map<F>(self, f: F) -> MapParser<Self, Try<F>>
    where
        Self: Sized
, { ... } fn try_map2<F>(self, f: F) -> MapParser<Self, Try<Function2<F>>>
    where
        Self: Sized
, { ... } fn try_map3<F>(self, f: F) -> MapParser<Self, Try<Function3<F>>>
    where
        Self: Sized
, { ... } fn try_map4<F>(self, f: F) -> MapParser<Self, Try<Function4<F>>>
    where
        Self: Sized
, { ... } fn try_map5<F>(self, f: F) -> MapParser<Self, Try<Function5<F>>>
    where
        Self: Sized
, { ... } fn pipe<P>(self, other: P) -> PipeParser<Self, P>
    where
        Self: Sized
, { ... } fn buffer(self) -> BufferedParser<Self>
    where
        Self: Sized
, { ... } }

A trait for stateless parsers.

Parsers are implemented either as committed parsers, which cannot backtrack, or uncommitted parsers, which can backtrack on their first token of input. For example character(char::is_alphabetic) is uncommitted because it will backtrack on any non-alphabetic character, but character(char::is_alphabetic).or_emit(default) is not, because it will produce default() rather than backtracking.

Provided Methods

Choice between parsers (returns a parser).

Gives a parser a default value (returns a committed parser).

Sequencing with a committed parser (returns a committed parser).

Sequencing with a committed parser (returns a committed parser which produces an error when this parser returns an error).

Sequencing with a committed parser (returns a committed parser which produces an error when the other parser returns an error).

Sequencing with a committed parser (returns a committed parser which produces an error when the other parser returns an error).

Iterate one or more times (returns a parser).

Iterate zero or more times (returns a committed parser).

Apply a function to the result (returns a committed parser).

Apply a 2-arguent function to the result (returns a committed parser).

Apply a 3-arguent function to the result (returns a committed parser).

Apply a 4-arguent function to the result (returns a committed parser).

Apply a 5-arguent function to the result (returns a committed parser).

Apply a function to the result (returns a committed parser which produces an error when this parser returns an error).

Apply a 2-argument function to the result (returns a committed parser which produces an error when this parser returns an error).

Apply a 3-argument function to the result (returns a committed parser which produces an error when this parser returns an error).

Apply a 4-argument function to the result (returns a committed parser which produces an error when this parser returns an error).

Apply a 5-argument function to the result (returns a committed parser which produces an error when this parser returns an error).

Take the results of iterating this parser, and feed it into another parser.

A parser which produces its input.

This does its best to avoid having to buffer the input. The result of a buffered parser may be borrowed (because no buffering was required) or owned (because buffering was required). Buffering is required in the case that the input was provided in chunks, rather than contiguously. For example:

fn ignore() {}
let parser = character(char::is_alphabetic).plus(ignore).buffer();
match parser.parse("abc!") {
    Commit(Done("!",result)) => assert_eq!(result,Borrowed("abc")),
    _ => panic!("can't happen"),
}
match parser.parse("abc") {
    Commit(Continue("",parsing)) => match parsing.parse("def!") {
        Done("!",result) => assert_eq!(result,Owned::<'static,str>(String::from("abcdef"))),
        _ => panic!("can't happen"),
    },
    _ => panic!("can't happen"),
}

Implementors