oni_comb_parser/primitive/
take_till0.rs1use core::marker::PhantomData;
2
3use crate::error::ParseError;
4use crate::fail::PResult;
5use crate::input::Input;
6use crate::parser::Parser;
7
8pub struct TakeTill0<F, I: Input>(F, PhantomData<fn(&mut I)>);
9
10pub fn take_till0<I: Input, F: FnMut(I::Token) -> bool>(f: F) -> TakeTill0<F, I> {
11 TakeTill0(f, PhantomData)
12}
13
14impl<I: Input, F> Parser<I> for TakeTill0<F, I>
15where
16 F: FnMut(I::Token) -> bool,
17{
18 type Error = ParseError;
19 type Output = I::Slice;
20
21 #[inline]
22 fn parse_next(&mut self, input: &mut I) -> PResult<I::Slice, ParseError> {
23 let cp = input.checkpoint();
24 while let Some(t) = input.peek_token() {
25 if (self.0)(t) {
26 break;
27 } else {
28 input.next_token();
29 }
30 }
31 Ok(input.slice_since(cp))
32 }
33}