Trait parsell::Parser [] [src]

pub trait Parser {
    fn or_else<P>(self, other: P) -> OrElse<Self, P>
    where
        Self: Sized,
        P: Parser
, { ... } fn and_then<P>(self, other: P) -> AndThen<Self, P>
    where
        Self: Sized,
        P: Parser
, { ... } fn try_and_then<P>(self, other: P) -> Map<AndThen<Self, P>, TryZip>
    where
        Self: Sized,
        P: Parser
, { ... } fn and_then_try<P>(self, other: P) -> Map<AndThen<Self, P>, ZipTry>
    where
        Self: Sized,
        P: Parser
, { ... } fn try_and_then_try<P>(
        self,
        other: P
    ) -> VariantMap<AndThen<Self, P>, TryZipTry>
    where
        Self: Sized,
        P: Parser
, { ... } fn plus<F>(self, factory: F) -> Plus<Self, F>
    where
        Self: Sized,
        F: Factory
, { ... } fn star<F>(self, factory: F) -> Star<Self, F>
    where
        Self: Sized,
        F: Factory
, { ... } fn map<F>(self, f: F) -> Map<Self, F>
    where
        Self: Sized
, { ... } fn map2<F>(self, f: F) -> Map<Self, Function2<F>>
    where
        Self: Sized
, { ... } fn map3<F>(self, f: F) -> Map<Self, Function3<F>>
    where
        Self: Sized
, { ... } fn map4<F>(self, f: F) -> Map<Self, Function4<F>>
    where
        Self: Sized
, { ... } fn map5<F>(self, f: F) -> Map<Self, Function5<F>>
    where
        Self: Sized
, { ... } fn map6<F>(self, f: F) -> Map<Self, Function6<F>>
    where
        Self: Sized
, { ... } fn try_map<F>(self, f: F) -> Map<Self, Try<F>>
    where
        Self: Sized
, { ... } fn try_map2<F>(self, f: F) -> Map<Self, Try<Function2<F>>>
    where
        Self: Sized
, { ... } fn try_map3<F>(self, f: F) -> Map<Self, Try<Function3<F>>>
    where
        Self: Sized
, { ... } fn try_map4<F>(self, f: F) -> Map<Self, Try<Function4<F>>>
    where
        Self: Sized
, { ... } fn try_map5<F>(self, f: F) -> Map<Self, Try<Function5<F>>>
    where
        Self: Sized
, { ... } fn try_map6<F>(self, f: F) -> Map<Self, Try<Function6<F>>>
    where
        Self: Sized
, { ... } fn map_ref<F>(self, f: F) -> Map<Self, Dereference<F>>
    where
        Self: Sized
, { ... } fn variant_map<F>(self, f: F) -> VariantMap<Self, F>
    where
        Self: Sized
, { ... } fn discard_and_then<P>(
        self,
        other: P
    ) -> VariantMap<AndThen<Discard<Self>, P>, Second>
    where
        Self: Sized,
        P: Parser
, { ... } fn and_then_discard<P>(
        self,
        other: P
    ) -> VariantMap<AndThen<Self, Discard<P>>, First>
    where
        Self: Sized,
        P: Parser
, { ... } fn try_discard_and_then<P>(
        self,
        other: P
    ) -> VariantMap<Map<AndThen<Map<Self, TryDiscard>, P>, TryZip>, Try<Second>>
    where
        Self: Sized,
        P: Parser
, { ... } fn and_then_try_discard<P>(
        self,
        other: P
    ) -> VariantMap<Map<AndThen<Self, Map<P, TryDiscard>>, ZipTry>, Try<First>>
    where
        Self: Sized,
        P: Parser
, { ... } fn try_discard_and_then_try<P>(
        self,
        other: P
    ) -> VariantMap<VariantMap<AndThen<Map<Self, TryDiscard>, P>, TryZipTry>, Try<Second>>
    where
        Self: Sized,
        P: Parser
, { ... } fn try_and_then_try_discard<P>(
        self,
        other: P
    ) -> VariantMap<VariantMap<AndThen<Self, Map<P, TryDiscard>>, TryZipTry>, Try<First>>
    where
        Self: Sized,
        P: Parser
, { ... } fn opt(self) -> Opt<Self>
    where
        Self: Sized
, { ... } fn try_opt(self) -> VariantMap<Opt<Self>, TryOpt>
    where
        Self: Sized
, { ... } fn discard(self) -> Discard<Self>
    where
        Self: Sized
, { ... } fn try_discard(self) -> Map<Self, TryDiscard>
    where
        Self: Sized
, { ... } fn boxed<F>(self, f: F) -> Boxed<Self, F>
    where
        Self: Sized
, { ... } fn in_state<State>(self, state: State) -> InState<Self, State>
    where
        Self: Sized
, { ... } fn buffer(self) -> Buffered<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 is not, because it will produce None rather than backtracking.

Provided Methods

Choice between parsers

Sequencing with a committed parser

Sequencing with a committed parser (bubble any errors from this parser).

Sequencing with a committed parser (bubble any errors from that parser).

Sequencing with a committed parser (bubble any errors from either parser).

Iterate one or more times (returns an uncommitted parser).

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

Apply a function to the result

Apply a 2-arguent function to the result

Apply a 3-arguent function to the result

Apply a 4-arguent function to the result

Apply a 5-arguent function to the result

Apply a 6-arguent function to the result

Apply a function to the result (bubble any errors).

Apply a 2-argument function to the result (bubble any errors).

Apply a 3-argument function to the result (bubble any errors).

Apply a 4-argument function to the result (bubble any errors).

Apply a 5-argument function to the result (bubble any errors).

Apply a 6-argument function to the result (bubble any errors).

Apply a by-reference function to the result

Apply a variant function to the result

Sequencing, discard the output of the first parse

Sequencing, discard the output of the second parse

Sequencing, discard the output of the first parse, bubble errors from the first parser

Sequencing, discard the output of the second parse, bubble errors from the second parser

Sequencing, discard the output of the first parse, bubble errors from either parser

Sequencing, discard the output of the second parse, bubble errors from either parser

Optional parse

Optional parse

Discard the output

Discard the output, bubbling errors

Box up this parser

Set the state of this 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.init(&mut "abc!".chars()).unwrap() {
    Done(Borrowed(result)) => assert_eq!(result,"abc"),
    _ => panic!("can't happen"),
}
match parser.init(&mut "abc".chars()).unwrap() {
    Continue(parsing) => match parsing.more(&mut "def!".chars()) {
        Done(Owned(result)) => assert_eq!(result,"abcdef"),
        _ => panic!("can't happen"),
    },
    _ => panic!("can't happen"),
}

Implementors