summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-10-24 00:42:18 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-10-24 00:42:18 -0400
commitda67ed8cd082a0550b95a9bb0b77a8870579cb40 (patch)
treeeceb96745079080f83e84e34e9fdcd120f5a98ed /src
parentfc4ae140ac8d3dd40868a18d44dfb4cd46711129 (diff)
downloadmon-da67ed8cd082a0550b95a9bb0b77a8870579cb40.tar.gz
impl Ignore combinator
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 686ce6f..4b01b57 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -180,6 +180,10 @@ pub trait Parser<I: Input>: Sized {
checker,
}
}
+
+ fn ignore(self) -> impl Parser<I, Output = ()> {
+ Ignore { parser: self }
+ }
}
impl<I, O, F> Parser<I> for F
@@ -849,6 +853,28 @@ where
}
}
+struct Ignore<P> {
+ parser: P,
+}
+
+impl<I, P> Parser<I> for Ignore<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) {
+ Ok((rest, _)) => Ok((rest, OM::bind(|| ()))),
+ Err(rest) => Err(EM::bind(|| rest)),
+ }
+ }
+}
+
pub fn alpha<I>() -> impl Parser<I, Output = I>
where
I: Input,