use std::borrow::Borrow;
use crate::parser::{code, Input, ParseError, Parser, ParseResult};
use super::CombinatorError;
pub fn verify<'a, 'b, O1, O2, F, G>(mut f: F, g: G) -> impl FnMut(Input<'a>) -> ParseResult<'a, O1>
where
O1: 'b + Borrow<O2>,
O2: 'b + ?Sized,
F: Parser<'a, 'b, O1>,
G: Fn(&O2) -> bool,
{
move |input: Input<'a>| {
let (value, cursor) = f.parse(input)?;
if !g(value.borrow()) {
return Err(ParseError::new(
input,
code::ERR_VERIFY,
CombinatorError::Verify,
));
}
Ok((value, cursor))
}
}