pub struct ErrorDetails<'a> {
pub source_name: Box<str>,
pub source_content: &'a str,
pub error_offset: u32,
pub line_start: u32,
pub line_end: u32,
pub kind: Box<ErrorKind>,
pub severity: Severity,
pub labels: Vec<DiagnosticLabel>,
pub notes: Vec<String>,
}Expand description
Contains detailed information about an error that occurred during parsing.
This struct contains the source name, source content, error offset,
line start and end positions, and the kind of error. All errors now use
the unified ErrorKind type.
Example usage:
use vb6parse::errors::{ErrorDetails, ErrorKind, Severity, LexerError};
let error_details = ErrorDetails {
source_name: "example.cls".to_string().into_boxed_str(),
source_content: "Some VB6 code here...",
error_offset: 10,
line_start: 1,
line_end: 1,
kind: Box::new(ErrorKind::Lexer(LexerError::UnknownToken { token: "???".to_string() })),
severity: Severity::Error,
labels: vec![],
notes: vec![],
};
error_details.print();Fields§
§source_name: Box<str>The name of the source file where the error occurred.
source_content: &'a strThe content of the source file where the error occurred.
error_offset: u32The offset in the source content where the error occurred.
Note: This is a u32 to reflect VB6’s 32-bit addressing limitations.
line_start: u32The starting line number of the error.
Note: This is a u32 to reflect VB6’s 32-bit addressing limitations.
line_end: u32The ending line number of the error.
Note: This is a u32 to reflect VB6’s 32-bit addressing limitations.
kind: Box<ErrorKind>The kind of error that occurred.
Boxed to reduce the size of Result<T, ErrorDetails> on the stack.
severity: SeverityThe severity of this diagnostic (Error, Warning, or Note).
labels: Vec<DiagnosticLabel>Additional labeled spans for multi-span diagnostics. This allows annotating multiple locations in the source code within a single error message.
notes: Vec<String>Additional notes to provide context for this diagnostic. These are displayed after the main error message.
Implementations§
Source§impl<'a> ErrorDetails<'a>
impl<'a> ErrorDetails<'a>
Sourcepub fn basic<E>(
source_name: Box<str>,
source_content: &'a str,
error_offset: u32,
line_start: u32,
line_end: u32,
kind: E,
severity: Severity,
) -> ErrorDetails<'a>
pub fn basic<E>( source_name: Box<str>, source_content: &'a str, error_offset: u32, line_start: u32, line_end: u32, kind: E, severity: Severity, ) -> ErrorDetails<'a>
Creates a basic ErrorDetails with no labels or notes.
This is a convenience constructor for the common case where only the basic error information is needed.
Accepts any error type that can be converted to ErrorKind, including
layer-specific errors like LexerError, ModuleError, ProjectError, etc.
Sourcepub fn with_label(self, label: DiagnosticLabel) -> Self
pub fn with_label(self, label: DiagnosticLabel) -> Self
Adds a labeled span to this error.
Sourcepub fn with_labels(self, labels: Vec<DiagnosticLabel>) -> Self
pub fn with_labels(self, labels: Vec<DiagnosticLabel>) -> Self
Adds multiple labeled spans to this error.
Sourcepub fn with_notes(self, notes: Vec<String>) -> Self
pub fn with_notes(self, notes: Vec<String>) -> Self
Adds multiple notes to this error.
Sourcepub fn emit(self, ctx: &mut ParserContext<'a>)
pub fn emit(self, ctx: &mut ParserContext<'a>)
Emit this error by pushing it to the provided parser context.
This is a terminal operation that consumes the error and adds it to the context’s error collection.
§Example
use vb6parse::errors::{ParserContext, DiagnosticLabel, LexerError, Span};
let mut ctx = ParserContext::new("test.bas", "Dim x");
let span = Span::at(0, 1);
let label_span = Span::at(4, 1);
ctx.error_with(span, LexerError::UnknownToken { token: "x".to_string() })
.with_label(DiagnosticLabel::new(label_span, "here"))
.with_note("Consider using 'Integer' instead")
.emit(&mut ctx);Source§impl ErrorDetails<'_>
impl ErrorDetails<'_>
Sourcepub fn print(&self)
pub fn print(&self)
Print the ErrorDetails using ariadne for formatting.
Example usage:
use vb6parse::errors::{ErrorDetails, ErrorKind, Severity, LexerError};
let error_details = ErrorDetails {
source_name: "example.cls".to_string().into_boxed_str(),
source_content: "Some VB6 code here...",
error_offset: 10,
line_start: 1,
line_end: 1,
kind: Box::new(ErrorKind::Lexer(LexerError::UnknownToken { token: "???".to_string() })),
severity: Severity::Error,
labels: vec![],
notes: vec![],
};
error_details.print();Sourcepub fn eprint(&self)
pub fn eprint(&self)
Eprint the ErrorDetails using ariadne for formatting.
Example usage:
use vb6parse::errors::{ErrorDetails, ErrorKind, Severity, LexerError};
let error_details = ErrorDetails {
source_name: "example.cls".to_string().into_boxed_str(),
source_content: "Some VB6 code here...",
error_offset: 10,
line_start: 1,
line_end: 1,
kind: Box::new(ErrorKind::Lexer(LexerError::UnknownToken {
token: "???".to_string(),
})),
severity: Severity::Error,
labels: vec![],
notes: vec![],
};
error_details.eprint();Trait Implementations§
Source§impl<'a> Clone for ErrorDetails<'a>
impl<'a> Clone for ErrorDetails<'a>
Source§fn clone(&self) -> ErrorDetails<'a>
fn clone(&self) -> ErrorDetails<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for ErrorDetails<'a>
impl<'a> Debug for ErrorDetails<'a>
Auto Trait Implementations§
impl<'a> Freeze for ErrorDetails<'a>
impl<'a> RefUnwindSafe for ErrorDetails<'a>
impl<'a> Send for ErrorDetails<'a>
impl<'a> Sync for ErrorDetails<'a>
impl<'a> Unpin for ErrorDetails<'a>
impl<'a> UnsafeUnpin for ErrorDetails<'a>
impl<'a> UnwindSafe for ErrorDetails<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);