use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinOp {
Add,
Sub,
Mul,
Div,
Mod,
Pow,
And,
Or,
Xor,
Shl,
Shr,
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
LogicalAnd,
LogicalOr,
}
impl fmt::Display for BinOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let op = match self {
BinOp::Add => "+",
BinOp::Sub => "-",
BinOp::Mul => "*",
BinOp::Div => "/",
BinOp::Mod => "%",
BinOp::Pow => "**",
BinOp::And => "&",
BinOp::Or => "|",
BinOp::Xor => "^",
BinOp::Shl => "<<",
BinOp::Shr => ">>",
BinOp::Eq => "==",
BinOp::Ne => "!=",
BinOp::Lt => "<",
BinOp::Le => "<=",
BinOp::Gt => ">",
BinOp::Ge => ">=",
BinOp::LogicalAnd => "&&",
BinOp::LogicalOr => "||",
};
write!(f, "{}", op)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnaryOp {
Neg,
Not,
LogicalNot,
Inc,
Dec,
Abs,
Sign,
}
impl fmt::Display for UnaryOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let op = match self {
UnaryOp::Neg => "-",
UnaryOp::Not => "~",
UnaryOp::LogicalNot => "!",
UnaryOp::Inc => "++",
UnaryOp::Dec => "--",
UnaryOp::Abs => "abs",
UnaryOp::Sign => "sign",
};
write!(f, "{}", op)
}
}