@surrealdb/lezer 1.0.3 → 1.0.5

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.
Files changed (58) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-run-tests.log +500 -42
  3. package/dist/index.cjs +68 -66
  4. package/dist/index.js +68 -66
  5. package/package.json +1 -1
  6. package/src/parser.js +18 -18
  7. package/src/parser.terms.js +234 -231
  8. package/src/surrealql.grammar +88 -80
  9. package/src/tokens.js +2 -0
  10. package/test/misc/comments.txt +44 -0
  11. package/test/misc/functions.txt +63 -0
  12. package/test/misc/identifiers.txt +22 -0
  13. package/test/misc/javascript.txt +34 -0
  14. package/test/misc/operators.txt +213 -0
  15. package/test/misc/parameters.txt +23 -0
  16. package/test/misc/subqueries.txt +23 -0
  17. package/test/statements/alter.txt +47 -0
  18. package/test/statements/break-continue.txt +15 -0
  19. package/test/statements/create.txt +103 -0
  20. package/test/statements/define.txt +281 -0
  21. package/test/statements/delete.txt +63 -0
  22. package/test/statements/for.txt +19 -0
  23. package/test/statements/if-else.txt +47 -0
  24. package/test/statements/info.txt +63 -0
  25. package/test/statements/insert.txt +63 -0
  26. package/test/statements/let.txt +39 -0
  27. package/test/statements/live.txt +47 -0
  28. package/test/statements/option.txt +23 -0
  29. package/test/statements/rebuild.txt +15 -0
  30. package/test/statements/relate.txt +63 -0
  31. package/test/statements/remove.txt +95 -0
  32. package/test/statements/return.txt +39 -0
  33. package/test/statements/select.txt +231 -0
  34. package/test/statements/show.txt +31 -0
  35. package/test/statements/sleep.txt +23 -0
  36. package/test/statements/throw.txt +23 -0
  37. package/test/statements/transactions.txt +47 -0
  38. package/test/statements/update.txt +87 -0
  39. package/test/statements/upsert.txt +55 -0
  40. package/test/statements/use.txt +39 -0
  41. package/test/test-surrealql.js +81 -9
  42. package/test/values/arrays.txt +47 -0
  43. package/test/values/casting.txt +95 -0
  44. package/test/values/closures.txt +39 -0
  45. package/test/values/durations.txt +41 -0
  46. package/test/values/format-strings.txt +39 -0
  47. package/test/values/geometries.txt +23 -0
  48. package/test/values/idioms.txt +228 -0
  49. package/test/values/literals.txt +46 -0
  50. package/test/values/numbers.txt +75 -0
  51. package/test/values/objects.txt +64 -0
  52. package/test/values/ranges.txt +31 -0
  53. package/test/values/record-ids.txt +71 -0
  54. package/test/values/regex.txt +31 -0
  55. package/test/values/sets.txt +31 -0
  56. package/test/values/strings.txt +69 -0
  57. package/test/statement.txt +0 -132
  58. package/test/value.txt +0 -259
