2025-05-04 13:55:56 +02:00
|
|
|
use crate::{command::CommandParseError, tokens::ScanError};
|
2025-05-03 21:55:06 +02:00
|
|
|
use ariadne::{Color, Label, Report, ReportKind, Source};
|
2025-05-03 18:39:36 +02:00
|
|
|
|
|
|
|
|
pub trait OSDBError {
|
2025-05-03 21:29:40 +02:00
|
|
|
fn display(&self, file: &str, input: &str);
|
2025-05-03 18:39:36 +02:00
|
|
|
}
|
|
|
|
|
|
2025-05-03 21:56:12 +02:00
|
|
|
impl OSDBError for CommandParseError {
|
2025-05-03 21:31:26 +02:00
|
|
|
fn display(&self, file: &str, input: &str) {
|
2025-05-10 10:41:30 +02:00
|
|
|
let CommandParseError::Scan(x) = self;
|
|
|
|
|
x.display(file, input);
|
2025-05-04 13:55:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl OSDBError for ScanError {
|
|
|
|
|
fn display(&self, file: &str, input: &str) {
|
|
|
|
|
let location = (file, Into::<std::ops::Range<usize>>::into(&self.location));
|
|
|
|
|
Report::build(ReportKind::Error, location.clone())
|
|
|
|
|
.with_message(format!("{self}"))
|
2025-05-10 10:33:57 +02:00
|
|
|
.with_label(
|
|
|
|
|
Label::new(location)
|
|
|
|
|
.with_color(Color::Red)
|
|
|
|
|
.with_message(format!("{self}")),
|
|
|
|
|
)
|
2025-05-10 10:41:30 +02:00
|
|
|
.with_help("Make sure you don't have any typos or unexpected characters.")
|
2025-05-03 21:31:26 +02:00
|
|
|
.finish()
|
|
|
|
|
.print((file, Source::from(input)))
|
|
|
|
|
.unwrap();
|
2025-05-03 18:39:36 +02:00
|
|
|
}
|
|
|
|
|
}
|