pub struct ParseFail {
pub input_span: (usize, usize),
pub expected: String,
pub parser_span: Option<(u32, u32)>,
pub partial: Option<GcRef>,
}Expand description
A single parse mismatch (§7.11), carrying structured detail for the crash debugger and the noninteractive fallback.
Constructed by the parser interpreter at each failure site via
ParseFail::here; the ParseDetail slot keeps the most specific one.
Fields§
§input_span: (usize, usize)[start, end) byte offsets into the input buffer where the mismatch
occurred. end may equal start for a zero-width expectation (e.g.
“expected a digit, found end-of-input”).
expected: StringWhat the parser expected, as a short human description ("int",
"literal ':'", "section header", "6 sections for `shapes`", …).
A String rather than a &'static str precisely so a description can
name the thing that came up short.
parser_span: Option<(u32, u32)>The source span of the failing parser expression (byte offsets into the
program source). None when no span was threaded (an internal-only
plan node); the renderer falls back to <unknown parser>.
partial: Option<GcRef>The best-effort partial root value built before the failure (the deepest
successfully-assembled sub-value), or None when no partial value was
available. The collector retains it because the runtime roots
ParseDetail (see crate::ParseDetail).
Implementations§
Source§impl ParseFail
impl ParseFail
Sourcepub fn here(offset: usize, expected: impl Into<String>) -> Self
pub fn here(offset: usize, expected: impl Into<String>) -> Self
Construct a failure at offset (zero-width) expecting expected.
Convenience for the common “found X, expected Y at this point” case.
Sourcepub fn at(offset: usize, len: usize, expected: impl Into<String>) -> Self
pub fn at(offset: usize, len: usize, expected: impl Into<String>) -> Self
With a width: the mismatch span is [offset, offset + len).
Sourcepub fn with_parser_span(self, span: Option<(u32, u32)>) -> Self
pub fn with_parser_span(self, span: Option<(u32, u32)>) -> Self
Attach the source span of the failing parser expression.
Sourcepub fn with_partial(self, partial: Option<GcRef>) -> Self
pub fn with_partial(self, partial: Option<GcRef>) -> Self
Attach the best-effort partial root value.