Trait Parser

pub trait Parser<Input>

All nom parsers implement this trait

Associated Types

type Output;

Type of the produced value

type Error: ParseError<Input>;

Error type of this parser

Required Methods

fn process<OM: OutputMode>(&mut self, input: Input) -> PResult<OM, Input, Self::Output, Self::Error>

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error

Provided Methods

fn parse(&mut self, input: Input) -> IResult<Input, Self::Output, Self::Error>

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error

fn parse_complete(&mut self, input: Input) -> IResult<Input, Self::Output, Self::Error>

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error

fn map<G, O2>(self, g: G) -> Map<Self, G>
where
    G: FnMut(Self::Output) -> O2,
    Self: Sized,

Maps a function over the result of a parser

fn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G>
where
    G: FnMut(Self::Output) -> Result<O2, E2>,
    Self::Error: FromExternalError<Input, E2>,
    Self: Sized,

Applies a function returning a Result over the result of a parser.

fn map_opt<G, O2>(self, g: G) -> MapOpt<Self, G>
where
    G: FnMut(Self::Output) -> Option<O2>,
    Self: Sized,

Applies a function returning an Option over the result of a parser.

fn flat_map<G, H>(self, g: G) -> FlatMap<Self, G>
where
    G: FnMut(Self::Output) -> H,
    H: Parser<Input, Error = Self::Error>,
    Self: Sized,

Creates a second parser from the output of the first one, then apply over the rest of the input

fn and_then<G>(self, g: G) -> AndThen<Self, G>
where
    G: Parser<Self::Output, Error = Self::Error>,
    Self: Sized,

Applies a second parser over the output of the first one

fn and<G, O2>(self, g: G) -> And<Self, G>
where
    G: Parser<Input, Output = O2, Error = Self::Error>,
    Self: Sized,

Applies a second parser after the first one, return their results as a tuple

fn or<G>(self, g: G) -> Or<Self, G>
where
    G: Parser<Input, Output = Self::Output, Error = Self::Error>,
    Self: Sized,

Applies a second parser over the input if the first one failed

fn into<O2: From<Self::Output>, E2: From<Self::Error>>(self) -> Into<Self, O2, E2>
where
    Self: Sized,

automatically converts the parser's output and error values to another type, as long as they implement the From trait

Implementors