lalrpop_util

Enum ParseError

Source
pub enum ParseError<L, T, E> {
    InvalidToken {
        location: L,
    },
    UnrecognizedEof {
        location: L,
        expected: Vec<String>,
    },
    UnrecognizedToken {
        token: (L, T, L),
        expected: Vec<String>,
    },
    ExtraToken {
        token: (L, T, L),
    },
    User {
        error: E,
    },
}
Expand description

Error type for errors returned by lalrpop parsers.

For the built-in lexer, the generic parameters default to: ParseError<usize, lexer::Token<’_>, &’static str>.

L: the location of the Token where the error occurred T: The token encountered where the error occurred E: A custom user-defined error

L and T are fixed types as listed above for built in lexers, and can be defined to whatever type you would like if implementing a custom lexer.

The type of E can be overridden by specifying type Error in your grammar like so:

extern {
    type Error = MyCustomErrorType;
}

Variants§

§

InvalidToken

Generated by the internal lexer when it encounters a token (or EOF) it did not expect.

Fields

§location: L

The end of the invalid token.

§

UnrecognizedEof

Generated by the parser when it encounters an EOF it did not expect.

Fields

§location: L

The end of the final token.

§expected: Vec<String>

The set of expected tokens: these names are taken from the grammar and hence may not necessarily be suitable for presenting to the user.

§

UnrecognizedToken

Generated by the parser when it encounters a token it did not expect.

This means that the next token in the stream was not valid at this point in the grammar.

Fields

§token: (L, T, L)

The unexpected token of type T with a span given by the two L values.

§expected: Vec<String>

The set of expected tokens: these names are taken from the grammar and hence may not necessarily be suitable for presenting to the user.

§

ExtraToken

Generated by the parser when it encounters additional, unexpected tokens.

Fields

§token: (L, T, L)

The extra token, with a type of T with a span given by the two L values.

§

User

Custom error type.

Fields

§error: E

Custom user error.

Implementations§

Source§

impl<L, T, E> ParseError<L, T, E>

Source

pub fn map_location<LL>(self, op: impl FnMut(L) -> LL) -> ParseError<LL, T, E>

Transform a ParseError by applying a function to the location field.

This could be useful to ensure that all fields implement some trait, or to apply an offset to a location.

(Note that unlike map_token() and map_error(), the closure argument for this function is FnMut. This is so that it can be called multiple times to apply to the starting and ending location of tokens.)

Source

pub fn map_token<TT>(self, op: impl FnOnce(T) -> TT) -> ParseError<L, TT, E>

Transform a ParseError by applying a function to the token field.

This could be useful to ensure that all fields implement some trait, or to transform a token in some way (eg escaping).

Source

pub fn map_error<EE>(self, op: impl FnOnce(E) -> EE) -> ParseError<L, T, EE>

Transform a ParseError by applying a function to the error field.

This could be useful to ensure that all fields implement some trait, or to transform to a different error type in place.

Trait Implementations§

Source§

impl<L: Clone, T: Clone, E: Clone> Clone for ParseError<L, T, E>

Source§

fn clone(&self) -> ParseError<L, T, E>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: Debug, T: Debug, E: Debug> Debug for ParseError<L, T, E>

Source§

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

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

impl<L, T, E> Display for ParseError<L, T, E>
where L: Display, T: Display, E: Display,

Source§

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

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

impl<L, T, E> Error for ParseError<L, T, E>
where L: Debug + Display, T: Debug + Display, E: Debug + Display,

Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
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 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<L, T, E> From<E> for ParseError<L, T, E>

Source§

fn from(error: E) -> Self

Converts to this type from the input type.
Source§

impl<L: Ord, T: Ord, E: Ord> Ord for ParseError<L, T, E>

Source§

fn cmp(&self, other: &ParseError<L, T, E>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<L: PartialEq, T: PartialEq, E: PartialEq> PartialEq for ParseError<L, T, E>

Source§

fn eq(&self, other: &ParseError<L, T, E>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<L: PartialOrd, T: PartialOrd, E: PartialOrd> PartialOrd for ParseError<L, T, E>

Source§

fn partial_cmp(&self, other: &ParseError<L, T, E>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<L: Eq, T: Eq, E: Eq> Eq for ParseError<L, T, E>

Source§

impl<L, T, E> StructuralPartialEq for ParseError<L, T, E>

Auto Trait Implementations§

§

impl<L, T, E> Freeze for ParseError<L, T, E>
where L: Freeze, E: Freeze, T: Freeze,

§

impl<L, T, E> RefUnwindSafe for ParseError<L, T, E>

§

impl<L, T, E> Send for ParseError<L, T, E>
where L: Send, E: Send, T: Send,

§

impl<L, T, E> Sync for ParseError<L, T, E>
where L: Sync, E: Sync, T: Sync,

§

impl<L, T, E> Unpin for ParseError<L, T, E>
where L: Unpin, E: Unpin, T: Unpin,

§

impl<L, T, E> UnwindSafe for ParseError<L, T, E>
where L: UnwindSafe, E: UnwindSafe, T: 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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.