oni_comb_parser/primitive/
none_of.rs1use core::marker::PhantomData;
2
3use crate::error::ParseError;
4use crate::fail::{Fail, PResult};
5use crate::input::Input;
6use crate::parser::Parser;
7
8pub struct NoneOf<'s, I: Input> {
9 set: &'s [I::Token],
10 _marker: PhantomData<fn(&mut I)>,
11}
12
13pub fn none_of<'s, I: Input>(set: &'s [I::Token]) -> NoneOf<'s, I> {
14 NoneOf {
15 set,
16 _marker: PhantomData,
17 }
18}
19
20impl<'s, I: Input> Parser<I> for NoneOf<'s, I> {
21 type Error = ParseError;
22 type Output = I::Token;
23
24 #[inline]
25 fn parse_next(&mut self, input: &mut I) -> PResult<I::Token, ParseError> {
26 let pos = input.offset();
27 match input.peek_token() {
28 Some(t) if !self.set.contains(&t) => {
29 input.next_token();
30 Ok(t)
31 }
32 _ => Err(Fail::Backtrack(ParseError::expected_description(pos, "none of set"))),
33 }
34 }
35}