From bc0148a918dd7bf0adce2cf241da49398c86c4f5 Mon Sep 17 00:00:00 2001 From: John Turner Date: Wed, 22 Oct 2025 17:10:55 -0400 Subject: impl Not combinator --- src/lib.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index fc91cb1..e0be671 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -740,6 +740,36 @@ where } } +struct Not

{ + parser: P, +} + +impl Parser for Not

+where + I: Input, + P: Parser, +{ + type Output = (); + + fn run>( + &mut self, + it: InputIter, + ) -> ParserResult { + match self.parser.check(it.clone()) { + Ok(_) => Ok((it, OM::bind(|| ()))), + Err(rest) => Err(EM::bind(|| rest)), + } + } +} + +pub fn not(parser: P) -> impl Parser +where + I: Input, + P: Parser, +{ + Not { parser } +} + pub fn alpha() -> impl Parser where I: Input, -- cgit v1.2.3