Trait parsa::Parser

source ·
pub trait Parser<T>: Sized {
    type Err;

    // Required method
    fn parse(&self, s: &mut ParserString) -> Result<T, Self::Err>;

    // Provided methods
    fn try_parse(&self, s: &mut ParserString) -> Result<T, Self::Err> { ... }
    fn chain<U, P2: Parser<U, Err = E>, E: Into<Self::Err>>(
        self,
        other: P2
    ) -> Chain<T, U, Self, P2> { ... }
    fn or<P2: Parser<T, Err = E>, E: Into<Self::Err>>(
        self,
        other: P2
    ) -> Or<T, E, Self, P2> { ... }
    fn many(self) -> Many<T, Self> { ... }
    fn many1(self) -> Many1<T, Self> { ... }
    fn map<U: 'static>(
        self,
        f: impl Fn(T) -> U + 'static
    ) -> impl Parser<U, Err = Self::Err> { ... }
    fn map_err<E: 'static>(
        self,
        f: impl Fn(Self::Err) -> E + 'static
    ) -> impl Parser<T, Err = E> { ... }
    fn and_then<U: 'static, E: Into<Self::Err>>(
        self,
        f: impl Fn(T) -> Result<U, E> + 'static
    ) -> impl Parser<U, Err = Self::Err> { ... }
    fn after<U, P2: Parser<U, Err = E>, E: Into<Self::Err>>(
        self,
        other: P2
    ) -> impl Parser<T, Err = Self::Err> { ... }
    fn replace<U, P2: Parser<U, Err = E>, E: Into<Self::Err>>(
        self,
        other: P2
    ) -> impl Parser<U, Err = Self::Err> { ... }
    fn convert_err<E: From<Self::Err> + 'static>(
        self
    ) -> impl Parser<T, Err = E> { ... }
}
Expand description

All parsers implement this trait. Any function or closure with the signature Fn(&mut ParserString) -> Result<T, E> implements Parser.

Required Associated Types§

source

type Err

The error type this parser can return

Required Methods§

source

fn parse(&self, s: &mut ParserString) -> Result<T, Self::Err>

Run this parser, using a ParserString.

Provided Methods§

source

fn try_parse(&self, s: &mut ParserString) -> Result<T, Self::Err>

Run this parser without affecting the string on failure. In other words, the string will be “rewinded” on failure.

source

fn chain<U, P2: Parser<U, Err = E>, E: Into<Self::Err>>( self, other: P2 ) -> Chain<T, U, Self, P2>

Constructs a Chain combinator.

source

fn or<P2: Parser<T, Err = E>, E: Into<Self::Err>>( self, other: P2 ) -> Or<T, E, Self, P2>

Constructs a Or combinator.

source

fn many(self) -> Many<T, Self>

Constructs a Many combinator.

source

fn many1(self) -> Many1<T, Self>

Constructs a Many1 combinator.

source

fn map<U: 'static>( self, f: impl Fn(T) -> U + 'static ) -> impl Parser<U, Err = Self::Err>

Apply a function to the output of this parser on success.

source

fn map_err<E: 'static>( self, f: impl Fn(Self::Err) -> E + 'static ) -> impl Parser<T, Err = E>

Apply a function to the Err output of this parser on failure.

source

fn and_then<U: 'static, E: Into<Self::Err>>( self, f: impl Fn(T) -> Result<U, E> + 'static ) -> impl Parser<U, Err = Self::Err>

Applies a function to the output of this parser on success, using error coercion rules.

source

fn after<U, P2: Parser<U, Err = E>, E: Into<Self::Err>>( self, other: P2 ) -> impl Parser<T, Err = Self::Err>

Similar to Chain, but only keeps the output of the first parser.

source

fn replace<U, P2: Parser<U, Err = E>, E: Into<Self::Err>>( self, other: P2 ) -> impl Parser<U, Err = Self::Err>

Similar to Chain, but only keeps the output of the second parser.

source

fn convert_err<E: From<Self::Err> + 'static>(self) -> impl Parser<T, Err = E>

Explicitly sets the target error type of this parser. Can help with type inference.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, E, F: Fn(&mut ParserString) -> Result<T, E>> Parser<T> for F

§

type Err = E

source§

impl<T, E, P1, P2> Parser<T> for Or<T, E, P1, P2>
where P1: Parser<T>, E: Into<P1::Err>, P2: Parser<T, Err = E>,

§

type Err = <P1 as Parser<T>>::Err

source§

impl<T, P> Parser<Vec<T>> for Many1<T, P>
where P: Parser<T>,

§

type Err = <P as Parser<T>>::Err

source§

impl<T, P> Parser<Vec<T>> for Many<T, P>
where P: Parser<T>,

source§

impl<T, U, P1, P2, E> Parser<(T, U)> for Chain<T, U, P1, P2>
where P1: Parser<T>, E: Into<P1::Err>, P2: Parser<U, Err = E>,

§

type Err = <P1 as Parser<T>>::Err