1use nom::{error::ParseError, Needed};
2
3#[derive(Debug, PartialEq)]
4pub struct Error<I> {
5 pub input: I,
6 pub code: ErrorKind<I>,
7}
8
9#[derive(Debug, PartialEq)]
10pub enum ErrorKind<I> {
11 Eof,
12 Lex,
13 Incomplete(Needed),
14 Nom(nom::error::ErrorKind),
15 Predicate,
16 Chain(Box<ErrorKind<I>>, Box<Error<I>>),
17}
18
19impl<I> ParseError<I> for Error<I> {
20 fn from_error_kind(input: I, kind: nom::error::ErrorKind) -> Self {
21 Error {
22 input,
23 code: ErrorKind::Nom(kind),
24 }
25 }
26
27 fn append(input: I, kind: nom::error::ErrorKind, other: Self) -> Self {
28 Error {
29 input,
30 code: ErrorKind::Chain(Box::new(ErrorKind::Nom(kind)), Box::new(other)),
31 }
32 }
33}