use crate::jsonpath::ast::function::functions::LogicalTypeFunction;
use super::comparison::ComparisonExpr;
use super::query::Query;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum LogicalExpr {
Comparison(ComparisonExpr),
Test(TestExpr),
And(AndExpr),
Or(OrExpr),
Not(NotExpr),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TestExpr {
not: bool,
kind: TestExprKind,
}
impl TestExpr {
pub fn new(not: bool, kind: TestExprKind) -> Self {
Self { not, kind }
}
pub fn not(&self) -> bool {
self.not
}
pub fn kind(&self) -> &TestExprKind {
&self.kind
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum TestExprKind {
FilterQuery(Query),
LogicalTypeFunction(Box<LogicalTypeFunction>),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AndExpr {
operands: Vec<LogicalExpr>,
}
impl AndExpr {
pub fn new(operands: Vec<LogicalExpr>) -> Self {
Self { operands }
}
pub fn operands(&self) -> &Vec<LogicalExpr> {
&self.operands
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OrExpr {
operands: Vec<LogicalExpr>,
}
impl OrExpr {
pub fn new(operands: Vec<LogicalExpr>) -> Self {
Self { operands }
}
pub fn operands(&self) -> &Vec<LogicalExpr> {
&self.operands
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NotExpr {
expr: Box<LogicalExpr>,
}
impl NotExpr {
pub fn new(expr: LogicalExpr) -> Self {
Self {
expr: Box::new(expr),
}
}
pub fn expr(&self) -> &LogicalExpr {
&self.expr
}
}