@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.
- package/LICENSE +201 -0
- package/dist/index.cjs +557 -0
- package/dist/index.js +553 -0
- package/package.json +28 -0
- package/rollup.config.js +15 -0
- package/src/highlight.js +23 -0
- package/src/parser.js +26 -0
- package/src/parser.terms.js +353 -0
- package/src/surrealql.grammar +1398 -0
- package/src/tokens.js +516 -0
- package/test/statement.txt +47 -0
- package/test/test-surrealql.js +24 -0
- package/test/value.txt +228 -0
package/test/value.txt
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
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
|
+
)
|