use std::ops::Deref;
use super::{Condition, Function, Ident, Node, Query, Value};
#[derive(Debug)]
pub enum Expr<'s, ID> {
Nested(Node<Box<Expr<'s, ID>>, ID>),
SubQuery(Node<Box<Query<'s, ID>>, ID>),
Unary(Box<UnaryExpr<'s, ID>>),
Binary(Box<BinaryExpr<'s, ID>>),
Case(Box<CaseExpr<'s, ID>>),
Value(Node<Value<'s>, ID>),
Function(Box<Function<'s, ID>>),
Identifier(Identifier<'s, ID>),
}
#[derive(Debug)]
pub struct ExprList<'s, ID>(pub Node<Vec<Expr<'s, ID>>, ID>);
impl<'s, ID> Deref for ExprList<'s, ID> {
type Target = [Expr<'s, ID>];
fn deref(&self) -> &Self::Target {
&self.0.0
}
}
#[derive(Debug)]
pub enum Identifier<'s, ID> {
Simple(Node<Ident<'s>, ID>),
Qualified(Vec<Node<Ident<'s>, ID>>),
}
impl<'s, ID> From<Node<Ident<'s>, ID>> for Identifier<'s, ID> {
fn from(value: Node<Ident<'s>, ID>) -> Self {
Self::Simple(value)
}
}
#[derive(Debug)]
pub struct UnaryExpr<'s, ID> {
pub op: Node<UnaryExprOp, ID>,
pub expr: Expr<'s, ID>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnaryExprOp {
Add,
Sub,
}
#[derive(Debug)]
pub struct BinaryExpr<'s, ID> {
pub left: Expr<'s, ID>,
pub op: Node<BinaryExprOp, ID>,
pub right: Expr<'s, ID>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinaryExprOp {
Add,
Sub,
Mul,
Div,
Concat,
}
#[derive(Debug)]
pub struct CaseExpr<'s, ID> {
pub case_token: Node<(), ID>,
pub when_branches: CaseWhens<'s, ID>,
pub else_branch: Option<CaseElse<'s, ID>>,
pub end_token: Node<(), ID>,
}
#[derive(Debug)]
pub enum CaseWhens<'s, ID> {
Simple {
case_expr: Expr<'s, ID>,
whens: Vec<CaseWhenSimple<'s, ID>>,
},
Searched {
whens: Vec<CaseWhenSearched<'s, ID>>,
},
}
#[derive(Debug)]
pub struct CaseWhenSimple<'s, ID> {
pub when_token: Node<(), ID>,
pub when_expr: Expr<'s, ID>,
pub then_token: Node<(), ID>,
pub return_expr: Expr<'s, ID>,
}
#[derive(Debug)]
pub struct CaseWhenSearched<'s, ID> {
pub when_token: Node<(), ID>,
pub when_condition: Condition<'s, ID>,
pub then_token: Node<(), ID>,
pub return_expr: Expr<'s, ID>,
}
#[derive(Debug)]
pub struct CaseElse<'s, ID> {
pub else_token: Node<(), ID>,
pub return_expr: Expr<'s, ID>,
}