Skip to main content

kes/
operator.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
4pub enum UnaryOperator {
5    /// !
6    Not,
7}
8
9impl UnaryOperator {
10    pub fn name(self) -> &'static str {
11        match self {
12            UnaryOperator::Not => "!",
13        }
14    }
15}
16
17#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
18pub enum BinaryOperator {
19    /// +
20    Add,
21    /// -
22    Sub,
23    /// /
24    Div,
25    /// *
26    Mul,
27    /// %
28    Rem,
29    /// &
30    And,
31    /// |
32    Or,
33    /// ^
34    Xor,
35
36    /// ==
37    Equal,
38    /// !=
39    NotEqual,
40    /// <
41    Less,
42    /// <=
43    LessOrEqual,
44    /// >
45    Greater,
46    /// >=
47    GreaterOrEqual,
48}
49
50impl BinaryOperator {
51    pub fn name(self) -> &'static str {
52        match self {
53            BinaryOperator::Add => "+",
54            BinaryOperator::Sub => "-",
55            BinaryOperator::Mul => "*",
56            BinaryOperator::Div => "/",
57            BinaryOperator::Rem => "%",
58            BinaryOperator::And => "&",
59            BinaryOperator::Or => "|",
60            BinaryOperator::Xor => "^",
61
62            BinaryOperator::Equal => "==",
63            BinaryOperator::NotEqual => "!=",
64            BinaryOperator::Greater => ">",
65            BinaryOperator::GreaterOrEqual => ">=",
66            BinaryOperator::Less => "<",
67            BinaryOperator::LessOrEqual => "<=",
68        }
69    }
70}
71
72#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
73pub enum TernaryOperator {
74    /// ? :
75    Conditional,
76}
77
78impl TernaryOperator {
79    pub fn first_name(self) -> &'static str {
80        match self {
81            TernaryOperator::Conditional => "?",
82        }
83    }
84
85    pub fn second_name(self) -> &'static str {
86        match self {
87            TernaryOperator::Conditional => ":",
88        }
89    }
90}