@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
@@ -1,132 +0,0 @@
1
- # Simple Select
2
-
3
- SELECT * FROM test
4
-
5
- ==>
6
-
7
- SurrealQL(SelectStatement(Keyword,Any,Keyword,Ident))
8
-
9
- # Define Function
10
-
11
- DEFINE FUNCTION fn::greet($name: string) {
12
- RETURN "Hello, " + $name + "!";
13
- };
14
-
15
- -- Returns: "Hello, Tobie!"
16
- RETURN fn::greet("Tobie");
17
-
18
- ==>
19
-
20
- SurrealQL(
21
- DefineStatement(
22
- Keyword,Keyword,FunctionName,ParamList(VariableName,Colon,TypeName),
23
- Block(BraceOpen,
24
- ReturnStatement(Keyword,BinaryExpression(BinaryExpression(String,Operator,VariableName),Operator,String)),
25
- BraceClose)),
26
- Comment,
27
- ReturnStatement(Keyword,FunctionCall(FunctionName,ArgumentList(String))))
28
-
29
- # Remove Function
30
-
31
- REMOVE FUNCTION fn::update_author;
32
-
33
- ==>
34
-
35
- SurrealQL(RemoveStatement(Keyword,Keyword,FunctionName))
36
-
37
- # Live Select targets
38
-
39
- LIVE SELECT * FROM person;
40
- LIVE SELECT * FROM person:tobie;
41
-
42
- ==>
43
-
44
- SurrealQL(
45
- LiveSelectStatement(Keyword,Keyword,Any,Keyword,Ident),
46
- LiveSelectStatement(Keyword,Keyword,Any,Keyword,RecordId(RecordTbIdent,Colon,RecordIdIdent)),
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/value.txt DELETED
@@ -1,259 +0,0 @@
1
- # Numbers
2
-
3
- 0;
4
- 0.0;
5
- 2e4f;
6
- 2.2e4;
7
- 4dec;
8
-
9
- ==>
10
-
11
- SurrealQL(Int,Float,Float,Float,Decimal)
12
-
13
- # Strings
14
-
15
- "A string with \"double\" and 'single' quotes";
16
- 'A string with "double" and \'single\' quotes';
17
- 'A string with new \
18
- line';
19
-
20
- ==>
21
-
22
- SurrealQL(String,String,String)
23
-
24
- # Identifiers
25
-
26
- theVar;
27
- theVar2;
28
-
29
- ==>
30
-
31
- SurrealQL(Ident,Ident)
32
-
33
- # Binary operators
34
-
35
- 1 + 2;
36
- a ∈ z;
37
- x containsnot y;
38
-
39
- ==>
40
-
41
- SurrealQL(
42
- BinaryExpression(Int,Operator,Int),
43
- BinaryExpression(Ident,Operator,Ident),
44
- BinaryExpression(Ident,Operator,Ident)
45
- )
46
-
47
- # Objects
48
-
49
- {a: 10};
50
- {block};
51
- {"stringkey": 1, 'single': 2};
52
- {};
53
- { };
54
- 123
55
-
56
- ==>
57
-
58
- SurrealQL(
59
- Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,Int)),BraceClose),
60
- Block(BraceOpen,Ident,BraceClose),
61
- Object(BraceOpen,ObjectContent(
62
- ObjectProperty(ObjectKey(String),Colon,Int),
63
- ObjectProperty(ObjectKey(String),Colon,Int)
64
- ),BraceClose),
65
- Object(BraceOpen,BraceClose),
66
- Object(BraceOpen,BraceClose),
67
- Int
68
- )
69
-
70
- # Points
71
-
72
- (10dec, 20dec)
73
-
74
- ==>
75
-
76
- SurrealQL(Point(Decimal,Decimal))
77
-
78
- # Function Calls
79
-
80
- a::b();
81
- fn::one::two(1, a);
82
- rand(3);
83
- count(x);
84
- some::versioned::function<1.2.3>(a);
85
-
86
- ==>
87
-
88
- SurrealQL(
89
- FunctionCall(FunctionName,ArgumentList),
90
- FunctionCall(FunctionName,ArgumentList(Int,Ident)),
91
- FunctionCall(FunctionName,ArgumentList(Int)),
92
- FunctionCall(FunctionName,ArgumentList(Ident)),
93
- FunctionCall(FunctionName,Version("<",VersionNumber,">"),ArgumentList(Ident))
94
- )
95
-
96
- # Durations
97
-
98
- 1s 1m 1 h
99
-
100
- ==>
101
-
102
- SurrealQL(Duration(DurationPart,DurationPart,DurationPart))
103
-
104
- # JavaScript functions
105
-
106
- function(123, 1d2h) {
107
- const number = 123;
108
- if (test("{")) {
109
- return number.toString();
110
- }
111
- }
112
-
113
- ==>
114
-
115
- SurrealQL(
116
- FunctionJs(
117
- FunctionName,
118
- ArgumentList(Int,Duration(DurationPart,DurationPart)),
119
- JavaScriptBlock(BraceOpen,JavaScriptContent,BraceClose)
120
- )
121
- )
122
-
123
- # Literals
124
-
125
- true;
126
- true
127
-
128
- ==>
129
-
130
- SurrealQL(Bool,Bool)
131
-
132
- # Keyword names in ident position
133
-
134
- create bla set true = 1, false = 2, null = 3, none = 4
135
-
136
- ==>
137
-
138
- SurrealQL(CreateStatement(
139
- Keyword,Ident,
140
- SetClause( Keyword,
141
- FieldAssignment(Ident,Operator,Int),
142
- FieldAssignment(Ident,Operator,Int),
143
- FieldAssignment(Ident,Operator,Int),
144
- FieldAssignment(Ident,Operator,Int))))
145
-
146
- # Idiom paths
147
-
148
- $variable.ident.ident;
149
- record:id.*;
150
- ident->?;
151
- ident->ident;
152
- ident->ident<-ident<->ident;
153
- ident->(? AS ident, ident, ident WHERE ident AS ident);
154
- record:id->ident;
155
- SELECT ->ident FROM ident;
156
- 123.to_string();
157
- {}[$variable];
158
- {}[ident];
159
- {}["string"];
160
- record:id[ident];
161
- [][0];
162
- [][$variable];
163
- [][WHERE ident = 123];
164
- [][? ident = 123];
165
-
166
- ==>
167
-
168
- SurrealQL(
169
- Path(VariableName,Subscript(Ident),Subscript(Ident)),
170
- Path(RecordId(RecordTbIdent,Colon,RecordIdIdent),Subscript(Any)),
171
- Path(Ident,GraphPath(ArrowRight,Any)),
172
- Path(Ident,GraphPath(ArrowRight,Ident)),
173
- Path(Ident,GraphPath(ArrowRight,Ident),GraphPath(ArrowLeft,Ident),GraphPath(ArrowBoth,Ident)),
174
- Path(Ident,GraphPath(ArrowRight,GraphPredicate(Any,Keyword,Ident),GraphPredicate(Ident),
175
- GraphPredicate(Ident,WhereClause(Keyword,Ident),Keyword,Ident))),
176
- Path(RecordId(RecordTbIdent,Colon,RecordIdIdent),GraphPath(ArrowRight,Ident)),
177
- SelectStatement(Keyword,Predicate(Path(GraphPath(ArrowRight,Ident))),Keyword,Ident),
178
- Path(Int,Subscript(FunctionName,ArgumentList)),
179
- Path(Object(BraceOpen,BraceClose),Filter("[",VariableName,"]")),
180
- Path(Object(BraceOpen,BraceClose),Filter("[",Ident,"]")),
181
- Path(Object(BraceOpen,BraceClose),Filter("[",String,"]")),
182
- Path(RecordId(RecordTbIdent,Colon,RecordIdIdent),Filter("[",Ident,"]")),
183
- Path(Array("[","]"),Filter("[",Int,"]")),
184
- Path(Array("[","]"),Filter("[",VariableName,"]")),
185
- Path(Array("[","]"),Filter("[",WhereClause(Keyword,BinaryExpression(Ident,Operator,Int)),"]")),
186
- Path(Array("[","]"),Filter("[",WhereClause(BinaryExpression(Ident,Operator,Int)),"]")))
187
-
188
- # Record ID number(ident)
189
-
190
- test:123;
191
- test:123ident;
192
-
193
- ==>
194
-
195
- SurrealQL(
196
- RecordId(RecordTbIdent,Colon,Int),
197
- RecordId(RecordTbIdent,Colon,RecordIdIdent),
198
- )
199
-
200
- # Casting
201
-
202
- <string> test;
203
- <string|number> test;
204
- <"test"> test;
205
- <"test"|number> test;
206
- <"a"|"b"> test;
207
- <["test"]> test;
208
- <["test"|number]> test;
209
- <{ "a": string }> test;
210
- <{ "a": "test"|number }> test;
211
- <{ "a": "test"|[number] }|number> test;
212
- <{ "a": string } | { "b": [record<hello>] | "test" }> test;
213
-
214
- ==>
215
-
216
- SurrealQL(
217
- TypeCast("<",TypeName,">",Ident),
218
- TypeCast("<",UnionType(TypeName,Pipe,TypeName),">",Ident),
219
- TypeCast("<",LiteralType(String),">",Ident),
220
- TypeCast("<",UnionType(LiteralType(String),Pipe,TypeName),">",Ident),
221
- TypeCast("<",UnionType(LiteralType(String),Pipe,LiteralType(String)),">",Ident),
222
- TypeCast("<",LiteralType(ArrayType("[",LiteralType(String),"]")),">",Ident),
223
- TypeCast("<",LiteralType(ArrayType("[",UnionType(LiteralType(String),Pipe,TypeName),"]")),">",Ident),
224
- TypeCast("<",LiteralType(ObjectType(BraceOpen,ObjectTypeContent(ObjectTypeProperty(ObjectKey(String),Colon,TypeName)),BraceClose)),">",Ident),
225
- TypeCast("<",LiteralType(ObjectType(BraceOpen,ObjectTypeContent(ObjectTypeProperty(ObjectKey(String),Colon,UnionType(LiteralType(String),Pipe,TypeName))),BraceClose)),">",Ident),
226
- TypeCast("<",UnionType(LiteralType(ObjectType(BraceOpen,ObjectTypeContent(ObjectTypeProperty(ObjectKey(String),Colon,UnionType(LiteralType(String),Pipe,LiteralType(ArrayType("[",TypeName,"]"))))),BraceClose)),Pipe,TypeName),">",Ident),
227
- TypeCast("<",UnionType(LiteralType(ObjectType(BraceOpen,ObjectTypeContent(ObjectTypeProperty(ObjectKey(String),Colon,TypeName)),BraceClose)),Pipe,LiteralType(ObjectType(BraceOpen,ObjectTypeContent(ObjectTypeProperty(ObjectKey(String),Colon,UnionType(LiteralType(ArrayType("[",ParameterizedType(TypeName,"<",TypeName,">"),"]")),Pipe,LiteralType(String)))),BraceClose))),">",Ident)
228
- )
229
-
230
- # Ranges
231
-
232
- 1>..2;
233
-
234
- -3..;
235
-
236
- ..='a';
237
-
238
- ==>
239
-
240
- SurrealQL(Range(Int,RangeOp,Int),Range(Int,RangeOp),Range(RangeOp,String))
241
-
242
- # Record ID Call
243
-
244
- stuff:ulid();
245
-
246
- ==>
247
-
248
- SurrealQL(FunctionCall(RecordId(RecordTbIdent,Colon,RecordIdIdent),ArgumentList))
249
-
250
- # Format Strings
251
-
252
- f"some \" quote {1 + 2 + 3} and \{ some } brackets";
253
- f'nested {f"string {22}"}'
254
-
255
- ==>
256
-
257
- SurrealQL(
258
- FormatString(Interpolation(BraceOpen,BinaryExpression(BinaryExpression(Int,Operator,Int),Operator,Int),BraceClose)),
259
- FormatString(Interpolation(BraceOpen,FormatString(Interpolation(BraceOpen,Int,BraceClose)),BraceClose)))