rimu_ast/
operator.rs

1use std::fmt::Display;
2
3/// A unary operator.
4#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
5pub enum UnaryOperator {
6    Negate,
7    Not,
8}
9
10impl Display for UnaryOperator {
11    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12        match self {
13            UnaryOperator::Negate => write!(f, "-"),
14            UnaryOperator::Not => write!(f, "!"),
15        }
16    }
17}
18
19/// A binary operator.
20#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
21pub enum BinaryOperator {
22    And,
23    Or,
24    Xor,
25    Add,
26    Subtract,
27    Multiply,
28    Divide,
29    Rem,
30    Greater,
31    GreaterEqual,
32    Less,
33    LessEqual,
34    Equal,
35    NotEqual,
36}
37
38impl Display for BinaryOperator {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        match self {
41            BinaryOperator::Add => write!(f, "+"),
42            BinaryOperator::Subtract => write!(f, "-"),
43            BinaryOperator::Multiply => write!(f, "*"),
44            BinaryOperator::Divide => write!(f, "/"),
45            BinaryOperator::Greater => write!(f, ">"),
46            BinaryOperator::GreaterEqual => write!(f, ">="),
47            BinaryOperator::Less => write!(f, "<"),
48            BinaryOperator::LessEqual => write!(f, "<="),
49            BinaryOperator::Equal => write!(f, "=="),
50            BinaryOperator::NotEqual => write!(f, "!="),
51            BinaryOperator::And => write!(f, "&&"),
52            BinaryOperator::Or => write!(f, "||"),
53            BinaryOperator::Xor => write!(f, "^"),
54            BinaryOperator::Rem => write!(f, "%"),
55        }
56    }
57}