pub struct ParseError { /* private fields */ }Expand description
Typed parse error with structured diagnostics and a
backwards compatible Display rendering.
Diagnostic detail lives behind a Box so ParseResult stays small
in Result returns (cold path allocation only).
Implementations§
Source§impl ParseError
impl ParseError
Sourcepub fn syntax(
message: String,
expected: Vec<String>,
hint: Option<String>,
ctx: &SpanContext<'_>,
) -> Self
pub fn syntax( message: String, expected: Vec<String>, hint: Option<String>, ctx: &SpanContext<'_>, ) -> Self
Low-level syntax failure. message must already contain the
parse error (expected: ...) header; the location block is
appended by Display unless already present.
Sourcepub fn invalid_syntax(
command: &str,
message: String,
found: Option<String>,
expected: Vec<String>,
hint: Option<String>,
ctx: &SpanContext<'_>,
) -> Self
pub fn invalid_syntax( command: &str, message: String, found: Option<String>, expected: Vec<String>, hint: Option<String>, ctx: &SpanContext<'_>, ) -> Self
Known command or keyword with malformed arguments.
Sourcepub fn unknown_command(
name: &str,
message: String,
hint: Option<String>,
ctx: &SpanContext<'_>,
) -> Self
pub fn unknown_command( name: &str, message: String, hint: Option<String>, ctx: &SpanContext<'_>, ) -> Self
Truly unknown command name. Callers must ensure classify
sent keyword led lines to invalid_syntax instead.
Sourcepub fn structural(rule: &str, message: String, ctx: &SpanContext<'_>) -> Self
pub fn structural(rule: &str, message: String, ctx: &SpanContext<'_>) -> Self
Structural failure (guards, blocks, WITH_IO, LET, FOR, IF).
Sourcepub fn validation(command: &str, message: String, ctx: &SpanContext<'_>) -> Self
pub fn validation(command: &str, message: String, ctx: &SpanContext<'_>) -> Self
Arity, flag, or static type failure for a known command.
Sourcepub fn from_diagnostic(
kind: ParseErrorKind,
diagnostic: Diagnostic,
ctx: &SpanContext<'_>,
) -> Self
pub fn from_diagnostic( kind: ParseErrorKind, diagnostic: Diagnostic, ctx: &SpanContext<'_>, ) -> Self
Build from an owning keyed Diagnostic. The diagnostic’s
rendered message becomes the legacy body (so Display output
is unchanged) and its hint is forwarded when the diagnostic
carries one. The ctx span is synced onto both the error and
the embedded diagnostic, so err.diagnostic().span() matches
the error’s span; later ParseError::with_span enrichment
keeps them in sync the same way.
Sourcepub fn diagnostic(&self) -> Option<&Diagnostic>
pub fn diagnostic(&self) -> Option<&Diagnostic>
Owning keyed diagnostic, when built via ParseError::from_diagnostic.
Sourcepub fn key(&self) -> Option<&'static str>
pub fn key(&self) -> Option<&'static str>
Stable dotted key of the owning diagnostic, when present.
Sourcepub fn with_span(self, ctx: &SpanContext<'_>) -> Self
pub fn with_span(self, ctx: &SpanContext<'_>) -> Self
Enrich an error produced without span context (e.g. from a
direct lower_command call) with the caller’s location.
Existing span fields are only overwritten when the current
value is None, so lexer spans are never clobbered. The
embedded diagnostic (when present) is synced the same way:
a span is attached only while it has none.
Sourcepub fn with_found(self, found: Option<String>) -> Self
pub fn with_found(self, found: Option<String>) -> Self
Attach the found text (builder style). Used by the
invalid_syntax path, whose helper computes it alongside the
diagnostic.
Sourcepub fn with_expected(self, expected: Vec<String>) -> Self
pub fn with_expected(self, expected: Vec<String>) -> Self
Attach expected syntax alternatives (builder style). Used by
the invalid_syntax path to keep expected() informative
through the diagnostic migration.
Sourcepub fn with_hint(self, hint: Option<String>) -> Self
pub fn with_hint(self, hint: Option<String>) -> Self
Attach the hint (builder style). Used by the invalid_syntax
and unknown_command paths: the hint rides inline in the
diagnostic message for legacy Display parity, and here so
the hint() accessor keeps working.
Sourcepub fn kind(&self) -> &ParseErrorKind
pub fn kind(&self) -> &ParseErrorKind
Machine readable kind.
Sourcepub fn source_line(&self) -> Option<&str>
pub fn source_line(&self) -> Option<&str>
Raw source line text, when available.
Sourcepub fn step_index(&self) -> Option<usize>
pub fn step_index(&self) -> Option<usize>
Zero-based step index, when known.
Trait Implementations§
Source§impl Clone for ParseError
impl Clone for ParseError
Source§impl Debug for ParseError
impl Debug for ParseError
Source§impl Display for ParseError
impl Display for ParseError
Source§impl Error for ParseError
impl Error for ParseError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()