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 #[serde(default)]
60 kind: PatternMatchKind,
61 },
62 InList {
63 expr: Box<Expr>,
64 list: Vec<Expr>,
65 negated: bool,
66 },
67 IsNull {
68 expr: Box<Expr>,
69 negated: bool,
70 },
71 VectorLiteral {
72 values: Vec<f64>,
73 },
74 ScalarSubquery {
75 subquery: Box<super::Statement>,
76 },
77 InSubquery {
78 expr: Box<Expr>,
79 subquery: Box<super::Statement>,
80 negated: bool,
81 },
82 Exists {
83 subquery: Box<super::Statement>,
84 negated: bool,
85 },
86 Quantified {
87 expr: Box<Expr>,
88 op: BinaryOp,
89 quantifier: Quantifier,
90 subquery: Box<super::Statement>,
91 },
92}
93
94#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
95pub enum PatternMatchKind {
96 #[default]
97 Like,
98 ILike,
99 Glob,
100 SimilarTo,
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(tag = "variant", content = "value")]
105pub enum Literal {
106 Number(String),
107 String(String),
108 Boolean(bool),
109 Null,
110}
111
112#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
113pub enum BinaryOp {
114 Add,
115 Sub,
116 Mul,
117 Div,
118 Mod,
119 Eq,
120 Neq,
121 Lt,
122 Gt,
123 LtEq,
124 GtEq,
125 And,
126 Or,
127 StringConcat,
128}
129
130#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
131pub enum UnaryOp {
132 Not,
133 Minus,
134}
135
136#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
137pub enum Quantifier {
138 Any,
139 All,
140}