@konomanoasa/tree-sitter-query 0.3.0 → 0.3.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/Cargo.toml +1 -1
- package/README.md +4 -0
- package/grammar.js +17 -30
- package/package.json +2 -2
- package/src/grammar.json +75 -86
- package/src/parser.c +78 -85
- package/test/bindings.test.rs +129 -278
- package/tree-sitter.json +1 -1
package/Cargo.toml
CHANGED
package/README.md
CHANGED
|
@@ -29,6 +29,10 @@ npm test
|
|
|
29
29
|
- [Tree-sitter query operators](https://tree-sitter.github.io/tree-sitter/using-parsers/queries/2-operators.html)
|
|
30
30
|
- [Tree-sitter query predicates and directives](https://tree-sitter.github.io/tree-sitter/using-parsers/queries/3-predicates-and-directives.html)
|
|
31
31
|
|
|
32
|
+
## Used By
|
|
33
|
+
|
|
34
|
+
[query-ts-mode](https://github.com/konomanoasa/query-ts-mode): Emacs major mode.
|
|
35
|
+
|
|
32
36
|
## License
|
|
33
37
|
|
|
34
38
|
[MIT](LICENSE)
|
package/grammar.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const namePattern = /[A-Za-z0-9_-][A-Za-z0-9_.-]*/;
|
|
2
|
-
const
|
|
2
|
+
const fieldNamePattern = /[A-Za-z0-9-][A-Za-z0-9_.-]*/;
|
|
3
3
|
|
|
4
4
|
const postfixed = ($, body) =>
|
|
5
5
|
seq(
|
|
@@ -37,6 +37,9 @@ const subtyped = ($, supertype) =>
|
|
|
37
37
|
),
|
|
38
38
|
);
|
|
39
39
|
|
|
40
|
+
const callOnlyGroupMembers = ($) =>
|
|
41
|
+
seq($._call_only_group_start, repeat(anchored($, $._call_only_member)));
|
|
42
|
+
|
|
40
43
|
const call = ($, marker) =>
|
|
41
44
|
seq(
|
|
42
45
|
"(",
|
|
@@ -53,7 +56,7 @@ export default grammar({
|
|
|
53
56
|
rules: {
|
|
54
57
|
query: ($) => optional($._members),
|
|
55
58
|
_members: ($) => seq($._member, optional($._members)),
|
|
56
|
-
_member: ($) => choice($.
|
|
59
|
+
_member: ($) => choice($._matching_child_pattern, $._call_only_member),
|
|
57
60
|
_call: ($) => choice($.predicate, $.directive),
|
|
58
61
|
_call_only_member: ($) => choice($._call_only_child_pattern, $._call),
|
|
59
62
|
|
|
@@ -67,8 +70,6 @@ export default grammar({
|
|
|
67
70
|
),
|
|
68
71
|
),
|
|
69
72
|
_delimited: ($) => choice($.node_pattern, $.group, $.alternation),
|
|
70
|
-
_child_pattern: ($) =>
|
|
71
|
-
choice($._matching_child_pattern, $._call_only_child_pattern),
|
|
72
73
|
_matching_child_pattern: ($) => choice($.pattern, $.field_constraint),
|
|
73
74
|
_call_only_child_pattern: ($) =>
|
|
74
75
|
choice(
|
|
@@ -86,13 +87,13 @@ export default grammar({
|
|
|
86
87
|
"node",
|
|
87
88
|
choice($.identifier, $.wildcard, $.supertype, $.missing_node),
|
|
88
89
|
),
|
|
89
|
-
repeat($.
|
|
90
|
+
repeat($._non_matching_child),
|
|
90
91
|
optional(
|
|
91
92
|
seq(
|
|
92
93
|
anchored($, $._matching_child_pattern),
|
|
93
94
|
repeat(
|
|
94
95
|
choice(
|
|
95
|
-
$.
|
|
96
|
+
$._non_matching_child,
|
|
96
97
|
anchored($, $._matching_child_pattern),
|
|
97
98
|
),
|
|
98
99
|
),
|
|
@@ -103,7 +104,7 @@ export default grammar({
|
|
|
103
104
|
),
|
|
104
105
|
")",
|
|
105
106
|
),
|
|
106
|
-
|
|
107
|
+
_non_matching_child: ($) =>
|
|
107
108
|
choice(anchored($, $._call_only_member), $.negated_field),
|
|
108
109
|
|
|
109
110
|
field_constraint: ($) => fieldConstraint($, $._matching_child_pattern),
|
|
@@ -128,24 +129,14 @@ export default grammar({
|
|
|
128
129
|
seq(
|
|
129
130
|
"(",
|
|
130
131
|
choice(
|
|
131
|
-
alias($.
|
|
132
|
-
seq(
|
|
133
|
-
$._call_only_group_start,
|
|
134
|
-
repeat(anchored($, $._call_only_member)),
|
|
135
|
-
anchored($, $._matching_child_pattern),
|
|
136
|
-
),
|
|
132
|
+
alias($._group_start_pattern, $.pattern),
|
|
133
|
+
seq(callOnlyGroupMembers($), anchored($, $._matching_child_pattern)),
|
|
137
134
|
),
|
|
138
135
|
repeat(anchored($, $._member)),
|
|
139
136
|
")",
|
|
140
137
|
),
|
|
141
|
-
|
|
142
|
-
_call_only_group: ($) =>
|
|
143
|
-
seq(
|
|
144
|
-
"(",
|
|
145
|
-
$._call_only_group_start,
|
|
146
|
-
repeat(anchored($, $._call_only_member)),
|
|
147
|
-
")",
|
|
148
|
-
),
|
|
138
|
+
_group_start_pattern: ($) => postfixed($, choice($._delimited, $.string)),
|
|
139
|
+
_call_only_group: ($) => seq("(", callOnlyGroupMembers($), ")"),
|
|
149
140
|
_call_only_group_start: ($) =>
|
|
150
141
|
choice($._call, alias($._call_only_pattern, $.pattern)),
|
|
151
142
|
|
|
@@ -169,7 +160,7 @@ export default grammar({
|
|
|
169
160
|
directive: ($) => call($, "!"),
|
|
170
161
|
|
|
171
162
|
identifier: () => namePattern,
|
|
172
|
-
_field_identifier: () =>
|
|
163
|
+
_field_identifier: () => fieldNamePattern,
|
|
173
164
|
_immediate_identifier: () => token.immediate(namePattern),
|
|
174
165
|
_name: ($) =>
|
|
175
166
|
choice(
|
|
@@ -187,15 +178,11 @@ export default grammar({
|
|
|
187
178
|
),
|
|
188
179
|
_string_line_break: () => token.immediate(/\n/),
|
|
189
180
|
_unmatchable: () => token(seq("\\", /[^\s\S]/)),
|
|
190
|
-
string_content: () =>
|
|
191
|
-
token.immediate(
|
|
192
|
-
prec(
|
|
193
|
-
1,
|
|
194
|
-
repeat1(choice(stringContent, seq("\0", optional(stringContent)))),
|
|
195
|
-
),
|
|
196
|
-
),
|
|
197
181
|
// Keep NUL distinct from EOF in the generated lexer.
|
|
198
|
-
|
|
182
|
+
string_content: () =>
|
|
183
|
+
token.immediate(prec(1, repeat1(choice(/[^"\\\n]+/, "\0")))),
|
|
184
|
+
escape_sequence: () =>
|
|
185
|
+
token.immediate(seq("\\", choice(/.|\n/, prec(1, "\0")))),
|
|
199
186
|
|
|
200
187
|
comment: () => /;[^\r\n]*(\r+[^\r\n]+)*/,
|
|
201
188
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konomanoasa/tree-sitter-query",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Tree-sitter grammar for Tree-sitter Query.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test:fuzz": "node --test --test-name-pattern=\"fixed-seed generated histories\" test/incremental.test.js",
|
|
30
30
|
"test:fuzz:corpus": "npm run tree-sitter -- fuzz-all --iterations 100 --edits 5",
|
|
31
31
|
"test:highlights": "node --test test/highlight.test.js",
|
|
32
|
-
"test:incremental": "node --test test/incremental.test.js",
|
|
32
|
+
"test:incremental": "node --test --test-concurrency=1 test/cst.test.js test/parser.test.js test/incremental.test.js",
|
|
33
33
|
"tree-sitter": "node scripts/tree-sitter.js"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
package/src/grammar.json
CHANGED
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"members": [
|
|
41
41
|
{
|
|
42
42
|
"type": "SYMBOL",
|
|
43
|
-
"name": "
|
|
43
|
+
"name": "_matching_child_pattern"
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
"type": "SYMBOL",
|
|
47
|
-
"name": "
|
|
47
|
+
"name": "_call_only_member"
|
|
48
48
|
}
|
|
49
49
|
]
|
|
50
50
|
},
|
|
@@ -197,19 +197,6 @@
|
|
|
197
197
|
}
|
|
198
198
|
]
|
|
199
199
|
},
|
|
200
|
-
"_child_pattern": {
|
|
201
|
-
"type": "CHOICE",
|
|
202
|
-
"members": [
|
|
203
|
-
{
|
|
204
|
-
"type": "SYMBOL",
|
|
205
|
-
"name": "_matching_child_pattern"
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
"type": "SYMBOL",
|
|
209
|
-
"name": "_call_only_child_pattern"
|
|
210
|
-
}
|
|
211
|
-
]
|
|
212
|
-
},
|
|
213
200
|
"_matching_child_pattern": {
|
|
214
201
|
"type": "CHOICE",
|
|
215
202
|
"members": [
|
|
@@ -301,7 +288,7 @@
|
|
|
301
288
|
"type": "REPEAT",
|
|
302
289
|
"content": {
|
|
303
290
|
"type": "SYMBOL",
|
|
304
|
-
"name": "
|
|
291
|
+
"name": "_non_matching_child"
|
|
305
292
|
}
|
|
306
293
|
},
|
|
307
294
|
{
|
|
@@ -338,7 +325,7 @@
|
|
|
338
325
|
"members": [
|
|
339
326
|
{
|
|
340
327
|
"type": "SYMBOL",
|
|
341
|
-
"name": "
|
|
328
|
+
"name": "_non_matching_child"
|
|
342
329
|
},
|
|
343
330
|
{
|
|
344
331
|
"type": "SEQ",
|
|
@@ -393,7 +380,7 @@
|
|
|
393
380
|
}
|
|
394
381
|
]
|
|
395
382
|
},
|
|
396
|
-
"
|
|
383
|
+
"_non_matching_child": {
|
|
397
384
|
"type": "CHOICE",
|
|
398
385
|
"members": [
|
|
399
386
|
{
|
|
@@ -689,7 +676,7 @@
|
|
|
689
676
|
"type": "ALIAS",
|
|
690
677
|
"content": {
|
|
691
678
|
"type": "SYMBOL",
|
|
692
|
-
"name": "
|
|
679
|
+
"name": "_group_start_pattern"
|
|
693
680
|
},
|
|
694
681
|
"named": true,
|
|
695
682
|
"value": "pattern"
|
|
@@ -698,32 +685,37 @@
|
|
|
698
685
|
"type": "SEQ",
|
|
699
686
|
"members": [
|
|
700
687
|
{
|
|
701
|
-
"type": "
|
|
702
|
-
"
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
{
|
|
710
|
-
"type": "
|
|
688
|
+
"type": "SEQ",
|
|
689
|
+
"members": [
|
|
690
|
+
{
|
|
691
|
+
"type": "SYMBOL",
|
|
692
|
+
"name": "_call_only_group_start"
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
"type": "REPEAT",
|
|
696
|
+
"content": {
|
|
697
|
+
"type": "SEQ",
|
|
711
698
|
"members": [
|
|
712
699
|
{
|
|
713
|
-
"type": "
|
|
714
|
-
"
|
|
700
|
+
"type": "CHOICE",
|
|
701
|
+
"members": [
|
|
702
|
+
{
|
|
703
|
+
"type": "SYMBOL",
|
|
704
|
+
"name": "anchor"
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
"type": "BLANK"
|
|
708
|
+
}
|
|
709
|
+
]
|
|
715
710
|
},
|
|
716
711
|
{
|
|
717
|
-
"type": "
|
|
712
|
+
"type": "SYMBOL",
|
|
713
|
+
"name": "_call_only_member"
|
|
718
714
|
}
|
|
719
715
|
]
|
|
720
|
-
},
|
|
721
|
-
{
|
|
722
|
-
"type": "SYMBOL",
|
|
723
|
-
"name": "_call_only_member"
|
|
724
716
|
}
|
|
725
|
-
|
|
726
|
-
|
|
717
|
+
}
|
|
718
|
+
]
|
|
727
719
|
},
|
|
728
720
|
{
|
|
729
721
|
"type": "SEQ",
|
|
@@ -780,7 +772,7 @@
|
|
|
780
772
|
}
|
|
781
773
|
]
|
|
782
774
|
},
|
|
783
|
-
"
|
|
775
|
+
"_group_start_pattern": {
|
|
784
776
|
"type": "SEQ",
|
|
785
777
|
"members": [
|
|
786
778
|
{
|
|
@@ -834,32 +826,37 @@
|
|
|
834
826
|
"value": "("
|
|
835
827
|
},
|
|
836
828
|
{
|
|
837
|
-
"type": "
|
|
838
|
-
"
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
{
|
|
846
|
-
"type": "
|
|
829
|
+
"type": "SEQ",
|
|
830
|
+
"members": [
|
|
831
|
+
{
|
|
832
|
+
"type": "SYMBOL",
|
|
833
|
+
"name": "_call_only_group_start"
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
"type": "REPEAT",
|
|
837
|
+
"content": {
|
|
838
|
+
"type": "SEQ",
|
|
847
839
|
"members": [
|
|
848
840
|
{
|
|
849
|
-
"type": "
|
|
850
|
-
"
|
|
841
|
+
"type": "CHOICE",
|
|
842
|
+
"members": [
|
|
843
|
+
{
|
|
844
|
+
"type": "SYMBOL",
|
|
845
|
+
"name": "anchor"
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
"type": "BLANK"
|
|
849
|
+
}
|
|
850
|
+
]
|
|
851
851
|
},
|
|
852
852
|
{
|
|
853
|
-
"type": "
|
|
853
|
+
"type": "SYMBOL",
|
|
854
|
+
"name": "_call_only_member"
|
|
854
855
|
}
|
|
855
856
|
]
|
|
856
|
-
},
|
|
857
|
-
{
|
|
858
|
-
"type": "SYMBOL",
|
|
859
|
-
"name": "_call_only_member"
|
|
860
857
|
}
|
|
861
|
-
|
|
862
|
-
|
|
858
|
+
}
|
|
859
|
+
]
|
|
863
860
|
},
|
|
864
861
|
{
|
|
865
862
|
"type": "STRING",
|
|
@@ -1263,25 +1260,8 @@
|
|
|
1263
1260
|
"value": "[^\"\\\\\\n]+"
|
|
1264
1261
|
},
|
|
1265
1262
|
{
|
|
1266
|
-
"type": "
|
|
1267
|
-
"
|
|
1268
|
-
{
|
|
1269
|
-
"type": "STRING",
|
|
1270
|
-
"value": "\u0000"
|
|
1271
|
-
},
|
|
1272
|
-
{
|
|
1273
|
-
"type": "CHOICE",
|
|
1274
|
-
"members": [
|
|
1275
|
-
{
|
|
1276
|
-
"type": "PATTERN",
|
|
1277
|
-
"value": "[^\"\\\\\\n]+"
|
|
1278
|
-
},
|
|
1279
|
-
{
|
|
1280
|
-
"type": "BLANK"
|
|
1281
|
-
}
|
|
1282
|
-
]
|
|
1283
|
-
}
|
|
1284
|
-
]
|
|
1263
|
+
"type": "STRING",
|
|
1264
|
+
"value": "\u0000"
|
|
1285
1265
|
}
|
|
1286
1266
|
]
|
|
1287
1267
|
}
|
|
@@ -1291,19 +1271,28 @@
|
|
|
1291
1271
|
"escape_sequence": {
|
|
1292
1272
|
"type": "IMMEDIATE_TOKEN",
|
|
1293
1273
|
"content": {
|
|
1294
|
-
"type": "
|
|
1274
|
+
"type": "SEQ",
|
|
1295
1275
|
"members": [
|
|
1296
1276
|
{
|
|
1297
|
-
"type": "
|
|
1298
|
-
"value": "
|
|
1277
|
+
"type": "STRING",
|
|
1278
|
+
"value": "\\"
|
|
1299
1279
|
},
|
|
1300
1280
|
{
|
|
1301
|
-
"type": "
|
|
1302
|
-
"
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1281
|
+
"type": "CHOICE",
|
|
1282
|
+
"members": [
|
|
1283
|
+
{
|
|
1284
|
+
"type": "PATTERN",
|
|
1285
|
+
"value": ".|\\n"
|
|
1286
|
+
},
|
|
1287
|
+
{
|
|
1288
|
+
"type": "PREC",
|
|
1289
|
+
"value": 1,
|
|
1290
|
+
"content": {
|
|
1291
|
+
"type": "STRING",
|
|
1292
|
+
"value": "\u0000"
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
]
|
|
1307
1296
|
}
|
|
1308
1297
|
]
|
|
1309
1298
|
}
|
package/src/parser.c
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#define LANGUAGE_VERSION 15
|
|
10
10
|
#define STATE_COUNT 146
|
|
11
11
|
#define LARGE_STATE_COUNT 2
|
|
12
|
-
#define SYMBOL_COUNT
|
|
12
|
+
#define SYMBOL_COUNT 67
|
|
13
13
|
#define ALIAS_COUNT 0
|
|
14
14
|
#define TOKEN_COUNT 26
|
|
15
15
|
#define EXTERNAL_TOKEN_COUNT 0
|
|
@@ -53,40 +53,39 @@ enum ts_symbol_identifiers {
|
|
|
53
53
|
sym_pattern = 31,
|
|
54
54
|
sym__call_only_pattern = 32,
|
|
55
55
|
sym__delimited = 33,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
aux_sym__string_tail_repeat1 = 67,
|
|
56
|
+
sym__matching_child_pattern = 34,
|
|
57
|
+
sym__call_only_child_pattern = 35,
|
|
58
|
+
sym_node_pattern = 36,
|
|
59
|
+
sym__non_matching_child = 37,
|
|
60
|
+
sym_field_constraint = 38,
|
|
61
|
+
sym__call_only_field_constraint = 39,
|
|
62
|
+
sym_negated_field = 40,
|
|
63
|
+
sym_supertype = 41,
|
|
64
|
+
sym__untyped_missing_node = 42,
|
|
65
|
+
sym_missing_node = 43,
|
|
66
|
+
sym__missing_supertype = 44,
|
|
67
|
+
sym_group = 45,
|
|
68
|
+
sym__group_start_pattern = 46,
|
|
69
|
+
sym__call_only_group = 47,
|
|
70
|
+
sym__call_only_group_start = 48,
|
|
71
|
+
sym_alternation = 49,
|
|
72
|
+
sym__call_only_alternation = 50,
|
|
73
|
+
sym_capture = 51,
|
|
74
|
+
sym_predicate = 52,
|
|
75
|
+
sym_directive = 53,
|
|
76
|
+
sym__name = 54,
|
|
77
|
+
sym_string = 55,
|
|
78
|
+
sym__immediate_string = 56,
|
|
79
|
+
sym__string_tail = 57,
|
|
80
|
+
aux_sym_pattern_repeat1 = 58,
|
|
81
|
+
aux_sym_node_pattern_repeat1 = 59,
|
|
82
|
+
aux_sym_node_pattern_repeat2 = 60,
|
|
83
|
+
aux_sym_group_repeat1 = 61,
|
|
84
|
+
aux_sym_group_repeat2 = 62,
|
|
85
|
+
aux_sym_alternation_repeat1 = 63,
|
|
86
|
+
aux_sym_alternation_repeat2 = 64,
|
|
87
|
+
aux_sym_predicate_repeat1 = 65,
|
|
88
|
+
aux_sym__string_tail_repeat1 = 66,
|
|
90
89
|
};
|
|
91
90
|
|
|
92
91
|
static const char * const ts_symbol_names[] = {
|
|
@@ -124,11 +123,10 @@ static const char * const ts_symbol_names[] = {
|
|
|
124
123
|
[sym_pattern] = "pattern",
|
|
125
124
|
[sym__call_only_pattern] = "pattern",
|
|
126
125
|
[sym__delimited] = "_delimited",
|
|
127
|
-
[sym__child_pattern] = "_child_pattern",
|
|
128
126
|
[sym__matching_child_pattern] = "_matching_child_pattern",
|
|
129
127
|
[sym__call_only_child_pattern] = "_call_only_child_pattern",
|
|
130
128
|
[sym_node_pattern] = "node_pattern",
|
|
131
|
-
[
|
|
129
|
+
[sym__non_matching_child] = "_non_matching_child",
|
|
132
130
|
[sym_field_constraint] = "field_constraint",
|
|
133
131
|
[sym__call_only_field_constraint] = "field_constraint",
|
|
134
132
|
[sym_negated_field] = "negated_field",
|
|
@@ -137,7 +135,7 @@ static const char * const ts_symbol_names[] = {
|
|
|
137
135
|
[sym_missing_node] = "missing_node",
|
|
138
136
|
[sym__missing_supertype] = "supertype",
|
|
139
137
|
[sym_group] = "group",
|
|
140
|
-
[
|
|
138
|
+
[sym__group_start_pattern] = "pattern",
|
|
141
139
|
[sym__call_only_group] = "group",
|
|
142
140
|
[sym__call_only_group_start] = "_call_only_group_start",
|
|
143
141
|
[sym_alternation] = "alternation",
|
|
@@ -195,11 +193,10 @@ static const TSSymbol ts_symbol_map[] = {
|
|
|
195
193
|
[sym_pattern] = sym_pattern,
|
|
196
194
|
[sym__call_only_pattern] = sym_pattern,
|
|
197
195
|
[sym__delimited] = sym__delimited,
|
|
198
|
-
[sym__child_pattern] = sym__child_pattern,
|
|
199
196
|
[sym__matching_child_pattern] = sym__matching_child_pattern,
|
|
200
197
|
[sym__call_only_child_pattern] = sym__call_only_child_pattern,
|
|
201
198
|
[sym_node_pattern] = sym_node_pattern,
|
|
202
|
-
[
|
|
199
|
+
[sym__non_matching_child] = sym__non_matching_child,
|
|
203
200
|
[sym_field_constraint] = sym_field_constraint,
|
|
204
201
|
[sym__call_only_field_constraint] = sym_field_constraint,
|
|
205
202
|
[sym_negated_field] = sym_negated_field,
|
|
@@ -208,7 +205,7 @@ static const TSSymbol ts_symbol_map[] = {
|
|
|
208
205
|
[sym_missing_node] = sym_missing_node,
|
|
209
206
|
[sym__missing_supertype] = sym_supertype,
|
|
210
207
|
[sym_group] = sym_group,
|
|
211
|
-
[
|
|
208
|
+
[sym__group_start_pattern] = sym_pattern,
|
|
212
209
|
[sym__call_only_group] = sym_group,
|
|
213
210
|
[sym__call_only_group_start] = sym__call_only_group_start,
|
|
214
211
|
[sym_alternation] = sym_alternation,
|
|
@@ -368,10 +365,6 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
|
|
|
368
365
|
.visible = false,
|
|
369
366
|
.named = true,
|
|
370
367
|
},
|
|
371
|
-
[sym__child_pattern] = {
|
|
372
|
-
.visible = false,
|
|
373
|
-
.named = true,
|
|
374
|
-
},
|
|
375
368
|
[sym__matching_child_pattern] = {
|
|
376
369
|
.visible = false,
|
|
377
370
|
.named = true,
|
|
@@ -384,7 +377,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
|
|
|
384
377
|
.visible = true,
|
|
385
378
|
.named = true,
|
|
386
379
|
},
|
|
387
|
-
[
|
|
380
|
+
[sym__non_matching_child] = {
|
|
388
381
|
.visible = false,
|
|
389
382
|
.named = true,
|
|
390
383
|
},
|
|
@@ -420,7 +413,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
|
|
|
420
413
|
.visible = true,
|
|
421
414
|
.named = true,
|
|
422
415
|
},
|
|
423
|
-
[
|
|
416
|
+
[sym__group_start_pattern] = {
|
|
424
417
|
.visible = true,
|
|
425
418
|
.named = true,
|
|
426
419
|
},
|
|
@@ -1414,10 +1407,10 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
|
|
|
1414
1407
|
[sym__members] = STATE(140),
|
|
1415
1408
|
[sym__member] = STATE(26),
|
|
1416
1409
|
[sym__call] = STATE(26),
|
|
1410
|
+
[sym__call_only_member] = STATE(26),
|
|
1417
1411
|
[sym_pattern] = STATE(26),
|
|
1418
1412
|
[sym__call_only_pattern] = STATE(89),
|
|
1419
1413
|
[sym__delimited] = STATE(55),
|
|
1420
|
-
[sym__child_pattern] = STATE(26),
|
|
1421
1414
|
[sym__matching_child_pattern] = STATE(26),
|
|
1422
1415
|
[sym__call_only_child_pattern] = STATE(26),
|
|
1423
1416
|
[sym_node_pattern] = STATE(55),
|
|
@@ -1485,7 +1478,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1485
1478
|
sym__call,
|
|
1486
1479
|
sym__call_only_member,
|
|
1487
1480
|
sym__call_only_child_pattern,
|
|
1488
|
-
|
|
1481
|
+
sym__non_matching_child,
|
|
1489
1482
|
sym_negated_field,
|
|
1490
1483
|
sym_predicate,
|
|
1491
1484
|
sym_directive,
|
|
@@ -1533,7 +1526,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1533
1526
|
sym__call,
|
|
1534
1527
|
sym__call_only_member,
|
|
1535
1528
|
sym__call_only_child_pattern,
|
|
1536
|
-
|
|
1529
|
+
sym__non_matching_child,
|
|
1537
1530
|
sym_negated_field,
|
|
1538
1531
|
sym_predicate,
|
|
1539
1532
|
sym_directive,
|
|
@@ -1579,7 +1572,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1579
1572
|
sym__call,
|
|
1580
1573
|
sym__call_only_member,
|
|
1581
1574
|
sym__call_only_child_pattern,
|
|
1582
|
-
|
|
1575
|
+
sym__non_matching_child,
|
|
1583
1576
|
sym_negated_field,
|
|
1584
1577
|
sym_predicate,
|
|
1585
1578
|
sym_directive,
|
|
@@ -1625,7 +1618,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1625
1618
|
sym__call,
|
|
1626
1619
|
sym__call_only_member,
|
|
1627
1620
|
sym__call_only_child_pattern,
|
|
1628
|
-
|
|
1621
|
+
sym__non_matching_child,
|
|
1629
1622
|
sym_negated_field,
|
|
1630
1623
|
sym_predicate,
|
|
1631
1624
|
sym_directive,
|
|
@@ -1669,7 +1662,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1669
1662
|
sym_pattern,
|
|
1670
1663
|
sym__matching_child_pattern,
|
|
1671
1664
|
sym__call_only_child_pattern,
|
|
1672
|
-
|
|
1665
|
+
sym__non_matching_child,
|
|
1673
1666
|
sym_field_constraint,
|
|
1674
1667
|
sym_negated_field,
|
|
1675
1668
|
sym_predicate,
|
|
@@ -1714,7 +1707,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1714
1707
|
sym_pattern,
|
|
1715
1708
|
sym__matching_child_pattern,
|
|
1716
1709
|
sym__call_only_child_pattern,
|
|
1717
|
-
|
|
1710
|
+
sym__non_matching_child,
|
|
1718
1711
|
sym_field_constraint,
|
|
1719
1712
|
sym_negated_field,
|
|
1720
1713
|
sym_predicate,
|
|
@@ -1759,7 +1752,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1759
1752
|
sym_pattern,
|
|
1760
1753
|
sym__matching_child_pattern,
|
|
1761
1754
|
sym__call_only_child_pattern,
|
|
1762
|
-
|
|
1755
|
+
sym__non_matching_child,
|
|
1763
1756
|
sym_field_constraint,
|
|
1764
1757
|
sym_negated_field,
|
|
1765
1758
|
sym_predicate,
|
|
@@ -1804,7 +1797,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1804
1797
|
sym_pattern,
|
|
1805
1798
|
sym__matching_child_pattern,
|
|
1806
1799
|
sym__call_only_child_pattern,
|
|
1807
|
-
|
|
1800
|
+
sym__non_matching_child,
|
|
1808
1801
|
sym_field_constraint,
|
|
1809
1802
|
sym_negated_field,
|
|
1810
1803
|
sym_predicate,
|
|
@@ -1849,7 +1842,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1849
1842
|
sym_pattern,
|
|
1850
1843
|
sym__matching_child_pattern,
|
|
1851
1844
|
sym__call_only_child_pattern,
|
|
1852
|
-
|
|
1845
|
+
sym__non_matching_child,
|
|
1853
1846
|
sym_field_constraint,
|
|
1854
1847
|
sym_negated_field,
|
|
1855
1848
|
sym_predicate,
|
|
@@ -1894,7 +1887,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1894
1887
|
sym_pattern,
|
|
1895
1888
|
sym__matching_child_pattern,
|
|
1896
1889
|
sym__call_only_child_pattern,
|
|
1897
|
-
|
|
1890
|
+
sym__non_matching_child,
|
|
1898
1891
|
sym_field_constraint,
|
|
1899
1892
|
sym_negated_field,
|
|
1900
1893
|
sym_predicate,
|
|
@@ -1939,7 +1932,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1939
1932
|
sym_pattern,
|
|
1940
1933
|
sym__matching_child_pattern,
|
|
1941
1934
|
sym__call_only_child_pattern,
|
|
1942
|
-
|
|
1935
|
+
sym__non_matching_child,
|
|
1943
1936
|
sym_field_constraint,
|
|
1944
1937
|
sym_negated_field,
|
|
1945
1938
|
sym_predicate,
|
|
@@ -1979,8 +1972,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
1979
1972
|
STATE(15), 10,
|
|
1980
1973
|
sym__member,
|
|
1981
1974
|
sym__call,
|
|
1975
|
+
sym__call_only_member,
|
|
1982
1976
|
sym_pattern,
|
|
1983
|
-
sym__child_pattern,
|
|
1984
1977
|
sym__matching_child_pattern,
|
|
1985
1978
|
sym__call_only_child_pattern,
|
|
1986
1979
|
sym_field_constraint,
|
|
@@ -2021,8 +2014,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2021
2014
|
STATE(21), 10,
|
|
2022
2015
|
sym__member,
|
|
2023
2016
|
sym__call,
|
|
2017
|
+
sym__call_only_member,
|
|
2024
2018
|
sym_pattern,
|
|
2025
|
-
sym__child_pattern,
|
|
2026
2019
|
sym__matching_child_pattern,
|
|
2027
2020
|
sym__call_only_child_pattern,
|
|
2028
2021
|
sym_field_constraint,
|
|
@@ -2063,8 +2056,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2063
2056
|
STATE(21), 10,
|
|
2064
2057
|
sym__member,
|
|
2065
2058
|
sym__call,
|
|
2059
|
+
sym__call_only_member,
|
|
2066
2060
|
sym_pattern,
|
|
2067
|
-
sym__child_pattern,
|
|
2068
2061
|
sym__matching_child_pattern,
|
|
2069
2062
|
sym__call_only_child_pattern,
|
|
2070
2063
|
sym_field_constraint,
|
|
@@ -2105,8 +2098,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2105
2098
|
STATE(18), 10,
|
|
2106
2099
|
sym__member,
|
|
2107
2100
|
sym__call,
|
|
2101
|
+
sym__call_only_member,
|
|
2108
2102
|
sym_pattern,
|
|
2109
|
-
sym__child_pattern,
|
|
2110
2103
|
sym__matching_child_pattern,
|
|
2111
2104
|
sym__call_only_child_pattern,
|
|
2112
2105
|
sym_field_constraint,
|
|
@@ -2147,8 +2140,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2147
2140
|
STATE(19), 10,
|
|
2148
2141
|
sym__member,
|
|
2149
2142
|
sym__call,
|
|
2143
|
+
sym__call_only_member,
|
|
2150
2144
|
sym_pattern,
|
|
2151
|
-
sym__child_pattern,
|
|
2152
2145
|
sym__matching_child_pattern,
|
|
2153
2146
|
sym__call_only_child_pattern,
|
|
2154
2147
|
sym_field_constraint,
|
|
@@ -2189,8 +2182,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2189
2182
|
STATE(21), 10,
|
|
2190
2183
|
sym__member,
|
|
2191
2184
|
sym__call,
|
|
2185
|
+
sym__call_only_member,
|
|
2192
2186
|
sym_pattern,
|
|
2193
|
-
sym__child_pattern,
|
|
2194
2187
|
sym__matching_child_pattern,
|
|
2195
2188
|
sym__call_only_child_pattern,
|
|
2196
2189
|
sym_field_constraint,
|
|
@@ -2231,8 +2224,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2231
2224
|
STATE(21), 10,
|
|
2232
2225
|
sym__member,
|
|
2233
2226
|
sym__call,
|
|
2227
|
+
sym__call_only_member,
|
|
2234
2228
|
sym_pattern,
|
|
2235
|
-
sym__child_pattern,
|
|
2236
2229
|
sym__matching_child_pattern,
|
|
2237
2230
|
sym__call_only_child_pattern,
|
|
2238
2231
|
sym_field_constraint,
|
|
@@ -2273,8 +2266,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2273
2266
|
STATE(14), 10,
|
|
2274
2267
|
sym__member,
|
|
2275
2268
|
sym__call,
|
|
2269
|
+
sym__call_only_member,
|
|
2276
2270
|
sym_pattern,
|
|
2277
|
-
sym__child_pattern,
|
|
2278
2271
|
sym__matching_child_pattern,
|
|
2279
2272
|
sym__call_only_child_pattern,
|
|
2280
2273
|
sym_field_constraint,
|
|
@@ -2315,8 +2308,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2315
2308
|
STATE(21), 10,
|
|
2316
2309
|
sym__member,
|
|
2317
2310
|
sym__call,
|
|
2311
|
+
sym__call_only_member,
|
|
2318
2312
|
sym_pattern,
|
|
2319
|
-
sym__child_pattern,
|
|
2320
2313
|
sym__matching_child_pattern,
|
|
2321
2314
|
sym__call_only_child_pattern,
|
|
2322
2315
|
sym_field_constraint,
|
|
@@ -2355,8 +2348,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2355
2348
|
STATE(24), 10,
|
|
2356
2349
|
sym__member,
|
|
2357
2350
|
sym__call,
|
|
2351
|
+
sym__call_only_member,
|
|
2358
2352
|
sym_pattern,
|
|
2359
|
-
sym__child_pattern,
|
|
2360
2353
|
sym__matching_child_pattern,
|
|
2361
2354
|
sym__call_only_child_pattern,
|
|
2362
2355
|
sym_field_constraint,
|
|
@@ -2395,8 +2388,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2395
2388
|
STATE(22), 10,
|
|
2396
2389
|
sym__member,
|
|
2397
2390
|
sym__call,
|
|
2391
|
+
sym__call_only_member,
|
|
2398
2392
|
sym_pattern,
|
|
2399
|
-
sym__child_pattern,
|
|
2400
2393
|
sym__matching_child_pattern,
|
|
2401
2394
|
sym__call_only_child_pattern,
|
|
2402
2395
|
sym_field_constraint,
|
|
@@ -2435,8 +2428,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2435
2428
|
STATE(24), 10,
|
|
2436
2429
|
sym__member,
|
|
2437
2430
|
sym__call,
|
|
2431
|
+
sym__call_only_member,
|
|
2438
2432
|
sym_pattern,
|
|
2439
|
-
sym__child_pattern,
|
|
2440
2433
|
sym__matching_child_pattern,
|
|
2441
2434
|
sym__call_only_child_pattern,
|
|
2442
2435
|
sym_field_constraint,
|
|
@@ -2475,8 +2468,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2475
2468
|
STATE(24), 10,
|
|
2476
2469
|
sym__member,
|
|
2477
2470
|
sym__call,
|
|
2471
|
+
sym__call_only_member,
|
|
2478
2472
|
sym_pattern,
|
|
2479
|
-
sym__child_pattern,
|
|
2480
2473
|
sym__matching_child_pattern,
|
|
2481
2474
|
sym__call_only_child_pattern,
|
|
2482
2475
|
sym_field_constraint,
|
|
@@ -2517,8 +2510,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2517
2510
|
STATE(26), 9,
|
|
2518
2511
|
sym__member,
|
|
2519
2512
|
sym__call,
|
|
2513
|
+
sym__call_only_member,
|
|
2520
2514
|
sym_pattern,
|
|
2521
|
-
sym__child_pattern,
|
|
2522
2515
|
sym__matching_child_pattern,
|
|
2523
2516
|
sym__call_only_child_pattern,
|
|
2524
2517
|
sym_field_constraint,
|
|
@@ -2598,8 +2591,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2598
2591
|
STATE(25), 10,
|
|
2599
2592
|
sym__member,
|
|
2600
2593
|
sym__call,
|
|
2594
|
+
sym__call_only_member,
|
|
2601
2595
|
sym_pattern,
|
|
2602
|
-
sym__child_pattern,
|
|
2603
2596
|
sym__matching_child_pattern,
|
|
2604
2597
|
sym__call_only_child_pattern,
|
|
2605
2598
|
sym_field_constraint,
|
|
@@ -2874,8 +2867,8 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
2874
2867
|
STATE(115), 9,
|
|
2875
2868
|
sym__member,
|
|
2876
2869
|
sym__call,
|
|
2870
|
+
sym__call_only_member,
|
|
2877
2871
|
sym_pattern,
|
|
2878
|
-
sym__child_pattern,
|
|
2879
2872
|
sym__matching_child_pattern,
|
|
2880
2873
|
sym__call_only_child_pattern,
|
|
2881
2874
|
sym_field_constraint,
|
|
@@ -3085,7 +3078,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
3085
3078
|
ACTIONS(145), 1,
|
|
3086
3079
|
sym_identifier,
|
|
3087
3080
|
STATE(13), 1,
|
|
3088
|
-
|
|
3081
|
+
sym__group_start_pattern,
|
|
3089
3082
|
STATE(112), 1,
|
|
3090
3083
|
sym__call_only_pattern,
|
|
3091
3084
|
STATE(142), 1,
|
|
@@ -3160,7 +3153,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
3160
3153
|
ACTIONS(145), 1,
|
|
3161
3154
|
sym_identifier,
|
|
3162
3155
|
STATE(13), 1,
|
|
3163
|
-
|
|
3156
|
+
sym__group_start_pattern,
|
|
3164
3157
|
STATE(112), 1,
|
|
3165
3158
|
sym__call_only_pattern,
|
|
3166
3159
|
STATE(142), 1,
|
|
@@ -3211,7 +3204,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|
|
3211
3204
|
sym__call,
|
|
3212
3205
|
sym__call_only_member,
|
|
3213
3206
|
sym__call_only_child_pattern,
|
|
3214
|
-
|
|
3207
|
+
sym__non_matching_child,
|
|
3215
3208
|
sym_negated_field,
|
|
3216
3209
|
sym_predicate,
|
|
3217
3210
|
sym_directive,
|
|
@@ -5099,10 +5092,10 @@ static const TSParseActionEntry ts_parse_actions[] = {
|
|
|
5099
5092
|
[319] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_node_pattern, 8, 0, 10),
|
|
5100
5093
|
[321] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_pattern_repeat1, 1, 0, 5),
|
|
5101
5094
|
[323] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_pattern_repeat1, 1, 0, 5),
|
|
5102
|
-
[325] = {.entry = {.count = 1, .reusable = true}}, REDUCE(
|
|
5103
|
-
[327] = {.entry = {.count = 1, .reusable = false}}, REDUCE(
|
|
5104
|
-
[329] = {.entry = {.count = 1, .reusable = true}}, REDUCE(
|
|
5105
|
-
[331] = {.entry = {.count = 1, .reusable = false}}, REDUCE(
|
|
5095
|
+
[325] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__group_start_pattern, 2, 0, 6),
|
|
5096
|
+
[327] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__group_start_pattern, 2, 0, 6),
|
|
5097
|
+
[329] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__group_start_pattern, 1, 0, 1),
|
|
5098
|
+
[331] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__group_start_pattern, 1, 0, 1),
|
|
5106
5099
|
[333] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_directive, 6, 0, 19),
|
|
5107
5100
|
[335] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_directive, 6, 0, 19),
|
|
5108
5101
|
[337] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_predicate, 6, 0, 19),
|
|
@@ -5146,8 +5139,8 @@ static const TSParseActionEntry ts_parse_actions[] = {
|
|
|
5146
5139
|
[417] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_negated_field, 2, 0, 13),
|
|
5147
5140
|
[419] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_supertype, 3, 0, 15),
|
|
5148
5141
|
[421] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_supertype, 3, 0, 15),
|
|
5149
|
-
[423] = {.entry = {.count = 1, .reusable = true}}, REDUCE(
|
|
5150
|
-
[425] = {.entry = {.count = 1, .reusable = false}}, REDUCE(
|
|
5142
|
+
[423] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__non_matching_child, 2, 0, 0),
|
|
5143
|
+
[425] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__non_matching_child, 2, 0, 0),
|
|
5151
5144
|
[427] = {.entry = {.count = 1, .reusable = true}}, SHIFT(110),
|
|
5152
5145
|
[429] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_supertype, 3, 0, 16),
|
|
5153
5146
|
[431] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_supertype, 3, 0, 16),
|
|
@@ -5240,7 +5233,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_query(void) {
|
|
|
5240
5233
|
.metadata = {
|
|
5241
5234
|
.major_version = 0,
|
|
5242
5235
|
.minor_version = 3,
|
|
5243
|
-
.patch_version =
|
|
5236
|
+
.patch_version = 1,
|
|
5244
5237
|
},
|
|
5245
5238
|
};
|
|
5246
5239
|
return &language;
|
package/test/bindings.test.rs
CHANGED
|
@@ -25,22 +25,12 @@ fn parses_valid_source() {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
#[test]
|
|
28
|
-
fn
|
|
29
|
-
let mut parser = parser();
|
|
30
|
-
let source = "; query\n";
|
|
31
|
-
let tree = parser.parse(source, None).unwrap();
|
|
32
|
-
let root = tree.root_node();
|
|
33
|
-
assert!(!root.has_error());
|
|
34
|
-
assert_eq!(root.kind(), "query");
|
|
35
|
-
assert_eq!(root.to_sexp(), "(query (comment))");
|
|
36
|
-
assert_eq!(root.named_child(0).unwrap().byte_range(), 0..7);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
#[test]
|
|
40
|
-
fn missing_node_forms_follow_public_query_api_syntax() {
|
|
28
|
+
fn node_designators_follow_public_query_api_syntax() {
|
|
41
29
|
let language = grammar::LANGUAGE.into();
|
|
42
30
|
let mut parser = parser();
|
|
43
31
|
for (source, valid) in [
|
|
32
|
+
("(_ @x)", false),
|
|
33
|
+
("(_+ _)", false),
|
|
44
34
|
("(MISSING)", true),
|
|
45
35
|
("(MISSING ; comment\n)", true),
|
|
46
36
|
("(MISSING identifier)", true),
|
|
@@ -68,6 +58,72 @@ fn missing_node_forms_follow_public_query_api_syntax() {
|
|
|
68
58
|
}
|
|
69
59
|
}
|
|
70
60
|
|
|
61
|
+
#[test]
|
|
62
|
+
fn call_placement_and_arguments_follow_public_query_api_syntax() {
|
|
63
|
+
let language = grammar::LANGUAGE.into();
|
|
64
|
+
let mut parser = parser();
|
|
65
|
+
for (source, valid) in [
|
|
66
|
+
("(#custom?)", true),
|
|
67
|
+
("[(#custom?)]", true),
|
|
68
|
+
("((#custom?))", true),
|
|
69
|
+
("(node_pattern (#custom?))", true),
|
|
70
|
+
("(#custom? 42 -1 0.5 _ MISSING)", true),
|
|
71
|
+
("(#_call? _arg)", true),
|
|
72
|
+
("(_) @_cap (#_call? _arg @_cap)", true),
|
|
73
|
+
("(#custom)", false),
|
|
74
|
+
("(#custom?) @capture", false),
|
|
75
|
+
("(#custom!)?", false),
|
|
76
|
+
("(# custom?)", false),
|
|
77
|
+
("(#custom ?)", false),
|
|
78
|
+
("(identifier) @ name", false),
|
|
79
|
+
] {
|
|
80
|
+
match Query::new(&language, source) {
|
|
81
|
+
Ok(_) => assert!(valid, "{source:?}"),
|
|
82
|
+
Err(error) => {
|
|
83
|
+
assert!(!valid, "{source:?}: {error:?}");
|
|
84
|
+
assert_eq!(error.kind, QueryErrorKind::Syntax, "{source:?}");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
assert_eq!(
|
|
88
|
+
parser.parse(source, None).unwrap().root_node().has_error(),
|
|
89
|
+
!valid,
|
|
90
|
+
"{source:?}"
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[test]
|
|
96
|
+
fn documented_call_prefix_overrides_the_public_query_api_extension() {
|
|
97
|
+
let language = grammar::LANGUAGE.into();
|
|
98
|
+
let mut parser = parser();
|
|
99
|
+
for (source, valid) in [
|
|
100
|
+
("(#custom?)", true),
|
|
101
|
+
("(#custom! key value)", true),
|
|
102
|
+
("(.custom?)", false),
|
|
103
|
+
("(.custom! key value)", false),
|
|
104
|
+
] {
|
|
105
|
+
assert!(Query::new(&language, source).is_ok(), "{source:?}");
|
|
106
|
+
assert_eq!(
|
|
107
|
+
parser.parse(source, None).unwrap().root_node().has_error(),
|
|
108
|
+
!valid,
|
|
109
|
+
"{source:?}"
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#[test]
|
|
115
|
+
fn postfix_order_and_repetition_follow_public_query_api_syntax() {
|
|
116
|
+
let language = grammar::LANGUAGE.into();
|
|
117
|
+
let mut parser = parser();
|
|
118
|
+
for source in ["(identifier) @x? @y+", "(identifier) +*?"] {
|
|
119
|
+
let query = Query::new(&language, source).unwrap();
|
|
120
|
+
assert_eq!(query.pattern_count(), 1, "{source:?}");
|
|
121
|
+
let tree = parser.parse(source, None).unwrap();
|
|
122
|
+
assert!(!tree.root_node().has_error(), "{source:?}");
|
|
123
|
+
assert_eq!(tree.root_node().named_child_count(), 1, "{source:?}");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
71
127
|
#[test]
|
|
72
128
|
fn field_constraints_and_call_anchors_follow_public_query_api_syntax() {
|
|
73
129
|
let language = grammar::LANGUAGE.into();
|
|
@@ -159,173 +215,76 @@ fn adjacent_bare_wildcards_follow_public_query_api_pattern_and_capture_counts()
|
|
|
159
215
|
}
|
|
160
216
|
|
|
161
217
|
#[test]
|
|
162
|
-
fn
|
|
163
|
-
{
|
|
218
|
+
fn underscored_names_reach_semantic_validation_without_wildcard_splitting() {
|
|
164
219
|
let language = grammar::LANGUAGE.into();
|
|
165
|
-
let query = Query::new(&language, "[(wildcard) (identifier)] @leaf").unwrap();
|
|
166
220
|
let mut parser = parser();
|
|
167
|
-
for (source,
|
|
168
|
-
(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
),
|
|
172
|
-
(
|
|
173
|
-
"_field: (x)",
|
|
174
|
-
vec![
|
|
175
|
-
("wildcard", 0..1),
|
|
176
|
-
("identifier", 1..6),
|
|
177
|
-
("identifier", 9..10),
|
|
178
|
-
],
|
|
179
|
-
),
|
|
180
|
-
(
|
|
181
|
-
"(_x !_field) @_cap",
|
|
182
|
-
vec![
|
|
183
|
-
("identifier", 1..3),
|
|
184
|
-
("identifier", 5..11),
|
|
185
|
-
("identifier", 14..18),
|
|
186
|
-
],
|
|
187
|
-
),
|
|
188
|
-
(
|
|
189
|
-
"(#_call? _arg @_cap)",
|
|
190
|
-
vec![
|
|
191
|
-
("identifier", 2..7),
|
|
192
|
-
("identifier", 9..13),
|
|
193
|
-
("identifier", 15..19),
|
|
194
|
-
],
|
|
195
|
-
),
|
|
196
|
-
(
|
|
197
|
-
"(MISSING _type) (_super/_sub)",
|
|
198
|
-
vec![
|
|
199
|
-
("identifier", 9..14),
|
|
200
|
-
("identifier", 17..23),
|
|
201
|
-
("identifier", 24..28),
|
|
202
|
-
],
|
|
203
|
-
),
|
|
221
|
+
for (source, error) in [
|
|
222
|
+
("(_x)", QueryErrorKind::NodeType),
|
|
223
|
+
("(_ !_x)", QueryErrorKind::Field),
|
|
224
|
+
("(node_pattern !_)", QueryErrorKind::Field),
|
|
204
225
|
] {
|
|
226
|
+
assert_eq!(
|
|
227
|
+
Query::new(&language, source).unwrap_err().kind,
|
|
228
|
+
error,
|
|
229
|
+
"{source:?}"
|
|
230
|
+
);
|
|
205
231
|
let tree = parser.parse(source, None).unwrap();
|
|
206
232
|
assert!(!tree.root_node().has_error(), "{source:?}");
|
|
207
|
-
|
|
208
|
-
let mut matches =
|
|
209
|
-
cursor.matches(&query, tree.root_node(), source.as_bytes());
|
|
210
|
-
let mut actual = Vec::new();
|
|
211
|
-
while let Some(item) = matches.next() {
|
|
212
|
-
let node = item.captures()[0].node;
|
|
213
|
-
assert_eq!(node.child_count(), 0);
|
|
214
|
-
actual.push((node.kind(), node.byte_range()));
|
|
215
|
-
}
|
|
216
|
-
assert_eq!(actual, expected, "{source:?}");
|
|
233
|
+
assert_eq!(tree.root_node().byte_range(), 0..source.len());
|
|
217
234
|
}
|
|
218
235
|
}
|
|
219
236
|
|
|
220
237
|
#[test]
|
|
221
|
-
fn
|
|
222
|
-
let
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
let child = target.child_by_field_name(field).unwrap();
|
|
251
|
-
assert_eq!(child.kind(), kind);
|
|
252
|
-
assert_eq!(child.byte_range(), range);
|
|
238
|
+
fn field_lookup_matches_cursor_ownership() {
|
|
239
|
+
let mut parser = parser();
|
|
240
|
+
for source in ["left: right: (_)+ @x", "(node . child: (_)+ @x !absent)"] {
|
|
241
|
+
let tree = parser.parse(source, None).unwrap();
|
|
242
|
+
let mut pending = vec![tree.root_node()];
|
|
243
|
+
let mut fields = 0;
|
|
244
|
+
while let Some(owner) = pending.pop() {
|
|
245
|
+
let mut cursor = owner.walk();
|
|
246
|
+
if !cursor.goto_first_child() {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
loop {
|
|
250
|
+
let child = cursor.node();
|
|
251
|
+
if let Some(field) = cursor.field_name() {
|
|
252
|
+
assert_eq!(
|
|
253
|
+
owner.child_by_field_name(field),
|
|
254
|
+
Some(child),
|
|
255
|
+
"{source:?}: {field}"
|
|
256
|
+
);
|
|
257
|
+
assert_eq!(child.parent(), Some(owner));
|
|
258
|
+
fields += 1;
|
|
259
|
+
}
|
|
260
|
+
pending.push(child);
|
|
261
|
+
if !cursor.goto_next_sibling() {
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
assert!(fields > 0, "{source:?}: no fields");
|
|
253
267
|
}
|
|
254
268
|
}
|
|
255
269
|
|
|
256
270
|
#[test]
|
|
257
|
-
fn
|
|
271
|
+
fn string_arguments_follow_public_query_api_syntax() {
|
|
258
272
|
let language = grammar::LANGUAGE.into();
|
|
259
273
|
let mut parser = parser();
|
|
260
|
-
for
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
),
|
|
271
|
-
(
|
|
272
|
-
"\";x\0\"",
|
|
273
|
-
vec![("\"", 0..1), ("string_content", 1..4), ("\"", 4..5)],
|
|
274
|
-
),
|
|
275
|
-
(
|
|
276
|
-
"\"\\\n;x\0\"",
|
|
277
|
-
vec![
|
|
278
|
-
("\"", 0..1),
|
|
279
|
-
("escape_sequence", 1..3),
|
|
280
|
-
("string_content", 3..6),
|
|
281
|
-
("\"", 6..7),
|
|
282
|
-
],
|
|
283
|
-
),
|
|
284
|
-
(
|
|
285
|
-
"\"a\0b\0\0c\"",
|
|
286
|
-
vec![("\"", 0..1), ("string_content", 1..7), ("\"", 7..8)],
|
|
287
|
-
),
|
|
288
|
-
(
|
|
289
|
-
"\"\0\"",
|
|
290
|
-
vec![("\"", 0..1), ("string_content", 1..2), ("\"", 2..3)],
|
|
291
|
-
),
|
|
292
|
-
(
|
|
293
|
-
"\"a\\\0b\"",
|
|
294
|
-
vec![
|
|
295
|
-
("\"", 0..1),
|
|
296
|
-
("string_content", 1..2),
|
|
297
|
-
("escape_sequence", 2..4),
|
|
298
|
-
("string_content", 4..5),
|
|
299
|
-
("\"", 5..6),
|
|
300
|
-
],
|
|
301
|
-
),
|
|
302
|
-
(
|
|
303
|
-
"\"\\\0\"",
|
|
304
|
-
vec![("\"", 0..1), ("escape_sequence", 1..3), ("\"", 3..4)],
|
|
305
|
-
),
|
|
274
|
+
for source in [
|
|
275
|
+
"\"日\\\"本\"",
|
|
276
|
+
"\";x\0\"",
|
|
277
|
+
"\"\\\n;x\0\"",
|
|
278
|
+
"\"a\0b\0\0c\"",
|
|
279
|
+
"\"\0\"",
|
|
280
|
+
"\"a\\\0b\"",
|
|
281
|
+
"\"\\\0\"",
|
|
282
|
+
r#""\q""#,
|
|
283
|
+
"\"\r\"",
|
|
306
284
|
] {
|
|
307
285
|
assert!(Query::new(&language, &format!("(#custom? {source})")).is_ok());
|
|
308
|
-
let tree = parser.parse(source, None).unwrap();
|
|
309
|
-
assert!(!tree.root_node().has_error(), "{source:?}");
|
|
310
|
-
let string = tree
|
|
311
|
-
.root_node()
|
|
312
|
-
.named_child(0)
|
|
313
|
-
.unwrap()
|
|
314
|
-
.child_by_field_name("body")
|
|
315
|
-
.unwrap();
|
|
316
|
-
let mut cursor = string.walk();
|
|
317
|
-
let actual: Vec<_> = string
|
|
318
|
-
.children(&mut cursor)
|
|
319
|
-
.map(|node| {
|
|
320
|
-
assert_eq!(node.child_count(), 0);
|
|
321
|
-
(node.kind(), node.byte_range())
|
|
322
|
-
})
|
|
323
|
-
.collect();
|
|
324
|
-
assert_eq!(actual, expected, "{source:?}");
|
|
325
|
-
}
|
|
326
|
-
for source in ["\"a\0", "\"\\\0", "\"a\\", "\"\0\n\""] {
|
|
327
286
|
assert!(
|
|
328
|
-
parser.parse(source, None).unwrap().root_node().has_error(),
|
|
287
|
+
!parser.parse(source, None).unwrap().root_node().has_error(),
|
|
329
288
|
"{source:?}"
|
|
330
289
|
);
|
|
331
290
|
}
|
|
@@ -353,20 +312,15 @@ fn string_newlines_cannot_skip_comments_before_nul() {
|
|
|
353
312
|
}
|
|
354
313
|
|
|
355
314
|
#[test]
|
|
356
|
-
fn
|
|
315
|
+
fn comments_with_carriage_returns_follow_public_query_api_syntax() {
|
|
357
316
|
let language = grammar::LANGUAGE.into();
|
|
358
317
|
let mut parser = parser();
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
root.to_sexp(),
|
|
366
|
-
"(query (comment) (pattern body: (node_pattern node: (wildcard))))"
|
|
367
|
-
);
|
|
368
|
-
assert_eq!(root.named_child(0).unwrap().byte_range(), 0..4);
|
|
369
|
-
assert_eq!(root.named_child(1).unwrap().byte_range(), 6..9);
|
|
318
|
+
for (source, patterns) in [(";a\rb\r\n(_)", 1), (";x\r(_)", 0)] {
|
|
319
|
+
let query = Query::new(&language, source).unwrap();
|
|
320
|
+
assert_eq!(query.pattern_count(), patterns, "{source:?}");
|
|
321
|
+
let tree = parser.parse(source, None).unwrap();
|
|
322
|
+
assert!(!tree.root_node().has_error(), "{source:?}");
|
|
323
|
+
}
|
|
370
324
|
}
|
|
371
325
|
|
|
372
326
|
#[test]
|
|
@@ -425,96 +379,8 @@ fn highlight_captures_use_leaf_ranges_even_during_recovery() {
|
|
|
425
379
|
}
|
|
426
380
|
|
|
427
381
|
#[test]
|
|
428
|
-
fn
|
|
429
|
-
let source = "(node . child: (_)+ @x !absent)";
|
|
430
|
-
let tree = parser().parse(source, None).unwrap();
|
|
431
|
-
assert!(!tree.root_node().has_error());
|
|
432
|
-
let mut cursor = tree.walk();
|
|
433
|
-
let mut depth = 0;
|
|
434
|
-
let mut actual = Vec::new();
|
|
435
|
-
'walk: loop {
|
|
436
|
-
let node = cursor.node();
|
|
437
|
-
actual.push((
|
|
438
|
-
depth,
|
|
439
|
-
node.kind(),
|
|
440
|
-
cursor.field_name(),
|
|
441
|
-
node.is_named(),
|
|
442
|
-
node.byte_range(),
|
|
443
|
-
));
|
|
444
|
-
assert_eq!(
|
|
445
|
-
node.start_position(),
|
|
446
|
-
Point {
|
|
447
|
-
row: 0,
|
|
448
|
-
column: node.start_byte()
|
|
449
|
-
}
|
|
450
|
-
);
|
|
451
|
-
assert_eq!(
|
|
452
|
-
node.end_position(),
|
|
453
|
-
Point {
|
|
454
|
-
row: 0,
|
|
455
|
-
column: node.end_byte()
|
|
456
|
-
}
|
|
457
|
-
);
|
|
458
|
-
if cursor.goto_first_child() {
|
|
459
|
-
depth += 1;
|
|
460
|
-
continue;
|
|
461
|
-
}
|
|
462
|
-
while !cursor.goto_next_sibling() {
|
|
463
|
-
if !cursor.goto_parent() {
|
|
464
|
-
break 'walk;
|
|
465
|
-
}
|
|
466
|
-
depth -= 1;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
assert_eq!(
|
|
470
|
-
actual,
|
|
471
|
-
vec![
|
|
472
|
-
(0, "query", None, true, 0..31),
|
|
473
|
-
(1, "pattern", None, true, 0..31),
|
|
474
|
-
(2, "node_pattern", Some("body"), true, 0..31),
|
|
475
|
-
(3, "(", None, false, 0..1),
|
|
476
|
-
(3, "identifier", Some("node"), true, 1..5),
|
|
477
|
-
(3, "anchor", None, true, 6..7),
|
|
478
|
-
(3, "field_constraint", None, true, 8..22),
|
|
479
|
-
(4, "identifier", Some("name"), true, 8..13),
|
|
480
|
-
(4, ":", None, false, 13..14),
|
|
481
|
-
(4, "pattern", Some("pattern"), true, 15..22),
|
|
482
|
-
(5, "node_pattern", Some("body"), true, 15..18),
|
|
483
|
-
(6, "(", None, false, 15..16),
|
|
484
|
-
(6, "wildcard", Some("node"), true, 16..17),
|
|
485
|
-
(6, ")", None, false, 17..18),
|
|
486
|
-
(5, "quantifier", Some("quantifier"), true, 18..19),
|
|
487
|
-
(5, "capture", Some("capture"), true, 20..22),
|
|
488
|
-
(6, "@", None, false, 20..21),
|
|
489
|
-
(6, "identifier", Some("name"), true, 21..22),
|
|
490
|
-
(3, "negated_field", None, true, 23..30),
|
|
491
|
-
(4, "!", None, false, 23..24),
|
|
492
|
-
(4, "identifier", Some("name"), true, 24..30),
|
|
493
|
-
(3, ")", None, false, 30..31),
|
|
494
|
-
]
|
|
495
|
-
);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
#[test]
|
|
499
|
-
fn bom_is_ignored_only_once_at_source_byte_zero() {
|
|
382
|
+
fn bom_at_an_included_range_start_is_not_a_source_bom() {
|
|
500
383
|
let mut parser = parser();
|
|
501
|
-
let source = "\u{feff}(node)\r\n";
|
|
502
|
-
let tree = parser.parse(source, None).unwrap();
|
|
503
|
-
assert!(!tree.root_node().has_error());
|
|
504
|
-
let pattern = tree.root_node().named_child(0).unwrap();
|
|
505
|
-
assert_eq!(pattern.byte_range(), 3..9);
|
|
506
|
-
assert_eq!(pattern.start_position(), Point { row: 0, column: 3 });
|
|
507
|
-
assert_eq!(tree.root_node().end_position(), Point { row: 1, column: 0 });
|
|
508
|
-
for invalid in [
|
|
509
|
-
" \u{feff}(node)",
|
|
510
|
-
"\u{feff}\u{feff}(node)",
|
|
511
|
-
"(node)\u{feff}",
|
|
512
|
-
] {
|
|
513
|
-
assert!(
|
|
514
|
-
parser.parse(invalid, None).unwrap().root_node().has_error(),
|
|
515
|
-
"{invalid:?}"
|
|
516
|
-
);
|
|
517
|
-
}
|
|
518
384
|
let embedded = "x\u{feff}(node)";
|
|
519
385
|
parser
|
|
520
386
|
.set_included_ranges(&[Range {
|
|
@@ -535,18 +401,3 @@ fn bom_is_ignored_only_once_at_source_byte_zero() {
|
|
|
535
401
|
.has_error()
|
|
536
402
|
);
|
|
537
403
|
}
|
|
538
|
-
|
|
539
|
-
#[test]
|
|
540
|
-
fn crlf_and_multibyte_comment_ranges_keep_source_coordinates() {
|
|
541
|
-
let mut parser = parser();
|
|
542
|
-
let source = "; 日\r\n(node)";
|
|
543
|
-
let tree = parser.parse(source, None).unwrap();
|
|
544
|
-
let root = tree.root_node();
|
|
545
|
-
assert!(!root.has_error());
|
|
546
|
-
let comment = root.named_child(0).unwrap();
|
|
547
|
-
assert_eq!(comment.byte_range(), 0..5);
|
|
548
|
-
assert_eq!(comment.end_position(), Point { row: 0, column: 5 });
|
|
549
|
-
let pattern = root.named_child(1).unwrap();
|
|
550
|
-
assert_eq!(pattern.byte_range(), 7..13);
|
|
551
|
-
assert_eq!(pattern.start_position(), Point { row: 1, column: 0 });
|
|
552
|
-
}
|