summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-10-22 17:10:55 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-10-22 17:10:55 -0400
commitbc0148a918dd7bf0adce2cf241da49398c86c4f5 (patch)
tree9a04fd5cd8f820b67337911d26a2f017fea49907
parent0e23b9fa82d95ca365523afac554a4fb6d461a23 (diff)
downloadmon-bc0148a918dd7bf0adce2cf241da49398c86c4f5.tar.gz
impl Not combinator
-rw-r--r--src/lib.rs30
1 files changed, 30 insertions, 0 deletions
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<P> {
+ parser: P,
+}
+
+impl<I, P> Parser<I> for Not<P>
+where
+ I: Input,
+ P: Parser<I>,
+{
+ type Output = ();
+
+ fn run<OM: Mode, EM: Mode, T: Trace<I>>(
+ &mut self,
+ it: InputIter<I>,
+ ) -> ParserResult<I, Self::Output, OM, EM> {
+ match self.parser.check(it.clone()) {
+ Ok(_) => Ok((it, OM::bind(|| ()))),
+ Err(rest) => Err(EM::bind(|| rest)),
+ }
+ }
+}
+
+pub fn not<I, P>(parser: P) -> impl Parser<I, Output = ()>
+where
+ I: Input,
+ P: Parser<I>,
+{
+ Not { parser }
+}
+
pub fn alpha<I>() -> impl Parser<I, Output = I>
where
I: Input,