Skip to main content

ParserExt

Trait ParserExt 

Source
pub trait ParserExt<I: SliceLike, O, S>: Parser<I, O, S> {
    // Required methods
    fn map<O2>(self, f: impl FnOnce(O) -> O2 + Copy) -> impl Parser<I, O2, S>;
    fn map_if<O2>(
        self,
        f: impl FnOnce(O) -> Option<O2> + Copy,
    ) -> impl Parser<I, O2, S>;
    fn filter(self, f: impl FnOnce(&O) -> bool + Copy) -> impl Parser<I, O, S>;
    fn bind<O2, P: Parser<I, O2, S>>(
        self,
        f: impl FnOnce(O) -> P + Copy,
    ) -> impl Parser<I, O2, S>;
    fn right<O2, P: Parser<I, O2, S>>(self, p: P) -> impl Parser<I, O2, S>;
    fn left<O2, P: Parser<I, O2, S>>(self, p: P) -> impl Parser<I, O, S>;
    fn parse_state(
        self,
        input: I,
        user_state: &mut S,
    ) -> AnpaResult<AnpaState<'_, I, S>, O>;
    fn parse_state_owned(
        self,
        input: I,
        user_state: S,
    ) -> AnpaResult<AnpaStateOwned<I, S>, O>;
    fn debug(self, name: &'static str) -> impl Parser<I, O, S>;
}
Expand description

Convenince extension functions for all parsers.

Required Methods§

Source

fn map<O2>(self, f: impl FnOnce(O) -> O2 + Copy) -> impl Parser<I, O2, S>

Transform the result of this parser. See crate::combinators::map

Source

fn map_if<O2>( self, f: impl FnOnce(O) -> Option<O2> + Copy, ) -> impl Parser<I, O2, S>

Transform the result of this parser, or fail, by returning Some or None respectively. See crate::combinators::map_if

Source

fn filter(self, f: impl FnOnce(&O) -> bool + Copy) -> impl Parser<I, O, S>

Accept or reject the parse based on the predicate f. See crate::combinators::filter

Source

fn bind<O2, P: Parser<I, O2, S>>( self, f: impl FnOnce(O) -> P + Copy, ) -> impl Parser<I, O2, S>

Create a new parser by taking the result of the previous and returning a new parser. See crate::combinators::bind

Source

fn right<O2, P: Parser<I, O2, S>>(self, p: P) -> impl Parser<I, O2, S>

Combine this parser with another, while ignoring the result of the former. See crate::combinators::right

Source

fn left<O2, P: Parser<I, O2, S>>(self, p: P) -> impl Parser<I, O, S>

Combine this parser with another, while ignoring the result of the latter. See crate::combinators::left

Source

fn parse_state( self, input: I, user_state: &mut S, ) -> AnpaResult<AnpaState<'_, I, S>, O>

Perform a parse with provided user state. See crate::core::parse_state.

Source

fn parse_state_owned( self, input: I, user_state: S, ) -> AnpaResult<AnpaStateOwned<I, S>, O>

Perform a parse with provided user state. Moves ownership of the state to the parser. See crate::core::parse_state.

Source

fn debug(self, name: &'static str) -> impl Parser<I, O, S>

Add some simple debug information to this parser.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<I: SliceLike, O, S, P: Parser<I, O, S>> ParserExt<I, O, S> for P