#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BinaryOp {
And,
Or,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UnaryOp {
Not,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Expression {
Boolean(bool),
Function { name: String, args: Vec<String> },
Binary {
left: Box<Expression>,
op: BinaryOp,
right: Box<Expression>,
},
Unary { op: UnaryOp, expr: Box<Expression> },
Group(Box<Expression>),
}
impl Expression {
pub fn function(name: impl Into<String>, args: Vec<String>) -> Self {
Expression::Function {
name: name.into(),
args,
}
}
pub fn and(left: Expression, right: Expression) -> Self {
Expression::Binary {
left: Box::new(left),
op: BinaryOp::And,
right: Box::new(right),
}
}
pub fn or(left: Expression, right: Expression) -> Self {
Expression::Binary {
left: Box::new(left),
op: BinaryOp::Or,
right: Box::new(right),
}
}
#[allow(clippy::should_implement_trait)]
pub fn not(expr: Expression) -> Self {
Expression::Unary {
op: UnaryOp::Not,
expr: Box::new(expr),
}
}
pub fn group(expr: Expression) -> Self {
Expression::Group(Box::new(expr))
}
}