refactor(CommandParseError): remove the display implementation
we want to be able to give additional arguments to the display function later, so this is needed
This commit is contained in:
parent
b8ed0868cb
commit
55b4779964
4 changed files with 33 additions and 11 deletions
10
notes.org
10
notes.org
|
|
@ -158,7 +158,15 @@ CLOCK: [2025-05-04 dim. 13:35]--[2025-05-04 dim. 13:38] => 0:03
|
||||||
:EFFORT: 10
|
:EFFORT: 10
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
**** TODO Remove the CommandParseError Display implementation
|
**** DONE Remove the CommandParseError Display implementation
|
||||||
|
:PROPERTIES:
|
||||||
|
:EFFORT: 10
|
||||||
|
:END:
|
||||||
|
:LOGBOOK:
|
||||||
|
CLOCK: [2025-05-04 dim. 13:38]--[2025-05-04 dim. 13:44] => 0:06
|
||||||
|
:END:
|
||||||
|
|
||||||
|
**** TODO implement OSDBError for ScanError
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:EFFORT: 10
|
:EFFORT: 10
|
||||||
:END:
|
:END:
|
||||||
|
|
|
||||||
|
|
@ -54,16 +54,12 @@ pub enum CommandParseError {
|
||||||
Scan(ScanError),
|
Scan(ScanError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for CommandParseError {
|
impl CommandParseError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
pub(crate) fn message(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
CommandParseError::MetaCommand(meta_command_parse_error) => {
|
CommandParseError::MetaCommand(x) => format!("{x}"),
|
||||||
write!(f, "{meta_command_parse_error}")
|
CommandParseError::Statement(x) => format!("{x}"),
|
||||||
}
|
CommandParseError::Scan(x) => format!("{x}"),
|
||||||
CommandParseError::Statement(statement_parse_error) => {
|
|
||||||
write!(f, "{statement_parse_error}")
|
|
||||||
}
|
|
||||||
CommandParseError::Scan(scan_error) => write!(f, "{scan_error:?}"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ 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))
|
Report::build(ReportKind::Error, (file, 0..input.len() - 1))
|
||||||
.with_message(format!("{self}"))
|
.with_message(self.message())
|
||||||
.with_label(Label::new((file, 0..input.len() - 1)).with_color(Color::Red))
|
.with_label(Label::new((file, 0..input.len() - 1)).with_color(Color::Red))
|
||||||
.finish()
|
.finish()
|
||||||
.print((file, Source::from(input)))
|
.print((file, Source::from(input)))
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,30 @@ pub enum ScanErrorKind {
|
||||||
UnknownMetaCommand(String),
|
UnknownMetaCommand(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ScanErrorKind {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
ScanErrorKind::UnexpectedChar(c) => write!(f, "unexpected char: {c:?}"),
|
||||||
|
ScanErrorKind::UnexpectedEndOfInput => write!(f, "unexpected end of input"),
|
||||||
|
ScanErrorKind::UnknownKeyword(x) => write!(f, "unknown keyword: {x:?}"),
|
||||||
|
ScanErrorKind::UnknownMetaCommand(x) => write!(f, "unknown meta-command: {x:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub struct ScanError {
|
pub struct ScanError {
|
||||||
pub location: Location,
|
pub location: Location,
|
||||||
pub kind: ScanErrorKind,
|
pub kind: ScanErrorKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ScanError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let kind = &self.kind;
|
||||||
|
write!(f, "{kind}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Tokenizer {
|
impl Tokenizer {
|
||||||
fn new(input: String, file: String) -> Self {
|
fn new(input: String, file: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue