@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.
- package/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-run-tests.log +500 -42
- package/dist/index.cjs +68 -66
- package/dist/index.js +68 -66
- package/package.json +1 -1
- package/src/parser.js +18 -18
- package/src/parser.terms.js +234 -231
- package/src/surrealql.grammar +88 -80
- package/src/tokens.js +2 -0
- package/test/misc/comments.txt +44 -0
- package/test/misc/functions.txt +63 -0
- package/test/misc/identifiers.txt +22 -0
- package/test/misc/javascript.txt +34 -0
- package/test/misc/operators.txt +213 -0
- package/test/misc/parameters.txt +23 -0
- package/test/misc/subqueries.txt +23 -0
- package/test/statements/alter.txt +47 -0
- package/test/statements/break-continue.txt +15 -0
- package/test/statements/create.txt +103 -0
- package/test/statements/define.txt +281 -0
- package/test/statements/delete.txt +63 -0
- package/test/statements/for.txt +19 -0
- package/test/statements/if-else.txt +47 -0
- package/test/statements/info.txt +63 -0
- package/test/statements/insert.txt +63 -0
- package/test/statements/let.txt +39 -0
- package/test/statements/live.txt +47 -0
- package/test/statements/option.txt +23 -0
- package/test/statements/rebuild.txt +15 -0
- package/test/statements/relate.txt +63 -0
- package/test/statements/remove.txt +95 -0
- package/test/statements/return.txt +39 -0
- package/test/statements/select.txt +231 -0
- package/test/statements/show.txt +31 -0
- package/test/statements/sleep.txt +23 -0
- package/test/statements/throw.txt +23 -0
- package/test/statements/transactions.txt +47 -0
- package/test/statements/update.txt +87 -0
- package/test/statements/upsert.txt +55 -0
- package/test/statements/use.txt +39 -0
- package/test/test-surrealql.js +81 -9
- package/test/values/arrays.txt +47 -0
- package/test/values/casting.txt +95 -0
- package/test/values/closures.txt +39 -0
- package/test/values/durations.txt +41 -0
- package/test/values/format-strings.txt +39 -0
- package/test/values/geometries.txt +23 -0
- package/test/values/idioms.txt +228 -0
- package/test/values/literals.txt +46 -0
- package/test/values/numbers.txt +75 -0
- package/test/values/objects.txt +64 -0
- package/test/values/ranges.txt +31 -0
- package/test/values/record-ids.txt +71 -0
- package/test/values/regex.txt +31 -0
- package/test/values/sets.txt +31 -0
- package/test/values/strings.txt +69 -0
- package/test/statement.txt +0 -132
- package/test/value.txt +0 -259
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Begin
|
|
2
|
+
|
|
3
|
+
BEGIN
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
SurrealQL(BeginStatement(Keyword))
|
|
8
|
+
|
|
9
|
+
# Begin transaction
|
|
10
|
+
|
|
11
|
+
BEGIN TRANSACTION
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(BeginStatement(Keyword,Keyword))
|
|
16
|
+
|
|
17
|
+
# Cancel
|
|
18
|
+
|
|
19
|
+
CANCEL
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
SurrealQL(CancelStatement(Keyword))
|
|
24
|
+
|
|
25
|
+
# Cancel transaction
|
|
26
|
+
|
|
27
|
+
CANCEL TRANSACTION
|
|
28
|
+
|
|
29
|
+
==>
|
|
30
|
+
|
|
31
|
+
SurrealQL(CancelStatement(Keyword,Keyword))
|
|
32
|
+
|
|
33
|
+
# Commit
|
|
34
|
+
|
|
35
|
+
COMMIT
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
SurrealQL(CommitStatement(Keyword))
|
|
40
|
+
|
|
41
|
+
# Commit transaction
|
|
42
|
+
|
|
43
|
+
COMMIT TRANSACTION
|
|
44
|
+
|
|
45
|
+
==>
|
|
46
|
+
|
|
47
|
+
SurrealQL(CommitStatement(Keyword,Keyword))
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Simple update
|
|
2
|
+
|
|
3
|
+
UPDATE person
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
SurrealQL(UpdateStatement(Keyword,Ident))
|
|
8
|
+
|
|
9
|
+
# Update ONLY
|
|
10
|
+
|
|
11
|
+
UPDATE ONLY person:tobie
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(UpdateStatement(Keyword,Keyword,RecordId(RecordTbIdent,Colon,RecordIdIdent)))
|
|
16
|
+
|
|
17
|
+
# Update with SET
|
|
18
|
+
|
|
19
|
+
UPDATE person SET age = 31
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
SurrealQL(UpdateStatement(Keyword,Ident,SetClause(Keyword,FieldAssignment(Ident,Operator,Number(Int)))))
|
|
24
|
+
|
|
25
|
+
# Update with CONTENT
|
|
26
|
+
|
|
27
|
+
UPDATE person CONTENT {name: "Tobie"}
|
|
28
|
+
|
|
29
|
+
==>
|
|
30
|
+
|
|
31
|
+
SurrealQL(UpdateStatement(Keyword,Ident,ContentClause(Keyword,Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,String)),BraceClose))))
|
|
32
|
+
|
|
33
|
+
# Update with MERGE
|
|
34
|
+
|
|
35
|
+
UPDATE person MERGE {age: 31}
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
SurrealQL(UpdateStatement(Keyword,Ident,MergeClause(Keyword,Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,Number(Int))),BraceClose))))
|
|
40
|
+
|
|
41
|
+
# Update with REPLACE
|
|
42
|
+
|
|
43
|
+
UPDATE person REPLACE {name: "Tobie"}
|
|
44
|
+
|
|
45
|
+
==>
|
|
46
|
+
|
|
47
|
+
SurrealQL(UpdateStatement(Keyword,Ident,ReplaceClause(Keyword,Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,String)),BraceClose))))
|
|
48
|
+
|
|
49
|
+
# Update with UNSET
|
|
50
|
+
|
|
51
|
+
UPDATE person UNSET temp = 0
|
|
52
|
+
|
|
53
|
+
==>
|
|
54
|
+
|
|
55
|
+
SurrealQL(UpdateStatement(Keyword,Ident,UnsetClause(Keyword,FieldAssignment(Ident,Operator,Number(Int)))))
|
|
56
|
+
|
|
57
|
+
# Update with WHERE
|
|
58
|
+
|
|
59
|
+
UPDATE person SET age = 31 WHERE name = "Tobie"
|
|
60
|
+
|
|
61
|
+
==>
|
|
62
|
+
|
|
63
|
+
SurrealQL(UpdateStatement(Keyword,Ident,SetClause(Keyword,FieldAssignment(Ident,Operator,Number(Int))),WhereClause(Keyword,BinaryExpression(Ident,Operator,String))))
|
|
64
|
+
|
|
65
|
+
# Update with RETURN
|
|
66
|
+
|
|
67
|
+
UPDATE person SET age = 31 RETURN AFTER
|
|
68
|
+
|
|
69
|
+
==>
|
|
70
|
+
|
|
71
|
+
SurrealQL(UpdateStatement(Keyword,Ident,SetClause(Keyword,FieldAssignment(Ident,Operator,Number(Int))),ReturnClause(Keyword,Literal)))
|
|
72
|
+
|
|
73
|
+
# Update with TIMEOUT
|
|
74
|
+
|
|
75
|
+
UPDATE person SET age = 31 TIMEOUT 5s
|
|
76
|
+
|
|
77
|
+
==>
|
|
78
|
+
|
|
79
|
+
SurrealQL(UpdateStatement(Keyword,Ident,SetClause(Keyword,FieldAssignment(Ident,Operator,Number(Int))),TimeoutClause(Keyword,Duration(DurationPart))))
|
|
80
|
+
|
|
81
|
+
# Update with PARALLEL
|
|
82
|
+
|
|
83
|
+
UPDATE person SET age = 31 PARALLEL
|
|
84
|
+
|
|
85
|
+
==>
|
|
86
|
+
|
|
87
|
+
SurrealQL(UpdateStatement(Keyword,Ident,SetClause(Keyword,FieldAssignment(Ident,Operator,Number(Int))),ParallelClause(Keyword)))
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Simple upsert
|
|
2
|
+
|
|
3
|
+
UPSERT person
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
SurrealQL(UpsertStatement(Keyword,Ident))
|
|
8
|
+
|
|
9
|
+
# Upsert ONLY
|
|
10
|
+
|
|
11
|
+
UPSERT ONLY person:tobie
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(UpsertStatement(Keyword,Keyword,RecordId(RecordTbIdent,Colon,RecordIdIdent)))
|
|
16
|
+
|
|
17
|
+
# Upsert with SET
|
|
18
|
+
|
|
19
|
+
UPSERT person SET name = "Tobie"
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
SurrealQL(UpsertStatement(Keyword,Ident,SetClause(Keyword,FieldAssignment(Ident,Operator,String))))
|
|
24
|
+
|
|
25
|
+
# Upsert with CONTENT
|
|
26
|
+
|
|
27
|
+
UPSERT person CONTENT {name: "Tobie"}
|
|
28
|
+
|
|
29
|
+
==>
|
|
30
|
+
|
|
31
|
+
SurrealQL(UpsertStatement(Keyword,Ident,ContentClause(Keyword,Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,String)),BraceClose))))
|
|
32
|
+
|
|
33
|
+
# Upsert with MERGE
|
|
34
|
+
|
|
35
|
+
UPSERT person MERGE {age: 31}
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
SurrealQL(UpsertStatement(Keyword,Ident,MergeClause(Keyword,Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,Number(Int))),BraceClose))))
|
|
40
|
+
|
|
41
|
+
# Upsert with WHERE
|
|
42
|
+
|
|
43
|
+
UPSERT person SET age = 31 WHERE name = "Tobie"
|
|
44
|
+
|
|
45
|
+
==>
|
|
46
|
+
|
|
47
|
+
SurrealQL(UpsertStatement(Keyword,Ident,SetClause(Keyword,FieldAssignment(Ident,Operator,Number(Int))),WhereClause(Keyword,BinaryExpression(Ident,Operator,String))))
|
|
48
|
+
|
|
49
|
+
# Upsert with RETURN
|
|
50
|
+
|
|
51
|
+
UPSERT person SET age = 31 RETURN AFTER
|
|
52
|
+
|
|
53
|
+
==>
|
|
54
|
+
|
|
55
|
+
SurrealQL(UpsertStatement(Keyword,Ident,SetClause(Keyword,FieldAssignment(Ident,Operator,Number(Int))),ReturnClause(Keyword,Literal)))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Use namespace short
|
|
2
|
+
|
|
3
|
+
USE NS test
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
SurrealQL(UseStatement(Keyword,Keyword,Ident))
|
|
8
|
+
|
|
9
|
+
# Use namespace long
|
|
10
|
+
|
|
11
|
+
USE NAMESPACE test
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(UseStatement(Keyword,Keyword,Ident))
|
|
16
|
+
|
|
17
|
+
# Use database short
|
|
18
|
+
|
|
19
|
+
USE DB test
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
SurrealQL(UseStatement(Keyword,Keyword,Ident))
|
|
24
|
+
|
|
25
|
+
# Use database long
|
|
26
|
+
|
|
27
|
+
USE DATABASE test
|
|
28
|
+
|
|
29
|
+
==>
|
|
30
|
+
|
|
31
|
+
SurrealQL(UseStatement(Keyword,Keyword,Ident))
|
|
32
|
+
|
|
33
|
+
# Use namespace and database
|
|
34
|
+
|
|
35
|
+
USE NS test DB test
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
SurrealQL(UseStatement(Keyword,Keyword,Ident,Keyword,Ident))
|
package/test/test-surrealql.js
CHANGED
|
@@ -4,21 +4,93 @@ import { fileTests } from "@lezer/generator/dist/test";
|
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
|
-
let caseDir = path.dirname(fileURLToPath(import.meta.url));
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
const testDir = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const subdirs = ["statements", "values", "misc"];
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
const llmMode = args.includes("--llm");
|
|
13
|
+
const filter = args.find((a) => a !== "--llm");
|
|
14
|
+
|
|
15
|
+
const green = (s) => (llmMode ? s : `\x1b[32m${s}\x1b[0m`);
|
|
16
|
+
const red = (s) => (llmMode ? s : `\x1b[31m${s}\x1b[0m`);
|
|
17
|
+
const bold = (s) => (llmMode ? s : `\x1b[1m${s}\x1b[0m`);
|
|
18
|
+
const dim = (s) => (llmMode ? s : `\x1b[2m${s}\x1b[0m`);
|
|
19
|
+
|
|
20
|
+
let totalPass = 0;
|
|
21
|
+
let totalFail = 0;
|
|
22
|
+
const failures = [];
|
|
23
|
+
|
|
24
|
+
for (const subdir of subdirs) {
|
|
25
|
+
const dirPath = path.join(testDir, subdir);
|
|
26
|
+
if (!fs.existsSync(dirPath)) continue;
|
|
27
|
+
|
|
28
|
+
if (!llmMode) console.log(`\n${bold(`=== ${subdir.toUpperCase()} ===`)}`);
|
|
29
|
+
|
|
30
|
+
for (const file of fs.readdirSync(dirPath).sort()) {
|
|
31
|
+
if (!/\.txt$/.test(file)) continue;
|
|
32
|
+
|
|
33
|
+
const filePath = path.join(dirPath, file);
|
|
34
|
+
const label = `${subdir}/${file}`;
|
|
35
|
+
const tests = fileTests(fs.readFileSync(filePath, "utf8"), file);
|
|
36
|
+
|
|
37
|
+
let filePass = 0;
|
|
38
|
+
let fileFail = 0;
|
|
39
|
+
const fileFailures = [];
|
|
40
|
+
|
|
41
|
+
if (!llmMode) console.log(`\n ${bold(label)}`);
|
|
42
|
+
|
|
43
|
+
for (const { name, run } of tests) {
|
|
44
|
+
if (filter && name.indexOf(filter) === -1) continue;
|
|
16
45
|
try {
|
|
17
46
|
run(parser);
|
|
18
|
-
|
|
47
|
+
filePass++;
|
|
48
|
+
totalPass++;
|
|
49
|
+
if (!llmMode) console.log(` ${green("✔")} ${name}`);
|
|
19
50
|
} catch (e) {
|
|
20
|
-
|
|
51
|
+
fileFail++;
|
|
52
|
+
totalFail++;
|
|
53
|
+
const msg = String(e.message || e);
|
|
54
|
+
fileFailures.push({ name, msg });
|
|
55
|
+
if (!llmMode) {
|
|
56
|
+
console.log(` ${red("✘")} ${name}\n ${red(msg.replace(/\n/g, "\n "))}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (llmMode && fileFail > 0) {
|
|
62
|
+
console.log(`FAIL ${label} (${filePass} passed, ${fileFail} failed)`);
|
|
63
|
+
for (const f of fileFailures) {
|
|
64
|
+
console.log(` FAIL: ${f.name}`);
|
|
65
|
+
console.log(` ${f.msg.replace(/\n/g, "\n ")}`);
|
|
21
66
|
}
|
|
22
67
|
}
|
|
68
|
+
|
|
69
|
+
if (fileFail > 0) {
|
|
70
|
+
failures.push({ label, fileFailures });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!llmMode) {
|
|
74
|
+
console.log(dim(` ${filePass + fileFail} tests: ${filePass} passed${fileFail > 0 ? `, ${fileFail} failed` : ""}`));
|
|
75
|
+
}
|
|
23
76
|
}
|
|
24
77
|
}
|
|
78
|
+
|
|
79
|
+
console.log("");
|
|
80
|
+
if (llmMode) {
|
|
81
|
+
console.log("--- SUMMARY ---");
|
|
82
|
+
console.log(`Total: ${totalPass + totalFail} | Passed: ${totalPass} | Failed: ${totalFail}`);
|
|
83
|
+
if (failures.length > 0) {
|
|
84
|
+
console.log("\nFailed tests:");
|
|
85
|
+
for (const { label, fileFailures } of failures) {
|
|
86
|
+
for (const f of fileFailures) {
|
|
87
|
+
console.log(` [${label}] ${f.name}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
const summary = `${bold("Total")}: ${totalPass + totalFail} | ${green(`Passed: ${totalPass}`)} | ${totalFail > 0 ? red(`Failed: ${totalFail}`) : dim("Failed: 0")}`;
|
|
93
|
+
console.log(summary);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (totalFail > 0) process.exit(1);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Empty array
|
|
2
|
+
|
|
3
|
+
[]
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
SurrealQL(Array("[","]"))
|
|
8
|
+
|
|
9
|
+
# Single element
|
|
10
|
+
|
|
11
|
+
[1]
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(Array("[",Number(Int),"]"))
|
|
16
|
+
|
|
17
|
+
# Multiple elements
|
|
18
|
+
|
|
19
|
+
[1, 2, 3]
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
SurrealQL(Array("[",Number(Int),Number(Int),Number(Int),"]"))
|
|
24
|
+
|
|
25
|
+
# Trailing comma
|
|
26
|
+
|
|
27
|
+
[1, 2, 3,]
|
|
28
|
+
|
|
29
|
+
==>
|
|
30
|
+
|
|
31
|
+
SurrealQL(Array("[",Number(Int),Number(Int),Number(Int),"]"))
|
|
32
|
+
|
|
33
|
+
# Nested arrays
|
|
34
|
+
|
|
35
|
+
[[1, 2], [3, 4]]
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
SurrealQL(Array("[",Array("[",Number(Int),Number(Int),"]"),Array("[",Number(Int),Number(Int),"]"),"]"))
|
|
40
|
+
|
|
41
|
+
# Mixed types
|
|
42
|
+
|
|
43
|
+
[1, "hello", true, null]
|
|
44
|
+
|
|
45
|
+
==>
|
|
46
|
+
|
|
47
|
+
SurrealQL(Array("[",Number(Int),String,Bool,None,"]"))
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Simple type cast
|
|
2
|
+
|
|
3
|
+
<string> test
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
SurrealQL(TypeCast("<",TypeName,">",Ident))
|
|
8
|
+
|
|
9
|
+
# Union type cast
|
|
10
|
+
|
|
11
|
+
<string|number> test
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(TypeCast("<",UnionType(TypeName,Pipe,TypeName),">",Ident))
|
|
16
|
+
|
|
17
|
+
# Literal string type cast
|
|
18
|
+
|
|
19
|
+
<"test"> test
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
SurrealQL(TypeCast("<",LiteralType(String),">",Ident))
|
|
24
|
+
|
|
25
|
+
# Literal union type cast
|
|
26
|
+
|
|
27
|
+
<"test"|number> test
|
|
28
|
+
|
|
29
|
+
==>
|
|
30
|
+
|
|
31
|
+
SurrealQL(TypeCast("<",UnionType(LiteralType(String),Pipe,TypeName),">",Ident))
|
|
32
|
+
|
|
33
|
+
# Literal string union
|
|
34
|
+
|
|
35
|
+
<"a"|"b"> test
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
SurrealQL(TypeCast("<",UnionType(LiteralType(String),Pipe,LiteralType(String)),">",Ident))
|
|
40
|
+
|
|
41
|
+
# Array literal type cast
|
|
42
|
+
|
|
43
|
+
<["test"]> test
|
|
44
|
+
|
|
45
|
+
==>
|
|
46
|
+
|
|
47
|
+
SurrealQL(TypeCast("<",LiteralType(ArrayType("[",LiteralType(String),"]")),">",Ident))
|
|
48
|
+
|
|
49
|
+
# Array union literal type cast
|
|
50
|
+
|
|
51
|
+
<["test"|number]> test
|
|
52
|
+
|
|
53
|
+
==>
|
|
54
|
+
|
|
55
|
+
SurrealQL(TypeCast("<",LiteralType(ArrayType("[",UnionType(LiteralType(String),Pipe,TypeName),"]")),">",Ident))
|
|
56
|
+
|
|
57
|
+
# Object type cast
|
|
58
|
+
|
|
59
|
+
<{ "a": string }> test
|
|
60
|
+
|
|
61
|
+
==>
|
|
62
|
+
|
|
63
|
+
SurrealQL(TypeCast("<",LiteralType(ObjectType(BraceOpen,ObjectTypeContent(ObjectTypeProperty(ObjectKey(String),Colon,TypeName)),BraceClose)),">",Ident))
|
|
64
|
+
|
|
65
|
+
# Object union type cast
|
|
66
|
+
|
|
67
|
+
<{ "a": "test"|number }> test
|
|
68
|
+
|
|
69
|
+
==>
|
|
70
|
+
|
|
71
|
+
SurrealQL(TypeCast("<",LiteralType(ObjectType(BraceOpen,ObjectTypeContent(ObjectTypeProperty(ObjectKey(String),Colon,UnionType(LiteralType(String),Pipe,TypeName))),BraceClose)),">",Ident))
|
|
72
|
+
|
|
73
|
+
# Complex nested type cast
|
|
74
|
+
|
|
75
|
+
<{ "a": "test"|[number] }|number> test
|
|
76
|
+
|
|
77
|
+
==>
|
|
78
|
+
|
|
79
|
+
SurrealQL(TypeCast("<",UnionType(LiteralType(ObjectType(BraceOpen,ObjectTypeContent(ObjectTypeProperty(ObjectKey(String),Colon,UnionType(LiteralType(String),Pipe,LiteralType(ArrayType("[",TypeName,"]"))))),BraceClose)),Pipe,TypeName),">",Ident))
|
|
80
|
+
|
|
81
|
+
# Parameterized type cast
|
|
82
|
+
|
|
83
|
+
<record<hello>> test
|
|
84
|
+
|
|
85
|
+
==>
|
|
86
|
+
|
|
87
|
+
SurrealQL(TypeCast("<",ParameterizedType(TypeName,"<",TypeName,">"),">",Ident))
|
|
88
|
+
|
|
89
|
+
# Complex union object type cast
|
|
90
|
+
|
|
91
|
+
<{ "a": string } | { "b": [record<hello>] | "test" }> test
|
|
92
|
+
|
|
93
|
+
==>
|
|
94
|
+
|
|
95
|
+
SurrealQL(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))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Empty closure
|
|
2
|
+
|
|
3
|
+
|| { 1 }
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
SurrealQL(Closure(Pipe,Pipe,Block(BraceOpen,Number(Int),BraceClose)))
|
|
8
|
+
|
|
9
|
+
# Closure with param
|
|
10
|
+
|
|
11
|
+
|$a| { $a }
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(Closure(Pipe,ParamDefinition(VariableName),Pipe,Block(BraceOpen,VariableName,BraceClose)))
|
|
16
|
+
|
|
17
|
+
# Closure with typed param
|
|
18
|
+
|
|
19
|
+
|$a: number| { $a + 1 }
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
SurrealQL(Closure(Pipe,ParamDefinition(VariableName,Colon,Type(TypeName)),Pipe,Block(BraceOpen,BinaryExpression(VariableName,Operator,Number(Int)),BraceClose)))
|
|
24
|
+
|
|
25
|
+
# Closure with multiple params
|
|
26
|
+
|
|
27
|
+
|$a, $b| { $a + $b }
|
|
28
|
+
|
|
29
|
+
==>
|
|
30
|
+
|
|
31
|
+
SurrealQL(Closure(Pipe,ParamDefinition(VariableName),ParamDefinition(VariableName),Pipe,Block(BraceOpen,BinaryExpression(VariableName,Operator,VariableName),BraceClose)))
|
|
32
|
+
|
|
33
|
+
# Closure with return type
|
|
34
|
+
|
|
35
|
+
|$a: number| -> number { $a + 1 }
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
SurrealQL(Closure(Pipe,ParamDefinition(VariableName,Colon,Type(TypeName)),Pipe,LookupRight,TypeName,Block(BraceOpen,BinaryExpression(VariableName,Operator,Number(Int)),BraceClose)))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Single duration parts
|
|
2
|
+
|
|
3
|
+
1ns;
|
|
4
|
+
1us;
|
|
5
|
+
1ms;
|
|
6
|
+
1s;
|
|
7
|
+
1m;
|
|
8
|
+
1h;
|
|
9
|
+
1d;
|
|
10
|
+
1w;
|
|
11
|
+
1y
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(
|
|
16
|
+
Duration(DurationPart),
|
|
17
|
+
Duration(DurationPart),
|
|
18
|
+
Duration(DurationPart),
|
|
19
|
+
Duration(DurationPart),
|
|
20
|
+
Duration(DurationPart),
|
|
21
|
+
Duration(DurationPart),
|
|
22
|
+
Duration(DurationPart),
|
|
23
|
+
Duration(DurationPart),
|
|
24
|
+
Duration(DurationPart)
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Multi-part duration
|
|
28
|
+
|
|
29
|
+
1s 1m 1 h
|
|
30
|
+
|
|
31
|
+
==>
|
|
32
|
+
|
|
33
|
+
SurrealQL(Duration(DurationPart,DurationPart,DurationPart))
|
|
34
|
+
|
|
35
|
+
# Complex duration
|
|
36
|
+
|
|
37
|
+
1d2h30m
|
|
38
|
+
|
|
39
|
+
==>
|
|
40
|
+
|
|
41
|
+
SurrealQL(Duration(DurationPart,DurationPart,DurationPart))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Basic format string
|
|
2
|
+
|
|
3
|
+
$"hello {name}"
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
SurrealQL(FormatString(Interpolation(BraceOpen,Ident,BraceClose)))
|
|
8
|
+
|
|
9
|
+
# Format string with expression
|
|
10
|
+
|
|
11
|
+
$"result is {1 + 2 + 3}"
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(FormatString(Interpolation(BraceOpen,BinaryExpression(BinaryExpression(Number(Int),Operator,Number(Int)),Operator,Number(Int)),BraceClose)))
|
|
16
|
+
|
|
17
|
+
# Escaped quote in format string
|
|
18
|
+
|
|
19
|
+
$"some \" quote {1 + 2 + 3} and \{ some } brackets"
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
SurrealQL(FormatString(Interpolation(BraceOpen,BinaryExpression(BinaryExpression(Number(Int),Operator,Number(Int)),Operator,Number(Int)),BraceClose)))
|
|
24
|
+
|
|
25
|
+
# Nested format strings
|
|
26
|
+
|
|
27
|
+
$'nested {$"string {22}"}'
|
|
28
|
+
|
|
29
|
+
==>
|
|
30
|
+
|
|
31
|
+
SurrealQL(FormatString(Interpolation(BraceOpen,FormatString(Interpolation(BraceOpen,Number(Int),BraceClose)),BraceClose)))
|
|
32
|
+
|
|
33
|
+
# Single quoted format string
|
|
34
|
+
|
|
35
|
+
$'hello {name}'
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
SurrealQL(FormatString(Interpolation(BraceOpen,Ident,BraceClose)))
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Point with decimals
|
|
2
|
+
|
|
3
|
+
(10dec, 20dec)
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
SurrealQL(Point(Number(Decimal),Number(Decimal)))
|
|
8
|
+
|
|
9
|
+
# Point with integers
|
|
10
|
+
|
|
11
|
+
(10, 20)
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
SurrealQL(Point(Number(Int),Number(Int)))
|
|
16
|
+
|
|
17
|
+
# Point with floats
|
|
18
|
+
|
|
19
|
+
(1.5, 2.5)
|
|
20
|
+
|
|
21
|
+
==>
|
|
22
|
+
|
|
23
|
+
SurrealQL(Point(Number(Float),Number(Float)))
|