diff --git a/nac3core/src/lib.rs b/nac3core/src/lib.rs index 785dfc0710..8384caa9b0 100644 --- a/nac3core/src/lib.rs +++ b/nac3core/src/lib.rs @@ -6,6 +6,7 @@ pub mod inference; pub mod primitives; pub mod typedef; pub mod expression; +mod operators; use std::error::Error; use std::fmt; diff --git a/nac3core/src/operators.rs b/nac3core/src/operators.rs new file mode 100644 index 0000000000..31990d6976 --- /dev/null +++ b/nac3core/src/operators.rs @@ -0,0 +1,41 @@ +use rustpython_parser::ast::{Comparison, Operator, UnaryOperator}; + +pub fn binop_name(op: Operator) -> &'static str { + match op { + Operator::Add => "add", + Operator::Sub => "sub", + Operator::Div => "truediv", + Operator::Mod => "mod", + Operator::Mult => "mul", + Operator::Pow => "pow", + Operator::BitOr => "or", + Operator::BitXor => "xor", + Operator::BitAnd => "and", + Operator::LShift => "lshift", + Operator::RShift => "rshift", + Operator::FloorDiv => "floordiv", + Operator::MatMult => "matmul", + } +} + +pub fn unaryop_name(op: UnaryOperator) -> &'static str { + match op { + UnaryOperator::Pos => "pos", + UnaryOperator::Neg => "neg", + UnaryOperator::Not => "not", + UnaryOperator::Inv => "inv", + } +} + +pub fn comparison_name(op: Comparison) -> Option<&'static str> { + match op { + Comparison::Less => Some("lt"), + Comparison::LessOrEqual => Some("le"), + Comparison::Greater => Some("gt"), + Comparison::GreaterOrEqual => Some("ge"), + Comparison::Equal => Some("eq"), + Comparison::NotEqual => Some("ne"), + _ => None, + } +} +