33 lines
872 B
Rust
33 lines
872 B
Rust
![]() |
use nom::bytes::complete::tag;
|
||
|
use nom::error::ErrorKind;
|
||
|
use nom::error::ParseError;
|
||
|
use nom::error::VerboseError;
|
||
|
use nom::IResult;
|
||
|
|
||
|
#[derive(Debug, PartialEq)]
|
||
|
pub enum CustomError<I> {
|
||
|
MyError(MyError<I>),
|
||
|
Nom(I, ErrorKind),
|
||
|
}
|
||
|
|
||
|
#[derive(Debug, PartialEq)]
|
||
|
pub struct MyError<I>(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
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Err(nom::Err::Error(nom::error::Error::from_error_kind(input, nom::error::ErrorKind::Char)))
|
||
|
|
||
|
fn test_parser<'a>(i: &'a str) -> IResult<&'a str, &'a str, CustomError<&'a str>> {
|
||
|
Err(nom::Err::Error(CustomError::MyError(MyError(i))))?;
|
||
|
tag("sdjfisdfjisudfjuwiefweufefefjwef")(i)
|
||
|
}
|