pub enum Error<T, R> {
Unexpected(Info<T, R>),
Expected(Info<T, R>),
Message(Info<T, R>),
Other(Box<dyn StdError + Send + Sync>),
}
Expand description
Enum used to store information about an error that has occurred during parsing.
Variants§
Unexpected(Info<T, R>)
Error indicating an unexpected token has been encountered in the stream
Expected(Info<T, R>)
Error indicating that the parser expected something else
Message(Info<T, R>)
Generic message
Other(Box<dyn StdError + Send + Sync>)
Variant for containing other types of errors
Implementations§
source§impl<T, R> Error<T, R>
impl<T, R> Error<T, R>
sourcepub fn end_of_input() -> Error<T, R>
pub fn end_of_input() -> Error<T, R>
Returns the end_of_input
error.
sourcepub fn fmt_errors(errors: &[Error<T, R>], f: &mut Formatter<'_>) -> Result
pub fn fmt_errors(errors: &[Error<T, R>], f: &mut Formatter<'_>) -> Result
Formats a slice of errors in a human readable way.
let input = r"
,123
";
let result = spaces().silent().with(char('.').or(char('a')).or(digit()))
.easy_parse(position::Stream::new(input));
let m = format!("{}", result.unwrap_err());
let expected = r"Parse error at line: 2, column: 3
Unexpected `,`
Expected `.`, `a` or digit
";
assert_eq!(m, expected);
Trait Implementations§
source§impl<Item, Range, Position> ParseError<Item, Range, Position> for Error<Item, Range>
impl<Item, Range, Position> ParseError<Item, Range, Position> for Error<Item, Range>
type StreamError = Error<Item, Range>
source§fn from_error(_: Position, err: Self::StreamError) -> Self
fn from_error(_: Position, err: Self::StreamError) -> Self
Creates a
ParseError
from a single Self::StreamError
fn position(&self) -> Position
source§fn set_position(&mut self, _position: Position)
fn set_position(&mut self, _position: Position)
Sets the position of this
ParseError
source§fn add(&mut self, err: Self::StreamError)
fn add(&mut self, err: Self::StreamError)
source§fn set_expected<F>(self_: &mut Tracked<Self>, info: Self::StreamError, f: F)
fn set_expected<F>(self_: &mut Tracked<Self>, info: Self::StreamError, f: F)
Sets
info
as the only Expected
error of self
fn is_unexpected_end_of_input(&self) -> bool
source§fn into_other<T>(self) -> Twhere
T: ParseError<Item, Range, Position>,
fn into_other<T>(self) -> Twhere
T: ParseError<Item, Range, Position>,
Does a best-effort conversion of
self
into another ParseError
source§fn merge(self, other: Self) -> Self
fn merge(self, other: Self) -> Self
Merges two errors. If they exist at the same position the errors of
other
are
added to self
(using the semantics of add
). If they are not at the same
position the error furthest ahead are returned, ignoring the other ParseError
.fn add_expected<E>(&mut self, info: E)where
E: for<'s> ErrorInfo<'s, Item, Range>,
fn add_unexpected<E>(&mut self, info: E)where
E: for<'s> ErrorInfo<'s, Item, Range>,
fn add_message<E>(&mut self, info: E)where
E: for<'s> ErrorInfo<'s, Item, Range>,
source§fn clear_expected(&mut self)
fn clear_expected(&mut self)
Removes any expected errors currently in
self
source§impl<Item, Range> StreamError<Item, Range> for Error<Item, Range>
impl<Item, Range> StreamError<Item, Range> for Error<Item, Range>
fn unexpected_token(token: Item) -> Self
fn unexpected_range(token: Range) -> Self
fn unexpected_format<T>(msg: T) -> Selfwhere
T: Display,
fn unexpected_static_message(msg: &'static str) -> Self
fn expected_token(token: Item) -> Self
fn expected_range(token: Range) -> Self
fn expected_format<T>(msg: T) -> Selfwhere
T: Display,
fn expected_static_message(msg: &'static str) -> Self
fn message_format<T>(msg: T) -> Selfwhere
T: Display,
fn message_static_message(msg: &'static str) -> Self
fn message_token(token: Item) -> Self
fn message_range(token: Range) -> Self
fn is_unexpected_end_of_input(&self) -> bool
fn other<E>(err: E) -> Self
source§fn into_other<T>(self) -> Twhere
T: StreamError<Item, Range>,
fn into_other<T>(self) -> Twhere
T: StreamError<Item, Range>,
fn unexpected<E>(info: E) -> Selfwhere
E: for<'s> ErrorInfo<'s, Item, Range>,
fn expected<E>(info: E) -> Selfwhere
E: for<'s> ErrorInfo<'s, Item, Range>,
fn message<E>(info: E) -> Selfwhere
E: for<'s> ErrorInfo<'s, Item, Range>,
fn end_of_input() -> Self
source§impl<Item, Range> StreamErrorInto<Item, Range> for Error<Item, Range>
impl<Item, Range> StreamErrorInto<Item, Range> for Error<Item, Range>
fn into_other_error<T, Item2, Range2>(self) -> T
Auto Trait Implementations§
impl<T, R> Freeze for Error<T, R>
impl<T, R> !RefUnwindSafe for Error<T, R>
impl<T, R> Send for Error<T, R>
impl<T, R> Sync for Error<T, R>
impl<T, R> Unpin for Error<T, R>
impl<T, R> !UnwindSafe for Error<T, R>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more