pub enum GenericErrorTree<Location, Tag, Context, ExternalError> {
Base {
location: Location,
kind: BaseErrorKind<Tag, ExternalError>,
},
Stack {
base: Box<Self>,
contexts: Vec<(Location, StackContext<Context>)>,
},
Alt(Vec<Self>),
}
Expand description
Generic version of ErrorTree
, which allows for arbitrary Tag
, Context
,
and ExternalError
types. See ErrorTree
for more extensive docs and
examples.
Tag
is typically something like&'static str
or&'static [u8]
.Context
is typically&'static str
, and it must be in order to interoperate with nom’scontext
combinator.nom-supreme
provides a more generic.context
combinator that allows for any kind of context to be attached to an error.Error
can usually be nothing, as it’s unusual for nom parsers to require external errors.Box<dyn Error + Send + Sync + 'static>
is a common catch-all.
Variants§
Base
A specific error event at a specific location. Often this will indicate that something like a tag or character was expected at that location.
Fields
location: Location
The location of this error in the input
kind: BaseErrorKind<Tag, ExternalError>
The specific error that occurred
Stack
A stack indicates a chain of error contexts was provided. The stack
should be read “backwards”; that is, errors earlier in the Vec
occurred “sooner” (deeper in the call stack).
Fields
contexts: Vec<(Location, StackContext<Context>)>
The stack of contexts attached to that error
Alt(Vec<Self>)
A series of parsers were tried at the same location (for instance, via
the alt
combinator) and all of them failed. All
of the errors in this set are “siblings”.
Implementations§
Source§impl<I, T, C, E> GenericErrorTree<I, T, C, E>
impl<I, T, C, E> GenericErrorTree<I, T, C, E>
Sourcepub fn map_locations<I2>(
self,
convert_location: impl FnMut(I) -> I2,
) -> GenericErrorTree<I2, T, C, E>
pub fn map_locations<I2>( self, convert_location: impl FnMut(I) -> I2, ) -> GenericErrorTree<I2, T, C, E>
Convert all of the locations in this error using some kind of mapping function. This is intended to help add additional context that may not have been available when the nom parsers were running, such as line and column numbers.
Trait Implementations§
Source§impl<I, T, E> ContextError<I> for GenericErrorTree<I, T, &'static str, E>
impl<I, T, E> ContextError<I> for GenericErrorTree<I, T, &'static str, E>
Source§fn add_context(location: I, ctx: &'static str, other: Self) -> Self
fn add_context(location: I, ctx: &'static str, other: Self) -> Self
Source§impl<I, T, C, E> ContextError<I, C> for GenericErrorTree<I, T, C, E>
impl<I, T, C, E> ContextError<I, C> for GenericErrorTree<I, T, C, E>
Source§fn add_context(location: I, ctx: C, other: Self) -> Self
fn add_context(location: I, ctx: C, other: Self) -> Self
.context
combinator to add friendly information to errors when backtracking
through a parse tree.Source§impl<Location: Debug, Tag: Debug, Context: Debug, ExternalError: Debug> Debug for GenericErrorTree<Location, Tag, Context, ExternalError>
impl<Location: Debug, Tag: Debug, Context: Debug, ExternalError: Debug> Debug for GenericErrorTree<Location, Tag, Context, ExternalError>
Source§impl<I: Display + Debug, T: Debug, C: Debug, E: Display + Debug> Error for GenericErrorTree<I, T, C, E>
impl<I: Display + Debug, T: Debug, C: Debug, E: Display + Debug> Error for GenericErrorTree<I, T, C, E>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl<I, T, C, E> ErrorConvert<GenericErrorTree<(I, usize), T, C, E>> for GenericErrorTree<I, T, C, E>
impl<I, T, C, E> ErrorConvert<GenericErrorTree<(I, usize), T, C, E>> for GenericErrorTree<I, T, C, E>
Source§fn convert(self) -> GenericErrorTree<(I, usize), T, C, E>
fn convert(self) -> GenericErrorTree<(I, usize), T, C, E>
Source§impl<I, T, C, E> ErrorConvert<GenericErrorTree<I, T, C, E>> for GenericErrorTree<(I, usize), T, C, E>
impl<I, T, C, E> ErrorConvert<GenericErrorTree<I, T, C, E>> for GenericErrorTree<(I, usize), T, C, E>
Source§fn convert(self) -> GenericErrorTree<I, T, C, E>
fn convert(self) -> GenericErrorTree<I, T, C, E>
Source§impl<I, I2, T, C, E> ExtractContext<I, GenericErrorTree<I2, T, C, E>> for GenericErrorTree<I, T, C, E>where
I: Clone,
I2: RecreateContext<I>,
impl<I, I2, T, C, E> ExtractContext<I, GenericErrorTree<I2, T, C, E>> for GenericErrorTree<I, T, C, E>where
I: Clone,
I2: RecreateContext<I>,
Source§fn extract_context(self, original_input: I) -> GenericErrorTree<I2, T, C, E>
fn extract_context(self, original_input: I) -> GenericErrorTree<I2, T, C, E>
Source§impl<I, T, C, E, E2> FromExternalError<I, E2> for GenericErrorTree<I, T, C, E>where
E: From<E2>,
impl<I, T, C, E, E2> FromExternalError<I, E2> for GenericErrorTree<I, T, C, E>where
E: From<E2>,
Source§fn from_external_error(location: I, _kind: NomErrorKind, e: E2) -> Self
fn from_external_error(location: I, _kind: NomErrorKind, e: E2) -> Self
Create an error from a given external error, such as from FromStr
Source§impl<I: InputLength, T, C, E> ParseError<I> for GenericErrorTree<I, T, C, E>
impl<I: InputLength, T, C, E> ParseError<I> for GenericErrorTree<I, T, C, E>
Source§fn from_error_kind(location: I, kind: NomErrorKind) -> Self
fn from_error_kind(location: I, kind: NomErrorKind) -> Self
Create a new error at the given position. Interpret kind
as an
Expectation
if possible, to give a more informative error message.
Source§fn append(location: I, kind: NomErrorKind, other: Self) -> Self
fn append(location: I, kind: NomErrorKind, other: Self) -> Self
Combine an existing error with a new one. This is how error context is accumulated when backtracing. “other” is the original error, and the inputs new error from higher in the call stack.
If other
is already an GenericErrorTree::Stack
, the context is added to
the stack; otherwise, a new stack is created, with other
at the root.
Source§fn from_char(location: I, character: char) -> Self
fn from_char(location: I, character: char) -> Self
Create an error indicating an expected character at a given position
Source§fn or(self, other: Self) -> Self
fn or(self, other: Self) -> Self
Combine two errors from branches of alt. If either or both errors are
already GenericErrorTree::Alt
, the different error sets are merged;
otherwise, a new GenericErrorTree::Alt
is created, containing both
self
and other
.