diff options
| -rw-r--r-- | src/lib.rs | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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, |
