gqlite 1.1.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/gqliterb/.cargo/config.toml +2 -0
- data/ext/gqliterb/Cargo.lock +1109 -0
- data/ext/gqliterb/Cargo.toml +43 -0
- data/ext/gqliterb/extconf.rb +4 -0
- data/ext/gqliterb/src/lib.rs +260 -0
- data/ext/gqliterb/vendor/gqlitedb/Cargo.lock +2060 -0
- data/ext/gqliterb/vendor/gqlitedb/Cargo.toml +132 -0
- data/ext/gqliterb/vendor/gqlitedb/askama.toml +3 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/common/mod.rs +25 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/common/pokec.rs +185 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/pokec_divan.rs +137 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/pokec_iai.rs +122 -0
- data/ext/gqliterb/vendor/gqlitedb/release.toml +7 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/arithmetic.rs +96 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/containers.rs +33 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/count.rs +35 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/stats.rs +168 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators.rs +74 -0
- data/ext/gqliterb/vendor/gqlitedb/src/capi.rs +236 -0
- data/ext/gqliterb/vendor/gqlitedb/src/compiler/expression_analyser.rs +427 -0
- data/ext/gqliterb/vendor/gqlitedb/src/compiler/variables_manager.rs +620 -0
- data/ext/gqliterb/vendor/gqlitedb/src/compiler.rs +1106 -0
- data/ext/gqliterb/vendor/gqlitedb/src/connection.rs +208 -0
- data/ext/gqliterb/vendor/gqlitedb/src/consts.rs +10 -0
- data/ext/gqliterb/vendor/gqlitedb/src/error.rs +621 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/containers.rs +115 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/edge.rs +20 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/math.rs +44 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/node.rs +16 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/path.rs +48 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/scalar.rs +86 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/string.rs +28 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/value.rs +99 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions.rs +412 -0
- data/ext/gqliterb/vendor/gqlitedb/src/graph.rs +268 -0
- data/ext/gqliterb/vendor/gqlitedb/src/interpreter/evaluators.rs +1788 -0
- data/ext/gqliterb/vendor/gqlitedb/src/interpreter/instructions.rs +262 -0
- data/ext/gqliterb/vendor/gqlitedb/src/interpreter/mod.rs +4 -0
- data/ext/gqliterb/vendor/gqlitedb/src/lib.rs +42 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser/ast.rs +625 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser/gql.pest +191 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser/parser.rs +1153 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser.rs +4 -0
- data/ext/gqliterb/vendor/gqlitedb/src/prelude.rs +8 -0
- data/ext/gqliterb/vendor/gqlitedb/src/serialize_with.rs +94 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store/pgql.rs +121 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store/redb.rs +1250 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store/sqlite.rs +994 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store.rs +432 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/compiler.rs +92 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/evaluators.rs +227 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/parser.rs +81 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/store/redb.rs +39 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/store/sqlite.rs +39 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/store.rs +462 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/ast.rs +356 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/programs.rs +455 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/templates.rs +2 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests.rs +39 -0
- data/ext/gqliterb/vendor/gqlitedb/src/utils.rs +28 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value/compare.rs +212 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value/contains.rs +47 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value/value_map.rs +298 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value.rs +559 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value_table.rs +616 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/call_stats.sql +22 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_count_for_node.sql +3 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_create.sql +6 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete_by_nodes.sql +2 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_select.sql +139 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_update.sql +4 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_create.sql +16 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_delete.sql +3 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_create_table.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_get.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_set.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_create.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_delete.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_select.sql +42 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_update.sql +4 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/table_exists.sql +5 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_from_1_01.sql +2 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_graph_from_1_01.sql +65 -0
- data/lib/gqlite.rb +1 -75
- metadata +118 -25
- data/ext/gqlite/extconf.rb +0 -21
- data/ext/gqlite/gqlite-amalgamate.cpp +0 -9599
- data/ext/gqlite/gqlite-c.h +0 -95
- data/ext/gqlite/gqlite.h +0 -141
@@ -0,0 +1,625 @@
|
|
1
|
+
use std::{
|
2
|
+
cell::RefCell,
|
3
|
+
collections::{hash_map::Entry, HashMap},
|
4
|
+
sync::atomic::AtomicU64,
|
5
|
+
};
|
6
|
+
|
7
|
+
use crate::graph;
|
8
|
+
|
9
|
+
/// Represent a variable name. Some variable are explicitly created by the parser, if a node/edge should be considered equal and appear in different expression.
|
10
|
+
/// For instance `()-[]->()-[]->()` needs the creation of a variable.
|
11
|
+
#[derive(Debug, Clone, Eq)]
|
12
|
+
pub(crate) struct VariableIdentifier
|
13
|
+
{
|
14
|
+
/// Name of the variable, only useful for debug purposes
|
15
|
+
name: String,
|
16
|
+
/// Unique identifier of the variable, the uniqueness is only guaranteed within a compilation unit.
|
17
|
+
id: u64,
|
18
|
+
}
|
19
|
+
|
20
|
+
impl VariableIdentifier
|
21
|
+
{
|
22
|
+
pub(crate) fn name(&self) -> &String
|
23
|
+
{
|
24
|
+
&self.name
|
25
|
+
}
|
26
|
+
pub(crate) fn take_name(self) -> String
|
27
|
+
{
|
28
|
+
self.name
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
impl PartialEq for VariableIdentifier
|
33
|
+
{
|
34
|
+
fn eq(&self, other: &Self) -> bool
|
35
|
+
{
|
36
|
+
self.id == other.id
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
impl std::hash::Hash for VariableIdentifier
|
41
|
+
{
|
42
|
+
fn hash<H: std::hash::Hasher>(&self, state: &mut H)
|
43
|
+
{
|
44
|
+
self.id.hash(state);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
#[derive(Default)]
|
49
|
+
pub(crate) struct VariableIdentifiers
|
50
|
+
{
|
51
|
+
next_id: AtomicU64,
|
52
|
+
identifiers: RefCell<HashMap<String, VariableIdentifier>>,
|
53
|
+
}
|
54
|
+
|
55
|
+
impl VariableIdentifiers
|
56
|
+
{
|
57
|
+
fn next_id(&self) -> u64
|
58
|
+
{
|
59
|
+
self
|
60
|
+
.next_id
|
61
|
+
.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
|
62
|
+
}
|
63
|
+
pub(crate) fn from_name(&self, name: impl Into<String>) -> VariableIdentifier
|
64
|
+
{
|
65
|
+
let name = name.into();
|
66
|
+
match self.identifiers.borrow_mut().entry(name)
|
67
|
+
{
|
68
|
+
Entry::Occupied(entry) => entry.get().clone(),
|
69
|
+
Entry::Vacant(entry) =>
|
70
|
+
{
|
71
|
+
let vn = VariableIdentifier {
|
72
|
+
name: entry.key().clone(),
|
73
|
+
id: self.next_id(),
|
74
|
+
};
|
75
|
+
entry.insert(vn.clone());
|
76
|
+
vn
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
pub(crate) fn from_name_optional(&self, name: Option<String>) -> Option<VariableIdentifier>
|
81
|
+
{
|
82
|
+
name.map(|name| self.from_name(name))
|
83
|
+
}
|
84
|
+
pub(crate) fn anonymous(&self) -> VariableIdentifier
|
85
|
+
{
|
86
|
+
let id = self.next_id();
|
87
|
+
VariableIdentifier {
|
88
|
+
name: format!("anonymous_{}", id),
|
89
|
+
id,
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
#[derive(Debug)]
|
95
|
+
pub(crate) enum Statement
|
96
|
+
{
|
97
|
+
CreateGraph(CreateGraph),
|
98
|
+
UseGraph(UseGraph),
|
99
|
+
Create(Create),
|
100
|
+
Match(Match),
|
101
|
+
Return(Return),
|
102
|
+
Call(Call),
|
103
|
+
With(With),
|
104
|
+
Unwind(Unwind),
|
105
|
+
Delete(Delete),
|
106
|
+
Update(Update),
|
107
|
+
}
|
108
|
+
|
109
|
+
macro_rules! create_into_statement {
|
110
|
+
( $x:tt ) => {
|
111
|
+
impl Into<Statement> for $x
|
112
|
+
{
|
113
|
+
fn into(self) -> Statement
|
114
|
+
{
|
115
|
+
Statement::$x(self)
|
116
|
+
}
|
117
|
+
}
|
118
|
+
};
|
119
|
+
}
|
120
|
+
|
121
|
+
pub(crate) type Statements = Vec<Statement>;
|
122
|
+
pub(crate) type Queries = Vec<Statements>;
|
123
|
+
|
124
|
+
#[derive(Debug)]
|
125
|
+
pub(crate) enum Node {}
|
126
|
+
|
127
|
+
#[derive(Debug)]
|
128
|
+
pub(crate) struct CreateGraph
|
129
|
+
{
|
130
|
+
pub(crate) name: String,
|
131
|
+
}
|
132
|
+
|
133
|
+
#[derive(Debug)]
|
134
|
+
pub(crate) struct UseGraph
|
135
|
+
{
|
136
|
+
pub(crate) name: String,
|
137
|
+
}
|
138
|
+
|
139
|
+
#[derive(Debug)]
|
140
|
+
pub(crate) struct Create
|
141
|
+
{
|
142
|
+
pub(crate) patterns: Vec<Pattern>,
|
143
|
+
}
|
144
|
+
|
145
|
+
create_into_statement! {Create}
|
146
|
+
|
147
|
+
#[derive(Debug)]
|
148
|
+
pub(crate) struct Match
|
149
|
+
{
|
150
|
+
pub(crate) patterns: Vec<Pattern>,
|
151
|
+
pub(crate) where_expression: Option<Expression>,
|
152
|
+
pub(crate) optional: bool,
|
153
|
+
}
|
154
|
+
|
155
|
+
create_into_statement! {Match}
|
156
|
+
|
157
|
+
#[derive(Debug)]
|
158
|
+
pub(crate) struct Return
|
159
|
+
{
|
160
|
+
pub(crate) all: bool,
|
161
|
+
pub(crate) expressions: Vec<NamedExpression>,
|
162
|
+
pub(crate) modifiers: Modifiers,
|
163
|
+
pub(crate) where_expression: Option<Expression>,
|
164
|
+
}
|
165
|
+
|
166
|
+
create_into_statement! {Return}
|
167
|
+
|
168
|
+
#[derive(Debug)]
|
169
|
+
pub(crate) struct With
|
170
|
+
{
|
171
|
+
pub(crate) all: bool,
|
172
|
+
pub(crate) expressions: Vec<NamedExpression>,
|
173
|
+
pub(crate) modifiers: Modifiers,
|
174
|
+
pub(crate) where_expression: Option<Expression>,
|
175
|
+
}
|
176
|
+
|
177
|
+
create_into_statement! {With}
|
178
|
+
|
179
|
+
#[derive(Debug)]
|
180
|
+
pub(crate) struct Unwind
|
181
|
+
{
|
182
|
+
pub(crate) identifier: VariableIdentifier,
|
183
|
+
pub(crate) expression: Expression,
|
184
|
+
}
|
185
|
+
|
186
|
+
create_into_statement! {Unwind}
|
187
|
+
|
188
|
+
#[derive(Debug)]
|
189
|
+
pub(crate) struct Delete
|
190
|
+
{
|
191
|
+
pub(crate) detach: bool,
|
192
|
+
pub(crate) expressions: Vec<Expression>,
|
193
|
+
}
|
194
|
+
|
195
|
+
#[derive(Debug)]
|
196
|
+
pub(crate) struct Update
|
197
|
+
{
|
198
|
+
pub(crate) updates: Vec<OneUpdate>,
|
199
|
+
}
|
200
|
+
|
201
|
+
#[derive(Debug)]
|
202
|
+
pub(crate) struct Remove
|
203
|
+
{
|
204
|
+
pub(crate) expressions: Vec<Expression>,
|
205
|
+
}
|
206
|
+
|
207
|
+
#[derive(Debug)]
|
208
|
+
pub(crate) struct Call
|
209
|
+
{
|
210
|
+
pub(crate) name: String,
|
211
|
+
pub(crate) arguments: Vec<Expression>,
|
212
|
+
pub(crate) yield_: Vec<String>,
|
213
|
+
}
|
214
|
+
|
215
|
+
// Set/remove Statements
|
216
|
+
|
217
|
+
#[derive(Debug)]
|
218
|
+
pub(crate) enum OneUpdate
|
219
|
+
{
|
220
|
+
SetProperty(UpdateProperty),
|
221
|
+
AddProperty(UpdateProperty),
|
222
|
+
RemoveProperty(RemoveProperty),
|
223
|
+
AddLabels(AddRemoveLabels),
|
224
|
+
RemoveLabels(AddRemoveLabels),
|
225
|
+
}
|
226
|
+
|
227
|
+
#[derive(Debug)]
|
228
|
+
pub(crate) struct UpdateProperty
|
229
|
+
{
|
230
|
+
pub(crate) target: VariableIdentifier,
|
231
|
+
pub(crate) path: Vec<String>,
|
232
|
+
pub(crate) expression: Expression,
|
233
|
+
}
|
234
|
+
|
235
|
+
#[derive(Debug)]
|
236
|
+
pub(crate) struct RemoveProperty
|
237
|
+
{
|
238
|
+
pub(crate) target: VariableIdentifier,
|
239
|
+
pub(crate) path: Vec<String>,
|
240
|
+
}
|
241
|
+
|
242
|
+
#[derive(Debug)]
|
243
|
+
pub(crate) struct AddRemoveLabels
|
244
|
+
{
|
245
|
+
pub(crate) target: VariableIdentifier,
|
246
|
+
pub(crate) labels: Vec<String>,
|
247
|
+
}
|
248
|
+
|
249
|
+
// Modifiers
|
250
|
+
|
251
|
+
#[derive(Debug)]
|
252
|
+
pub(crate) struct OrderBy
|
253
|
+
{
|
254
|
+
pub(crate) expressions: Vec<OrderByExpression>,
|
255
|
+
}
|
256
|
+
|
257
|
+
#[derive(Default, Debug)]
|
258
|
+
pub(crate) struct Modifiers
|
259
|
+
{
|
260
|
+
pub(crate) skip: Option<Expression>,
|
261
|
+
pub(crate) limit: Option<Expression>,
|
262
|
+
pub(crate) order_by: Option<OrderBy>,
|
263
|
+
}
|
264
|
+
|
265
|
+
// Expressions
|
266
|
+
|
267
|
+
#[derive(Debug, Clone, PartialEq)]
|
268
|
+
pub(crate) enum Expression
|
269
|
+
{
|
270
|
+
Array(Array),
|
271
|
+
FunctionCall(FunctionCall),
|
272
|
+
Map(Map),
|
273
|
+
IndexAccess(Box<IndexAccess>),
|
274
|
+
RangeAccess(Box<RangeAccess>),
|
275
|
+
MemberAccess(Box<MemberAccess>),
|
276
|
+
Parameter(Parameter),
|
277
|
+
Value(Value),
|
278
|
+
Variable(Variable),
|
279
|
+
|
280
|
+
LogicalAnd(Box<LogicalAnd>),
|
281
|
+
LogicalOr(Box<LogicalOr>),
|
282
|
+
LogicalXor(Box<LogicalXor>),
|
283
|
+
RelationalEqual(Box<RelationalEqual>),
|
284
|
+
RelationalDifferent(Box<RelationalDifferent>),
|
285
|
+
RelationalInferior(Box<RelationalInferior>),
|
286
|
+
RelationalSuperior(Box<RelationalSuperior>),
|
287
|
+
RelationalInferiorEqual(Box<RelationalInferiorEqual>),
|
288
|
+
RelationalSuperiorEqual(Box<RelationalSuperiorEqual>),
|
289
|
+
RelationalIn(Box<RelationalIn>),
|
290
|
+
RelationalNotIn(Box<RelationalNotIn>),
|
291
|
+
|
292
|
+
Addition(Box<Addition>),
|
293
|
+
Subtraction(Box<Subtraction>),
|
294
|
+
Multiplication(Box<Multiplication>),
|
295
|
+
Division(Box<Division>),
|
296
|
+
Modulo(Box<Modulo>),
|
297
|
+
|
298
|
+
Negation(Box<Negation>),
|
299
|
+
LogicalNegation(Box<LogicalNegation>),
|
300
|
+
IsNull(Box<IsNull>),
|
301
|
+
IsNotNull(Box<IsNotNull>),
|
302
|
+
}
|
303
|
+
|
304
|
+
// Order By Expression
|
305
|
+
|
306
|
+
#[derive(Debug)]
|
307
|
+
pub(crate) struct OrderByExpression
|
308
|
+
{
|
309
|
+
pub asc: bool,
|
310
|
+
pub expression: Expression,
|
311
|
+
}
|
312
|
+
|
313
|
+
// Values: CreatePatterns
|
314
|
+
|
315
|
+
#[derive(Debug)]
|
316
|
+
pub(crate) enum Pattern
|
317
|
+
{
|
318
|
+
Node(NodePattern),
|
319
|
+
Edge(EdgePattern),
|
320
|
+
Path(PathPattern),
|
321
|
+
}
|
322
|
+
|
323
|
+
#[derive(Debug, Clone)]
|
324
|
+
pub(crate) struct NodePattern
|
325
|
+
{
|
326
|
+
pub(crate) variable: Option<VariableIdentifier>,
|
327
|
+
pub(crate) labels: LabelExpression,
|
328
|
+
pub(crate) properties: Option<Expression>,
|
329
|
+
}
|
330
|
+
|
331
|
+
#[derive(Debug, Clone)]
|
332
|
+
pub(crate) struct EdgePattern
|
333
|
+
{
|
334
|
+
pub(crate) variable: Option<VariableIdentifier>,
|
335
|
+
pub(crate) source: NodePattern,
|
336
|
+
pub(crate) destination: NodePattern,
|
337
|
+
pub(crate) directivity: graph::EdgeDirectivity,
|
338
|
+
pub(crate) labels: LabelExpression,
|
339
|
+
pub(crate) properties: Option<Expression>,
|
340
|
+
}
|
341
|
+
|
342
|
+
#[derive(Debug, Clone)]
|
343
|
+
pub(crate) struct PathPattern
|
344
|
+
{
|
345
|
+
pub(crate) variable: VariableIdentifier,
|
346
|
+
pub(crate) edge: EdgePattern,
|
347
|
+
}
|
348
|
+
|
349
|
+
// Label Expression
|
350
|
+
#[derive(Debug, Clone, PartialEq)]
|
351
|
+
pub(crate) enum LabelExpression
|
352
|
+
{
|
353
|
+
Not(Box<LabelExpression>),
|
354
|
+
And(Vec<Box<LabelExpression>>),
|
355
|
+
Or(Vec<Box<LabelExpression>>),
|
356
|
+
String(String),
|
357
|
+
None,
|
358
|
+
}
|
359
|
+
|
360
|
+
impl LabelExpression
|
361
|
+
{
|
362
|
+
pub(crate) fn and(self, rhs: LabelExpression) -> LabelExpression
|
363
|
+
{
|
364
|
+
match self
|
365
|
+
{
|
366
|
+
LabelExpression::None => rhs,
|
367
|
+
LabelExpression::And(mut vec) => match rhs
|
368
|
+
{
|
369
|
+
LabelExpression::None => LabelExpression::And(vec),
|
370
|
+
LabelExpression::And(mut rhs_vec) =>
|
371
|
+
{
|
372
|
+
vec.append(&mut rhs_vec);
|
373
|
+
LabelExpression::And(vec)
|
374
|
+
}
|
375
|
+
other =>
|
376
|
+
{
|
377
|
+
vec.push(other.boxed());
|
378
|
+
LabelExpression::And(vec)
|
379
|
+
}
|
380
|
+
},
|
381
|
+
_ => match rhs
|
382
|
+
{
|
383
|
+
LabelExpression::None => self,
|
384
|
+
LabelExpression::And(mut vec) =>
|
385
|
+
{
|
386
|
+
vec.push(self.boxed());
|
387
|
+
LabelExpression::And(vec)
|
388
|
+
}
|
389
|
+
_ => LabelExpression::And(vec![self.boxed(), rhs.boxed()]),
|
390
|
+
},
|
391
|
+
}
|
392
|
+
}
|
393
|
+
pub(crate) fn or(self, rhs: LabelExpression) -> LabelExpression
|
394
|
+
{
|
395
|
+
match self
|
396
|
+
{
|
397
|
+
LabelExpression::None => rhs,
|
398
|
+
LabelExpression::Or(mut vec) => match rhs
|
399
|
+
{
|
400
|
+
LabelExpression::None => LabelExpression::And(vec),
|
401
|
+
LabelExpression::Or(mut rhs_vec) =>
|
402
|
+
{
|
403
|
+
vec.append(&mut rhs_vec);
|
404
|
+
LabelExpression::Or(vec)
|
405
|
+
}
|
406
|
+
other =>
|
407
|
+
{
|
408
|
+
vec.push(other.boxed());
|
409
|
+
LabelExpression::Or(vec)
|
410
|
+
}
|
411
|
+
},
|
412
|
+
_ => match rhs
|
413
|
+
{
|
414
|
+
LabelExpression::None => self,
|
415
|
+
LabelExpression::Or(mut vec) =>
|
416
|
+
{
|
417
|
+
vec.push(self.boxed());
|
418
|
+
LabelExpression::Or(vec)
|
419
|
+
}
|
420
|
+
_ => LabelExpression::Or(vec![self.boxed(), rhs.boxed()]),
|
421
|
+
},
|
422
|
+
}
|
423
|
+
}
|
424
|
+
fn clone_boxed(&self) -> Box<LabelExpression>
|
425
|
+
{
|
426
|
+
self.clone().boxed()
|
427
|
+
}
|
428
|
+
pub(crate) fn boxed(self) -> Box<LabelExpression>
|
429
|
+
{
|
430
|
+
Box::new(self)
|
431
|
+
}
|
432
|
+
pub(crate) fn is_all_inclusive(&self) -> bool
|
433
|
+
{
|
434
|
+
match self
|
435
|
+
{
|
436
|
+
LabelExpression::None => true,
|
437
|
+
LabelExpression::And(exprs) => !exprs.iter().any(|f| !f.is_all_inclusive()),
|
438
|
+
LabelExpression::Or(_) => false,
|
439
|
+
LabelExpression::String(_) => true,
|
440
|
+
LabelExpression::Not(_) => false,
|
441
|
+
}
|
442
|
+
}
|
443
|
+
pub(crate) fn is_none(&self) -> bool
|
444
|
+
{
|
445
|
+
match self
|
446
|
+
{
|
447
|
+
LabelExpression::None => true,
|
448
|
+
_ => false,
|
449
|
+
}
|
450
|
+
}
|
451
|
+
pub(crate) fn is_string(&self) -> bool
|
452
|
+
{
|
453
|
+
match self
|
454
|
+
{
|
455
|
+
LabelExpression::String(_) => true,
|
456
|
+
_ => false,
|
457
|
+
}
|
458
|
+
}
|
459
|
+
}
|
460
|
+
|
461
|
+
// Expressions
|
462
|
+
|
463
|
+
macro_rules! create_into_expr {
|
464
|
+
( $x:tt ) => {
|
465
|
+
impl Into<Expression> for $x
|
466
|
+
{
|
467
|
+
fn into(self) -> Expression
|
468
|
+
{
|
469
|
+
Expression::$x(self)
|
470
|
+
}
|
471
|
+
}
|
472
|
+
};
|
473
|
+
}
|
474
|
+
|
475
|
+
macro_rules! create_into_boxed_expr {
|
476
|
+
( $x:tt ) => {
|
477
|
+
impl Into<Expression> for $x
|
478
|
+
{
|
479
|
+
fn into(self) -> Expression
|
480
|
+
{
|
481
|
+
Expression::$x(Box::new(self))
|
482
|
+
}
|
483
|
+
}
|
484
|
+
};
|
485
|
+
}
|
486
|
+
|
487
|
+
#[derive(Debug)]
|
488
|
+
pub(crate) struct NamedExpression
|
489
|
+
{
|
490
|
+
pub(crate) identifier: VariableIdentifier,
|
491
|
+
pub(crate) expression: Expression,
|
492
|
+
}
|
493
|
+
|
494
|
+
#[derive(Debug, Clone, PartialEq)]
|
495
|
+
pub(crate) struct Parameter
|
496
|
+
{
|
497
|
+
pub(crate) name: String,
|
498
|
+
}
|
499
|
+
|
500
|
+
#[derive(Debug, Clone, PartialEq)]
|
501
|
+
pub(crate) struct Variable
|
502
|
+
{
|
503
|
+
pub(crate) identifier: VariableIdentifier,
|
504
|
+
}
|
505
|
+
|
506
|
+
create_into_expr! {Variable}
|
507
|
+
|
508
|
+
#[derive(Debug, Clone, PartialEq)]
|
509
|
+
pub(crate) struct MemberAccess
|
510
|
+
{
|
511
|
+
pub(crate) left: Expression,
|
512
|
+
pub(crate) path: Vec<String>,
|
513
|
+
}
|
514
|
+
|
515
|
+
create_into_boxed_expr! {MemberAccess}
|
516
|
+
|
517
|
+
#[derive(Debug, Clone, PartialEq)]
|
518
|
+
pub(crate) struct IndexAccess
|
519
|
+
{
|
520
|
+
pub(crate) left: Expression,
|
521
|
+
pub(crate) index: Expression,
|
522
|
+
}
|
523
|
+
|
524
|
+
create_into_boxed_expr! {IndexAccess}
|
525
|
+
|
526
|
+
#[derive(Debug, Clone, PartialEq)]
|
527
|
+
pub(crate) struct RangeAccess
|
528
|
+
{
|
529
|
+
pub(crate) left: Expression,
|
530
|
+
pub(crate) start: Option<Expression>,
|
531
|
+
pub(crate) end: Option<Expression>,
|
532
|
+
}
|
533
|
+
#[derive(Debug)]
|
534
|
+
pub(crate) struct HasLabels
|
535
|
+
{
|
536
|
+
pub(crate) left: String,
|
537
|
+
pub(crate) labels: Vec<String>,
|
538
|
+
}
|
539
|
+
|
540
|
+
#[derive(Debug, Clone, PartialEq)]
|
541
|
+
pub(crate) struct FunctionCall
|
542
|
+
{
|
543
|
+
pub(crate) name: String,
|
544
|
+
pub(crate) arguments: Vec<Expression>,
|
545
|
+
}
|
546
|
+
|
547
|
+
create_into_expr! {FunctionCall}
|
548
|
+
|
549
|
+
macro_rules! create_binary_op {
|
550
|
+
( $x:tt ) => {
|
551
|
+
#[derive(Debug, Clone, PartialEq)]
|
552
|
+
pub(crate) struct $x
|
553
|
+
{
|
554
|
+
pub(crate) left: Expression,
|
555
|
+
pub(crate) right: Expression,
|
556
|
+
}
|
557
|
+
|
558
|
+
create_into_boxed_expr! { $x }
|
559
|
+
};
|
560
|
+
}
|
561
|
+
|
562
|
+
create_binary_op! {LogicalAnd}
|
563
|
+
create_binary_op! {LogicalOr}
|
564
|
+
create_binary_op! {LogicalXor}
|
565
|
+
create_binary_op! {RelationalEqual}
|
566
|
+
create_binary_op! {RelationalDifferent}
|
567
|
+
create_binary_op! {RelationalInferior}
|
568
|
+
create_binary_op! {RelationalSuperior}
|
569
|
+
create_binary_op! {RelationalInferiorEqual}
|
570
|
+
create_binary_op! {RelationalSuperiorEqual}
|
571
|
+
create_binary_op! {RelationalIn}
|
572
|
+
create_binary_op! {RelationalNotIn}
|
573
|
+
|
574
|
+
create_binary_op! {Addition}
|
575
|
+
create_binary_op! {Subtraction}
|
576
|
+
create_binary_op! {Multiplication}
|
577
|
+
create_binary_op! {Division}
|
578
|
+
create_binary_op! {Modulo}
|
579
|
+
|
580
|
+
macro_rules! create_unary_op {
|
581
|
+
( $x:tt ) => {
|
582
|
+
#[derive(Debug, Clone, PartialEq)]
|
583
|
+
pub(crate) struct $x
|
584
|
+
{
|
585
|
+
pub(crate) value: Expression,
|
586
|
+
}
|
587
|
+
create_into_boxed_expr! { $x }
|
588
|
+
};
|
589
|
+
}
|
590
|
+
|
591
|
+
create_unary_op! {LogicalNegation}
|
592
|
+
create_unary_op! {Negation}
|
593
|
+
create_unary_op! {IsNull}
|
594
|
+
create_unary_op! {IsNotNull}
|
595
|
+
|
596
|
+
// Values
|
597
|
+
|
598
|
+
#[derive(Debug)]
|
599
|
+
pub(crate) struct All {}
|
600
|
+
#[derive(Debug)]
|
601
|
+
pub(crate) struct EndOfList {}
|
602
|
+
|
603
|
+
#[derive(Debug, Clone, PartialEq)]
|
604
|
+
pub(crate) struct Value
|
605
|
+
{
|
606
|
+
pub(crate) value: crate::value::Value,
|
607
|
+
}
|
608
|
+
|
609
|
+
create_into_expr! {Value}
|
610
|
+
|
611
|
+
#[derive(Debug, Clone, PartialEq)]
|
612
|
+
pub(crate) struct Map
|
613
|
+
{
|
614
|
+
pub(crate) map: Vec<(String, Expression)>,
|
615
|
+
}
|
616
|
+
|
617
|
+
create_into_expr! {Map}
|
618
|
+
|
619
|
+
#[derive(Debug, Clone, PartialEq)]
|
620
|
+
pub(crate) struct Array
|
621
|
+
{
|
622
|
+
pub(crate) array: Vec<Expression>,
|
623
|
+
}
|
624
|
+
|
625
|
+
create_into_expr! {Array}
|