1use super::span::{Span, Spanned};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Expr {
6 pub kind: ExprKind,
7 pub span: Span,
8}
9
10impl Expr {
11 pub fn new(kind: ExprKind, span: Span) -> Self {
12 Self { kind, span }
13 }
14}
15
16impl Spanned for Expr {
17 fn span(&self) -> Span {
18 self.span
19 }
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(tag = "variant")]
24#[allow(clippy::large_enum_variant)]
25pub enum ExprKind {
26 Literal {
27 literal: Literal,
28 },
29 ColumnRef {
30 table: Option<String>,
31 column: String,
32 },
33 BinaryOp {
34 left: Box<Expr>,
35 op: BinaryOp,
36 right: Box<Expr>,
37 },
38 UnaryOp {
39 op: UnaryOp,
40 operand: Box<Expr>,
41 },
42 FunctionCall {
43 name: String,
44 args: Vec<Expr>,
45 distinct: bool,
46 star: bool,
47 },
48 Between {
49 expr: Box<Expr>,
50 low: Box<Expr>,
51 high: Box<Expr>,
52 negated: bool,
53 },
54 Like {
55 expr: Box<Expr>,
56 pattern: Box<Expr>,
57 escape: Option<Box<Expr>>,
58 negated: bool,
59 },
60 InList {
61 expr: Box<Expr>,
62 list: Vec<Expr>,
63 negated: bool,
64 },
65 IsNull {
66 expr: Box<Expr>,
67 negated: bool,
68 },
69 VectorLiteral {
70 values: Vec<f64>,
71 },
72 ScalarSubquery {
73 subquery: Box<super::Statement>,
74 },
75 InSubquery {
76 expr: Box<Expr>,
77 subquery: Box<super::Statement>,
78 negated: bool,
79 },
80 Exists {
81 subquery: Box<super::Statement>,
82 negated: bool,
83 },
84 Quantified {
85 expr: Box<Expr>,
86 op: BinaryOp,
87 quantifier: Quantifier,
88 subquery: Box<super::Statement>,
89 },
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(tag = "variant", content = "value")]
94pub enum Literal {
95 Number(String),
96 String(String),
97 Boolean(bool),
98 Null,
99}
100
101#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
102pub enum BinaryOp {
103 Add,
104 Sub,
105 Mul,
106 Div,
107 Mod,
108 Eq,
109 Neq,
110 Lt,
111 Gt,
112 LtEq,
113 GtEq,
114 And,
115 Or,
116 StringConcat,
117}
118
119#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
120pub enum UnaryOp {
121 Not,
122 Minus,
123}
124
125#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
126pub enum Quantifier {
127 Any,
128 All,
129}