Skip to main content

oni_comb_parser/combinator/
map.rs

1use crate::fail::PResult;
2use crate::input::Input;
3use crate::parser::Parser;
4
5pub struct Map<P, F> {
6  pub(crate) parser: P,
7  pub(crate) f: F,
8}
9
10impl<I, P, F, O2> Parser<I> for Map<P, F>
11where
12  I: Input,
13  P: Parser<I>,
14  F: FnMut(P::Output) -> O2,
15{
16  type Error = P::Error;
17  type Output = O2;
18
19  #[inline]
20  fn parse_next(&mut self, input: &mut I) -> PResult<Self::Output, Self::Error> {
21    match self.parser.parse_next(input) {
22      Ok(v) => Ok((self.f)(v)),
23      Err(e) => Err(e),
24    }
25  }
26}