feat(ScanError) implement OSDBError trait
This commit is contained in:
parent
55b4779964
commit
80cbbab6ef
3 changed files with 34 additions and 6 deletions
|
|
@ -153,7 +153,7 @@ CLOCK: [2025-05-04 dim. 13:27]--[2025-05-04 dim. 13:32] => 0:05
|
|||
CLOCK: [2025-05-04 dim. 13:35]--[2025-05-04 dim. 13:38] => 0:03
|
||||
:END:
|
||||
|
||||
*** TODO ScanErrors must be convertible to ariadne reports
|
||||
*** DONE ScanErrors must be convertible to ariadne reports
|
||||
:PROPERTIES:
|
||||
:EFFORT: 10
|
||||
:END:
|
||||
|
|
@ -166,10 +166,13 @@ CLOCK: [2025-05-04 dim. 13:35]--[2025-05-04 dim. 13:38] => 0:03
|
|||
CLOCK: [2025-05-04 dim. 13:38]--[2025-05-04 dim. 13:44] => 0:06
|
||||
:END:
|
||||
|
||||
**** TODO implement OSDBError for ScanError
|
||||
**** DONE implement OSDBError for ScanError
|
||||
:PROPERTIES:
|
||||
:EFFORT: 10
|
||||
:END:
|
||||
:LOGBOOK:
|
||||
CLOCK: [2025-05-04 dim. 13:45]--[2025-05-04 dim. 13:56] => 0:11
|
||||
:END:
|
||||
|
||||
*** TODO remove token types which are not recognized at all
|
||||
:PROPERTIES:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::command::CommandParseError;
|
||||
use crate::{command::CommandParseError, tokens::ScanError};
|
||||
use ariadne::{Color, Label, Report, ReportKind, Source};
|
||||
|
||||
pub trait OSDBError {
|
||||
|
|
@ -7,9 +7,25 @@ pub trait OSDBError {
|
|||
|
||||
impl OSDBError for CommandParseError {
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
Report::build(ReportKind::Error, (file, 0..input.len() - 1))
|
||||
.with_message(self.message())
|
||||
.with_label(Label::new((file, 0..input.len() - 1)).with_color(Color::Red))
|
||||
if let CommandParseError::Scan(x) = self {
|
||||
x.display(file, input);
|
||||
} else {
|
||||
Report::build(ReportKind::Error, (file, 0..input.len() - 1))
|
||||
.with_message(self.message())
|
||||
.with_label(Label::new((file, 0..input.len() - 1)).with_color(Color::Red))
|
||||
.finish()
|
||||
.print((file, Source::from(input)))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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}"))
|
||||
.with_label(Label::new(location).with_color(Color::Red))
|
||||
.finish()
|
||||
.print((file, Source::from(input)))
|
||||
.unwrap();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,15 @@ pub struct Location {
|
|||
pub length: usize,
|
||||
}
|
||||
|
||||
impl From<&Location> for std::ops::Range<usize> {
|
||||
fn from(val: &Location) -> Self {
|
||||
std::ops::Range {
|
||||
start: val.offset,
|
||||
end: val.offset + val.length,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Location {
|
||||
/// ```
|
||||
/// use osdb::tokens::Location;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue