#[derive(Clone, Copy)] pub enum Operator { Equal, NotEqual, LessThan, GreaterThan, LessThanEqual, GreaterThanEqual, Add, Subtract, Multiply, Divide, Modulo, Exponent, LeftShift, RightShift, BitAnd, BitOr, BitXor, BitNot, Length, } impl Operator { pub fn from_str(string: &str) -> Option { match string { "=" => Some(Operator::Equal), "==" => Some(Operator::Equal), "" => Some(Operator::Equal), "!=" => Some(Operator::NotEqual), "" => Some(Operator::NotEqual), "<" => Some(Operator::LessThan), "" => Some(Operator::LessThan), ">" => Some(Operator::GreaterThan), "" => Some(Operator::GreaterThan), "<=" => Some(Operator::LessThanEqual), "" => Some(Operator::LessThanEqual), ">=" => Some(Operator::GreaterThanEqual), "" => Some(Operator::GreaterThanEqual), "+" => Some(Operator::Add), "" => Some(Operator::Add), "-" => Some(Operator::Subtract), "" => Some(Operator::Subtract), "*" => Some(Operator::Multiply), "" => Some(Operator::Multiply), "/" => Some(Operator::Divide), "
" => Some(Operator::Divide), "" => Some(Operator::Modulo), "**" => Some(Operator::Exponent), "" => Some(Operator::Exponent), "<<" => Some(Operator::LeftShift), "" => Some(Operator::LeftShift), ">>" => Some(Operator::RightShift), "" => Some(Operator::RightShift), "" => Some(Operator::BitAnd), "" => Some(Operator::BitOr), "" => Some(Operator::BitXor), "" => Some(Operator::BitNot), "" => Some(Operator::Length), _ => None, } } } impl std::fmt::Display for Operator { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { let string = match self { Operator::Equal => "", Operator::NotEqual => "", Operator::LessThan => "", Operator::GreaterThan => "", Operator::LessThanEqual => "", Operator::GreaterThanEqual => "", Operator::Add => "", Operator::Subtract => "", Operator::Multiply => "", Operator::Divide => "
", Operator::Modulo => "", Operator::Exponent => "", Operator::LeftShift => "", Operator::RightShift => "", Operator::BitAnd => "", Operator::BitOr => "", Operator::BitXor => "", Operator::BitNot => "", Operator::Length => "", }; write!(f, "{string}") } }