@surrealdb/lezer 1.0.0-beta.1

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.
@@ -0,0 +1,1398 @@
1
+ @top SurrealQL {
2
+ expressions | WhereClause
3
+ }
4
+
5
+ @top PermissionInput {
6
+ WhereClause | none | full
7
+ }
8
+
9
+ @top CombinedResults {
10
+ combinedExpressions
11
+ }
12
+
13
+ @precedence {
14
+ range @left
15
+ method
16
+ binary @left
17
+ union @left
18
+ filter
19
+ }
20
+
21
+ expressions {
22
+ (expression ";")* expression ";"?
23
+ }
24
+
25
+ combinedExpressions {
26
+ CombinedResult { CommentResult expression CommentResultClose { "" } }+
27
+ }
28
+
29
+ expression {
30
+ statement |
31
+ value
32
+ }
33
+
34
+ SubQuery {
35
+ "("
36
+ expression
37
+ ")"
38
+ }
39
+
40
+ Block {
41
+ "{" expressions? "}"
42
+ }
43
+
44
+ Closure {
45
+ ParamList { "|" commaSep<VariableName ":" safeType>? "|" } ("->" type)? Block
46
+ }
47
+
48
+ statement[@isGroup=Statement] {
49
+ BeginStatement |
50
+ CancelStatement |
51
+ CommitStatement |
52
+ DefineStatement |
53
+ AlterStatement |
54
+ RemoveStatement |
55
+ InfoForStatement |
56
+ KillStatement |
57
+ LiveSelectStatement |
58
+ ShowStatement |
59
+ SleepStatement |
60
+ UseStatement |
61
+ OptionStatement |
62
+ RebuildStatement |
63
+ CreateStatement |
64
+ SelectStatement |
65
+ DeleteStatement |
66
+ InsertStatement |
67
+ BreakStatement |
68
+ ContinueStatement |
69
+ ForStatement |
70
+ ReturnStatement |
71
+ ThrowStatement |
72
+ IfElseStatement |
73
+ LetStatement |
74
+ RelateStatement |
75
+ UpdateStatement |
76
+ UpsertStatement
77
+ }
78
+
79
+ // Transaction statements
80
+
81
+ BeginStatement { begin transaction? }
82
+ CancelStatement { cancel transaction? }
83
+ CommitStatement { commit transaction? }
84
+
85
+ // Define statements
86
+
87
+ DefineStatement {
88
+ define
89
+ (
90
+ ( namespace defineNamespaceOptions ) |
91
+ ( database defineDatabaseOptions ) |
92
+ ( user defineUserOptions ) |
93
+ ( token defineTokenOptions ) |
94
+ ( event defineEventOptions ) |
95
+ ( field defineFieldOptions ) |
96
+ ( index defineIndexOptions ) |
97
+ ( analyzer defineAnalyzerOptions ) |
98
+ ( functionKw defineFunctionOptions ) |
99
+ ( param defineParamOptions ) |
100
+ ( scope defineScopeOptions ) |
101
+ ( table defineTableOptions )
102
+ )
103
+ }
104
+
105
+ defineAnalyzerOptions {
106
+ (IfNotExistsClause | overwrite)?
107
+ Ident
108
+ (
109
+ TokenizersClause |
110
+ FiltersClause |
111
+ FunctionClause |
112
+ CommentClause
113
+ )*
114
+ }
115
+
116
+ defineEventOptions {
117
+ (IfNotExistsClause | overwrite)?
118
+ Ident
119
+ OnTableClause
120
+ WhenThenClause
121
+ CommentClause?
122
+ }
123
+
124
+ defineDatabaseOptions {
125
+ (IfNotExistsClause | overwrite)?
126
+ Ident on Ident
127
+ CommentClause?
128
+ }
129
+
130
+ defineFieldOptions {
131
+ (IfNotExistsClause | overwrite)?
132
+ Ident
133
+ OnTableClause
134
+ (
135
+ TypeClause |
136
+ DefaultClause |
137
+ ReadonlyClause |
138
+ ValueClause |
139
+ AssertClause |
140
+ PermissionsForClause |
141
+ CommentClause
142
+ )*
143
+ }
144
+
145
+ defineFunctionOptions {
146
+ (IfNotExistsClause | overwrite)?
147
+ customFunctionName
148
+ ParamList { "(" commaSep<VariableName ":" type>? ")" }
149
+ ("->" type)?
150
+ Block
151
+ (
152
+ PermissionsBasicClause |
153
+ CommentClause
154
+ )*
155
+ }
156
+
157
+ functionKw[@name=Keyword] { function }
158
+
159
+ defineIndexOptions {
160
+ (IfNotExistsClause | overwrite)?
161
+ Ident
162
+ OnTableClause
163
+ FieldsColumnsClause
164
+ (
165
+ UniqueClause |
166
+ SearchAnalyzerClause |
167
+ MtreeClause |
168
+ HnswClause
169
+ )
170
+ }
171
+
172
+ defineNamespaceOptions {
173
+ (IfNotExistsClause | overwrite)?
174
+ Ident
175
+ CommentClause?
176
+ }
177
+
178
+ defineParamOptions {
179
+ (IfNotExistsClause | overwrite)?
180
+ VariableName
181
+ valueKeyword
182
+ value
183
+ }
184
+
185
+ defineScopeOptions {
186
+ (IfNotExistsClause | overwrite)?
187
+ Ident
188
+ (
189
+ SessionClause |
190
+ SigninClause |
191
+ SignupClause |
192
+ CommentClause
193
+ )*
194
+ }
195
+
196
+ defineTableOptions {
197
+ (IfNotExistsClause | overwrite)?
198
+ Ident
199
+ (
200
+ drop |
201
+ (schemafull | schemaless) |
202
+ TableTypeClause |
203
+ TableViewClause |
204
+ ChangefeedClause |
205
+ PermissionsForClause |
206
+ CommentClause
207
+ )*
208
+ }
209
+
210
+ defineTokenOptions {
211
+ (IfNotExistsClause | overwrite)?
212
+ Ident
213
+ ( on ( namespace | database | scope Ident ) )
214
+ TokenTypeClause
215
+ ( valueKeyword String )
216
+ }
217
+
218
+ defineUserOptions {
219
+ (IfNotExistsClause | overwrite)?
220
+ Ident
221
+ ( on ( root | namespace | database ) )
222
+ ( ( password | passhash ) String )
223
+ ( roles commaSep<Ident> )
224
+ }
225
+
226
+ // Alter statement
227
+
228
+ AlterStatement {
229
+ alter
230
+ (
231
+ ( table alterTableOptions )
232
+ )
233
+ }
234
+
235
+ alterTableOptions {
236
+ IfNotExistsClause?
237
+ Ident
238
+ (
239
+ drop |
240
+ (schemafull | schemaless) |
241
+ PermissionsForClause |
242
+ CommentClause
243
+ )*
244
+ }
245
+
246
+ // Remove statement
247
+
248
+ RemoveStatement {
249
+ remove
250
+ (
251
+ ( namespace IfExistsClause? Ident ) |
252
+ ( database IfExistsClause? Ident ) |
253
+ ( user IfExistsClause? Ident on ( root | namespace | database ) ) |
254
+ ( token IfExistsClause? Ident on ( namespace | database | scope ) ) |
255
+ ( event IfExistsClause? Ident on table? Ident ) |
256
+ ( field IfExistsClause? Ident on table? Ident ) |
257
+ ( index IfExistsClause? Ident on table? Ident ) |
258
+ ( analyzer IfExistsClause? Ident ) |
259
+ ( functionKw IfExistsClause? customFunctionName ) |
260
+ ( param IfExistsClause? VariableName ) |
261
+ ( scope IfExistsClause? Ident ) |
262
+ ( table IfExistsClause? Ident )
263
+ )
264
+ }
265
+
266
+ // Data statements
267
+
268
+ CreateStatement {
269
+ create only?
270
+ createTarget { Ident | VariableName | FunctionCall | RecordId }
271
+ createContent { ContentClause | SetClause | UnsetClause | () }
272
+ ReturnClause?
273
+ TimeoutClause?
274
+ ParallelClause?
275
+ }
276
+
277
+ SelectStatement {
278
+ (select)
279
+ (
280
+ valueKeyword Predicate |
281
+ commaSep<inclusivePredicate>
282
+ )
283
+ (from)
284
+ (only)?
285
+ (
286
+ statement |
287
+ (
288
+ commaSep<value>
289
+ selectClauses1 {
290
+ WithClause?
291
+ WhereClause?
292
+ SplitClause?
293
+ }
294
+ selectClauses2 {
295
+ GroupClause?
296
+ OrderClause?
297
+ LimitStartComboClause?
298
+ }
299
+ selectClauses3 {
300
+ FetchClause?
301
+ TimeoutClause?
302
+ ParallelClause?
303
+ TempfilesClause?
304
+ ExplainClause?
305
+ }
306
+ )
307
+ )
308
+ }
309
+
310
+ DeleteStatement {
311
+ delete only?
312
+ (
313
+ statement |
314
+ (
315
+ commaSep<value>
316
+ WhereClause?
317
+ ReturnClause?
318
+ TimeoutClause?
319
+ ParallelClause?
320
+ )
321
+ )
322
+ }
323
+
324
+ InsertStatement {
325
+ insert
326
+ ignore?
327
+ relation?
328
+ into
329
+ Ident
330
+ (
331
+ Object |
332
+ ( "[" commaSep<Object> "]" ) |
333
+ (
334
+ "(" commaSep<Ident> ")"
335
+ values
336
+ commaSep<(
337
+ "(" commaSep<value> ")"
338
+ )>
339
+ on duplicate key update
340
+ commaSep<FieldAssignment>
341
+ )
342
+ )
343
+ }
344
+
345
+ IfElseStatement {
346
+ if
347
+ (
348
+ Legacy {
349
+ value
350
+ then
351
+ ( Block | SubQuery)
352
+ (
353
+ else if
354
+ value
355
+ then
356
+ ( Block | SubQuery)
357
+ )*
358
+ (
359
+ else
360
+ ( Block | SubQuery)
361
+ )?
362
+ end
363
+ } |
364
+ Modern {
365
+ value Block
366
+ (
367
+ else if
368
+ value Block
369
+ )*
370
+ (
371
+ else Block
372
+ )?
373
+ }
374
+ )
375
+ }
376
+
377
+ relateSubject { Array | Ident | FunctionCall | VariableName | RecordId }
378
+ RelateStatement {
379
+ relate only?
380
+ relateSubject "->" relateSubject "->" relateSubject
381
+ ( ContentClause | SetClause )?
382
+ ReturnClause?
383
+ TimeoutClause?
384
+ ParallelClause?
385
+ }
386
+
387
+ InfoForStatement {
388
+ info for
389
+ (
390
+ root |
391
+ ns | namespace |
392
+ db | database |
393
+ ( sc Ident | scope Ident) |
394
+ ( tb Ident | table Ident)
395
+ )
396
+ structure?
397
+ }
398
+
399
+ UpdateStatement {
400
+ update only?
401
+ (
402
+ statement |
403
+ (
404
+ commaSep<value>
405
+ updateClause1 {
406
+ ContentClause |
407
+ MergeClause |
408
+ PatchClause |
409
+ SetClause |
410
+ UnsetClause
411
+ }?
412
+ updateClause2 {
413
+ WhereClause?
414
+ ReturnClause?
415
+ TimeoutClause?
416
+ ParallelClause?
417
+ }
418
+ )
419
+ )
420
+ }
421
+
422
+ UpsertStatement {
423
+ upsert only?
424
+ (
425
+ statement |
426
+ (
427
+ commaSep<value>
428
+ updateClause1 {
429
+ ContentClause |
430
+ MergeClause |
431
+ PatchClause |
432
+ SetClause |
433
+ UnsetClause
434
+ }?
435
+ updateClause2 {
436
+ WhereClause?
437
+ ReturnClause?
438
+ TimeoutClause?
439
+ ParallelClause?
440
+ }
441
+ )
442
+ )
443
+ }
444
+
445
+ // Control statements
446
+ BreakStatement { break }
447
+ ContinueStatement { continue }
448
+ ForStatement { for VariableName in ( Array | VariableName | SubQuery | Block ) Block }
449
+ ReturnStatement { return expression }
450
+ ThrowStatement { throw value }
451
+
452
+ // Live statements
453
+ KillStatement { kill String }
454
+ LiveSelectStatement {
455
+ live select
456
+ (
457
+ diff |
458
+ valueKeyword Predicate |
459
+ commaSep<inclusivePredicate>
460
+ )
461
+ from commaSep<( Ident | RecordId )>
462
+ WhereClause?
463
+ FetchClause?
464
+ }
465
+
466
+ // Other statements
467
+ LetStatement { let VariableName "=" value }
468
+ ShowStatement {
469
+ show changes for table
470
+ Ident
471
+ ( since String )?
472
+ ( limit Int )?
473
+ }
474
+
475
+ SleepStatement {
476
+ sleep Duration
477
+ }
478
+
479
+ useNs { ( ns | namespace ) Ident }
480
+ useDb { ( db | database ) Ident }
481
+ UseStatement {
482
+ use
483
+ ( useNs | useDb | ( useNs useDb ) )
484
+ }
485
+
486
+ OptionStatement {
487
+ option
488
+ Ident
489
+ ( "=" ( true | false ) )?
490
+ }
491
+
492
+ RebuildStatement {
493
+ rebuild index
494
+ IfExistsClause?
495
+ Ident
496
+ OnTableClause
497
+ }
498
+
499
+ // Values
500
+
501
+ baseValue {
502
+ String |
503
+ prefixedString |
504
+ number |
505
+ true |
506
+ false |
507
+ null |
508
+ none |
509
+ VariableName |
510
+ Ident[@dynamicPrecedence=-1] { rawident } |
511
+ Array |
512
+ RecordId |
513
+ FunctionJs |
514
+ FunctionCall |
515
+ SubQuery |
516
+ Block |
517
+ Closure |
518
+ Object |
519
+ TypeCast |
520
+ Duration |
521
+ Point { "(" Decimal "," Decimal ")" }
522
+ }
523
+
524
+ Any { "?" }
525
+ AnyStar[@name=Any] { "*" }
526
+
527
+ value[@isGroup=Value] {
528
+ baseValue |
529
+ BinaryExpression |
530
+ Path
531
+ }
532
+
533
+ // Binary expressions
534
+
535
+ BinaryExpression {
536
+ value !binary Operator value
537
+ }
538
+
539
+ Path {
540
+ baseValue pathElement+ |
541
+ GraphPath pathElement*
542
+ }
543
+
544
+ pathElement {
545
+ GraphPath |
546
+ Subscript {
547
+ "."
548
+ (
549
+ Ident |
550
+ FunctionName { rawident !method } ArgumentList |
551
+ AnyStar |
552
+ Destructure
553
+ )
554
+ } |
555
+ Filter { !filter "[" (WhereClause | value | WhereClause { "?" value } ) "]" }
556
+ }
557
+
558
+ GraphPath {
559
+ ("<-" | "->" | "<->")
560
+ (Ident | Any | "(" commaSep<GraphPredicate> ")")
561
+ }
562
+
563
+ GraphPredicate {
564
+ (value | Any) WhereClause? (as Ident)?
565
+ }
566
+
567
+ Destructure {
568
+ "{" commaSep<((Ident ":")? Ident pathElement?)> "}"
569
+ }
570
+
571
+ // Objects
572
+
573
+ ObjectKey {
574
+ KeyName { rawident } |
575
+ String
576
+ }
577
+
578
+ ObjectProperty {
579
+ ObjectKey ":" value
580
+ }
581
+
582
+ ObjectContent {
583
+ commaSep<ObjectProperty>
584
+ }
585
+
586
+ Object {
587
+ objectOpen ObjectContent? "}"
588
+ }
589
+
590
+ // Arrays
591
+
592
+ Array { "[" commaSep<value>? "]"}
593
+
594
+ // Record Ids
595
+
596
+ RecordTbIdent {
597
+ rawident |
598
+ tickIdent |
599
+ bracketIdent
600
+ }
601
+
602
+ RecordIdIdent {
603
+ numberident |
604
+ tickIdent |
605
+ bracketIdent
606
+ }
607
+
608
+ recordIdValue {
609
+ RecordIdIdent |
610
+ Int |
611
+ Array |
612
+ Object
613
+ }
614
+
615
+ RecordIdRange {
616
+ ( recordIdValue !range ">"? )?
617
+ ".."
618
+ ( !range "="? recordIdValue )?
619
+ }
620
+
621
+ RecordId {
622
+ RecordTbIdent
623
+ ":"
624
+ ( recordIdValue | RecordIdRange )
625
+ }
626
+
627
+ // Durations
628
+
629
+ Duration {
630
+ DurationPart+
631
+ }
632
+
633
+ // JS Functions
634
+
635
+ FunctionJs {
636
+ FunctionName { function }
637
+ ArgumentList
638
+ JavaScriptBlock
639
+ }
640
+
641
+ @skip {} {
642
+ JavaScriptBlock {
643
+ "{" JavaScriptContent { javaScriptElement* } "}"
644
+ }
645
+ javaScriptElement {
646
+ javaScriptContent | javaScriptBraceOpen javaScriptElement* javaScriptBraceClose
647
+ }
648
+ }
649
+
650
+ // Function invocation
651
+
652
+ FunctionCall {
653
+ ( count ArgumentListCount ) |
654
+ (
655
+ (FunctionName | customFunctionName | rand)
656
+ Version { "<" VersionNumber ">" }?
657
+ ArgumentList
658
+ )
659
+ }
660
+
661
+ ArgumentList { "(" commaSep<value>? ")" }
662
+ ArgumentListCount[@name=ArgumentList] { "(" ( commaSep<value>? | statement ) ")" }
663
+
664
+ // Assignment
665
+
666
+ FieldAssignment {
667
+ Ident
668
+ assignmentOperator
669
+ value
670
+ }
671
+
672
+ // Clauses
673
+
674
+ MergeClause {
675
+ merge Object
676
+ }
677
+
678
+ PatchClause {
679
+ patch Array
680
+ }
681
+
682
+ TableTypeClause {
683
+ type
684
+ (
685
+ any |
686
+ normal |
687
+ (
688
+ relation
689
+ ( ( in | from ) piped<Ident> )?
690
+ ( ( out | to ) piped<Ident> )?
691
+ )
692
+ )
693
+ }
694
+
695
+ TableViewClause {
696
+ as
697
+ select
698
+ commaSep<inclusivePredicate>
699
+ from
700
+ commaSep<value>
701
+ WhereClause?
702
+ GroupClause?
703
+ }
704
+
705
+ ChangefeedClause {
706
+ changefeed
707
+ Duration
708
+ }
709
+
710
+ SessionClause {
711
+ session
712
+ Duration
713
+ }
714
+
715
+ SignupClause {
716
+ signup
717
+ ( SubQuery | Block )
718
+ }
719
+
720
+ SigninClause {
721
+ signin
722
+ ( SubQuery | Block )
723
+ }
724
+
725
+ OnTableClause {
726
+ on table? Ident
727
+ }
728
+
729
+ FieldsColumnsClause {
730
+ ( fields | columns ) commaSep<Ident>
731
+ }
732
+
733
+ UniqueClause {
734
+ unique
735
+ }
736
+
737
+ SearchAnalyzerClause {
738
+ search analyzer
739
+ Ident
740
+ (Bm25Clause | DocIdsOrderClause | DocLenghtsOrderClause | PostingsOrderClause |
741
+ TermsOrderClause | DocIdsCacheClause | DocLenghtsCacheClause | PostingsCacheClause |
742
+ TermsCacheClause | highlights)*
743
+ }
744
+
745
+ Bm25Clause { bm25 ( "(" Float "," Float ")")? }
746
+ DocIdsCacheClause { doc_ids_cache Int }
747
+ DocIdsOrderClause { doc_ids_order Int }
748
+ DocLenghtsCacheClause { doc_lengths_cache Int }
749
+ DocLenghtsOrderClause { doc_lengths_order Int }
750
+ PostingsCacheClause { postings_cache Int }
751
+ PostingsOrderClause { postings_order Int }
752
+ TermsCacheClause { terms_cache Int }
753
+ TermsOrderClause { terms_order Int }
754
+
755
+ MtreeClause {
756
+ mtree
757
+ IndexDimensionClause
758
+ (
759
+ MtreeDistClause |
760
+ IndexTypeClause |
761
+ IndexCapacityClause |
762
+ DocIdsOrderClause |
763
+ DocIdsCacheClause |
764
+ MtreeCacheClause
765
+ )*
766
+ }
767
+
768
+ MtreeCacheClause { mtree_cache Int }
769
+ MtreeDistClause { dist ( cosine | euclidean | manhattan ) }
770
+
771
+ HnswClause {
772
+ hnsw
773
+ IndexDimensionClause
774
+ (
775
+ HnswDistClause |
776
+ IndexTypeClause |
777
+ IndexCapacityClause |
778
+ IndexLmClause |
779
+ IndexM0Clause |
780
+ IndexMClause |
781
+ IndexEfcClause |
782
+ IndexExtendCandidatesClause |
783
+ IndexKeepPrunedConnectionsClause
784
+ )*
785
+ }
786
+
787
+ HnswDistClause { dist ( chebyshev | cosine | euclidean | hamming | jaccard | manhattan | ( minkowski number ) | pearson ) }
788
+
789
+ IndexDimensionClause { dimension Int }
790
+ IndexTypeClause { type ( f32 | f64 | i16 | i32 | i64 ) }
791
+ IndexCapacityClause { capacity Int }
792
+ IndexLmClause { lm Float }
793
+ IndexM0Clause { m0 Int }
794
+ IndexMClause { m Int }
795
+ IndexEfcClause { efc Int }
796
+ IndexExtendCandidatesClause { extend_candidates }
797
+ IndexKeepPrunedConnectionsClause { keep_pruned_connections }
798
+
799
+ ContentClause {
800
+ content Object
801
+ }
802
+
803
+ SetClause {
804
+ set commaSep<FieldAssignment>
805
+ }
806
+
807
+ UnsetClause {
808
+ unset commaSep<FieldAssignment>
809
+ }
810
+
811
+ IfNotExistsClause {
812
+ if not exists
813
+ }
814
+
815
+ IfExistsClause {
816
+ if exists
817
+ }
818
+
819
+ ReturnClause {
820
+ return
821
+ ( before | after | diff | commaSep<inclusivePredicate> )
822
+ }
823
+
824
+ TimeoutClause {
825
+ timeout
826
+ Duration
827
+ }
828
+
829
+ ParallelClause {
830
+ parallel
831
+ }
832
+
833
+ TempfilesClause {
834
+ tempfiles
835
+ }
836
+
837
+ FetchClause {
838
+ fetch
839
+ commaSep<Ident>
840
+ }
841
+
842
+ StartClause {
843
+ start
844
+ at?
845
+ (Int | VariableName)
846
+ }
847
+
848
+ LimitClause {
849
+ limit
850
+ by?
851
+ (Int | VariableName)
852
+ }
853
+
854
+ LimitStartComboClause {
855
+ StartClause LimitClause? |
856
+ LimitClause StartClause?
857
+ }
858
+
859
+ GroupClause {
860
+ group
861
+ by?
862
+ commaSep<Ident>
863
+ }
864
+
865
+ OrderClause {
866
+ order
867
+ by?
868
+ commaSep<Ident>
869
+ ( asc | desc )?
870
+ }
871
+
872
+ SplitClause {
873
+ split
874
+ on?
875
+ Ident
876
+ }
877
+
878
+ WhereClause {
879
+ where
880
+ value
881
+ }
882
+
883
+ WithClause {
884
+ with
885
+ (
886
+ noindex |
887
+ index commaSep<Ident>
888
+ )
889
+ }
890
+
891
+ ExplainClause {
892
+ explain
893
+ full?
894
+ }
895
+
896
+ TokenizersClause { tokenizers commaSep<AnalyzerTokenizers> }
897
+
898
+ FiltersClause {
899
+ filters
900
+ commaSep<AnalyzerFilters>
901
+ }
902
+
903
+ FunctionClause {
904
+ functionKw
905
+ customFunctionName
906
+ }
907
+
908
+ WhenThenClause {
909
+ (
910
+ when
911
+ value
912
+ )?
913
+ then?
914
+ commaSep<(SubQuery | Block)>
915
+ }
916
+
917
+ TypeClause {
918
+ flexible?
919
+ typeKeyword
920
+ type
921
+ }
922
+
923
+ ReadonlyClause {
924
+ readonly
925
+ }
926
+
927
+ DefaultClause {
928
+ default
929
+ value
930
+ }
931
+
932
+ ValueClause {
933
+ valueKeyword
934
+ value
935
+ }
936
+
937
+ AssertClause {
938
+ assert
939
+ value
940
+ }
941
+
942
+ PermissionsForClause {
943
+ permissions
944
+ (
945
+ none | full |
946
+ (
947
+ for
948
+ commaSep<( selectPermissions | createPermissions | updatePermissions | deletePermissions )>
949
+ ( WhereClause | none | full )
950
+ )+
951
+ )
952
+ }
953
+
954
+ PermissionsBasicClause {
955
+ permissions
956
+ none | full | WhereClause
957
+ }
958
+
959
+ CommentClause {
960
+ comment
961
+ String
962
+ }
963
+
964
+ TokenTypeClause {
965
+ type
966
+ (
967
+ jwks |
968
+ eddsa |
969
+ es256 |
970
+ es384 |
971
+ es512 |
972
+ ps256 |
973
+ ps384 |
974
+ ps512 |
975
+ rs256 |
976
+ rs384 |
977
+ rs512
978
+ )
979
+ }
980
+
981
+ // Support
982
+
983
+ AnalyzerTokenizers {
984
+ blank |
985
+ camel |
986
+ class |
987
+ punct
988
+ }
989
+
990
+ AnalyzerFilters {
991
+ ascii |
992
+ lowercase |
993
+ uppercase |
994
+ ( edgengram "(" Int "," Int ")" ) |
995
+ ( ngram "(" Int "," Int ")" ) |
996
+ ( snowball "(" Ident ")" )
997
+ }
998
+
999
+ Predicate {
1000
+ value |
1001
+ value as Ident
1002
+ }
1003
+
1004
+ inclusivePredicate {
1005
+ AnyStar | Predicate
1006
+ }
1007
+
1008
+ // Types
1009
+
1010
+ literalType {
1011
+ String |
1012
+ ArrayType { "[" type "]" } |
1013
+ ObjectType { objectOpen ObjectTypeContent? "}" }
1014
+ // TODO support number and duration types
1015
+ }
1016
+
1017
+ singleType {
1018
+ TypeName { rawident } |
1019
+ ParameterizedType { singleType "<" (type | Int) ">" } |
1020
+ LiteralType { literalType }
1021
+ }
1022
+
1023
+ type {
1024
+ singleType |
1025
+ UnionType { type (!union "|" type)+ }
1026
+ }
1027
+
1028
+ safeType {
1029
+ singleType | "<" type ">"
1030
+ }
1031
+
1032
+ ObjectTypeContent {
1033
+ commaSep<ObjectTypeProperty>
1034
+ }
1035
+
1036
+ ObjectTypeProperty {
1037
+ ObjectKey ":" type
1038
+ }
1039
+
1040
+ TypeCast {
1041
+ "<" type ">" baseValue
1042
+ }
1043
+
1044
+ Ident {
1045
+ rawident |
1046
+ tickIdent
1047
+ }
1048
+
1049
+ number { Int | Float | Decimal }
1050
+
1051
+ Operator {
1052
+ binaryOperator |
1053
+ "-" | "=" | ">" | "<" |
1054
+ and |
1055
+ or |
1056
+ is |
1057
+ ( is opNot ) |
1058
+ contains |
1059
+ containsnot |
1060
+ containsall |
1061
+ containsany |
1062
+ containsnone |
1063
+ inside | in |
1064
+ notinside | ( opNot opIn ) |
1065
+ allinside |
1066
+ anyinside |
1067
+ noneinside |
1068
+
1069
+ outside |
1070
+ intersects |
1071
+
1072
+ ( "@" Int "@" ) |
1073
+ (
1074
+ "<|"
1075
+ Int
1076
+ ( "," ( Int | chebyshev | cosine | euclidean | hamming | jaccard | manhattan | ( minkowski number ) | pearson ) )
1077
+ "|>"
1078
+ )
1079
+ }
1080
+
1081
+ @external tokens objectToken from "./tokens" {
1082
+ objectOpen[@name=BraceOpen]
1083
+ }
1084
+
1085
+ @tokens {
1086
+ // Characters
1087
+ "{"[@name=BraceOpen]
1088
+ "}"[@name=BraceClose]
1089
+ "[" "]"
1090
+ "<" ">"
1091
+ ":"[@name=Colon]
1092
+ "->"[@name=ArrowRight]
1093
+ "<-"[@name=ArrowLeft]
1094
+ "<->"[@name=ArrowBoth]
1095
+ "|"[@name=Pipe]
1096
+
1097
+ // Helpers
1098
+ whitespace { $[ \n\r\t] }
1099
+
1100
+ // Comments
1101
+ Comment { CommentHash | CommentDash | CommentSlash }
1102
+ CommentHash { "#" ![\n]* }
1103
+ CommentDash { "--" ![\n]* }
1104
+ CommentSlash { "//" ![\n]* }
1105
+ CommentResult[@name=Comment,closedBy=CommentResultClose] { "-------- Query" ![\n]* }
1106
+
1107
+ // Numbers
1108
+ Int { "-"? @digit+ }
1109
+ frac { '.' @digit+ }
1110
+ exp { $[eE] $[+\-]? @digit+ }
1111
+ Float { "-"? @digit+ (frac exp? | exp) "f"? }
1112
+ Decimal { "-"? @digit+ frac? exp? "dec" }
1113
+ VersionNumber { @digit+ ("." @digit+ ("." @digit+)?)? }
1114
+
1115
+ String { "'" (!['\\] | "\\" _)* "'" | '"' (!["\\] | "\\" _)* '"' }
1116
+ prefixedString[@name=String] { $[ruds] String }
1117
+
1118
+ // Language
1119
+ VariableName { "$" (@asciiLetter | @digit | "_" )+ }
1120
+ tickIdent {
1121
+ "`" ![`]+ '`'
1122
+ }
1123
+ bracketIdent {
1124
+ "⟨" ![⟩]+ "⟩"
1125
+ }
1126
+ rawident { (@asciiLetter | "_") (@asciiLetter | @digit | "_")* }
1127
+ numberident {
1128
+ rawident |
1129
+ ( @digit+ (@asciiLetter | "_") (@asciiLetter | @digit | "_")* )
1130
+ }
1131
+
1132
+ functionNameSegment { (@asciiLetter | "_") (@asciiLetter | "_" | @digit)* }
1133
+ FunctionName {
1134
+ functionNameSegment ("::" functionNameSegment)+
1135
+ }
1136
+ customFunctionName[@name=FunctionName] {
1137
+ "fn" ("::" functionNameSegment)*
1138
+ }
1139
+
1140
+ durationUnit { "ns" | "us" | "µs" | "ms" | "s" | "m" | "h" | "d" | "w" | "y"}
1141
+ DurationPart { @digit+ " "* durationUnit }
1142
+
1143
+ @precedence { CommentResult Comment Int "-" }
1144
+ @precedence { Comment binaryOperator }
1145
+ @precedence { prefixedString rawident }
1146
+ @precedence { customFunctionName FunctionName rawident }
1147
+ @precedence { Float Decimal Int rawident }
1148
+ @precedence { DurationPart rawident }
1149
+ @precedence { DurationPart Int }
1150
+ @precedence { numberident Int rawident }
1151
+
1152
+ javaScriptContent { "\n" | ![{}\n'"]+ "\n"? | String }
1153
+ javaScriptBraceOpen { "{" }
1154
+ javaScriptBraceClose { "}" }
1155
+
1156
+ binaryOperator {
1157
+ "&&" | "||" | "??" | "?:" | "!=" | "==" | "?=" | "*=" | "~" | "!~" | "*~" |
1158
+ "<=" | ">=" | "+" | "+=" | "-=" | "*" | "×" | "/" | "÷" | "**" |
1159
+ $[∋∌⊇⊃⊅∈∉⊆⊂⊄] | "@@"
1160
+ }
1161
+
1162
+ assignmentOperator[@name=Operator] {
1163
+ "=" |
1164
+ "+=" |
1165
+ "-="
1166
+ }
1167
+ }
1168
+
1169
+ commaSep<content> {
1170
+ content ("," content)*
1171
+ }
1172
+
1173
+ piped<content> {
1174
+ content ("|" content)*
1175
+ }
1176
+
1177
+ @skip { whitespace | Comment }
1178
+ @detectDelim
1179
+
1180
+ @external propSource surqlHighlighting from "./highlight"
1181
+
1182
+ @external extend { rawident } tokens from "./tokens" {
1183
+ alter [@name=Keyword],
1184
+ analyzer [@name=Keyword],
1185
+ any [@name=Keyword],
1186
+ as [@name=Keyword],
1187
+ asc [@name=Keyword],
1188
+ assert [@name=Keyword],
1189
+ at [@name=Keyword],
1190
+ begin [@name=Keyword],
1191
+ bm25 [@name=Keyword],
1192
+ break [@name=Keyword],
1193
+ by [@name=Keyword],
1194
+ cancel [@name=Keyword],
1195
+ capacity [@name=Keyword],
1196
+ changefeed [@name=Keyword],
1197
+ changes [@name=Keyword],
1198
+ columns [@name=Keyword],
1199
+ comment [@name=Keyword],
1200
+ commit [@name=Keyword],
1201
+ content [@name=Keyword],
1202
+ continue [@name=Keyword],
1203
+ create [@name=Keyword],
1204
+ database [@name=Keyword],
1205
+ db [@name=Keyword],
1206
+ default [@name=Keyword],
1207
+ define [@name=Keyword],
1208
+ delete [@name=Keyword],
1209
+ desc [@name=Keyword],
1210
+ dimension [@name=Keyword],
1211
+ dist [@name=Keyword],
1212
+ doc_ids_cache [@name=Keyword],
1213
+ doc_ids_order [@name=Keyword],
1214
+ doc_lengths_cache [@name=Keyword],
1215
+ doc_lengths_order [@name=Keyword],
1216
+ drop [@name=Keyword],
1217
+ duplicate [@name=Keyword],
1218
+ efc [@name=Keyword],
1219
+ else [@name=Keyword],
1220
+ end [@name=Keyword],
1221
+ event [@name=Keyword],
1222
+ exists [@name=Keyword],
1223
+ explain [@name=Keyword],
1224
+ extend_candidates [@name=Keyword],
1225
+ fetch [@name=Keyword],
1226
+ field [@name=Keyword],
1227
+ fields [@name=Keyword],
1228
+ filters [@name=Keyword],
1229
+ flexible [@name=Keyword],
1230
+ for [@name=Keyword],
1231
+ from [@name=Keyword],
1232
+ group [@name=Keyword],
1233
+ highlights [@name=Keyword],
1234
+ hnsw [@name=Keyword],
1235
+ if [@name=Keyword],
1236
+ ignore [@name=Keyword],
1237
+ in [@name=Keyword],
1238
+ index [@name=Keyword],
1239
+ info [@name=Keyword],
1240
+ insert [@name=Keyword],
1241
+ into [@name=Keyword],
1242
+ keep_pruned_connections [@name=Keyword],
1243
+ key [@name=Keyword],
1244
+ kill [@name=Keyword],
1245
+ let [@name=Keyword],
1246
+ limit [@name=Keyword],
1247
+ live [@name=Keyword],
1248
+ lm [@name=Keyword],
1249
+ m [@name=Keyword],
1250
+ m0 [@name=Keyword],
1251
+ merge [@name=Keyword],
1252
+ mtree [@name=Keyword],
1253
+ mtree_cache [@name=Keyword],
1254
+ namespace [@name=Keyword],
1255
+ noindex [@name=Keyword],
1256
+ normal [@name=Keyword],
1257
+ not [@name=Keyword],
1258
+ ns [@name=Keyword],
1259
+ on [@name=Keyword],
1260
+ only [@name=Keyword],
1261
+ option [@name=Keyword],
1262
+ order [@name=Keyword],
1263
+ out [@name=Keyword],
1264
+ overwrite [@name=Keyword],
1265
+ parallel [@name=Keyword],
1266
+ param [@name=Keyword],
1267
+ passhash [@name=Keyword],
1268
+ password [@name=Keyword],
1269
+ patch [@name=Keyword],
1270
+ permissions [@name=Keyword],
1271
+ postings_cache [@name=Keyword],
1272
+ postings_order [@name=Keyword],
1273
+ readonly [@name=Keyword],
1274
+ rebuild [@name=Keyword],
1275
+ relate [@name=Keyword],
1276
+ relation [@name=Keyword],
1277
+ remove [@name=Keyword],
1278
+ return [@name=Keyword],
1279
+ roles [@name=Keyword],
1280
+ root [@name=Keyword],
1281
+ sc [@name=Keyword],
1282
+ schemafull [@name=Keyword],
1283
+ schemaless [@name=Keyword],
1284
+ scope [@name=Keyword],
1285
+ search [@name=Keyword],
1286
+ select [@name=Keyword],
1287
+ session [@name=Keyword],
1288
+ set [@name=Keyword],
1289
+ show [@name=Keyword],
1290
+ signin [@name=Keyword],
1291
+ signup [@name=Keyword],
1292
+ since [@name=Keyword],
1293
+ sleep [@name=Keyword],
1294
+ split [@name=Keyword],
1295
+ start [@name=Keyword],
1296
+ structure [@name=Keyword],
1297
+ table [@name=Keyword],
1298
+ tb [@name=Keyword],
1299
+ tempfiles [@name=Keyword],
1300
+ terms_cache [@name=Keyword],
1301
+ terms_order [@name=Keyword],
1302
+ then [@name=Keyword],
1303
+ throw [@name=Keyword],
1304
+ timeout [@name=Keyword],
1305
+ to [@name=Keyword],
1306
+ token [@name=Keyword],
1307
+ tokenizers [@name=Keyword],
1308
+ transaction [@name=Keyword],
1309
+ typeKeyword [@name=Keyword],
1310
+ unique [@name=Keyword],
1311
+ unset [@name=Keyword],
1312
+ update [@name=Keyword],
1313
+ upsert [@name=Keyword],
1314
+ use [@name=Keyword],
1315
+ user [@name=Keyword],
1316
+ valueKeyword [@name=Keyword],
1317
+ values [@name=Keyword],
1318
+ when [@name=Keyword],
1319
+ where [@name=Keyword],
1320
+ with [@name=Keyword],
1321
+
1322
+ // Literals
1323
+ after [@name=Literal],
1324
+ before [@name=Literal],
1325
+ diff [@name=Literal],
1326
+ false [@name=Bool],
1327
+ full [@name=Literal],
1328
+ none [@name=None],
1329
+ null [@name=None],
1330
+ true [@name=Bool],
1331
+
1332
+ f32 [@name=Literal],
1333
+ f64 [@name=Literal],
1334
+ i16 [@name=Literal],
1335
+ i32 [@name=Literal],
1336
+ i64 [@name=Literal],
1337
+
1338
+ createPermissions [@name=PermissionTarget],
1339
+ deletePermissions [@name=PermissionTarget],
1340
+ selectPermissions [@name=PermissionTarget],
1341
+ updatePermissions [@name=PermissionTarget],
1342
+
1343
+ jwks [@name=TokenType],
1344
+ eddsa [@name=TokenType],
1345
+ es256 [@name=TokenType],
1346
+ es384 [@name=TokenType],
1347
+ es512 [@name=TokenType],
1348
+ ps256 [@name=TokenType],
1349
+ ps384 [@name=TokenType],
1350
+ ps512 [@name=TokenType],
1351
+ rs256 [@name=TokenType],
1352
+ rs384 [@name=TokenType],
1353
+ rs512 [@name=TokenType],
1354
+
1355
+ // Operators
1356
+ allinside,
1357
+ and,
1358
+ anyinside,
1359
+ contains,
1360
+ containsall,
1361
+ containsany,
1362
+ containsnone,
1363
+ containsnot,
1364
+ inside,
1365
+ intersects,
1366
+ is,
1367
+ noneinside,
1368
+ notinside,
1369
+ opIn,
1370
+ opNot,
1371
+ or,
1372
+ outside,
1373
+
1374
+ chebyshev [@name=Distance],
1375
+ cosine [@name=Distance],
1376
+ euclidean [@name=Distance],
1377
+ hamming [@name=Distance],
1378
+ jaccard [@name=Distance],
1379
+ manhattan [@name=Distance],
1380
+ minkowski [@name=Distance],
1381
+ pearson [@name=Distance],
1382
+
1383
+ ascii [@name=Filter],
1384
+ edgengram [@name=Filter],
1385
+ lowercase [@name=Filter],
1386
+ ngram [@name=Filter],
1387
+ snowball [@name=Filter],
1388
+ uppercase [@name=Filter],
1389
+
1390
+ blank [@name=Tokenizer],
1391
+ camel [@name=Tokenizer],
1392
+ class [@name=Tokenizer],
1393
+ punct [@name=Tokenizer],
1394
+
1395
+ function,
1396
+ rand [@name=FunctionName],
1397
+ count [@name=FunctionName]
1398
+ }