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.
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
ExtraToken
Generated by the parser when it encounters additional, unexpected tokens.
User
Custom error type.
Fields
error: E
Custom user error.
Implementations§
Source§impl<L, T, E> ParseError<L, T, E>
impl<L, T, E> ParseError<L, T, E>
Sourcepub fn map_location<LL>(self, op: impl FnMut(L) -> LL) -> ParseError<LL, T, E>
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.)
Sourcepub fn map_token<TT>(self, op: impl FnOnce(T) -> TT) -> ParseError<L, TT, E>
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).
Sourcepub fn map_error<EE>(self, op: impl FnOnce(E) -> EE) -> ParseError<L, T, EE>
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>
impl<L: Clone, T: Clone, E: Clone> Clone for ParseError<L, T, E>
Source§fn clone(&self) -> ParseError<L, T, E>
fn clone(&self) -> ParseError<L, T, E>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more