pub trait EasyParser<Input: Stream>: Parser<Stream<Input>> where
    Input::Token: PartialEq,
    Input::Range: PartialEq
{ fn easy_parse(
        &mut self,
        input: Input
    ) -> Result<(<Self as Parser<Stream<Input>>>::Output, Input), ParseError<Input>>
    where
        Input: Stream,
        Stream<Input>: StreamOnce<Token = Input::Token, Range = Input::Range, Error = ParseError<Stream<Input>>, Position = Input::Position>,
        Input::Position: Default,
        Self: Sized + Parser<Stream<Input>>
, { ... } }
Expand description

Provides the easy_parse method which provides good error messages by default

Provided Methods

Entry point of the parser. Takes some input and tries to parse it, returning an easy to use and format error if parsing did not succeed.

Returns the parsed result and the remaining input if the parser succeeds, or a This function wraps requires Input == easy::Stream<Input> which makes it return return easy::Errors if an error occurs. Due to this wrapping it is recommended that the parser Self is written with a generic input type.


use combine::*;
use combine::parser::repeat::many1;
use combine::parser::char::letter;

// Good!
parser!{
fn my_parser[Input]()(Input) -> String
    where [Input: Stream<Token = char>]
{
    many1::<String, _, _>(letter())
}
}

// Won't compile with `easy_parse` since it is specialized on `&str`
parser!{
fn my_parser2['a]()(&'a str) -> String
    where [&'a str: Stream<Token = char, Range = &'a str>]
{
    many1(letter())
}
}

fn main() {
    assert_eq!(my_parser().parse("abc"), Ok(("abc".to_string(), "")));
    // Would fail to compile if uncommented
    // my_parser2().parse("abc")
}

Implementors