use super::{Expr, ExprList, Node, Query};
#[derive(Debug)]
pub enum Condition<'s, ID> {
Nested(Node<Box<Condition<'s, ID>>, ID>),
Exists(ExistsCondition<'s, ID>),
Between(Box<BetweenCondition<'s, ID>>),
In(Box<InCondition<'s, ID>>),
Compare(CompareCondition<'s, ID>),
And(AndCondition<'s, ID>),
Or(OrCondition<'s, ID>),
Not(NotCondition<'s, ID>),
Like(Box<LikeCondition<'s, ID>>),
RegexpLike(Box<RegexpLikeCondition<'s, ID>>),
IsNull(IsNullCondition<'s, ID>),
IsFloat(IsFloatCondition<'s, ID>),
}
#[derive(Debug)]
pub struct ExistsCondition<'s, ID> {
pub exists_token: Node<(), ID>,
pub query: Node<Box<Query<'s, ID>>, ID>,
}
#[derive(Debug)]
pub struct BetweenCondition<'s, ID> {
pub expr: Expr<'s, ID>,
pub not_token: Option<Node<(), ID>>,
pub between_token: Node<(), ID>,
pub range_from: Expr<'s, ID>,
pub and_token: Node<(), ID>,
pub range_upto: Expr<'s, ID>,
}
#[derive(Debug)]
pub struct AndCondition<'s, ID> {
pub left: Box<Condition<'s, ID>>,
pub and_token: Node<(), ID>,
pub right: Box<Condition<'s, ID>>,
}
#[derive(Debug)]
pub struct OrCondition<'s, ID> {
pub left: Box<Condition<'s, ID>>,
pub or_token: Node<(), ID>,
pub right: Box<Condition<'s, ID>>,
}
#[derive(Debug)]
pub struct IsNullCondition<'s, ID> {
pub expr: Box<Expr<'s, ID>>,
pub is_token: Node<(), ID>,
pub not_token: Option<Node<(), ID>>,
pub null_token: Node<(), ID>,
}
#[derive(Debug)]
pub struct IsFloatCondition<'s, ID> {
pub expr: Box<Expr<'s, ID>>,
pub is_token: Node<(), ID>,
pub not_token: Option<Node<(), ID>>,
pub float_type: Node<FloatType, ID>,
}
#[derive(Debug)]
pub enum FloatType {
Nan,
Infinite,
}
#[derive(Debug)]
pub struct InCondition<'s, ID> {
pub expr: CompareExpr<'s, ID>,
pub not_token: Option<Node<(), ID>>,
pub in_token: Node<(), ID>,
pub values: CompareExpr<'s, ID>,
}
#[derive(Debug)]
pub struct LikeCondition<'s, ID> {
pub source: Expr<'s, ID>,
pub not_token: Option<Node<(), ID>>,
pub like_token: Node<LikeVariant, ID>,
pub pattern: Expr<'s, ID>,
pub escape: Option<LikeEscape<'s, ID>>,
}
#[derive(Debug)]
pub struct RegexpLikeCondition<'s, ID> {
pub regexp_like_token: Node<(), ID>,
pub params: Node<RegexpLikeParams<'s, ID>, ID>,
}
#[derive(Debug)]
pub struct RegexpLikeParams<'s, ID> {
pub source: Expr<'s, ID>,
pub pattern: Expr<'s, ID>,
pub options: Option<Expr<'s, ID>>,
}
#[derive(Debug)]
pub struct LikeEscape<'s, ID> {
pub escape_token: Node<(), ID>,
pub escape_char: Expr<'s, ID>,
}
#[derive(Debug)]
pub enum LikeVariant {
Like,
Like2,
Like4,
LikeC,
}
#[derive(Debug)]
pub struct CompareCondition<'s, ID> {
pub left: Box<CompareExpr<'s, ID>>,
pub op: CompareOp<ID>,
pub right: Box<CompareExpr<'s, ID>>,
}
#[derive(Debug)]
pub enum CompareExpr<'s, ID> {
Expr(Expr<'s, ID>),
List(ExprList<'s, ID>),
Lists(Node<Vec<ExprList<'s, ID>>, ID>),
}
#[derive(Debug)]
pub struct NotCondition<'s, ID> {
pub not_token: Node<(), ID>,
pub condition: Box<Condition<'s, ID>>,
}
impl<'s, ID> From<Expr<'s, ID>> for CompareExpr<'s, ID> {
fn from(value: Expr<'s, ID>) -> Self {
Self::Expr(value)
}
}
#[derive(Debug)]
pub struct CompareOp<ID> {
pub kind: Node<CompareKind, ID>,
pub quantifier: Option<Node<CompareQuantifier, ID>>,
}
#[derive(Debug, Clone, Copy)]
pub enum CompareKind {
Eq,
NotEq(NotEqSymbol),
Lt,
LtEq,
Gt,
GtEq,
}
#[derive(Debug, Clone, Copy)]
pub enum NotEqSymbol {
Logical,
Diamond,
Bitwise,
}
#[derive(Debug, Clone, Copy)]
pub enum CompareQuantifier {
All,
Any,
Some,
}