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