use crate::parser::*;
use std::marker::PhantomData;
pub struct PNot<P, O> {
p: P,
_marker: PhantomData<O>,
}
pub fn pnot<P, O>(p: P) -> PNot<P, O> {
PNot {
p,
_marker: PhantomData,
}
}
impl<'a, K, O, P> ParserCore<'a, K, ()> for PNot<P, O>
where
K: PartialEq + Clone + 'a,
O: 'a,
P: Parser<'a, K, O>,
{
fn parse(&self, i: PInput<'a, K>) -> Result<PSuccess<'a, K, ()>, PFail<'a, K>> {
let start = i.loc;
match self.p.parse(i) {
Ok(PSuccess { val: _, rest }) => Err(PFail {
error: vec!["Was what was not expected.".to_string()],
span: vec![(start, rest.loc)],
rest,
}),
Err(PFail {
error: _,
span: _,
rest,
}) => Ok(PSuccess { val: (), rest }),
}
}
}
impl<'a, K, O, P> Parser<'a, K, ()> for PNot<P, O>
where
K: PartialEq + Clone + 'a,
O: 'a,
P: Parser<'a, K, O>,
{
}