flowquery 1.0.14 → 1.0.15
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.
- package/.editorconfig +21 -0
- package/.husky/pre-commit +1 -0
- package/.prettierrc +22 -0
- package/dist/flowquery.min.js +1 -1
- package/dist/parsing/expressions/expression_map.d.ts +8 -0
- package/dist/parsing/expressions/expression_map.d.ts.map +1 -0
- package/dist/parsing/expressions/expression_map.js +21 -0
- package/dist/parsing/expressions/expression_map.js.map +1 -0
- package/dist/parsing/operations/call.d.ts +17 -0
- package/dist/parsing/operations/call.d.ts.map +1 -0
- package/dist/parsing/operations/call.js +103 -0
- package/dist/parsing/operations/call.js.map +1 -0
- package/dist/parsing/operations/load.d.ts +6 -6
- package/dist/parsing/operations/load.d.ts.map +1 -1
- package/dist/parsing/operations/load.js +8 -6
- package/dist/parsing/operations/load.js.map +1 -1
- package/dist/parsing/operations/operation.d.ts +1 -0
- package/dist/parsing/operations/operation.d.ts.map +1 -1
- package/dist/parsing/operations/operation.js +6 -5
- package/dist/parsing/operations/operation.js.map +1 -1
- package/dist/parsing/operations/projection.d.ts +1 -1
- package/dist/parsing/operations/projection.d.ts.map +1 -1
- package/dist/parsing/operations/projection.js.map +1 -1
- package/dist/parsing/parser.d.ts +1 -0
- package/dist/parsing/parser.d.ts.map +1 -1
- package/dist/parsing/parser.js +148 -99
- package/dist/parsing/parser.js.map +1 -1
- package/dist/parsing/token_to_node.d.ts +2 -2
- package/dist/parsing/token_to_node.d.ts.map +1 -1
- package/dist/parsing/token_to_node.js +12 -12
- package/dist/parsing/token_to_node.js.map +1 -1
- package/dist/tokenization/token.d.ts +5 -1
- package/dist/tokenization/token.d.ts.map +1 -1
- package/dist/tokenization/token.js +17 -5
- package/dist/tokenization/token.js.map +1 -1
- package/docs/flowquery.min.js +1 -1
- package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
- package/misc/apps/RAG/package.json +1 -1
- package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +66 -0
- package/misc/apps/RAG/src/plugins/loaders/Llm.ts +4 -3
- package/misc/apps/RAG/src/plugins/loaders/MockData.ts +7 -5
- package/misc/apps/RAG/src/plugins/loaders/Table.ts +3 -3
- package/misc/apps/RAG/src/plugins/loaders/Weather.ts +4 -3
- package/package.json +12 -2
- package/src/parsing/expressions/expression_map.ts +19 -0
- package/src/parsing/operations/call.ts +67 -0
- package/src/parsing/operations/load.ts +123 -120
- package/src/parsing/operations/operation.ts +14 -13
- package/src/parsing/operations/projection.ts +3 -3
- package/src/parsing/parser.ts +303 -239
- package/src/parsing/token_to_node.ts +67 -50
- package/src/tokenization/token.ts +29 -14
- package/tests/compute/runner.test.ts +277 -165
- package/tests/parsing/parser.test.ts +355 -303
- package/vscode-settings.json.recommended +16 -0
package/dist/parsing/parser.js
CHANGED
|
@@ -3,43 +3,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const token_1 = __importDefault(require("../tokenization/token"));
|
|
7
|
+
const object_utils_1 = __importDefault(require("../utils/object_utils"));
|
|
8
|
+
const alias_1 = __importDefault(require("./alias"));
|
|
9
|
+
const alias_option_1 = require("./alias_option");
|
|
8
10
|
const ast_node_1 = __importDefault(require("./ast_node"));
|
|
9
11
|
const base_parser_1 = __importDefault(require("./base_parser"));
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
+
const from_1 = __importDefault(require("./components/from"));
|
|
13
|
+
const headers_1 = __importDefault(require("./components/headers"));
|
|
14
|
+
const null_1 = __importDefault(require("./components/null"));
|
|
15
|
+
const post_1 = __importDefault(require("./components/post"));
|
|
16
|
+
const context_1 = __importDefault(require("./context"));
|
|
12
17
|
const associative_array_1 = __importDefault(require("./data_structures/associative_array"));
|
|
13
18
|
const json_array_1 = __importDefault(require("./data_structures/json_array"));
|
|
14
19
|
const key_value_pair_1 = __importDefault(require("./data_structures/key_value_pair"));
|
|
15
|
-
const with_1 = __importDefault(require("./operations/with"));
|
|
16
|
-
const unwind_1 = __importDefault(require("./operations/unwind"));
|
|
17
|
-
const where_1 = __importDefault(require("./operations/where"));
|
|
18
|
-
const alias_option_1 = require("./alias_option");
|
|
19
|
-
const load_1 = __importDefault(require("./operations/load"));
|
|
20
|
-
const from_1 = __importDefault(require("./components/from"));
|
|
21
|
-
const alias_1 = __importDefault(require("./alias"));
|
|
22
|
-
const headers_1 = __importDefault(require("./components/headers"));
|
|
23
|
-
const case_1 = __importDefault(require("./logic/case"));
|
|
24
|
-
const when_1 = __importDefault(require("./logic/when"));
|
|
25
|
-
const else_1 = __importDefault(require("./logic/else"));
|
|
26
|
-
const then_1 = __importDefault(require("./logic/then"));
|
|
27
20
|
const lookup_1 = __importDefault(require("./data_structures/lookup"));
|
|
21
|
+
const range_lookup_1 = __importDefault(require("./data_structures/range_lookup"));
|
|
22
|
+
const expression_1 = __importDefault(require("./expressions/expression"));
|
|
23
|
+
const f_string_1 = __importDefault(require("./expressions/f_string"));
|
|
24
|
+
const identifier_1 = __importDefault(require("./expressions/identifier"));
|
|
28
25
|
const operator_1 = require("./expressions/operator");
|
|
29
26
|
const reference_1 = __importDefault(require("./expressions/reference"));
|
|
30
|
-
const post_1 = __importDefault(require("./components/post"));
|
|
31
|
-
const aggregated_return_1 = __importDefault(require("./operations/aggregated_return"));
|
|
32
|
-
const context_1 = __importDefault(require("./context"));
|
|
33
|
-
const aggregate_function_1 = __importDefault(require("./functions/aggregate_function"));
|
|
34
|
-
const object_utils_1 = __importDefault(require("../utils/object_utils"));
|
|
35
|
-
const token_1 = __importDefault(require("../tokenization/token"));
|
|
36
|
-
const f_string_1 = __importDefault(require("./expressions/f_string"));
|
|
37
27
|
const string_1 = __importDefault(require("./expressions/string"));
|
|
28
|
+
const aggregate_function_1 = __importDefault(require("./functions/aggregate_function"));
|
|
29
|
+
const function_1 = __importDefault(require("./functions/function"));
|
|
30
|
+
const function_factory_1 = __importDefault(require("./functions/function_factory"));
|
|
31
|
+
const case_1 = __importDefault(require("./logic/case"));
|
|
32
|
+
const else_1 = __importDefault(require("./logic/else"));
|
|
33
|
+
const then_1 = __importDefault(require("./logic/then"));
|
|
34
|
+
const when_1 = __importDefault(require("./logic/when"));
|
|
35
|
+
const aggregated_return_1 = __importDefault(require("./operations/aggregated_return"));
|
|
38
36
|
const aggregated_with_1 = __importDefault(require("./operations/aggregated_with"));
|
|
39
|
-
const
|
|
37
|
+
const call_1 = __importDefault(require("./operations/call"));
|
|
40
38
|
const limit_1 = __importDefault(require("./operations/limit"));
|
|
41
|
-
const
|
|
42
|
-
const
|
|
39
|
+
const load_1 = __importDefault(require("./operations/load"));
|
|
40
|
+
const return_1 = __importDefault(require("./operations/return"));
|
|
41
|
+
const unwind_1 = __importDefault(require("./operations/unwind"));
|
|
42
|
+
const where_1 = __importDefault(require("./operations/where"));
|
|
43
|
+
const with_1 = __importDefault(require("./operations/with"));
|
|
43
44
|
/**
|
|
44
45
|
* Main parser for FlowQuery statements.
|
|
45
46
|
*
|
|
@@ -86,10 +87,13 @@ class Parser extends base_parser_1.default {
|
|
|
86
87
|
}
|
|
87
88
|
operation = this.parseOperation();
|
|
88
89
|
if (operation === null) {
|
|
89
|
-
throw new Error(
|
|
90
|
+
throw new Error("Expected one of WITH, UNWIND, RETURN, LOAD, OR CALL");
|
|
90
91
|
}
|
|
91
92
|
if (this._returns > 1) {
|
|
92
|
-
throw new Error(
|
|
93
|
+
throw new Error("Only one RETURN statement is allowed");
|
|
94
|
+
}
|
|
95
|
+
if (previous instanceof call_1.default && !previous.hasYield) {
|
|
96
|
+
throw new Error("CALL operations must have a YIELD clause unless they are the last operation");
|
|
93
97
|
}
|
|
94
98
|
if (previous !== null) {
|
|
95
99
|
previous.addSibling(operation);
|
|
@@ -114,8 +118,8 @@ class Parser extends base_parser_1.default {
|
|
|
114
118
|
}
|
|
115
119
|
previous = operation;
|
|
116
120
|
}
|
|
117
|
-
if (!(operation instanceof return_1.default)) {
|
|
118
|
-
throw new Error(
|
|
121
|
+
if (!(operation instanceof return_1.default) && !(operation instanceof call_1.default)) {
|
|
122
|
+
throw new Error("Last statement must be a RETURN, WHERE, or a CALL statement");
|
|
119
123
|
}
|
|
120
124
|
return root;
|
|
121
125
|
}
|
|
@@ -123,7 +127,8 @@ class Parser extends base_parser_1.default {
|
|
|
123
127
|
return (this.parseWith() ||
|
|
124
128
|
this.parseUnwind() ||
|
|
125
129
|
this.parseReturn() ||
|
|
126
|
-
this.parseLoad()
|
|
130
|
+
this.parseLoad() ||
|
|
131
|
+
this.parseCall());
|
|
127
132
|
}
|
|
128
133
|
parseWith() {
|
|
129
134
|
if (!this.token.isWith()) {
|
|
@@ -133,7 +138,7 @@ class Parser extends base_parser_1.default {
|
|
|
133
138
|
this.expectAndSkipWhitespaceAndComments();
|
|
134
139
|
const expressions = Array.from(this.parseExpressions(alias_option_1.AliasOption.REQUIRED));
|
|
135
140
|
if (expressions.length === 0) {
|
|
136
|
-
throw new Error(
|
|
141
|
+
throw new Error("Expected expression");
|
|
137
142
|
}
|
|
138
143
|
if (expressions.some((expression) => expression.has_reducers())) {
|
|
139
144
|
return new aggregated_with_1.default(expressions);
|
|
@@ -148,10 +153,16 @@ class Parser extends base_parser_1.default {
|
|
|
148
153
|
this.expectAndSkipWhitespaceAndComments();
|
|
149
154
|
const expression = this.parseExpression();
|
|
150
155
|
if (expression === null) {
|
|
151
|
-
throw new Error(
|
|
156
|
+
throw new Error("Expected expression");
|
|
152
157
|
}
|
|
153
|
-
if (!object_utils_1.default.isInstanceOfAny(expression.firstChild(), [
|
|
154
|
-
|
|
158
|
+
if (!object_utils_1.default.isInstanceOfAny(expression.firstChild(), [
|
|
159
|
+
json_array_1.default,
|
|
160
|
+
function_1.default,
|
|
161
|
+
reference_1.default,
|
|
162
|
+
lookup_1.default,
|
|
163
|
+
range_lookup_1.default,
|
|
164
|
+
])) {
|
|
165
|
+
throw new Error("Expected array, function, reference, or lookup.");
|
|
155
166
|
}
|
|
156
167
|
this.expectAndSkipWhitespaceAndComments();
|
|
157
168
|
const alias = this.parseAlias();
|
|
@@ -159,7 +170,7 @@ class Parser extends base_parser_1.default {
|
|
|
159
170
|
expression.setAlias(alias.getAlias());
|
|
160
171
|
}
|
|
161
172
|
else {
|
|
162
|
-
throw new Error(
|
|
173
|
+
throw new Error("Expected alias");
|
|
163
174
|
}
|
|
164
175
|
const unwind = new unwind_1.default(expression);
|
|
165
176
|
this.variables.set(alias.getAlias(), unwind);
|
|
@@ -173,7 +184,7 @@ class Parser extends base_parser_1.default {
|
|
|
173
184
|
this.expectAndSkipWhitespaceAndComments();
|
|
174
185
|
const expressions = Array.from(this.parseExpressions(alias_option_1.AliasOption.OPTIONAL));
|
|
175
186
|
if (expressions.length === 0) {
|
|
176
|
-
throw new Error(
|
|
187
|
+
throw new Error("Expected expression");
|
|
177
188
|
}
|
|
178
189
|
if (expressions.some((expression) => expression.has_reducers())) {
|
|
179
190
|
return new aggregated_return_1.default(expressions);
|
|
@@ -190,10 +201,10 @@ class Parser extends base_parser_1.default {
|
|
|
190
201
|
this.expectAndSkipWhitespaceAndComments();
|
|
191
202
|
const expression = this.parseExpression();
|
|
192
203
|
if (expression === null) {
|
|
193
|
-
throw new Error(
|
|
204
|
+
throw new Error("Expected expression");
|
|
194
205
|
}
|
|
195
206
|
if (object_utils_1.default.isInstanceOfAny(expression.firstChild(), [json_array_1.default, associative_array_1.default])) {
|
|
196
|
-
throw new Error(
|
|
207
|
+
throw new Error("Expected an expression which can be evaluated to a boolean");
|
|
197
208
|
}
|
|
198
209
|
return new where_1.default(expression);
|
|
199
210
|
}
|
|
@@ -205,13 +216,13 @@ class Parser extends base_parser_1.default {
|
|
|
205
216
|
this.setNextToken();
|
|
206
217
|
this.expectAndSkipWhitespaceAndComments();
|
|
207
218
|
if (!(this.token.isJSON() || this.token.isCSV() || this.token.isText())) {
|
|
208
|
-
throw new Error(
|
|
219
|
+
throw new Error("Expected JSON, CSV, or TEXT");
|
|
209
220
|
}
|
|
210
221
|
load.addChild(this.token.node);
|
|
211
222
|
this.setNextToken();
|
|
212
223
|
this.expectAndSkipWhitespaceAndComments();
|
|
213
224
|
if (!this.token.isFrom()) {
|
|
214
|
-
throw new Error(
|
|
225
|
+
throw new Error("Expected FROM");
|
|
215
226
|
}
|
|
216
227
|
this.setNextToken();
|
|
217
228
|
this.expectAndSkipWhitespaceAndComments();
|
|
@@ -225,7 +236,7 @@ class Parser extends base_parser_1.default {
|
|
|
225
236
|
else {
|
|
226
237
|
const expression = this.parseExpression();
|
|
227
238
|
if (expression === null) {
|
|
228
|
-
throw new Error(
|
|
239
|
+
throw new Error("Expected expression or async function");
|
|
229
240
|
}
|
|
230
241
|
from.addChild(expression);
|
|
231
242
|
}
|
|
@@ -236,7 +247,7 @@ class Parser extends base_parser_1.default {
|
|
|
236
247
|
this.expectAndSkipWhitespaceAndComments();
|
|
237
248
|
const header = this.parseExpression();
|
|
238
249
|
if (header === null) {
|
|
239
|
-
throw new Error(
|
|
250
|
+
throw new Error("Expected expression");
|
|
240
251
|
}
|
|
241
252
|
headers.addChild(header);
|
|
242
253
|
load.addChild(headers);
|
|
@@ -248,7 +259,7 @@ class Parser extends base_parser_1.default {
|
|
|
248
259
|
this.expectAndSkipWhitespaceAndComments();
|
|
249
260
|
const payload = this.parseExpression();
|
|
250
261
|
if (payload === null) {
|
|
251
|
-
throw new Error(
|
|
262
|
+
throw new Error("Expected expression");
|
|
252
263
|
}
|
|
253
264
|
post.addChild(payload);
|
|
254
265
|
load.addChild(post);
|
|
@@ -260,10 +271,35 @@ class Parser extends base_parser_1.default {
|
|
|
260
271
|
this.variables.set(alias.getAlias(), load);
|
|
261
272
|
}
|
|
262
273
|
else {
|
|
263
|
-
throw new Error(
|
|
274
|
+
throw new Error("Expected alias");
|
|
264
275
|
}
|
|
265
276
|
return load;
|
|
266
277
|
}
|
|
278
|
+
parseCall() {
|
|
279
|
+
if (!this.token.isCall()) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
this.setNextToken();
|
|
283
|
+
this.expectAndSkipWhitespaceAndComments();
|
|
284
|
+
const asyncFunction = this.parseAsyncFunction();
|
|
285
|
+
if (asyncFunction === null) {
|
|
286
|
+
throw new Error("Expected async function");
|
|
287
|
+
}
|
|
288
|
+
const call = new call_1.default();
|
|
289
|
+
call.function = asyncFunction;
|
|
290
|
+
this.skipWhitespaceAndComments();
|
|
291
|
+
if (this.token.isYield()) {
|
|
292
|
+
this.expectPreviousTokenToBeWhitespaceOrComment();
|
|
293
|
+
this.setNextToken();
|
|
294
|
+
this.expectAndSkipWhitespaceAndComments();
|
|
295
|
+
const expressions = Array.from(this.parseExpressions(alias_option_1.AliasOption.OPTIONAL));
|
|
296
|
+
if (expressions.length === 0) {
|
|
297
|
+
throw new Error("Expected at least one expression");
|
|
298
|
+
}
|
|
299
|
+
call.yielded = expressions;
|
|
300
|
+
}
|
|
301
|
+
return call;
|
|
302
|
+
}
|
|
267
303
|
parseLimit() {
|
|
268
304
|
this.skipWhitespaceAndComments();
|
|
269
305
|
if (!this.token.isLimit()) {
|
|
@@ -273,9 +309,9 @@ class Parser extends base_parser_1.default {
|
|
|
273
309
|
this.setNextToken();
|
|
274
310
|
this.expectAndSkipWhitespaceAndComments();
|
|
275
311
|
if (!this.token.isNumber()) {
|
|
276
|
-
throw new Error(
|
|
312
|
+
throw new Error("Expected number");
|
|
277
313
|
}
|
|
278
|
-
const limit = new limit_1.default(parseInt(this.token.value ||
|
|
314
|
+
const limit = new limit_1.default(parseInt(this.token.value || "0"));
|
|
279
315
|
this.setNextToken();
|
|
280
316
|
return limit;
|
|
281
317
|
}
|
|
@@ -289,13 +325,16 @@ class Parser extends base_parser_1.default {
|
|
|
289
325
|
expression.setAlias(reference.identifier);
|
|
290
326
|
this.variables.set(reference.identifier, expression);
|
|
291
327
|
}
|
|
292
|
-
else if (alias_option === alias_option_1.AliasOption.REQUIRED &&
|
|
293
|
-
|
|
328
|
+
else if (alias_option === alias_option_1.AliasOption.REQUIRED &&
|
|
329
|
+
alias === null &&
|
|
330
|
+
!(expression.firstChild() instanceof reference_1.default)) {
|
|
331
|
+
throw new Error("Alias required");
|
|
294
332
|
}
|
|
295
333
|
else if (alias_option === alias_option_1.AliasOption.NOT_ALLOWED && alias !== null) {
|
|
296
|
-
throw new Error(
|
|
334
|
+
throw new Error("Alias not allowed");
|
|
297
335
|
}
|
|
298
|
-
else if ([alias_option_1.AliasOption.OPTIONAL, alias_option_1.AliasOption.REQUIRED].includes(alias_option) &&
|
|
336
|
+
else if ([alias_option_1.AliasOption.OPTIONAL, alias_option_1.AliasOption.REQUIRED].includes(alias_option) &&
|
|
337
|
+
alias !== null) {
|
|
299
338
|
expression.setAlias(alias.getAlias());
|
|
300
339
|
this.variables.set(alias.getAlias(), expression);
|
|
301
340
|
}
|
|
@@ -317,7 +356,7 @@ class Parser extends base_parser_1.default {
|
|
|
317
356
|
while (true) {
|
|
318
357
|
this.skipWhitespaceAndComments();
|
|
319
358
|
if (this.token.isIdentifier() && !((_a = this.peek()) === null || _a === void 0 ? void 0 : _a.isLeftParenthesis())) {
|
|
320
|
-
const identifier = this.token.value ||
|
|
359
|
+
const identifier = this.token.value || "";
|
|
321
360
|
const reference = new reference_1.default(identifier, this.variables.get(identifier));
|
|
322
361
|
this.setNextToken();
|
|
323
362
|
const lookup = this.parseLookup(reference);
|
|
@@ -337,7 +376,7 @@ class Parser extends base_parser_1.default {
|
|
|
337
376
|
else if (this.token.isFString()) {
|
|
338
377
|
const f_string = this.parseFString();
|
|
339
378
|
if (f_string === null) {
|
|
340
|
-
throw new Error(
|
|
379
|
+
throw new Error("Expected f-string");
|
|
341
380
|
}
|
|
342
381
|
expression.addNode(f_string);
|
|
343
382
|
}
|
|
@@ -345,10 +384,10 @@ class Parser extends base_parser_1.default {
|
|
|
345
384
|
this.setNextToken();
|
|
346
385
|
const sub = this.parseExpression();
|
|
347
386
|
if (sub === null) {
|
|
348
|
-
throw new Error(
|
|
387
|
+
throw new Error("Expected expression");
|
|
349
388
|
}
|
|
350
389
|
if (!this.token.isRightParenthesis()) {
|
|
351
|
-
throw new Error(
|
|
390
|
+
throw new Error("Expected right parenthesis");
|
|
352
391
|
}
|
|
353
392
|
this.setNextToken();
|
|
354
393
|
const lookup = this.parseLookup(sub);
|
|
@@ -357,7 +396,7 @@ class Parser extends base_parser_1.default {
|
|
|
357
396
|
else if (this.token.isOpeningBrace() || this.token.isOpeningBracket()) {
|
|
358
397
|
const json = this.parseJSON();
|
|
359
398
|
if (json === null) {
|
|
360
|
-
throw new Error(
|
|
399
|
+
throw new Error("Expected JSON object");
|
|
361
400
|
}
|
|
362
401
|
const lookup = this.parseLookup(json);
|
|
363
402
|
expression.addNode(lookup);
|
|
@@ -365,7 +404,7 @@ class Parser extends base_parser_1.default {
|
|
|
365
404
|
else if (this.token.isCase()) {
|
|
366
405
|
const _case = this.parseCase();
|
|
367
406
|
if (_case === null) {
|
|
368
|
-
throw new Error(
|
|
407
|
+
throw new Error("Expected CASE statement");
|
|
369
408
|
}
|
|
370
409
|
expression.addNode(_case);
|
|
371
410
|
}
|
|
@@ -374,14 +413,14 @@ class Parser extends base_parser_1.default {
|
|
|
374
413
|
this.setNextToken();
|
|
375
414
|
const sub = this.parseExpression();
|
|
376
415
|
if (sub === null) {
|
|
377
|
-
throw new Error(
|
|
416
|
+
throw new Error("Expected expression");
|
|
378
417
|
}
|
|
379
418
|
not.addChild(sub);
|
|
380
419
|
expression.addNode(not);
|
|
381
420
|
}
|
|
382
421
|
else {
|
|
383
422
|
if (expression.nodesAdded()) {
|
|
384
|
-
throw new Error(
|
|
423
|
+
throw new Error("Expected operand or left parenthesis");
|
|
385
424
|
}
|
|
386
425
|
else {
|
|
387
426
|
break;
|
|
@@ -409,10 +448,10 @@ class Parser extends base_parser_1.default {
|
|
|
409
448
|
if (this.token.isDot()) {
|
|
410
449
|
this.setNextToken();
|
|
411
450
|
if (!this.token.isIdentifier() && !this.token.isKeyword()) {
|
|
412
|
-
throw new Error(
|
|
451
|
+
throw new Error("Expected identifier");
|
|
413
452
|
}
|
|
414
453
|
lookup = new lookup_1.default();
|
|
415
|
-
lookup.index = new identifier_1.default(this.token.value ||
|
|
454
|
+
lookup.index = new identifier_1.default(this.token.value || "");
|
|
416
455
|
lookup.variable = variable;
|
|
417
456
|
this.setNextToken();
|
|
418
457
|
}
|
|
@@ -430,13 +469,13 @@ class Parser extends base_parser_1.default {
|
|
|
430
469
|
}
|
|
431
470
|
else {
|
|
432
471
|
if (index === null) {
|
|
433
|
-
throw new Error(
|
|
472
|
+
throw new Error("Expected expression");
|
|
434
473
|
}
|
|
435
474
|
lookup = new lookup_1.default();
|
|
436
475
|
}
|
|
437
476
|
this.skipWhitespaceAndComments();
|
|
438
477
|
if (!this.token.isClosingBracket()) {
|
|
439
|
-
throw new Error(
|
|
478
|
+
throw new Error("Expected closing bracket");
|
|
440
479
|
}
|
|
441
480
|
this.setNextToken();
|
|
442
481
|
if (lookup instanceof range_lookup_1.default) {
|
|
@@ -466,7 +505,7 @@ class Parser extends base_parser_1.default {
|
|
|
466
505
|
while (true) {
|
|
467
506
|
const when = this.parseWhen();
|
|
468
507
|
if (when === null && parts === 0) {
|
|
469
|
-
throw new Error(
|
|
508
|
+
throw new Error("Expected WHEN");
|
|
470
509
|
}
|
|
471
510
|
else if (when === null && parts > 0) {
|
|
472
511
|
break;
|
|
@@ -477,7 +516,7 @@ class Parser extends base_parser_1.default {
|
|
|
477
516
|
this.expectAndSkipWhitespaceAndComments();
|
|
478
517
|
const then = this.parseThen();
|
|
479
518
|
if (then === null) {
|
|
480
|
-
throw new Error(
|
|
519
|
+
throw new Error("Expected THEN");
|
|
481
520
|
}
|
|
482
521
|
else {
|
|
483
522
|
_case.addChild(then);
|
|
@@ -487,14 +526,14 @@ class Parser extends base_parser_1.default {
|
|
|
487
526
|
}
|
|
488
527
|
const _else = this.parseElse();
|
|
489
528
|
if (_else === null) {
|
|
490
|
-
throw new Error(
|
|
529
|
+
throw new Error("Expected ELSE");
|
|
491
530
|
}
|
|
492
531
|
else {
|
|
493
532
|
_case.addChild(_else);
|
|
494
533
|
}
|
|
495
534
|
this.expectAndSkipWhitespaceAndComments();
|
|
496
535
|
if (!this.token.isEnd()) {
|
|
497
|
-
throw new Error(
|
|
536
|
+
throw new Error("Expected END");
|
|
498
537
|
}
|
|
499
538
|
this.setNextToken();
|
|
500
539
|
return _case;
|
|
@@ -508,7 +547,7 @@ class Parser extends base_parser_1.default {
|
|
|
508
547
|
this.expectAndSkipWhitespaceAndComments();
|
|
509
548
|
const expression = this.parseExpression();
|
|
510
549
|
if (expression === null) {
|
|
511
|
-
throw new Error(
|
|
550
|
+
throw new Error("Expected expression");
|
|
512
551
|
}
|
|
513
552
|
when.addChild(expression);
|
|
514
553
|
return when;
|
|
@@ -522,7 +561,7 @@ class Parser extends base_parser_1.default {
|
|
|
522
561
|
this.expectAndSkipWhitespaceAndComments();
|
|
523
562
|
const expression = this.parseExpression();
|
|
524
563
|
if (expression === null) {
|
|
525
|
-
throw new Error(
|
|
564
|
+
throw new Error("Expected expression");
|
|
526
565
|
}
|
|
527
566
|
then.addChild(expression);
|
|
528
567
|
return then;
|
|
@@ -536,7 +575,7 @@ class Parser extends base_parser_1.default {
|
|
|
536
575
|
this.expectAndSkipWhitespaceAndComments();
|
|
537
576
|
const expression = this.parseExpression();
|
|
538
577
|
if (expression === null) {
|
|
539
|
-
throw new Error(
|
|
578
|
+
throw new Error("Expected expression");
|
|
540
579
|
}
|
|
541
580
|
_else.addChild(expression);
|
|
542
581
|
return _else;
|
|
@@ -550,9 +589,9 @@ class Parser extends base_parser_1.default {
|
|
|
550
589
|
this.setNextToken();
|
|
551
590
|
this.expectAndSkipWhitespaceAndComments();
|
|
552
591
|
if ((!this.token.isIdentifier() && !this.token.isKeyword()) || this.token.value === null) {
|
|
553
|
-
throw new Error(
|
|
592
|
+
throw new Error("Expected identifier");
|
|
554
593
|
}
|
|
555
|
-
const alias = new alias_1.default(this.token.value ||
|
|
594
|
+
const alias = new alias_1.default(this.token.value || "");
|
|
556
595
|
this.setNextToken();
|
|
557
596
|
return alias;
|
|
558
597
|
}
|
|
@@ -562,14 +601,14 @@ class Parser extends base_parser_1.default {
|
|
|
562
601
|
return null;
|
|
563
602
|
}
|
|
564
603
|
if (this.token.value === null) {
|
|
565
|
-
throw new Error(
|
|
604
|
+
throw new Error("Expected identifier");
|
|
566
605
|
}
|
|
567
606
|
if (!((_a = this.peek()) === null || _a === void 0 ? void 0 : _a.isLeftParenthesis())) {
|
|
568
607
|
return null;
|
|
569
608
|
}
|
|
570
609
|
const func = function_factory_1.default.create(this.token.value);
|
|
571
610
|
if (func instanceof aggregate_function_1.default && this.context.containsType(aggregate_function_1.default)) {
|
|
572
|
-
throw new Error(
|
|
611
|
+
throw new Error("Aggregate functions cannot be nested");
|
|
573
612
|
}
|
|
574
613
|
this.context.push(func);
|
|
575
614
|
this.setNextToken();
|
|
@@ -583,7 +622,7 @@ class Parser extends base_parser_1.default {
|
|
|
583
622
|
func.parameters = Array.from(this.parseExpressions(alias_option_1.AliasOption.NOT_ALLOWED));
|
|
584
623
|
this.skipWhitespaceAndComments();
|
|
585
624
|
if (!this.token.isRightParenthesis()) {
|
|
586
|
-
throw new Error(
|
|
625
|
+
throw new Error("Expected right parenthesis");
|
|
587
626
|
}
|
|
588
627
|
this.setNextToken();
|
|
589
628
|
this.context.pop();
|
|
@@ -617,27 +656,32 @@ class Parser extends base_parser_1.default {
|
|
|
617
656
|
asyncFunc.parameters = Array.from(this.parseExpressions(alias_option_1.AliasOption.NOT_ALLOWED));
|
|
618
657
|
this.skipWhitespaceAndComments();
|
|
619
658
|
if (!this.token.isRightParenthesis()) {
|
|
620
|
-
throw new Error(
|
|
659
|
+
throw new Error("Expected right parenthesis");
|
|
621
660
|
}
|
|
622
661
|
this.setNextToken();
|
|
623
662
|
return asyncFunc;
|
|
624
663
|
}
|
|
625
664
|
parsePredicateFunction() {
|
|
626
|
-
if (!this.ahead([
|
|
665
|
+
if (!this.ahead([
|
|
666
|
+
token_1.default.IDENTIFIER(""),
|
|
667
|
+
token_1.default.LEFT_PARENTHESIS,
|
|
668
|
+
token_1.default.IDENTIFIER(""),
|
|
669
|
+
token_1.default.IN,
|
|
670
|
+
])) {
|
|
627
671
|
return null;
|
|
628
672
|
}
|
|
629
673
|
if (this.token.value === null) {
|
|
630
|
-
throw new Error(
|
|
674
|
+
throw new Error("Expected identifier");
|
|
631
675
|
}
|
|
632
676
|
const func = function_factory_1.default.createPredicate(this.token.value);
|
|
633
677
|
this.setNextToken();
|
|
634
678
|
if (!this.token.isLeftParenthesis()) {
|
|
635
|
-
throw new Error(
|
|
679
|
+
throw new Error("Expected left parenthesis");
|
|
636
680
|
}
|
|
637
681
|
this.setNextToken();
|
|
638
682
|
this.skipWhitespaceAndComments();
|
|
639
683
|
if (!this.token.isIdentifier()) {
|
|
640
|
-
throw new Error(
|
|
684
|
+
throw new Error("Expected identifier");
|
|
641
685
|
}
|
|
642
686
|
const reference = new reference_1.default(this.token.value);
|
|
643
687
|
this.variables.set(reference.identifier, reference);
|
|
@@ -645,26 +689,31 @@ class Parser extends base_parser_1.default {
|
|
|
645
689
|
this.setNextToken();
|
|
646
690
|
this.expectAndSkipWhitespaceAndComments();
|
|
647
691
|
if (!this.token.isIn()) {
|
|
648
|
-
throw new Error(
|
|
692
|
+
throw new Error("Expected IN");
|
|
649
693
|
}
|
|
650
694
|
this.setNextToken();
|
|
651
695
|
this.expectAndSkipWhitespaceAndComments();
|
|
652
696
|
const expression = this.parseExpression();
|
|
653
697
|
if (expression === null) {
|
|
654
|
-
throw new Error(
|
|
698
|
+
throw new Error("Expected expression");
|
|
655
699
|
}
|
|
656
|
-
if (!object_utils_1.default.isInstanceOfAny(expression.firstChild(), [
|
|
657
|
-
|
|
700
|
+
if (!object_utils_1.default.isInstanceOfAny(expression.firstChild(), [
|
|
701
|
+
json_array_1.default,
|
|
702
|
+
reference_1.default,
|
|
703
|
+
lookup_1.default,
|
|
704
|
+
function_1.default,
|
|
705
|
+
])) {
|
|
706
|
+
throw new Error("Expected array or reference");
|
|
658
707
|
}
|
|
659
708
|
func.addChild(expression);
|
|
660
709
|
this.skipWhitespaceAndComments();
|
|
661
710
|
if (!this.token.isPipe()) {
|
|
662
|
-
throw new Error(
|
|
711
|
+
throw new Error("Expected pipe");
|
|
663
712
|
}
|
|
664
713
|
this.setNextToken();
|
|
665
714
|
const _return = this.parseExpression();
|
|
666
715
|
if (_return === null) {
|
|
667
|
-
throw new Error(
|
|
716
|
+
throw new Error("Expected expression");
|
|
668
717
|
}
|
|
669
718
|
func.addChild(_return);
|
|
670
719
|
const where = this.parseWhere();
|
|
@@ -673,7 +722,7 @@ class Parser extends base_parser_1.default {
|
|
|
673
722
|
}
|
|
674
723
|
this.skipWhitespaceAndComments();
|
|
675
724
|
if (!this.token.isRightParenthesis()) {
|
|
676
|
-
throw new Error(
|
|
725
|
+
throw new Error("Expected right parenthesis");
|
|
677
726
|
}
|
|
678
727
|
this.setNextToken();
|
|
679
728
|
this.variables.delete(reference.identifier);
|
|
@@ -693,11 +742,11 @@ class Parser extends base_parser_1.default {
|
|
|
693
742
|
this.setNextToken();
|
|
694
743
|
const expression = this.parseExpression();
|
|
695
744
|
if (expression === null) {
|
|
696
|
-
throw new Error(
|
|
745
|
+
throw new Error("Expected expression");
|
|
697
746
|
}
|
|
698
747
|
f_string.addChild(expression);
|
|
699
748
|
if (!this.token.isClosingBrace()) {
|
|
700
|
-
throw new Error(
|
|
749
|
+
throw new Error("Expected closing brace");
|
|
701
750
|
}
|
|
702
751
|
this.setNextToken();
|
|
703
752
|
}
|
|
@@ -711,18 +760,18 @@ class Parser extends base_parser_1.default {
|
|
|
711
760
|
if (this.token.isOpeningBrace()) {
|
|
712
761
|
const array = this.parseAssociativeArray();
|
|
713
762
|
if (array === null) {
|
|
714
|
-
throw new Error(
|
|
763
|
+
throw new Error("Expected associative array");
|
|
715
764
|
}
|
|
716
765
|
return array;
|
|
717
766
|
}
|
|
718
767
|
else if (this.token.isOpeningBracket()) {
|
|
719
768
|
const array = this.parseJSONArray();
|
|
720
769
|
if (array === null) {
|
|
721
|
-
throw new Error(
|
|
770
|
+
throw new Error("Expected JSON array");
|
|
722
771
|
}
|
|
723
772
|
return array;
|
|
724
773
|
}
|
|
725
|
-
throw new Error(
|
|
774
|
+
throw new Error("Expected opening brace or bracket");
|
|
726
775
|
}
|
|
727
776
|
parseAssociativeArray() {
|
|
728
777
|
if (!this.token.isOpeningBrace()) {
|
|
@@ -736,22 +785,22 @@ class Parser extends base_parser_1.default {
|
|
|
736
785
|
break;
|
|
737
786
|
}
|
|
738
787
|
if (!this.token.isIdentifier() && !this.token.isKeyword()) {
|
|
739
|
-
throw new Error(
|
|
788
|
+
throw new Error("Expected identifier");
|
|
740
789
|
}
|
|
741
790
|
const key = this.token.value;
|
|
742
791
|
if (key === null) {
|
|
743
|
-
throw new Error(
|
|
792
|
+
throw new Error("Expected string");
|
|
744
793
|
}
|
|
745
794
|
this.setNextToken();
|
|
746
795
|
this.skipWhitespaceAndComments();
|
|
747
796
|
if (!this.token.isColon()) {
|
|
748
|
-
throw new Error(
|
|
797
|
+
throw new Error("Expected colon");
|
|
749
798
|
}
|
|
750
799
|
this.setNextToken();
|
|
751
800
|
this.skipWhitespaceAndComments();
|
|
752
801
|
const value = this.parseExpression();
|
|
753
802
|
if (value === null) {
|
|
754
|
-
throw new Error(
|
|
803
|
+
throw new Error("Expected expression");
|
|
755
804
|
}
|
|
756
805
|
array.addKeyValue(new key_value_pair_1.default(key, value));
|
|
757
806
|
this.skipWhitespaceAndComments();
|
|
@@ -775,7 +824,7 @@ class Parser extends base_parser_1.default {
|
|
|
775
824
|
}
|
|
776
825
|
const value = this.parseExpression();
|
|
777
826
|
if (value === null) {
|
|
778
|
-
throw new Error(
|
|
827
|
+
throw new Error("Expected expression");
|
|
779
828
|
}
|
|
780
829
|
array.addValue(value);
|
|
781
830
|
this.skipWhitespaceAndComments();
|
|
@@ -789,7 +838,7 @@ class Parser extends base_parser_1.default {
|
|
|
789
838
|
expectAndSkipWhitespaceAndComments() {
|
|
790
839
|
const skipped = this.skipWhitespaceAndComments();
|
|
791
840
|
if (!skipped) {
|
|
792
|
-
throw new Error(
|
|
841
|
+
throw new Error("Expected whitespace or comment");
|
|
793
842
|
}
|
|
794
843
|
}
|
|
795
844
|
skipWhitespaceAndComments() {
|
|
@@ -802,7 +851,7 @@ class Parser extends base_parser_1.default {
|
|
|
802
851
|
}
|
|
803
852
|
expectPreviousTokenToBeWhitespaceOrComment() {
|
|
804
853
|
if (!this.previousToken.isWhitespaceOrComment()) {
|
|
805
|
-
throw new Error(
|
|
854
|
+
throw new Error("Expected whitespace or comment");
|
|
806
855
|
}
|
|
807
856
|
}
|
|
808
857
|
}
|