alopex_sql/ast/
expr.rs

1use super::span::{Span, Spanned};
2
3#[derive(Debug, Clone)]
4pub struct Expr {
5    pub kind: ExprKind,
6    pub span: Span,
7}
8
9impl Expr {
10    pub fn new(kind: ExprKind, span: Span) -> Self {
11        Self { kind, span }
12    }
13}
14
15impl Spanned for Expr {
16    fn span(&self) -> Span {
17        self.span
18    }
19}
20
21#[derive(Debug, Clone)]
22pub enum ExprKind {
23    Literal(Literal),
24    ColumnRef {
25        table: Option<String>,
26        column: String,
27    },
28    BinaryOp {
29        left: Box<Expr>,
30        op: BinaryOp,
31        right: Box<Expr>,
32    },
33    UnaryOp {
34        op: UnaryOp,
35        operand: Box<Expr>,
36    },
37    FunctionCall {
38        name: String,
39        args: Vec<Expr>,
40    },
41    Between {
42        expr: Box<Expr>,
43        low: Box<Expr>,
44        high: Box<Expr>,
45        negated: bool,
46    },
47    Like {
48        expr: Box<Expr>,
49        pattern: Box<Expr>,
50        escape: Option<Box<Expr>>,
51        negated: bool,
52    },
53    InList {
54        expr: Box<Expr>,
55        list: Vec<Expr>,
56        negated: bool,
57    },
58    IsNull {
59        expr: Box<Expr>,
60        negated: bool,
61    },
62    VectorLiteral(Vec<f64>),
63}
64
65#[derive(Debug, Clone)]
66pub enum Literal {
67    Number(String),
68    String(String),
69    Boolean(bool),
70    Null,
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74pub enum BinaryOp {
75    Add,
76    Sub,
77    Mul,
78    Div,
79    Mod,
80    Eq,
81    Neq,
82    Lt,
83    Gt,
84    LtEq,
85    GtEq,
86    And,
87    Or,
88    StringConcat,
89}
90
91#[derive(Debug, Clone, Copy, PartialEq, Eq)]
92pub enum UnaryOp {
93    Not,
94    Minus,
95}