@surrealdb/lezer 1.0.3 → 1.0.4

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 +67 -65
  4. package/dist/index.js +67 -65
  5. package/package.json +1 -1
  6. package/src/parser.js +17 -17
  7. package/src/parser.terms.js +231 -229
  8. package/src/surrealql.grammar +41 -37
  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,75 @@
1
+ # Integer
2
+
3
+ 0;
4
+ 42;
5
+ 123456
6
+
7
+ ==>
8
+
9
+ SurrealQL(Int,Int,Int)
10
+
11
+ # Float
12
+
13
+ 0.0;
14
+ 2.5;
15
+ 3.14
16
+
17
+ ==>
18
+
19
+ SurrealQL(Float,Float,Float)
20
+
21
+ # Float with exponent
22
+
23
+ 2e4;
24
+ 2.2e4;
25
+ 1e+10;
26
+ 5E-3
27
+
28
+ ==>
29
+
30
+ SurrealQL(Float,Float,Float,Float)
31
+
32
+ # Float with f suffix
33
+
34
+ 2e4f;
35
+ 3.14f
36
+
37
+ ==>
38
+
39
+ SurrealQL(Float,Float)
40
+
41
+ # Float special values
42
+
43
+ Infinity;
44
+ NaN
45
+
46
+ ==>
47
+
48
+ SurrealQL(Float,Float)
49
+
50
+ # Decimal
51
+
52
+ 4dec;
53
+ 100dec
54
+
55
+ ==>
56
+
57
+ SurrealQL(Decimal,Decimal)
58
+
59
+ # Negative numbers
60
+
61
+ -1;
62
+ -3.14
63
+
64
+ ==>
65
+
66
+ SurrealQL(Int,Float)
67
+
68
+ # Positive explicit sign
69
+
70
+ +1;
71
+ +3.14
72
+
73
+ ==>
74
+
75
+ SurrealQL(Int,Float)
@@ -0,0 +1,64 @@
1
+ # Simple object
2
+
3
+ {a: 10}
4
+
5
+ ==>
6
+
7
+ SurrealQL(Object(BraceOpen,ObjectContent(ObjectProperty(ObjectKey(KeyName),Colon,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,Int),
17
+ ObjectProperty(ObjectKey(String),Colon,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,Int)),BraceClose),
53
+ 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,Int)),BraceClose)
64
+ )),BraceClose))
@@ -0,0 +1,31 @@
1
+ # Exclusive range
2
+
3
+ 1>..2
4
+
5
+ ==>
6
+
7
+ SurrealQL(Range(Int,RangeOp,Int))
8
+
9
+ # Right-open range
10
+
11
+ -3..
12
+
13
+ ==>
14
+
15
+ SurrealQL(Range(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(Int,RangeOp,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,Int)),BraceClose)))
56
+
57
+ # Record ID with array value
58
+
59
+ test:[1, 2]
60
+
61
+ ==>
62
+
63
+ SurrealQL(RecordId(RecordTbIdent,Colon,Array("[",Int,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,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,Int,Int,BraceClose))
24
+
25
+ # Set with three elements
26
+
27
+ {1, 2, 3}
28
+
29
+ ==>
30
+
31
+ SurrealQL(Set(BraceOpen,Int,Int,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)
@@ -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
- )