pub struct RichError {
pub message: String,
pub span: Span,
pub context: Option<String>,
pub children: Vec<RichError>,
pub severity: ErrorSeverity,
}Expand description
A rich, tree-structured parse error
Fields§
§message: StringThe error message
span: SpanWhere the error occurred
context: Option<String>What was being parsed (e.g., “expression”, “term”)
children: Vec<RichError>Child errors (causes)
severity: ErrorSeverityError severity
Implementations§
Source§impl RichError
impl RichError
Sourcepub fn at_position(
message: impl Into<String>,
offset: usize,
line: usize,
column: usize,
) -> Self
pub fn at_position( message: impl Into<String>, offset: usize, line: usize, column: usize, ) -> Self
Create an error at a single position
Sourcepub fn with_context(self, context: impl Into<String>) -> Self
pub fn with_context(self, context: impl Into<String>) -> Self
Add context to the error
Sourcepub fn with_child(self, child: RichError) -> Self
pub fn with_child(self, child: RichError) -> Self
Add a child error (cause)
Sourcepub fn with_severity(self, severity: ErrorSeverity) -> Self
pub fn with_severity(self, severity: ErrorSeverity) -> Self
Set severity
Sourcepub fn unexpected(found: &str, span: Span) -> Self
pub fn unexpected(found: &str, span: Span) -> Self
Create an “unexpected” error
Sourcepub fn failed_to_match(what: &str, span: Span) -> Self
pub fn failed_to_match(what: &str, span: Span) -> Self
Create a “failed to match” error
Sourcepub fn deepest_position(&self) -> Span
pub fn deepest_position(&self) -> Span
Get the deepest error position
Sourcepub fn deepest(&self) -> &RichError
pub fn deepest(&self) -> &RichError
Get the deepest error (the error that occurred at the furthest position)
Sourcepub fn ascii_tree(&self) -> String
pub fn ascii_tree(&self) -> String
Format as ASCII tree (like Parslet)
Sourcepub fn format_with_source(&self, source: &str) -> String
pub fn format_with_source(&self, source: &str) -> String
Format with source code context
Sourcepub fn format_with_source_and_captures(
&self,
source: &str,
captures: &HashMap<&str, &str>,
) -> String
pub fn format_with_source_and_captures( &self, source: &str, captures: &HashMap<&str, &str>, ) -> String
Format with source code context and captures
This method extends format_with_source to include captured values
in the error message for better debugging.
§Arguments
source- The source input that was being parsedcaptures- A HashMap of capture names to their text values
§Example
ⓘ
use parsanol::portable::{ParseError, RichError};
use std::collections::HashMap;
let error = ParseError::at_position(5);
let rich = error.into_rich("hello world");
let mut captures = HashMap::new();
captures.insert("greeting", "hello");
println!("{}", rich.format_with_source_and_captures("hello world", &captures));Trait Implementations§
Source§impl Error for RichError
impl Error for RichError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<ParseError> for RichError
impl From<ParseError> for RichError
Source§fn from(error: ParseError) -> Self
fn from(error: ParseError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for RichError
impl RefUnwindSafe for RichError
impl Send for RichError
impl Sync for RichError
impl Unpin for RichError
impl UnsafeUnpin for RichError
impl UnwindSafe for RichError
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