diff --git a/src/lib.rs b/src/lib.rs index 16da3dd..b523613 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,18 @@ trait Parser { { BoxedParser::new(map(self, map_fn)) } + + fn then<'a, P, O2>(self, next_parser: P) -> BoxedParser<'a, I, (O, O2), E> + where + Self: Sized + 'a, + I: 'a, + O: 'a, + O2: 'a, + E: 'a, + P: Parser + 'a, + { + BoxedParser::new(seq(self, next_parser)) + } } struct BoxedParser<'a, I, O, E> { @@ -198,6 +210,9 @@ mod tests { fn test_seq() { let p = seq(identifier, seq(literal(" "), literal("ruts"))); assert_matches!(p.parse("fort1 ruts"), Ok((r, "")) if r.0 == "fort1" && r.1 == (" ", "ruts") ); + + let p = identifier.then(literal(" ")).then(literal("ruts")); + assert_matches!(p.parse("fort1 ruts"), Ok((r, "")) if r.0.0 == "fort1" && r.0.1== " " && r.1 == "ruts"); } #[test]