Trait Parser

Source
pub trait Parser<'a>: Debug {
    type Error: Error;
    type Output;
    type Requirement: Debug + Display;
    type RequirementContext;

    // Required methods
    fn parse(
        &self,
        src: &'a str,
        pos: &mut usize,
    ) -> Result<Self::Output, Self::Error>;
    fn requirement(
        &self,
        context: Option<&Self::RequirementContext>,
    ) -> Self::Requirement;

    // Provided methods
    fn skip(&self, src: &'a str, pos: &mut usize) -> Result<(), Self::Error> { ... }
    fn and_then<P>(self, next: P) -> SequenceParser<'a, Self, P>
       where Self: Sized,
             P: Parser<'a> { ... }
    fn or<P>(self, next: P) -> OrderParser<'a, Self, P>
       where Self: Sized,
             P: Parser<'a> { ... }
    fn map<R>(
        self,
        mapper: &'a dyn Fn(Self::Output) -> R,
    ) -> MapParser<'a, Self, R>
       where Self: Sized { ... }
    fn and_gen<P>(
        self,
        generator: &'a dyn Fn(&Self::Output) -> P,
    ) -> GenParser<'a, Self, P>
       where Self: Sized,
             P: Parser<'a> { ... }
    fn repeat(self, min: usize, max: usize) -> RepetitionParser<'a, Self>
       where Self: Sized { ... }
    fn zero_or_more(self) -> RepetitionParser<'a, Self>
       where Self: Sized { ... }
    fn one_or_more(self) -> RepetitionParser<'a, Self>
       where Self: Sized { ... }
    fn stringify(self) -> StringifyParser<'a, Self>
       where Self: Sized { ... }
}

Required Associated Types§

Required Methods§

Source

fn parse( &self, src: &'a str, pos: &mut usize, ) -> Result<Self::Output, Self::Error>

Source

fn requirement( &self, context: Option<&Self::RequirementContext>, ) -> Self::Requirement

Provided Methods§

Source

fn skip(&self, src: &'a str, pos: &mut usize) -> Result<(), Self::Error>

Source

fn and_then<P>(self, next: P) -> SequenceParser<'a, Self, P>
where Self: Sized, P: Parser<'a>,

Source

fn or<P>(self, next: P) -> OrderParser<'a, Self, P>
where Self: Sized, P: Parser<'a>,

Source

fn map<R>(self, mapper: &'a dyn Fn(Self::Output) -> R) -> MapParser<'a, Self, R>
where Self: Sized,

Source

fn and_gen<P>( self, generator: &'a dyn Fn(&Self::Output) -> P, ) -> GenParser<'a, Self, P>
where Self: Sized, P: Parser<'a>,

Source

fn repeat(self, min: usize, max: usize) -> RepetitionParser<'a, Self>
where Self: Sized,

Source

fn zero_or_more(self) -> RepetitionParser<'a, Self>
where Self: Sized,

Source

fn one_or_more(self) -> RepetitionParser<'a, Self>
where Self: Sized,

Source

fn stringify(self) -> StringifyParser<'a, Self>
where Self: Sized,

Implementors§

Source§

impl<'a> Parser<'a> for CharacterClassParser<'a>

Source§

impl<'a> Parser<'a> for CharacterParser

Source§

impl<'a> Parser<'a> for StringParser<'a>

Source§

impl<'a, P1, P2> Parser<'a> for GenParser<'a, P1, P2>
where P1: Parser<'a>, P2: Parser<'a>,

Source§

type Error = GenParserError<'a, P1, P2>

Source§

type Output = (<P1 as Parser<'a>>::Output, <P2 as Parser<'a>>::Output)

Source§

type Requirement = GenParserRequirement<'a, P1, P2>

Source§

type RequirementContext = P2

Source§

impl<'a, P1, P2> Parser<'a> for OrderParser<'a, P1, P2>
where P1: Parser<'a>, P2: Parser<'a>,

Source§

impl<'a, P1, P2> Parser<'a> for SequenceParser<'a, P1, P2>
where P1: Parser<'a>, P2: Parser<'a>,

Source§

impl<'a, P> Parser<'a> for AndParser<'a, P>
where P: Parser<'a>,

Source§

impl<'a, P> Parser<'a> for NotParser<'a, P>
where P: Parser<'a>,

Source§

impl<'a, P> Parser<'a> for ParseableParser<'a, P>
where P: Parseable<'a>,

Source§

impl<'a, P> Parser<'a> for RepetitionParser<'a, P>
where P: Parser<'a>,

Source§

impl<'a, P> Parser<'a> for StringifyParser<'a, P>
where P: Parser<'a>,

Source§

impl<'a, P, R> Parser<'a> for MapParser<'a, P, R>
where P: Parser<'a>,