From b8ed0868cb892e61861baa2a08af23400230acee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Sun, 4 May 2025 13:36:39 +0200 Subject: [PATCH] feat(CommandParseError): add ScanError variand with Into impl --- notes.org | 5 ++++- src/command.rs | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/notes.org b/notes.org index c440953..47adb70 100644 --- a/notes.org +++ b/notes.org @@ -145,10 +145,13 @@ CLOCK: [2025-05-04 dim. 13:32]--[2025-05-04 dim. 13:35] => 0:03 CLOCK: [2025-05-04 dim. 13:27]--[2025-05-04 dim. 13:32] => 0:05 :END: -*** TODO CommandParseError must have a ScanError variant with an Into impl +*** DONE CommandParseError must have a ScanError variant with an Into impl :PROPERTIES: :EFFORT: 10 :END: +:LOGBOOK: +CLOCK: [2025-05-04 dim. 13:35]--[2025-05-04 dim. 13:38] => 0:03 +:END: *** TODO ScanErrors must be convertible to ariadne reports :PROPERTIES: diff --git a/src/command.rs b/src/command.rs index 32e4cd0..cfbfd5e 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,5 +1,6 @@ use crate::meta_commands::{MetaCommand, MetaCommandExecuteResult, MetaCommandParseError}; use crate::statements::{Statement, StatementExecuteResult, StatementParseError}; +use crate::tokens::ScanError; #[derive(Debug)] pub enum Command { @@ -50,6 +51,7 @@ impl Command { pub enum CommandParseError { MetaCommand(MetaCommandParseError), Statement(StatementParseError), + Scan(ScanError), } impl std::fmt::Display for CommandParseError { @@ -61,6 +63,7 @@ impl std::fmt::Display for CommandParseError { CommandParseError::Statement(statement_parse_error) => { write!(f, "{statement_parse_error}") } + CommandParseError::Scan(scan_error) => write!(f, "{scan_error:?}"), } } } @@ -89,6 +92,12 @@ impl From for CommandParseError { } } +impl From for CommandParseError { + fn from(value: ScanError) -> Self { + CommandParseError::Scan(value) + } +} + impl std::str::FromStr for Command { type Err = CommandParseError;