J-F-Liu / pom

PEG parser combinators using operator overloading without macros.
MIT License
496 stars 30 forks source link

Issue from "Parser::new" method on current version. #35

Closed pictca closed 4 years ago

pictca commented 4 years ago

In the legendary project clacks use pom = "1.1.0". My current job to merge some legendary code to a new project with current pom version v 3.0 which changed on core API. I'm stuck on define new method on Parser old but it works well source

fn output<T: 'static>(inner: Parser<u8, T>) -> Parser<u8, Matched<T>> {
        Parser::new(move |input| {
            let start = input.position();
            let output = inner.parse(input)?;
            let end = input.position();
            Ok(Matched(output, utf8(input.segment(start, end))))
        })
    }
#[derive(Debug, Clone)]
pub struct Matched<T>(pub T, pub String);
fn utf8(v: Vec<u8>) -> String {
     String::from_utf8(v).unwrap()
}

How can i apply Parser::new with current version?

J-F-Liu commented 4 years ago

Try something like:

Parser::new(move |input: &'a [u8], start: usize| {
    inner.parse(input, start).map(|(_, end)| (&input[start..end], end))
})
pictca commented 4 years ago

thank you