2025-05-03 18:39:36 +02:00
|
|
|
use crate::{
|
|
|
|
|
command::CommandParseError, meta_commands::MetaCommandParseError,
|
|
|
|
|
statements::StatementParseError,
|
|
|
|
|
};
|
2025-05-03 21:31:26 +02:00
|
|
|
use ariadne::{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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl OSDBError for MetaCommandParseError {
|
2025-05-03 21:31:26 +02:00
|
|
|
fn display(&self, file: &str, input: &str) {
|
|
|
|
|
Report::build(ReportKind::Error, (file, 0..input.len()))
|
|
|
|
|
.with_message(format!("{self}"))
|
|
|
|
|
.finish()
|
|
|
|
|
.print((file, Source::from(input)))
|
|
|
|
|
.unwrap();
|
2025-05-03 18:39:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl OSDBError for StatementParseError {
|
2025-05-03 21:31:26 +02:00
|
|
|
fn display(&self, file: &str, input: &str) {
|
|
|
|
|
Report::build(ReportKind::Error, (file, 0..input.len()))
|
|
|
|
|
.with_message(format!("{self}"))
|
|
|
|
|
.finish()
|
|
|
|
|
.print((file, Source::from(input)))
|
|
|
|
|
.unwrap();
|
2025-05-03 18:39:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl OSDBError for CommandParseError {
|
2025-05-03 21:31:26 +02:00
|
|
|
fn display(&self, file: &str, input: &str) {
|
|
|
|
|
match self {
|
|
|
|
|
CommandParseError::MetaCommand(err) => err.display(file, input),
|
|
|
|
|
CommandParseError::Statement(err) => err.display(file, input),
|
|
|
|
|
}
|
2025-05-03 18:39:36 +02:00
|
|
|
}
|
|
|
|
|
}
|