use {
::nom::{
IResult,
error::{ErrorKind, ParseError}
},
};
pub(crate) mod nom {
pub use nom::{
*,
error,
multi,
branch,
methods,
sequence,
combinator,
bits::complete as bits,
bytes::complete as bytes,
number::complete as number,
character::complete as character,
};
}
pub type Input<'i> = &'i str;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Error<'i> {
pub input: Input<'i>,
pub kind: ErrorKind,
pub context: &'static str
}
impl <'i> ParseError<Input<'i>> for Error<'i> {
fn from_error_kind(input: Input<'i>, kind: ErrorKind) -> Self {
Error {
input,
kind,
context: ""
}
}
fn append(input: Input<'i>, kind: ErrorKind, other: Self) -> Self {
Error {
input,
kind,
..other
}
}
fn add_context(input: Input<'i>, context: &'static str, other: Self) -> Self {
Error {
input,
context,
..other
}
}
}
pub type ParseResult<'i, T, E = Error<'i>> = IResult<Input<'i>, T, E>;
pub trait Parse<'i, E = Error<'i>>
where
E: ParseError<Input<'i>>,
Self: Sized
{
fn parse(input: Input<'i>) -> ParseResult<Self, E>;
}