@konomanoasa/tree-sitter-query 0.3.0 → 0.3.2
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 +2 -2
- package/README.md +4 -0
- package/grammar.js +17 -30
- package/package.json +5 -5
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "konomanoasa-tree-sitter-query"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.2"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
description = "Tree-sitter grammar for Tree-sitter Query."
|
|
6
6
|
readme = "README.md"
|
|
@@ -30,7 +30,7 @@ path = "test/bindings.test.rs"
|
|
|
30
30
|
tree-sitter-language = "0.1.8"
|
|
31
31
|
|
|
32
32
|
[dev-dependencies]
|
|
33
|
-
tree-sitter = "0.27.
|
|
33
|
+
tree-sitter = "0.27.1"
|
|
34
34
|
|
|
35
35
|
[build-dependencies]
|
|
36
36
|
cc = "1.4"
|
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.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Tree-sitter grammar for Tree-sitter Query.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,13 +29,13 @@
|
|
|
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": {
|
|
36
|
-
"@biomejs/biome": "2.5.
|
|
37
|
-
"@types/node": "26.5
|
|
38
|
-
"tree-sitter-cli": "0.27.
|
|
36
|
+
"@biomejs/biome": "2.5.15",
|
|
37
|
+
"@types/node": "26.6.5",
|
|
38
|
+
"tree-sitter-cli": "0.27.1",
|
|
39
39
|
"typescript": "7.0.2"
|
|
40
40
|
},
|
|
41
41
|
"allowScripts": {
|
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
|
}
|