//! Repl commands use super::*; use std::str::FromStr; use super::env::*; #[derive(Debug)] pub struct Context<'a> { /// Environment containing variable name mappings. env: &'a mut Lexenv, } /// Trait for commands. /// /// # Defining commands /// A command object should be created once only, and then referenced and executed using `params` and through mutating `cx`. pub trait Command: fmt::Debug { fn execute(&self, cx: &mut Context<'_>, params: Vec) -> eyre::Result<()>; } /// Command structurally parsed. /// /// Can be converted into `Command` with the `TryInto` trait. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct IR { op: String, params: Vec, } impl FromStr for IR { type Err = CommandParseError; fn from_str(s: &str) -> Result { todo!() } } /// Error when parsing a command into `IR`. #[derive(Debug)] pub struct CommandParseError(String); impl error::Error for CommandParseError{} impl fmt::Display for CommandParseError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "failed to parse command from {:?}", self.0) } }