nom_supreme::error

Enum GenericErrorTree

Source
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’s context 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

§base: Box<Self>

The original error

§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>

Source

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>

Source§

fn add_context(location: I, ctx: &'static str, other: Self) -> Self

Creates a new error from an input position, a static string and an existing error. This is used mainly in the context combinator, to add user friendly information to errors when backtracking through a parse tree
Source§

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

Create a new error from an input position, a context, and an existing error. This is used by the .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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I: Display, T: Debug, C: Debug, E: Display> Display for GenericErrorTree<I, T, C, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

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>

Transform to another error type
Source§

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>

Transform to another error type
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>,

Source§

fn extract_context(self, original_input: I) -> GenericErrorTree<I2, T, C, E>

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information. Read more
Source§

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

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>

Source§

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

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

Create an error indicating an expected character at a given position

Source§

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.

Source§

impl<I, T: AsRef<[u8]>, C, E> TagError<I, T> for GenericErrorTree<I, T, C, E>

Source§

fn from_tag(location: I, tag: T) -> Self

Create an error from an expected tag at a location.
Source§

fn from_tag_no_case(input: I, tag: T) -> Self

As above, but for a case insensitive tag. By default this just calls from_tag

Auto Trait Implementations§

§

impl<Location, Tag, Context, ExternalError> Freeze for GenericErrorTree<Location, Tag, Context, ExternalError>
where Location: Freeze, ExternalError: Freeze, Tag: Freeze,

§

impl<Location, Tag, Context, ExternalError> RefUnwindSafe for GenericErrorTree<Location, Tag, Context, ExternalError>
where Location: RefUnwindSafe, ExternalError: RefUnwindSafe, Tag: RefUnwindSafe, Context: RefUnwindSafe,

§

impl<Location, Tag, Context, ExternalError> Send for GenericErrorTree<Location, Tag, Context, ExternalError>
where Location: Send, ExternalError: Send, Tag: Send, Context: Send,

§

impl<Location, Tag, Context, ExternalError> Sync for GenericErrorTree<Location, Tag, Context, ExternalError>
where Location: Sync, ExternalError: Sync, Tag: Sync, Context: Sync,

§

impl<Location, Tag, Context, ExternalError> Unpin for GenericErrorTree<Location, Tag, Context, ExternalError>
where Location: Unpin, ExternalError: Unpin, Tag: Unpin, Context: Unpin,

§

impl<Location, Tag, Context, ExternalError> UnwindSafe for GenericErrorTree<Location, Tag, Context, ExternalError>
where Location: UnwindSafe, ExternalError: UnwindSafe, Tag: UnwindSafe, Context: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<I, T> ExtractContext<I, ()> for T

Source§

fn extract_context(self, _original_input: I)

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Indentable for T
where T: Display,

Source§

fn indented(self, indent: &str) -> Indented<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line of the formatted output will be prefixed with the indent. Read more
Source§

fn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line except for the first of the formatted output will be prefixed with the indent. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<I> RecreateContext<I> for I

Source§

fn recreate_context(_original_input: I, tail: I) -> I

Given the original input, as well as the context reported by nom, recreate a context in the original string where the error occurred. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.