@surrealdb/lezer 1.0.0-beta.8 → 1.0.0
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/dist/index.cjs +367 -301
- package/dist/index.js +367 -303
- package/dist/typing.d.ts +6 -0
- package/package.json +35 -27
- package/rollup.config.js +9 -5
- package/src/highlight.js +6 -4
- package/src/index.js +2 -0
- package/src/parser.js +21 -18
- package/src/parser.terms.js +382 -365
- package/src/surrealql.grammar +837 -600
- package/src/tokens.js +171 -132
- package/src/typing.d.ts +6 -0
- package/src/version.js +15 -0
- package/test/statement.txt +85 -0
- package/test/test-surrealql.js +5 -5
- package/test/value.txt +32 -1
- package/LICENSE +0 -201
package/src/tokens.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ExternalTokenizer} from "@lezer/lr";
|
|
1
|
+
import { ExternalTokenizer } from "@lezer/lr";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
_break,
|
|
@@ -15,28 +15,40 @@ import {
|
|
|
15
15
|
_with,
|
|
16
16
|
access,
|
|
17
17
|
algorithm,
|
|
18
|
+
all,
|
|
18
19
|
alter,
|
|
20
|
+
always,
|
|
19
21
|
analyzer,
|
|
20
22
|
any,
|
|
23
|
+
api,
|
|
21
24
|
as,
|
|
22
25
|
asc,
|
|
23
26
|
assert,
|
|
24
27
|
at,
|
|
25
28
|
authenticate,
|
|
29
|
+
auto,
|
|
30
|
+
backend,
|
|
26
31
|
begin,
|
|
27
32
|
bm25,
|
|
33
|
+
bucket,
|
|
28
34
|
by,
|
|
29
35
|
cancel,
|
|
30
36
|
capacity,
|
|
37
|
+
cascade,
|
|
31
38
|
changefeed,
|
|
32
39
|
changes,
|
|
40
|
+
collate,
|
|
33
41
|
columns,
|
|
34
42
|
comment,
|
|
35
43
|
commit,
|
|
44
|
+
computed,
|
|
45
|
+
concurrently,
|
|
46
|
+
config,
|
|
36
47
|
content,
|
|
37
48
|
create,
|
|
38
49
|
database,
|
|
39
50
|
db,
|
|
51
|
+
defer,
|
|
40
52
|
define,
|
|
41
53
|
desc,
|
|
42
54
|
dimension,
|
|
@@ -50,9 +62,12 @@ import {
|
|
|
50
62
|
duration,
|
|
51
63
|
efc,
|
|
52
64
|
end,
|
|
65
|
+
enforced,
|
|
53
66
|
event,
|
|
67
|
+
exclude,
|
|
54
68
|
exists,
|
|
55
69
|
explain,
|
|
70
|
+
expunge,
|
|
56
71
|
extend_candidates,
|
|
57
72
|
fetch,
|
|
58
73
|
field,
|
|
@@ -60,10 +75,14 @@ import {
|
|
|
60
75
|
filters,
|
|
61
76
|
flexible,
|
|
62
77
|
from,
|
|
78
|
+
functions,
|
|
79
|
+
get,
|
|
80
|
+
graphql,
|
|
63
81
|
group,
|
|
64
82
|
highlights,
|
|
65
83
|
hnsw,
|
|
66
84
|
ignore,
|
|
85
|
+
include,
|
|
67
86
|
index,
|
|
68
87
|
info,
|
|
69
88
|
insert,
|
|
@@ -79,6 +98,7 @@ import {
|
|
|
79
98
|
m,
|
|
80
99
|
m0,
|
|
81
100
|
merge,
|
|
101
|
+
middleware,
|
|
82
102
|
mtree_cache,
|
|
83
103
|
mtree,
|
|
84
104
|
namespace,
|
|
@@ -86,6 +106,8 @@ import {
|
|
|
86
106
|
normal,
|
|
87
107
|
not,
|
|
88
108
|
ns,
|
|
109
|
+
numeric,
|
|
110
|
+
omit,
|
|
89
111
|
on,
|
|
90
112
|
only,
|
|
91
113
|
option,
|
|
@@ -98,14 +120,19 @@ import {
|
|
|
98
120
|
password,
|
|
99
121
|
patch,
|
|
100
122
|
permissions,
|
|
123
|
+
post,
|
|
101
124
|
postings_cache,
|
|
102
125
|
postings_order,
|
|
126
|
+
put,
|
|
103
127
|
readonly,
|
|
104
128
|
rebuild,
|
|
105
129
|
record,
|
|
130
|
+
reference,
|
|
131
|
+
reject,
|
|
106
132
|
relate,
|
|
107
133
|
relation,
|
|
108
134
|
remove,
|
|
135
|
+
replace,
|
|
109
136
|
roles,
|
|
110
137
|
root,
|
|
111
138
|
sc,
|
|
@@ -119,12 +146,13 @@ import {
|
|
|
119
146
|
show,
|
|
120
147
|
signin,
|
|
121
148
|
signup,
|
|
122
|
-
since,
|
|
149
|
+
since as _since,
|
|
123
150
|
sleep,
|
|
124
151
|
split,
|
|
125
152
|
start,
|
|
126
153
|
structure,
|
|
127
154
|
table,
|
|
155
|
+
tables,
|
|
128
156
|
tb,
|
|
129
157
|
tempfiles,
|
|
130
158
|
terms_cache,
|
|
@@ -134,6 +162,7 @@ import {
|
|
|
134
162
|
to,
|
|
135
163
|
token,
|
|
136
164
|
tokenizers,
|
|
165
|
+
trace,
|
|
137
166
|
transaction,
|
|
138
167
|
typeKeyword,
|
|
139
168
|
unique,
|
|
@@ -145,6 +174,7 @@ import {
|
|
|
145
174
|
user,
|
|
146
175
|
valueKeyword,
|
|
147
176
|
values,
|
|
177
|
+
version,
|
|
148
178
|
when,
|
|
149
179
|
where,
|
|
150
180
|
|
|
@@ -157,103 +187,67 @@ import {
|
|
|
157
187
|
diff,
|
|
158
188
|
full,
|
|
159
189
|
none,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
f64,
|
|
163
|
-
i16,
|
|
164
|
-
i32,
|
|
165
|
-
i64,
|
|
166
|
-
|
|
167
|
-
createPermissions,
|
|
168
|
-
deletePermissions,
|
|
169
|
-
selectPermissions,
|
|
170
|
-
updatePermissions,
|
|
171
|
-
|
|
172
|
-
jwks,
|
|
173
|
-
eddsa,
|
|
174
|
-
es256,
|
|
175
|
-
es384,
|
|
176
|
-
es512,
|
|
177
|
-
ps256,
|
|
178
|
-
ps384,
|
|
179
|
-
ps512,
|
|
180
|
-
rs256,
|
|
181
|
-
rs384,
|
|
182
|
-
rs512,
|
|
183
|
-
|
|
184
|
-
allinside,
|
|
185
|
-
and,
|
|
186
|
-
anyinside,
|
|
187
|
-
contains,
|
|
188
|
-
containsall,
|
|
189
|
-
containsany,
|
|
190
|
-
containsnone,
|
|
191
|
-
containsnot,
|
|
192
|
-
inside,
|
|
193
|
-
intersects,
|
|
190
|
+
IndexTypeClause,
|
|
191
|
+
TokenType,
|
|
194
192
|
is,
|
|
195
|
-
|
|
196
|
-
notinside,
|
|
193
|
+
binaryOperatorKeyword,
|
|
197
194
|
opIn,
|
|
198
195
|
opNot,
|
|
199
|
-
|
|
200
|
-
outside,
|
|
201
|
-
|
|
202
|
-
chebyshev,
|
|
203
|
-
cosine,
|
|
204
|
-
euclidean,
|
|
205
|
-
hamming,
|
|
206
|
-
jaccard,
|
|
207
|
-
manhattan,
|
|
196
|
+
Distance,
|
|
208
197
|
minkowski,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
ascii,
|
|
212
|
-
edgengram,
|
|
213
|
-
ngram,
|
|
214
|
-
snowball,
|
|
215
|
-
uppercase,
|
|
216
|
-
|
|
217
|
-
_class,
|
|
218
|
-
blank,
|
|
219
|
-
camel,
|
|
220
|
-
punct,
|
|
221
|
-
|
|
198
|
+
Filter,
|
|
199
|
+
AnalyzerTokenizer,
|
|
222
200
|
_function,
|
|
223
201
|
rand,
|
|
224
202
|
count,
|
|
225
|
-
|
|
226
203
|
objectOpen,
|
|
204
|
+
|
|
205
|
+
rangeOp,
|
|
206
|
+
rangeOpOpenLeft,
|
|
207
|
+
rangeOpOpenRight,
|
|
208
|
+
rangeOpOpenBoth
|
|
227
209
|
} from "./parser.terms";
|
|
228
210
|
|
|
229
211
|
const tokenMap = {
|
|
230
212
|
access,
|
|
231
213
|
algorithm,
|
|
214
|
+
all,
|
|
232
215
|
alter,
|
|
216
|
+
always,
|
|
233
217
|
analyzer,
|
|
234
218
|
any,
|
|
219
|
+
api,
|
|
235
220
|
as,
|
|
236
221
|
asc,
|
|
237
222
|
assert,
|
|
238
223
|
at,
|
|
239
224
|
authenticate,
|
|
225
|
+
auto,
|
|
226
|
+
backend,
|
|
240
227
|
begin,
|
|
241
228
|
bm25,
|
|
242
229
|
break: _break,
|
|
230
|
+
bucket,
|
|
243
231
|
by,
|
|
244
232
|
cancel,
|
|
245
233
|
capacity,
|
|
234
|
+
cascade,
|
|
246
235
|
changefeed,
|
|
247
236
|
changes,
|
|
237
|
+
collate,
|
|
248
238
|
columns,
|
|
249
239
|
comment,
|
|
250
240
|
commit,
|
|
241
|
+
computed,
|
|
242
|
+
concurrently,
|
|
243
|
+
config,
|
|
251
244
|
content,
|
|
252
245
|
continue: _continue,
|
|
253
246
|
create,
|
|
254
247
|
database,
|
|
255
248
|
db,
|
|
256
249
|
default: _default,
|
|
250
|
+
defer,
|
|
257
251
|
define,
|
|
258
252
|
delete: _delete,
|
|
259
253
|
desc,
|
|
@@ -269,9 +263,12 @@ const tokenMap = {
|
|
|
269
263
|
efc,
|
|
270
264
|
else: _else,
|
|
271
265
|
end,
|
|
266
|
+
enforced,
|
|
272
267
|
event,
|
|
268
|
+
exclude,
|
|
273
269
|
exists,
|
|
274
270
|
explain,
|
|
271
|
+
expunge,
|
|
275
272
|
extend_candidates,
|
|
276
273
|
fetch,
|
|
277
274
|
field,
|
|
@@ -280,12 +277,16 @@ const tokenMap = {
|
|
|
280
277
|
flexible,
|
|
281
278
|
for: _for,
|
|
282
279
|
from,
|
|
280
|
+
functions,
|
|
281
|
+
get,
|
|
282
|
+
graphql,
|
|
283
283
|
group,
|
|
284
284
|
highlights,
|
|
285
285
|
hnsw,
|
|
286
286
|
if: _if,
|
|
287
287
|
ignore,
|
|
288
288
|
in: _in,
|
|
289
|
+
include,
|
|
289
290
|
index,
|
|
290
291
|
info,
|
|
291
292
|
insert,
|
|
@@ -302,6 +303,7 @@ const tokenMap = {
|
|
|
302
303
|
m,
|
|
303
304
|
m0,
|
|
304
305
|
merge,
|
|
306
|
+
middleware,
|
|
305
307
|
mtree_cache,
|
|
306
308
|
mtree,
|
|
307
309
|
namespace,
|
|
@@ -309,6 +311,8 @@ const tokenMap = {
|
|
|
309
311
|
normal,
|
|
310
312
|
not,
|
|
311
313
|
ns,
|
|
314
|
+
numeric,
|
|
315
|
+
omit,
|
|
312
316
|
on,
|
|
313
317
|
only,
|
|
314
318
|
option,
|
|
@@ -321,14 +325,19 @@ const tokenMap = {
|
|
|
321
325
|
password,
|
|
322
326
|
patch,
|
|
323
327
|
permissions,
|
|
328
|
+
post,
|
|
324
329
|
postings_cache,
|
|
325
330
|
postings_order,
|
|
331
|
+
put,
|
|
326
332
|
readonly,
|
|
327
333
|
rebuild,
|
|
328
334
|
record,
|
|
335
|
+
reference,
|
|
336
|
+
reject,
|
|
329
337
|
relate,
|
|
330
338
|
relation,
|
|
331
339
|
remove,
|
|
340
|
+
replace,
|
|
332
341
|
return: _return,
|
|
333
342
|
roles,
|
|
334
343
|
root,
|
|
@@ -343,12 +352,13 @@ const tokenMap = {
|
|
|
343
352
|
show,
|
|
344
353
|
signin,
|
|
345
354
|
signup,
|
|
346
|
-
since,
|
|
355
|
+
since: _since,
|
|
347
356
|
sleep,
|
|
348
357
|
split,
|
|
349
358
|
start,
|
|
350
359
|
structure,
|
|
351
360
|
table,
|
|
361
|
+
tables,
|
|
352
362
|
tb,
|
|
353
363
|
tempfiles,
|
|
354
364
|
terms_cache,
|
|
@@ -359,6 +369,7 @@ const tokenMap = {
|
|
|
359
369
|
to,
|
|
360
370
|
token,
|
|
361
371
|
tokenizers,
|
|
372
|
+
trace,
|
|
362
373
|
transaction,
|
|
363
374
|
type: typeKeyword,
|
|
364
375
|
unique,
|
|
@@ -370,6 +381,7 @@ const tokenMap = {
|
|
|
370
381
|
user,
|
|
371
382
|
value: valueKeyword,
|
|
372
383
|
values,
|
|
384
|
+
version,
|
|
373
385
|
when,
|
|
374
386
|
where,
|
|
375
387
|
with: _with,
|
|
@@ -384,59 +396,58 @@ const tokenMap = {
|
|
|
384
396
|
null: _null,
|
|
385
397
|
true: _true,
|
|
386
398
|
|
|
387
|
-
f32,
|
|
388
|
-
f64,
|
|
389
|
-
i16,
|
|
390
|
-
i32,
|
|
391
|
-
i64,
|
|
399
|
+
f32: IndexTypeClause,
|
|
400
|
+
f64: IndexTypeClause,
|
|
401
|
+
i16: IndexTypeClause,
|
|
402
|
+
i32: IndexTypeClause,
|
|
403
|
+
i64: IndexTypeClause,
|
|
392
404
|
|
|
393
|
-
jwks,
|
|
394
|
-
eddsa,
|
|
395
|
-
es256,
|
|
396
|
-
es384,
|
|
397
|
-
es512,
|
|
398
|
-
ps256,
|
|
399
|
-
ps384,
|
|
400
|
-
ps512,
|
|
401
|
-
rs256,
|
|
402
|
-
rs384,
|
|
403
|
-
rs512,
|
|
405
|
+
jwks: TokenType,
|
|
406
|
+
eddsa: TokenType,
|
|
407
|
+
es256: TokenType,
|
|
408
|
+
es384: TokenType,
|
|
409
|
+
es512: TokenType,
|
|
410
|
+
ps256: TokenType,
|
|
411
|
+
ps384: TokenType,
|
|
412
|
+
ps512: TokenType,
|
|
413
|
+
rs256: TokenType,
|
|
414
|
+
rs384: TokenType,
|
|
415
|
+
rs512: TokenType,
|
|
404
416
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
containsall,
|
|
410
|
-
containsany,
|
|
411
|
-
containsnone,
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
417
|
+
and: binaryOperatorKeyword,
|
|
418
|
+
or: binaryOperatorKeyword,
|
|
419
|
+
contains: binaryOperatorKeyword,
|
|
420
|
+
containsnot: binaryOperatorKeyword,
|
|
421
|
+
containsall: binaryOperatorKeyword,
|
|
422
|
+
containsany: binaryOperatorKeyword,
|
|
423
|
+
containsnone: binaryOperatorKeyword,
|
|
424
|
+
inside: binaryOperatorKeyword, notinside: binaryOperatorKeyword,
|
|
425
|
+
allinside: binaryOperatorKeyword,
|
|
426
|
+
anyinside: binaryOperatorKeyword,
|
|
427
|
+
noneinside: binaryOperatorKeyword,
|
|
428
|
+
outside: binaryOperatorKeyword,
|
|
429
|
+
intersects: binaryOperatorKeyword,
|
|
415
430
|
is,
|
|
416
|
-
noneinside,
|
|
417
|
-
notinside,
|
|
418
|
-
or,
|
|
419
|
-
outside,
|
|
420
431
|
|
|
421
|
-
chebyshev,
|
|
422
|
-
cosine,
|
|
423
|
-
euclidean,
|
|
424
|
-
hamming,
|
|
425
|
-
jaccard,
|
|
426
|
-
manhattan,
|
|
432
|
+
chebyshev: Distance,
|
|
433
|
+
cosine: Distance,
|
|
434
|
+
euclidean: Distance,
|
|
435
|
+
hamming: Distance,
|
|
436
|
+
jaccard: Distance,
|
|
437
|
+
manhattan: Distance,
|
|
427
438
|
minkowski,
|
|
428
|
-
pearson,
|
|
439
|
+
pearson: Distance,
|
|
429
440
|
|
|
430
|
-
ascii,
|
|
431
|
-
edgengram,
|
|
432
|
-
ngram,
|
|
433
|
-
snowball,
|
|
434
|
-
uppercase,
|
|
441
|
+
ascii: Filter,
|
|
442
|
+
edgengram: Filter,
|
|
443
|
+
ngram: Filter,
|
|
444
|
+
snowball: Filter,
|
|
445
|
+
uppercase: Filter,
|
|
435
446
|
|
|
436
|
-
blank,
|
|
437
|
-
camel,
|
|
438
|
-
class:
|
|
439
|
-
punct,
|
|
447
|
+
blank: AnalyzerTokenizer,
|
|
448
|
+
camel: AnalyzerTokenizer,
|
|
449
|
+
class: AnalyzerTokenizer,
|
|
450
|
+
punct: AnalyzerTokenizer,
|
|
440
451
|
|
|
441
452
|
// Function names
|
|
442
453
|
function: _function,
|
|
@@ -444,32 +455,26 @@ const tokenMap = {
|
|
|
444
455
|
count,
|
|
445
456
|
};
|
|
446
457
|
|
|
447
|
-
const
|
|
448
|
-
["select", [selectPermissions]],
|
|
449
|
-
["create", [createPermissions]],
|
|
450
|
-
["update", [updatePermissions]],
|
|
451
|
-
["delete", [deletePermissions]],
|
|
452
|
-
["not", [opNot]],
|
|
453
|
-
["in", [opIn]],
|
|
454
|
-
]);
|
|
455
|
-
|
|
456
|
-
export const tokens = function(t, stack) {
|
|
457
|
-
for (const tk of tryMapped.get(t.toLowerCase()) ?? []) {
|
|
458
|
-
if (stack.canShift(tk)) return tk;
|
|
459
|
-
}
|
|
460
|
-
|
|
458
|
+
export const tokens = function (t, stack) {
|
|
461
459
|
return tokenMap[t.toLowerCase()] ?? -1;
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
function isSpace(ch) {
|
|
463
|
+
return ch === 32 || ch === 9 || ch === 10 || ch === 13
|
|
462
464
|
}
|
|
463
465
|
|
|
464
466
|
function skipSpace(input, off) {
|
|
465
|
-
for (
|
|
467
|
+
for (; ;) {
|
|
466
468
|
let next = input.peek(off);
|
|
467
|
-
if (next
|
|
469
|
+
if (isSpace(next)) {
|
|
468
470
|
off++;
|
|
469
|
-
} else if (
|
|
470
|
-
|
|
471
|
+
} else if (
|
|
472
|
+
next === 35 /* '#' */ ||
|
|
473
|
+
((next === 47 /* '/' */ || next === 45) /* '-' */ &&
|
|
474
|
+
input.peek(off + 1) === next)
|
|
475
|
+
) {
|
|
471
476
|
off++;
|
|
472
|
-
for (
|
|
477
|
+
for (; ;) {
|
|
473
478
|
let next = input.peek(off);
|
|
474
479
|
if (next < 0 || next === 10 || next === 13) break;
|
|
475
480
|
off++;
|
|
@@ -481,7 +486,12 @@ function skipSpace(input, off) {
|
|
|
481
486
|
}
|
|
482
487
|
|
|
483
488
|
function isIdentifierChar(ch) {
|
|
484
|
-
return
|
|
489
|
+
return (
|
|
490
|
+
ch === 95 ||
|
|
491
|
+
(ch >= 65 && ch <= 90) ||
|
|
492
|
+
(ch >= 97 && ch <= 122) ||
|
|
493
|
+
(ch >= 48 && ch <= 57)
|
|
494
|
+
);
|
|
485
495
|
}
|
|
486
496
|
|
|
487
497
|
function skipObjKey(input, off) {
|
|
@@ -491,17 +501,19 @@ function skipObjKey(input, off) {
|
|
|
491
501
|
off++;
|
|
492
502
|
} while (isIdentifierChar(input.peek(off)));
|
|
493
503
|
return off;
|
|
494
|
-
} else if (first ===
|
|
495
|
-
for (let escaped = false
|
|
504
|
+
} else if (first === 39 /* "'" */ || first === 34 /* '"' */) {
|
|
505
|
+
for (let escaped = false; ;) {
|
|
496
506
|
let next = input.peek(++off);
|
|
497
507
|
if (next < 0) return off;
|
|
498
508
|
if (next === first && !escaped) return off + 1;
|
|
499
|
-
escaped = next === 92 /* '\\' */
|
|
509
|
+
escaped = next === 92; /* '\\' */
|
|
500
510
|
}
|
|
501
511
|
}
|
|
512
|
+
|
|
513
|
+
return null;
|
|
502
514
|
}
|
|
503
515
|
|
|
504
|
-
export const objectToken = new ExternalTokenizer(
|
|
516
|
+
export const objectToken = new ExternalTokenizer(input => {
|
|
505
517
|
if (input.next === 123 /* '{' */) {
|
|
506
518
|
let off = skipSpace(input, 1);
|
|
507
519
|
|
|
@@ -530,3 +542,30 @@ export const objectToken = new ExternalTokenizer((input, _stack) => {
|
|
|
530
542
|
}
|
|
531
543
|
}
|
|
532
544
|
});
|
|
545
|
+
|
|
546
|
+
function closedRangeBefore(ch) {
|
|
547
|
+
return isSpace(ch) || ch < 0 || ch === 91 /* '[' */ || ch === 44 /* ',' */ ||
|
|
548
|
+
ch === 123 /* '{' */ || ch === 40 /* '(' */ || ch === 59 /* ';' */ || ch === 58 /* ':' */
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function closedRangeAfter(ch) {
|
|
552
|
+
return isSpace(ch) || ch < 0 || ch === 93 /* ']' */ || ch === 44 /* ',' */ ||
|
|
553
|
+
ch === 125 /* '}' */ || ch === 41 /* ')' */ || ch === 59 /* ';' */ || ch === 58 /* ':' */
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export const rangeOperator = new ExternalTokenizer(input => {
|
|
557
|
+
if (input.next === 46 /* '.' */ && input.peek(1) === 46 ||
|
|
558
|
+
input.next === 62 /* '>' */ && input.peek(1) === 46 && input.peek(1) === 46) {
|
|
559
|
+
let inclStart = input.next !== 62
|
|
560
|
+
let closedBefore = closedRangeBefore(input.peek(-1))
|
|
561
|
+
if (!inclStart && closedBefore) return
|
|
562
|
+
input.advance(inclStart ? 2 : 3)
|
|
563
|
+
let inclEnd = input.next === 61 /* '=' */
|
|
564
|
+
if (inclEnd) input.advance()
|
|
565
|
+
let closedAfter = closedRangeAfter(input.next) || input.next < 0
|
|
566
|
+
if (inclEnd && closedAfter) return
|
|
567
|
+
input.acceptToken(closedBefore && closedAfter ? rangeOpOpenBoth
|
|
568
|
+
: closedBefore ? rangeOpOpenLeft
|
|
569
|
+
: closedAfter ? rangeOpOpenRight : rangeOp)
|
|
570
|
+
}
|
|
571
|
+
})
|
package/src/typing.d.ts
ADDED
package/src/version.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NodeProp } from '@lezer/common';
|
|
2
|
+
|
|
3
|
+
export const since = new NodeProp({
|
|
4
|
+
perNode: false,
|
|
5
|
+
deserialize(str) {
|
|
6
|
+
return str.replace(/_/g, '.').toLowerCase();
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const until = new NodeProp({
|
|
11
|
+
perNode: false,
|
|
12
|
+
deserialize(str) {
|
|
13
|
+
return str.replace(/_/g, '.').toLowerCase();
|
|
14
|
+
},
|
|
15
|
+
});
|
package/test/statement.txt
CHANGED
|
@@ -45,3 +45,88 @@ SurrealQL(
|
|
|
45
45
|
LiveSelectStatement(Keyword,Keyword,Any,Keyword,Ident),
|
|
46
46
|
LiveSelectStatement(Keyword,Keyword,Any,Keyword,RecordId(RecordTbIdent,Colon,RecordIdIdent)),
|
|
47
47
|
)
|
|
48
|
+
|
|
49
|
+
# Let Substatements
|
|
50
|
+
|
|
51
|
+
LET $bla = (SELECT * FROM 123);
|
|
52
|
+
LET $bla = SELECT * FROM 123;
|
|
53
|
+
|
|
54
|
+
==>
|
|
55
|
+
|
|
56
|
+
SurrealQL(
|
|
57
|
+
LetStatement(Keyword,VariableName,SubQuery(SelectStatement(Keyword,Any,Keyword,Int))),
|
|
58
|
+
LetStatement(Keyword,VariableName,SelectStatement(Keyword,Any,Keyword,Int)))
|
|
59
|
+
|
|
60
|
+
# Block Comments
|
|
61
|
+
|
|
62
|
+
1 /* this is
|
|
63
|
+
a block
|
|
64
|
+
comment */ + 2;
|
|
65
|
+
|
|
66
|
+
==>
|
|
67
|
+
|
|
68
|
+
SurrealQL(BinaryExpression(Int,BlockComment,Operator,Int))
|
|
69
|
+
|
|
70
|
+
# Version Clause
|
|
71
|
+
|
|
72
|
+
SELECT * FROM person VERSION d'2024-10-10T14:37:08.444Z'
|
|
73
|
+
|
|
74
|
+
==>
|
|
75
|
+
|
|
76
|
+
SurrealQL(SelectStatement(Keyword,Any,Keyword,Ident,VersionClause(Keyword,String)))
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# Recurse part
|
|
80
|
+
|
|
81
|
+
person:tobie.{..}->knows->person;
|
|
82
|
+
person:tobie.{..}(->knows->person).name;
|
|
83
|
+
person:tobie.{..}.{ id, name, knows: ->knows->person.@ };
|
|
84
|
+
a:1.{1};
|
|
85
|
+
a:1.{1..};
|
|
86
|
+
a:1.{1..2};
|
|
87
|
+
a:1.{..2};
|
|
88
|
+
@.name;
|
|
89
|
+
@name;
|
|
90
|
+
|
|
91
|
+
==>
|
|
92
|
+
|
|
93
|
+
SurrealQL(
|
|
94
|
+
Path(
|
|
95
|
+
RecordId(RecordTbIdent,Colon,RecordIdIdent),
|
|
96
|
+
Subscript(Recurse(BraceOpen,RecurseRange(RangeOp),BraceClose)),
|
|
97
|
+
GraphPath(ArrowRight,Ident), GraphPath(ArrowRight,Ident)
|
|
98
|
+
),
|
|
99
|
+
Path(
|
|
100
|
+
RecordId(RecordTbIdent,Colon,RecordIdIdent),
|
|
101
|
+
Subscript(
|
|
102
|
+
Recurse(
|
|
103
|
+
BraceOpen, RecurseRange(RangeOp), BraceClose,
|
|
104
|
+
Path(GraphPath(ArrowRight,Ident), GraphPath(ArrowRight,Ident))
|
|
105
|
+
)
|
|
106
|
+
),
|
|
107
|
+
Subscript(Ident)
|
|
108
|
+
),
|
|
109
|
+
Path(
|
|
110
|
+
RecordId(RecordTbIdent,Colon,RecordIdIdent),
|
|
111
|
+
Subscript(Recurse(BraceOpen,RecurseRange(RangeOp),BraceClose)),
|
|
112
|
+
Subscript(Destructure(BraceOpen,Ident,Ident,Ident,Colon,GraphPath(ArrowRight,Ident),GraphPath(ArrowRight,Ident),Subscript(At),BraceClose))
|
|
113
|
+
),
|
|
114
|
+
Path(
|
|
115
|
+
RecordId(RecordTbIdent,Colon,Int),
|
|
116
|
+
Subscript(Recurse(BraceOpen,RecurseRange(Int),BraceClose))
|
|
117
|
+
),
|
|
118
|
+
Path(
|
|
119
|
+
RecordId(RecordTbIdent,Colon,Int),
|
|
120
|
+
Subscript(Recurse(BraceOpen,RecurseRange(Int,RangeOp),BraceClose))
|
|
121
|
+
),
|
|
122
|
+
Path(
|
|
123
|
+
RecordId(RecordTbIdent,Colon,Int),
|
|
124
|
+
Subscript(Recurse(BraceOpen,RecurseRange(Int,RangeOp,Int),BraceClose))
|
|
125
|
+
),
|
|
126
|
+
Path(
|
|
127
|
+
RecordId(RecordTbIdent,Colon,Int),
|
|
128
|
+
Subscript(Recurse(BraceOpen,RecurseRange(RangeOp,Int),BraceClose))
|
|
129
|
+
),
|
|
130
|
+
Path(At,Subscript(Ident)),
|
|
131
|
+
Path(At,Ident)
|
|
132
|
+
)
|
package/test/test-surrealql.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {parser} from "../dist/index.js";
|
|
2
|
-
import {fileTests} from "@lezer/generator/dist/test";
|
|
1
|
+
import { parser } from "../dist/index.js";
|
|
2
|
+
import { fileTests } from "@lezer/generator/dist/test";
|
|
3
3
|
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
6
|
-
import {fileURLToPath} from "url";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
7
|
let caseDir = path.dirname(fileURLToPath(import.meta.url));
|
|
8
8
|
|
|
9
9
|
let filter = process.argv[2];
|
|
@@ -11,12 +11,12 @@ let filter = process.argv[2];
|
|
|
11
11
|
for (let file of fs.readdirSync(caseDir)) {
|
|
12
12
|
if (!/\.txt$/.test(file)) continue;
|
|
13
13
|
console.log("File " + file + ":");
|
|
14
|
-
for (let {name, run} of fileTests(fs.readFileSync(path.join(caseDir, file), "utf8"), file)) {
|
|
14
|
+
for (let { name, run } of fileTests(fs.readFileSync(path.join(caseDir, file), "utf8"), file)) {
|
|
15
15
|
if (!filter || name.indexOf(filter) > -1) {
|
|
16
16
|
try {
|
|
17
17
|
run(parser);
|
|
18
18
|
console.log(" ✔ " + name);
|
|
19
|
-
} catch(e) {
|
|
19
|
+
} catch (e) {
|
|
20
20
|
console.log(" ✘ " + name + "\n " + String(e.message || e).replace(/\n/g, "\n "))
|
|
21
21
|
}
|
|
22
22
|
}
|