forked from M-Labs/nac3
added operators
This commit is contained in:
parent
7b1ea58bc0
commit
1cc4c3f8d4
@ -6,6 +6,7 @@ pub mod inference;
|
|||||||
pub mod primitives;
|
pub mod primitives;
|
||||||
pub mod typedef;
|
pub mod typedef;
|
||||||
pub mod expression;
|
pub mod expression;
|
||||||
|
mod operators;
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
41
nac3core/src/operators.rs
Normal file
41
nac3core/src/operators.rs
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user