From 00d866f2a1d647d66e78f4fdc5e5d99c1cb9da21 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 16 Oct 2022 01:10:48 -0700 Subject: [PATCH] then method --- src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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]