#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Operator{
NOT,
AND,
OR,
CON,
BICON,
}
impl Operator{
pub fn is_and(&self) -> bool{
match self{
Self::AND => true,
_ => false,
}
}
pub fn is_or(&self) -> bool{
match self{
Self::OR => true,
_ => false,
}
}
pub fn is_con(&self) -> bool{
match self{
Self::CON => true,
_ => false,
}
}
pub fn is_bicon(&self) -> bool{
match self{
Self::BICON => true,
_ => false,
}
}
pub fn is_not(&self) -> bool{
match self{
Self::NOT => true,
_ => false,
}
}
pub fn precedence(&self) -> u8{
match self{
Self::AND => 3,
Self::OR => 3,
Self::CON => 2,
Self::BICON => 1,
Self::NOT => 0,
}
}
pub fn execute(&self, left: bool, right: bool) -> bool{
match self{
Self::AND => left && right,
Self::OR => left || right,
Self::CON => !left || right,
Self::BICON => left == right,
Self::NOT => panic!("Operator nodes cannot be Negation nodes"),
}
}
pub fn short_circuit(&self, left: bool) -> Option<bool>{
match self{
Self::AND => if !left {Some(false)} else {None},
Self::OR => if left {Some(true)} else {None},
Self::CON => if !left {Some(true)} else {None} ,
Self::BICON => None,
Self::NOT => panic!("Operator nodes cannot be Negation nodes"),
}
}
}