use nom::{
Err as NomErr,
IResult,
error::{VerboseError, convert_error},
};
pub type ParserResult<'a, O> = IResult<&'a str, O, VerboseError<&'a str>>;
pub fn convert_result<'a, O>(result: ParserResult<'a, O>, input: &'a str) -> String {
match result {
Ok(_) => "Parsing was successful.".to_string(),
Err(error) => match error {
NomErr::Incomplete(_) => "Parsing failed to consume the entire input.".to_string(),
NomErr::Error(err) | NomErr::Failure(err) => convert_error(input, err),
},
}
}
pub trait Parser: core::fmt::Display + core::str::FromStr {
fn parse(string: &str) -> ParserResult<Self>
where
Self: Sized;
}