34 lines
872 B
Rust
34 lines
872 B
Rust
use nom::error::ErrorKind;
|
|
use nom::error::ParseError;
|
|
use nom::IResult;
|
|
|
|
pub(crate) type Res<T, U> = IResult<T, U, CustomError<T>>;
|
|
|
|
// TODO: MyError probably shouldn't be based on the same type as the input type since it's used exclusively with static strings right now.
|
|
#[derive(Debug)]
|
|
pub enum CustomError<I> {
|
|
MyError(MyError<I>),
|
|
Nom(I, ErrorKind),
|
|
IO(std::io::Error),
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct MyError<I>(pub(crate) I);
|
|
|
|
impl<I> ParseError<I> for CustomError<I> {
|
|
fn from_error_kind(input: I, kind: ErrorKind) -> Self {
|
|
CustomError::Nom(input, kind)
|
|
}
|
|
|
|
fn append(_input: I, _kind: ErrorKind, /*mut*/ other: Self) -> Self {
|
|
// Doesn't do append like VerboseError
|
|
other
|
|
}
|
|
}
|
|
|
|
impl<I> From<std::io::Error> for CustomError<I> {
|
|
fn from(value: std::io::Error) -> Self {
|
|
CustomError::IO(value)
|
|
}
|
|
}
|