@willbooster/tree-sitter-rust 3.2.0 → 4.0.0
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/README.md +9 -5
- package/grammar.js +56 -10
- package/package.json +2 -3
- package/queries/tags.scm +4 -15
- package/src/node-types.json +103 -1
- package/tree-sitter-rust.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](https://crates.io/crates/willbooster-tree-sitter-rust)
|
|
10
10
|
|
|
11
11
|
Rust grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
@@ -81,14 +81,18 @@ let mut parser = tree_sitter::Parser::new();
|
|
|
81
81
|
parser.set_language(&tree_sitter_rust::LANGUAGE.into())?;
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
##
|
|
84
|
+
## Attributes
|
|
85
85
|
|
|
86
86
|
An attribute in an expression position can produce an `attributed_expression` node with a `value` field.
|
|
87
87
|
For example, in `let x = #[allow(unused)] 1 + 2;`, that field contains `1`; the enclosing binary expression
|
|
88
|
-
still contains `+ 2`.
|
|
89
|
-
these wrappers
|
|
88
|
+
still contains `+ 2`. Consecutive attributes share one wrapper. Queries matching `_expression` include
|
|
89
|
+
these wrappers, including attributed block statements. The `value` field identifies the operand.
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
Outer declaration attributes belong to an `attributed_declaration` node whose `declaration` field identifies
|
|
92
|
+
the item. In declaration and statement positions, outer attributes without a following declaration or
|
|
93
|
+
expression produce a syntax error.
|
|
94
|
+
|
|
95
|
+
Parameter and list attributes retain their sibling nodes. Attributes inside parentheses also precede
|
|
92
96
|
the operand as siblings. List and parenthesized operands remain queryable through
|
|
93
97
|
`_expression`. Compiler feature gates and attribute-placement diagnostics remain the compiler's responsibility.
|
|
94
98
|
|
package/grammar.js
CHANGED
|
@@ -146,7 +146,16 @@ module.exports = grammar({
|
|
|
146
146
|
sym('_frontmatter_context'),
|
|
147
147
|
],
|
|
148
148
|
|
|
149
|
-
supertypes: ($) => [
|
|
149
|
+
supertypes: ($) => [
|
|
150
|
+
$._declaration_statement,
|
|
151
|
+
$._foreign_declaration_statement,
|
|
152
|
+
$._block_statement_expression,
|
|
153
|
+
$._expression,
|
|
154
|
+
$._type,
|
|
155
|
+
$._literal,
|
|
156
|
+
$._literal_pattern,
|
|
157
|
+
$._pattern,
|
|
158
|
+
],
|
|
150
159
|
|
|
151
160
|
inline: ($) => [
|
|
152
161
|
$._path,
|
|
@@ -160,13 +169,13 @@ module.exports = grammar({
|
|
|
160
169
|
],
|
|
161
170
|
|
|
162
171
|
conflicts: ($) => [
|
|
172
|
+
[$._attributed_block_statement, $._expression_except_range],
|
|
163
173
|
[$.type_parameters, $.for_lifetimes],
|
|
164
174
|
[$.lifetime_parameter, $.for_lifetimes],
|
|
165
175
|
[$._token_pattern, $.token_repetition_pattern],
|
|
166
176
|
[$.token_tree, $.token_repetition],
|
|
167
177
|
[$.field_initializer_list, $.block],
|
|
168
178
|
[$._expression_except_range, $.shorthand_field_initializer],
|
|
169
|
-
[$._declaration_statement, $.attributed_expression],
|
|
170
179
|
[$._expression_except_range, $.struct_expression],
|
|
171
180
|
[$.function_modifiers, $.modified_trait_bound],
|
|
172
181
|
[$.function_modifiers, $.impl_item, $.modified_trait_bound],
|
|
@@ -196,17 +205,30 @@ module.exports = grammar({
|
|
|
196
205
|
|
|
197
206
|
empty_statement: () => ';',
|
|
198
207
|
|
|
199
|
-
expression_statement: ($) =>
|
|
208
|
+
expression_statement: ($) =>
|
|
209
|
+
choice(
|
|
210
|
+
seq($._expression, ';'),
|
|
211
|
+
prec(1, $._expression_ending_with_block),
|
|
212
|
+
prec(1, alias($._block_statement_expression, $._expression))
|
|
213
|
+
),
|
|
214
|
+
|
|
215
|
+
_block_statement_expression: ($) => alias($._attributed_block_statement, $.attributed_expression),
|
|
216
|
+
|
|
217
|
+
_outer_attributes: ($) => prec.right(seq($.attribute_item, repeat($.attribute_item))),
|
|
218
|
+
|
|
219
|
+
_attributed_block_statement: ($) => seq($._outer_attributes, field('value', $._expression_ending_with_block)),
|
|
200
220
|
|
|
201
221
|
_declaration_statement: ($) =>
|
|
222
|
+
choice($.empty_statement, $.inner_attribute_item, $._attributable_declaration, $.attributed_declaration),
|
|
223
|
+
|
|
224
|
+
attributed_declaration: ($) => seq($._outer_attributes, field('declaration', $._attributable_declaration)),
|
|
225
|
+
|
|
226
|
+
_attributable_declaration: ($) =>
|
|
202
227
|
choice(
|
|
203
228
|
$.const_item,
|
|
204
229
|
$.macro_invocation,
|
|
205
230
|
$.macro_definition,
|
|
206
231
|
$.decl_macro,
|
|
207
|
-
$.empty_statement,
|
|
208
|
-
$.attribute_item,
|
|
209
|
-
$.inner_attribute_item,
|
|
210
232
|
$.mod_item,
|
|
211
233
|
$.foreign_mod_item,
|
|
212
234
|
$.struct_item,
|
|
@@ -406,7 +428,31 @@ module.exports = grammar({
|
|
|
406
428
|
// `_foreign_declaration_start` required by qualified extern items. Keep this context marker so `safe` remains
|
|
407
429
|
// an identifier outside extern blocks while qualified items still participate in declaration supertype queries.
|
|
408
430
|
_foreign_declaration_list: ($) =>
|
|
409
|
-
seq(
|
|
431
|
+
seq(
|
|
432
|
+
'{',
|
|
433
|
+
repeat(
|
|
434
|
+
seq(
|
|
435
|
+
optional(sym('_foreign_declaration_context')),
|
|
436
|
+
alias($._foreign_declaration_statement, $._declaration_statement)
|
|
437
|
+
)
|
|
438
|
+
),
|
|
439
|
+
'}'
|
|
440
|
+
),
|
|
441
|
+
|
|
442
|
+
_foreign_declaration_statement: ($) =>
|
|
443
|
+
choice(
|
|
444
|
+
$.empty_statement,
|
|
445
|
+
$.inner_attribute_item,
|
|
446
|
+
$._attributable_declaration,
|
|
447
|
+
alias($._foreign_attributed_declaration, $.attributed_declaration)
|
|
448
|
+
),
|
|
449
|
+
|
|
450
|
+
_foreign_attributed_declaration: ($) =>
|
|
451
|
+
seq(
|
|
452
|
+
$._outer_attributes,
|
|
453
|
+
optional(sym('_foreign_declaration_context')),
|
|
454
|
+
field('declaration', $._attributable_declaration)
|
|
455
|
+
),
|
|
410
456
|
|
|
411
457
|
_safe_function_signature_item: ($) =>
|
|
412
458
|
seq(
|
|
@@ -1009,7 +1055,7 @@ module.exports = grammar({
|
|
|
1009
1055
|
_expression: ($) => choice($._expression_except_range, $.range_expression, $.attributed_expression),
|
|
1010
1056
|
|
|
1011
1057
|
attributed_expression: ($) =>
|
|
1012
|
-
prec.dynamic(-1, prec.right(PREC.unary,
|
|
1058
|
+
prec.dynamic(-1, seq($._outer_attributes, prec.right(PREC.unary, field('value', $._expression)))),
|
|
1013
1059
|
|
|
1014
1060
|
_expression_ending_with_block: ($) =>
|
|
1015
1061
|
choice(
|
|
@@ -1210,11 +1256,11 @@ module.exports = grammar({
|
|
|
1210
1256
|
),
|
|
1211
1257
|
|
|
1212
1258
|
shorthand_field_initializer: ($) =>
|
|
1213
|
-
seq(
|
|
1259
|
+
seq(optional($._outer_attributes), choice($.identifier, alias(choice(...fieldIdentifierKeywords), $.identifier))),
|
|
1214
1260
|
|
|
1215
1261
|
field_initializer: ($) =>
|
|
1216
1262
|
seq(
|
|
1217
|
-
|
|
1263
|
+
optional($._outer_attributes),
|
|
1218
1264
|
field(
|
|
1219
1265
|
'field',
|
|
1220
1266
|
choice(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-rust",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Rust grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
48
48
|
"@willbooster/oxlint-config": "1.4.8",
|
|
49
49
|
"@willbooster/wb": "22.26.1",
|
|
50
|
-
"@willbooster/web-tree-sitter": "2.0.
|
|
50
|
+
"@willbooster/web-tree-sitter": "2.0.27",
|
|
51
51
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
52
52
|
"lefthook": "2.2.1",
|
|
53
53
|
"oxfmt": "0.72.0",
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"playwright": "1.64.0",
|
|
57
57
|
"semantic-release": "25.0.9",
|
|
58
58
|
"sort-package-json": "4.0.0",
|
|
59
|
-
"typescript": "7.0.2",
|
|
60
59
|
"vite": "8.3.4",
|
|
61
60
|
"vitest": "5.0.3",
|
|
62
61
|
"wrangler": "4.149.0"
|
package/queries/tags.scm
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
; ADT definitions
|
|
2
|
-
|
|
3
1
|
(struct_item
|
|
4
2
|
name: (type_identifier) @name) @definition.class
|
|
5
3
|
|
|
@@ -9,43 +7,36 @@
|
|
|
9
7
|
(union_item
|
|
10
8
|
name: (type_identifier) @name) @definition.class
|
|
11
9
|
|
|
12
|
-
; type aliases
|
|
13
|
-
|
|
14
10
|
(type_item
|
|
15
11
|
name: (type_identifier) @name) @definition.class
|
|
16
12
|
|
|
17
|
-
; method definitions
|
|
18
|
-
|
|
19
13
|
(declaration_list
|
|
20
14
|
(function_item
|
|
21
15
|
name: (identifier) @name) @definition.method)
|
|
22
16
|
|
|
23
|
-
|
|
17
|
+
(declaration_list
|
|
18
|
+
(attributed_declaration
|
|
19
|
+
declaration: (function_item
|
|
20
|
+
name: (identifier) @name) @definition.method))
|
|
24
21
|
|
|
25
22
|
(function_item
|
|
26
23
|
name: (identifier) @name) @definition.function
|
|
27
24
|
|
|
28
|
-
; trait definitions
|
|
29
25
|
(trait_item
|
|
30
26
|
name: (type_identifier) @name) @definition.interface
|
|
31
27
|
|
|
32
28
|
(trait_alias
|
|
33
29
|
name: (type_identifier) @name) @definition.interface
|
|
34
30
|
|
|
35
|
-
; module definitions
|
|
36
31
|
(mod_item
|
|
37
32
|
name: (identifier) @name) @definition.module
|
|
38
33
|
|
|
39
|
-
; macro definitions
|
|
40
|
-
|
|
41
34
|
(macro_definition
|
|
42
35
|
name: (identifier) @name) @definition.macro
|
|
43
36
|
|
|
44
37
|
(decl_macro
|
|
45
38
|
name: (identifier) @name) @definition.macro
|
|
46
39
|
|
|
47
|
-
; references
|
|
48
|
-
|
|
49
40
|
(call_expression
|
|
50
41
|
function: (identifier) @name) @reference.call
|
|
51
42
|
|
|
@@ -56,8 +47,6 @@
|
|
|
56
47
|
(macro_invocation
|
|
57
48
|
macro: (identifier) @name) @reference.call
|
|
58
49
|
|
|
59
|
-
; implementations
|
|
60
|
-
|
|
61
50
|
(impl_item
|
|
62
51
|
trait: (type_identifier) @name) @reference.implementation
|
|
63
52
|
|
package/src/node-types.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"named": true
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
|
-
"type": "
|
|
11
|
+
"type": "attributed_declaration",
|
|
12
12
|
"named": true
|
|
13
13
|
},
|
|
14
14
|
{
|
|
@@ -782,6 +782,108 @@
|
|
|
782
782
|
]
|
|
783
783
|
}
|
|
784
784
|
},
|
|
785
|
+
{
|
|
786
|
+
"type": "attributed_declaration",
|
|
787
|
+
"named": true,
|
|
788
|
+
"fields": {
|
|
789
|
+
"declaration": {
|
|
790
|
+
"multiple": false,
|
|
791
|
+
"required": true,
|
|
792
|
+
"types": [
|
|
793
|
+
{
|
|
794
|
+
"type": "associated_type",
|
|
795
|
+
"named": true
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
"type": "const_item",
|
|
799
|
+
"named": true
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
"type": "decl_macro",
|
|
803
|
+
"named": true
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
"type": "enum_item",
|
|
807
|
+
"named": true
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
"type": "extern_crate_declaration",
|
|
811
|
+
"named": true
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
"type": "foreign_mod_item",
|
|
815
|
+
"named": true
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
"type": "function_item",
|
|
819
|
+
"named": true
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
"type": "function_signature_item",
|
|
823
|
+
"named": true
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
"type": "impl_item",
|
|
827
|
+
"named": true
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
"type": "let_declaration",
|
|
831
|
+
"named": true
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
"type": "macro_definition",
|
|
835
|
+
"named": true
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
"type": "macro_invocation",
|
|
839
|
+
"named": true
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
"type": "mod_item",
|
|
843
|
+
"named": true
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
"type": "static_item",
|
|
847
|
+
"named": true
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
"type": "struct_item",
|
|
851
|
+
"named": true
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
"type": "trait_alias",
|
|
855
|
+
"named": true
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
"type": "trait_item",
|
|
859
|
+
"named": true
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
"type": "type_item",
|
|
863
|
+
"named": true
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
"type": "union_item",
|
|
867
|
+
"named": true
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
"type": "use_declaration",
|
|
871
|
+
"named": true
|
|
872
|
+
}
|
|
873
|
+
]
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
"children": {
|
|
877
|
+
"multiple": true,
|
|
878
|
+
"required": true,
|
|
879
|
+
"types": [
|
|
880
|
+
{
|
|
881
|
+
"type": "attribute_item",
|
|
882
|
+
"named": true
|
|
883
|
+
}
|
|
884
|
+
]
|
|
885
|
+
}
|
|
886
|
+
},
|
|
785
887
|
{
|
|
786
888
|
"type": "attributed_expression",
|
|
787
889
|
"named": true,
|
package/tree-sitter-rust.wasm
CHANGED
|
Binary file
|