use std::rc::Rc; use std::str::FromStr; use crate::builtin::Builtin; #[derive(Debug, PartialEq, Clone)] pub struct PrefixOp { pub sigil: Rc, pub builtin: Option, } impl PrefixOp { pub fn sigil(&self) -> &Rc { &self.sigil } pub fn is_prefix(op: &str) -> bool { match op { "+" => true, "-" => true, "!" => true, _ => false } } } impl FromStr for PrefixOp { type Err = (); fn from_str(s: &str) -> Result { use Builtin::*; let builtin = match s { "+" => Ok(Increment), "-" => Ok(Negate), "!" => Ok(BooleanNot), _ => Err(()) }; builtin.map(|builtin| PrefixOp { sigil: Rc::new(s.to_string()), builtin: Some(builtin) }) } }