pub struct ParseError<'t> {
pub text: &'t str,
pub message: String,
}
Expand description
Tracks an error that occurred while parsing. The parse error records the input text it saw, which will be some suffix of the original input, along with a message.
The actual ParseResult
type tracks a set of parse errors.
When parse errors are generated, there is just one (e.g., “expected identifier”),
but when there are choice points in the grammar (e.g., when parsing an enum),
those errors can be combined by require_unambiguous
.
Fields§
§text: &'t str
Input that triggered the parse error. Some suffix of the original input.
message: String
Message describing what was expected.
Implementations§
Source§impl<'t> ParseError<'t>
impl<'t> ParseError<'t>
Sourcepub fn at(text: &'t str, message: String) -> Set<Self>
pub fn at(text: &'t str, message: String) -> Set<Self>
Creates a single parse error at the given point. Returns
a set so that it can be wrapped as a ParseResult
.
Sourcepub fn offset(&self, text: &str) -> usize
pub fn offset(&self, text: &str) -> usize
Offset of this error relative to the starting point text
Sourcepub fn consumed_before<'s>(&self, text: &'s str) -> &'s str
pub fn consumed_before<'s>(&self, text: &'s str) -> &'s str
Returns the text that was consumed before this error occurred,
with text
is the starting point.
Trait Implementations§
Source§impl<'t> Clone for ParseError<'t>
impl<'t> Clone for ParseError<'t>
Source§fn clone(&self) -> ParseError<'t>
fn clone(&self) -> ParseError<'t>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more