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
|
CLOCK: [2025-05-04 dim. 13:35]--[2025-05-04 dim. 13:38] => 0:03
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
*** TODO ScanErrors must be convertible to ariadne reports
|
*** DONE ScanErrors must be convertible to ariadne reports
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:EFFORT: 10
|
:EFFORT: 10
|
||||||
:END:
|
: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
|
CLOCK: [2025-05-04 dim. 13:38]--[2025-05-04 dim. 13:44] => 0:06
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
**** TODO implement OSDBError for ScanError
|
**** DONE implement OSDBError for ScanError
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:EFFORT: 10
|
:EFFORT: 10
|
||||||
:END:
|
: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
|
*** TODO remove token types which are not recognized at all
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::command::CommandParseError;
|
use crate::{command::CommandParseError, tokens::ScanError};
|
||||||
use ariadne::{Color, Label, Report, ReportKind, Source};
|
use ariadne::{Color, Label, Report, ReportKind, Source};
|
||||||
|
|
||||||
pub trait OSDBError {
|
pub trait OSDBError {
|
||||||
|
|
@ -7,9 +7,25 @@ pub trait OSDBError {
|
||||||
|
|
||||||
impl OSDBError for CommandParseError {
|
impl OSDBError for CommandParseError {
|
||||||
fn display(&self, file: &str, input: &str) {
|
fn display(&self, file: &str, input: &str) {
|
||||||
Report::build(ReportKind::Error, (file, 0..input.len() - 1))
|
if let CommandParseError::Scan(x) = self {
|
||||||
.with_message(self.message())
|
x.display(file, input);
|
||||||
.with_label(Label::new((file, 0..input.len() - 1)).with_color(Color::Red))
|
} 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()
|
.finish()
|
||||||
.print((file, Source::from(input)))
|
.print((file, Source::from(input)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,15 @@ pub struct Location {
|
||||||
pub length: usize,
|
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 {
|
impl Location {
|
||||||
/// ```
|
/// ```
|
||||||
/// use osdb::tokens::Location;
|
/// use osdb::tokens::Location;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue