jhpratt, Preview of what I have been working on recently. The core of this crate is a mere two traits. The crate will ship with a number of parsers and combinators, none of which rely on anything not exposed to downstream users.
I've attached a real-world situation, taken verbatim from the test suite. Parsing integers isn't as efficient as it could be yet, as it's using a naïve method.
Parsing in general compiles to be extremely efficient, and using it is ergonomic.
pub trait Combinator<'input, P> where P: ByteParser<'input>, { type NewParser: ByteParser<'input>; fn apply_to(self, parser: P) -> Self::NewParser; }
#[test] fn parse_date() -> parcom::Result<()> { let parser = ascii::int:: .limit_length(4) .and(verbatim(b"-").discard()) .and(ascii::int::.limit_length(2)) .and(verbatim(b"-").discard()) .and(ascii::int::.limit_length(2)); let (seq!(year, _, month, _, day), remaining) = parser.parse("2021-07-04")?.into_parts(); assert!(remaining.is_empty()); assert_eq!(year, 2021); assert_eq!(month, 7); assert_eq!(day, 4); Ok(()) }
Add comment