Create a custom error enum to contain regular nom errors.

This commit is contained in:
Tom Alexander 2022-12-15 22:57:08 -05:00
parent 4a9bb31aed
commit f2e68612c4
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -276,29 +276,30 @@ fn flat_link<'s, 'r>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Link<
Ok((remaining, ret)) Ok((remaining, ret))
} }
#[derive(Debug, PartialEq)]
pub enum CustomError<I> {
MyError(MyError<I>),
Nom(I, ErrorKind),
}
#[derive(Debug, PartialEq)]
pub struct MyError<I>(I); pub struct MyError<I>(I);
impl<I> ParseError<I> for MyError<I> { impl<I> ParseError<I> for CustomError<I> {
fn from_error_kind(input: I, kind: ErrorKind) -> Self { fn from_error_kind(input: I, kind: ErrorKind) -> Self {
// MyError((input, kind)) CustomError::Nom(input, kind)
todo!()
} }
fn append(input: I, kind: ErrorKind, mut other: Self) -> Self { fn append(input: I, kind: ErrorKind, mut other: Self) -> Self {
// Doesn't do append like VerboseError // Doesn't do append like VerboseError
other other
} }
fn from_char(input: I, c: char) -> Self {
// MyError((input, c))
todo!()
}
} }
// Err(nom::Err::Error(nom::error::Error::from_error_kind(input, nom::error::ErrorKind::Char))) // 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, VerboseError<&'a str>> { fn test_parser<'a>(i: &'a str) -> IResult<&'a str, &'a str, CustomError<&'a str>> {
Err(nom::Err::Error(MyError(i)))?; Err(nom::Err::Error(CustomError::MyError(MyError(i))))?;
tag("sdjfisdfjisudfjuwiefweufefefjwef")(i) tag("sdjfisdfjisudfjuwiefweufefefjwef")(i)
} }