@@ -0,0 +1,228 @@
1
+ # Dot notation path
2
+
3
+ $variable.ident.ident
4
+
5
+ ==>
6
+
7
+ SurrealQL(Path(VariableName,Subscript(Ident),Subscript(Ident)))
8
+
9
+ # Wildcard on record ID
10
+
11
+ record:id.*
12
+
13
+ ==>
14
+
15
+ SurrealQL(Path(RecordId(RecordTbIdent,Colon,RecordIdIdent),Subscript(Any)))
16
+
17
+ # Lookup arrow right with any
18
+
19
+ ident->?
20
+
21
+ ==>
22
+
23
+ SurrealQL(Path(Ident,Lookup(LookupRight,Any)))
24
+
25
+ # Lookup arrow right
26
+
27
+ ident->ident
28
+
29
+ ==>
30
+
31
+ SurrealQL(Path(Ident,Lookup(LookupRight,Ident)))
32
+
33
+ # Multiple lookups
34
+
35
+ ident->ident<-ident<->ident
36
+
37
+ ==>
38
+
39
+ SurrealQL(Path(Ident,Lookup(LookupRight,Ident),Lookup(LookupLeft,Ident),Lookup(LookupBoth,Ident)))
40
+
41
+ # Record ID lookup
42
+
43
+ record:id->ident
44
+
45
+ ==>
46
+
47
+ SurrealQL(Path(RecordId(RecordTbIdent,Colon,RecordIdIdent),Lookup(LookupRight,Ident)))
48
+
49
+ # SELECT with lookup path
50
+
51
+ SELECT ->ident FROM ident
52
+
53
+ ==>
54
+
55
+ SurrealQL(SelectStatement(Keyword,Fields(Predicate(Path(Lookup(LookupRight,Ident)))),Keyword,Ident))
56
+
57
+ # Method call on number
58
+
59
+ 123.to_string()
60
+
61
+ ==>
62
+
63
+ SurrealQL(Path(Number(Int),Subscript(IdiomFunction(FunctionName,ArgumentList))))
64
+
65
+ # Filter with variable key
66
+
67
+ {}[$variable]
68
+
69
+ ==>
70
+
71
+ SurrealQL(Path(Object(BraceOpen,BraceClose),Filter("[",VariableName,"]")))
72
+
73
+ # Filter with ident key
74
+
75
+ {}[ident]
76
+
77
+ ==>
78
+
79
+ SurrealQL(Path(Object(BraceOpen,BraceClose),Filter("[",Ident,"]")))
80
+
81
+ # Filter with string key
82
+
83
+ {}["string"]
84
+
85
+ ==>
86
+
87
+ SurrealQL(Path(Object(BraceOpen,BraceClose),Filter("[",String,"]")))
88
+
89
+ # Record ID filter
90
+
91
+ record:id[ident]
92
+
93
+ ==>
94
+
95
+ SurrealQL(Path(RecordId(RecordTbIdent,Colon,RecordIdIdent),Filter("[",Ident,"]")))
96
+
97
+ # Array index access
98
+
99
+ [][0]
100
+
101
+ ==>
102
+
103
+ SurrealQL(Path(Array("[","]"),Filter("[",Number(Int),"]")))
104
+
105
+ # Array variable access
106
+
107
+ [][$variable]
108
+
109
+ ==>
110
+
111
+ SurrealQL(Path(Array("[","]"),Filter("[",VariableName,"]")))
112
+
113
+ # Array WHERE filter
114
+
115
+ [][WHERE ident = 123]
116
+
117
+ ==>
118
+
119
+ SurrealQL(Path(Array("[","]"),Filter("[",WhereClause(Keyword,BinaryExpression(Ident,Operator,Number(Int))),"]")))
120
+
121
+ # Array question mark filter
122
+
123
+ [][? ident = 123]
124
+
125
+ ==>
126
+
127
+ SurrealQL(Path(Array("[","]"),Filter("[",WhereClause(BinaryExpression(Ident,Operator,Number(Int))),"]")))
128
+
129
+ # Recurse unbounded
130
+
131
+ person:tobie.{..}->knows->person
132
+
133
+ ==>
134
+
135
+ SurrealQL(Path(
136
+ RecordId(RecordTbIdent,Colon,RecordIdIdent),
137
+ Subscript(Recurse(BraceOpen,RecurseRange(RangeOp),RecurseOptions,BraceClose)),
138
+ Lookup(LookupRight,Ident), Lookup(LookupRight,Ident)
139
+ ))
140
+
141
+ # Recurse with path expression
142
+
143
+ person:tobie.{..}(->knows->person).name
144
+
145
+ ==>
146
+
147
+ SurrealQL(Path(
148
+ RecordId(RecordTbIdent,Colon,RecordIdIdent),
149
+ Subscript(
150
+ Recurse(
151
+ BraceOpen, RecurseRange(RangeOp), RecurseOptions, BraceClose,
152
+ Lookup(LookupRight,Ident), Lookup(LookupRight,Ident)
153
+ )
154
+ ),
155
+ Subscript(Ident)
156
+ ))
157
+
158
+ # Recurse with destructure
159
+
160
+ person:tobie.{..}.{ id, name, knows: ->knows->person.@ }
161
+
162
+ ==>
163
+
164
+ SurrealQL(Path(
165
+ RecordId(RecordTbIdent,Colon,RecordIdIdent),
166
+ Subscript(Recurse(BraceOpen,RecurseRange(RangeOp),RecurseOptions,BraceClose)),
167
+ Subscript(Destructure(BraceOpen,Ident,Ident,Ident,Colon,Lookup(LookupRight,Ident),Lookup(LookupRight,Ident),Subscript(At),BraceClose))
168
+ ))
169
+
170
+ # Recurse with fixed depth
171
+
172
+ a:b.{1}
173
+
174
+ ==>
175
+
176
+ SurrealQL(Path(
177
+ RecordId(RecordTbIdent,Colon,RecordIdIdent),
178
+ Subscript(Recurse(BraceOpen,RecurseRange(Number(Int)),RecurseOptions,BraceClose))
179
+ ))
180
+
181
+ # Recurse with min range
182
+
183
+ a:b.{1..}
184
+
185
+ ==>
186
+
187
+ SurrealQL(Path(
188
+ RecordId(RecordTbIdent,Colon,RecordIdIdent),
189
+ Subscript(Recurse(BraceOpen,RecurseRange(Number(Int),RangeOp),RecurseOptions,BraceClose))
190
+ ))
191
+
192
+ # Recurse with full range
193
+
194
+ a:b.{1..2}
195
+
196
+ ==>
197
+
198
+ SurrealQL(Path(
199
+ RecordId(RecordTbIdent,Colon,RecordIdIdent),
200
+ Subscript(Recurse(BraceOpen,RecurseRange(Number(Int),RangeOp,Number(Int)),RecurseOptions,BraceClose))
201
+ ))
202
+
203
+ # Recurse with max range
204
+
205
+ a:b.{..2}
206
+
207
+ ==>
208
+
209
+ SurrealQL(Path(
210
+ RecordId(RecordTbIdent,Colon,RecordIdIdent),
211
+ Subscript(Recurse(BraceOpen,RecurseRange(RangeOp,Number(Int)),RecurseOptions,BraceClose))
212
+ ))
213
+
214
+ # At reference with subscript
215
+
216
+ @.name
217
+
218
+ ==>
219
+
220
+ SurrealQL(Path(At,Subscript(Ident)))
221
+
222
+ # At reference with ident
223
+
224
+ @name
225
+
226
+ ==>
227
+
228
+ SurrealQL(Path(At,Ident))
@@ -0,0 +1,46 @@
1
+ # Boolean true
2
+
3
+ true;
4
+ true
5
+
6
+ ==>
7
+
8
+ SurrealQL(Bool,Bool)
9
+
10
+ # Boolean false
11
+
12
+ false;
13
+ false
14
+
15
+ ==>
16
+
17
+ SurrealQL(Bool,Bool)
18
+
19
+ # Null
20
+
21
+ null;
22
+ null
23
+
24
+ ==>
25
+
26
+ SurrealQL(None,None)
27
+
28
+ # None
29
+
30
+ none;
31
+ none
32
+
33
+ ==>
34
+
35
+ SurrealQL(None,None)
36
+
37
+ # Mixed literals
38
+
39
+ true;
40
+ false;
41
+ null;
42
+ none
43
+
44
+ ==>
45
+
46
+ SurrealQL(Bool,Bool,None,None)
@@ -0,0 +1,75 @@
1
+ # Integer
2
+
3
+ 0;
4
+ 42;
5
+ 123456
6
+
7
+ ==>
8
+
9
+ SurrealQL(Number(Int),Number(Int),Number(Int))
10
+
11
+ # Float
12
+
13
+ 0.0;
14
+ 2.5;
15
+ 3.14
16
+
17
+ ==>
18
+
19
+ SurrealQL(Number(Float),Number(Float),Number(Float))
20
+
21
+ # Float with exponent
22
+
23
+ 2e4;
24
+ 2.2e4;
25
+ 1e+10;
26
+ 5E-3
27
+
28
+ ==>
29
+
30
+ SurrealQL(Number(Float),Number(Float),Number(Float),Number(Float))
31
+
32
+ # Float with f suffix
33
+
34
+ 2e4f;
35
+ 3.14f
36
+
37
+ ==>
38
+
39
+ SurrealQL(Number(Float),Number(Float))
40
+
41
+ # Float special values
42
+
43
+ Infinity;
44
+ NaN
45
+
46
+ ==>
47
+
48
+ SurrealQL(Number(Float),Number(Float))
49
+
50
+ # Decimal
51
+
52
+ 4dec;
53
+ 100dec
54
+
55
+ ==>
56
+
57
+ SurrealQL(Number(Decimal),Number(Decimal))
58
+
59
+ # Negative numbers
60
+
61
+ -1;
62
+ -3.14
63
+
64
+ ==>
65
+
66
+ SurrealQL(Number(Int),Number(Float))
67
+
68
+ # Positive explicit sign
69
+
70
+ +1;
71
+ +3.14
72
+
73
+ ==>
74
+
75
+ SurrealQL(Number(Int),Number(Float))
@@ -0,0 +1,64 @@
1
+ # Simple object
2
+
3
+ {a: 10}
4
+
5
+ ==>
6
+
7
+ SurrealQL(Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,Number(Int))),BraceClose))
8
+
9
+ # Object with string keys
10
+
11
+ {"stringkey": 1, 'single': 2}
12
+
13
+ ==>
14
+
15
+ SurrealQL(Object(BraceOpen,ObjectContent(
16
+ ObjectProperty(ObjectKey(String),Colon,Number(Int)),
17
+ ObjectProperty(ObjectKey(String),Colon,Number(Int))
18
+ ),BraceClose))
19
+
20
+ # Empty object
21
+
22
+ {}
23
+
24
+ ==>
25
+
26
+ SurrealQL(Object(BraceOpen,BraceClose))
27
+
28
+ # Empty object with space
29
+
30
+ { }
31
+
32
+ ==>
33
+
34
+ SurrealQL(Object(BraceOpen,BraceClose))
35
+
36
+ # Block vs Object
37
+
38
+ {block}
39
+
40
+ ==>
41
+
42
+ SurrealQL(Block(BraceOpen,Ident,BraceClose))
43
+
44
+ # Object followed by value
45
+
46
+ {a: 10};
47
+ 123
48
+
49
+ ==>
50
+
51
+ SurrealQL(
52
+ Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,Number(Int))),BraceClose),
53
+ Number(Int)
54
+ )
55
+
56
+ # Nested objects
57
+
58
+ {a: {b: 1}}
59
+
60
+ ==>
61
+
62
+ SurrealQL(Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,
63
+ Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,Number(Int))),BraceClose)
64
+ )),BraceClose))
@@ -0,0 +1,31 @@
1
+ # Exclusive range
2
+
3
+ 1>..2
4
+
5
+ ==>
6
+
7
+ SurrealQL(Range(Number(Int),RangeOp,Number(Int)))
8
+
9
+ # Right-open range
10
+
11
+ -3..
12
+
13
+ ==>
14
+
15
+ SurrealQL(Range(Number(Int),RangeOp))
16
+
17
+ # Left-open inclusive range
18
+
19
+ ..='a'
20
+
21
+ ==>
22
+
23
+ SurrealQL(Range(RangeOp,String))
24
+
25
+ # Simple range
26
+
27
+ 1..5
28
+
29
+ ==>
30
+
31
+ SurrealQL(Range(Number(Int),RangeOp,Number(Int)))
@@ -0,0 +1,71 @@
1
+ # Simple record ID
2
+
3
+ test:123
4
+
5
+ ==>
6
+
7
+ SurrealQL(RecordId(RecordTbIdent,Colon,RecordIdIdent))
8
+
9
+ # Record ID with ident value
10
+
11
+ test:abc
12
+
13
+ ==>
14
+
15
+ SurrealQL(RecordId(RecordTbIdent,Colon,RecordIdIdent))
16
+
17
+ # Number followed by ident in record ID
18
+
19
+ test:123ident
20
+
21
+ ==>
22
+
23
+ SurrealQL(RecordId(RecordTbIdent,Colon,RecordIdIdent))
24
+
25
+ # Record ID function call
26
+
27
+ stuff:ulid()
28
+
29
+ ==>
30
+
31
+ SurrealQL(FunctionCall(RecordId(RecordTbIdent,Colon,RecordIdIdent),ArgumentList))
32
+
33
+ # Record ID with tick-quoted table
34
+
35
+ `my table`:abc
36
+
37
+ ==>
38
+
39
+ SurrealQL(RecordId(RecordTbIdent,Colon,RecordIdIdent))
40
+
41
+ # Record ID with tick-quoted value
42
+
43
+ test:`my id`
44
+
45
+ ==>
46
+
47
+ SurrealQL(RecordId(RecordTbIdent,Colon,RecordIdIdent))
48
+
49
+ # Record ID with object value
50
+
51
+ test:{a: 1}
52
+
53
+ ==>
54
+
55
+ SurrealQL(RecordId(RecordTbIdent,Colon,Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,Number(Int))),BraceClose)))
56
+
57
+ # Record ID with array value
58
+
59
+ test:[1, 2]
60
+
61
+ ==>
62
+
63
+ SurrealQL(RecordId(RecordTbIdent,Colon,Array("[",Number(Int),Number(Int),"]")))
64
+
65
+ # Record ID with prefixed string value
66
+
67
+ test:u"my-uuid-here"
68
+
69
+ ==>
70
+
71
+ SurrealQL(RecordId(RecordTbIdent,Colon,RecordIdString(String)))
@@ -0,0 +1,31 @@
1
+ # Basic regex
2
+
3
+ /hello/
4
+
5
+ ==>
6
+
7
+ SurrealQL(Regex)
8
+
9
+ # Regex with flags
10
+
11
+ /test/gi
12
+
13
+ ==>
14
+
15
+ SurrealQL(Regex)
16
+
17
+ # Regex with character class
18
+
19
+ /[a-z]+/
20
+
21
+ ==>
22
+
23
+ SurrealQL(Regex)
24
+
25
+ # Regex with escape
26
+
27
+ /foo\.bar/
28
+
29
+ ==>
30
+
31
+ SurrealQL(Regex)
@@ -0,0 +1,31 @@
1
+ # Set with single trailing comma
2
+
3
+ {1,}
4
+
5
+ ==>
6
+
7
+ SurrealQL(Set(BraceOpen,Number(Int),BraceClose))
8
+
9
+ # Set with lone comma
10
+
11
+ {,}
12
+
13
+ ==>
14
+
15
+ SurrealQL(Set(BraceOpen,BraceClose))
16
+
17
+ # Set with two elements
18
+
19
+ {1, 2}
20
+
21
+ ==>
22
+
23
+ SurrealQL(Set(BraceOpen,Number(Int),Number(Int),BraceClose))
24
+
25
+ # Set with three elements
26
+
27
+ {1, 2, 3}
28
+
29
+ ==>
30
+
31
+ SurrealQL(Set(BraceOpen,Number(Int),Number(Int),Number(Int),BraceClose))
@@ -0,0 +1,69 @@
1
+ # Double quoted string
2
+
3
+ "hello world"
4
+
5
+ ==>
6
+
7
+ SurrealQL(String)
8
+
9
+ # Single quoted string
10
+
11
+ 'hello world'
12
+
13
+ ==>
14
+
15
+ SurrealQL(String)
16
+
17
+ # Escaped double quotes
18
+
19
+ "A string with \"double\" quotes"
20
+
21
+ ==>
22
+
23
+ SurrealQL(String)
24
+
25
+ # Escaped single quotes
26
+
27
+ 'A string with \'single\' quotes'
28
+
29
+ ==>
30
+
31
+ SurrealQL(String)
32
+
33
+ # Mixed quotes
34
+
35
+ "A string with 'single' quotes";
36
+ 'A string with "double" quotes'
37
+
38
+ ==>
39
+
40
+ SurrealQL(String,String)
41
+
42
+ # Multiline string
43
+
44
+ 'A string with new \
45
+ line'
46
+
47
+ ==>
48
+
49
+ SurrealQL(String)
50
+
51
+ # Empty strings
52
+
53
+ "";
54
+ ''
55
+
56
+ ==>
57
+
58
+ SurrealQL(String,String)
59
+
60
+ # Prefixed strings
61
+
62
+ r"raw string";
63
+ u"uuid";
64
+ d"2024-01-01T00:00:00Z";
65
+ b"base64data"
66
+
67
+ ==>
68
+
69
+ SurrealQL(String,String,String,String)