use core::fmt;
#[derive(Debug, PartialEq, Eq)]
pub enum CommandParseError<'a> {
UnknownCommand(&'a String),
MissingArguments(Vec<&'a str>),
IncompleteCommand,
ExecuteTooEarly,
#[cfg(feature = "lex")]
TokenTransformError(crate::lex::TokenTransformError<'a>),
#[cfg(feature = "lex")]
TokenTransformErrorRef(&'a crate::lex::TokenTransformError<'a>),
}
impl fmt::Display for CommandParseError<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CommandParseError::UnknownCommand(command) => {
write!(f, "Unknown command: {}", command)
}
CommandParseError::MissingArguments(missing) => {
write!(f, "Missing arguments: {}", missing.join(", "))
}
CommandParseError::IncompleteCommand => write!(f, "Incomplete command"),
CommandParseError::ExecuteTooEarly => write!(f, "Execute too early"),
#[cfg(feature = "lex")]
CommandParseError::TokenTransformError(error) => {
write!(f, "Token transform error: {}", error)
}
#[cfg(feature = "lex")]
CommandParseError::TokenTransformErrorRef(error) => {
write!(f, "Token transform error: {}", error)
}
}
}
}
impl std::error::Error for CommandParseError<'_> {}
#[cfg(feature = "lex")]
impl<'a> From<crate::lex::TokenTransformError<'a>> for CommandParseError<'a> {
fn from(err: crate::lex::TokenTransformError<'a>) -> Self {
Self::TokenTransformError(err)
}
}
#[cfg(feature = "lex")]
impl<'a> From<&'a crate::lex::TokenTransformError<'a>> for CommandParseError<'a> {
fn from(err: &'a crate::lex::TokenTransformError<'a>) -> Self {
Self::TokenTransformErrorRef(err)
}
}