diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-10-22 17:10:55 -0400 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-10-22 17:10:55 -0400 |
| commit | bc0148a918dd7bf0adce2cf241da49398c86c4f5 (patch) | |
| tree | 9a04fd5cd8f820b67337911d26a2f017fea49907 | |
| parent | 0e23b9fa82d95ca365523afac554a4fb6d461a23 (diff) | |
| download | mon-bc0148a918dd7bf0adce2cf241da49398c86c4f5.tar.gz | |
impl Not combinator
| -rw-r--r-- | src/lib.rs | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -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, |
