use anyhow::anyhow;
use nom::error::{convert_error, ParseError, VerboseError};
use nom::{Err, IResult};
pub trait ParseCss<'a>
where
Self: Sized,
{
fn parse<E>(input: &'a str) -> IResult<&'a str, Self, E>
where
E: ParseError<&'a str>;
}
pub fn unwrap_parse_error(input: &str, err: Err<VerboseError<&str>>) -> anyhow::Error {
match err {
Err::Error(e) | Err::Failure(e) => {
anyhow!("Error parsing, unknown:\n{}", convert_error(input, e))
}
Err::Incomplete(needed) => anyhow!("Error parsing, unexpected input:\n {:?}", needed),
}
}