@willbooster/tree-sitter-rust 3.2.0 → 4.0.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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.36.11-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.41.8-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-rust.svg)](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
- ## Expression attributes
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`. Multiple attributes can form nested wrappers. Queries matching `_expression` include
89
- these wrappers. Follow each wrapper's `value` field until reaching the operand.
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
- Existing item, parameter and list attributes retain their sibling nodes. Attributes inside parentheses also precede
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: ($) => [$._declaration_statement, $._expression, $._type, $._literal, $._literal_pattern, $._pattern],
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],
@@ -178,7 +187,6 @@ module.exports = grammar({
178
187
  [$.scoped_identifier, $.scoped_type_identifier],
179
188
  [$.parameters, $._pattern],
180
189
  [$.parameters, $.tuple_struct_pattern],
181
- [$.array_expression],
182
190
  [$.visibility_modifier],
183
191
  [$.visibility_modifier, $.scoped_identifier, $.scoped_type_identifier],
184
192
  [$.foreign_mod_item, $.function_modifiers],
@@ -196,17 +204,30 @@ module.exports = grammar({
196
204
 
197
205
  empty_statement: () => ';',
198
206
 
199
- expression_statement: ($) => choice(seq($._expression, ';'), prec(1, $._expression_ending_with_block)),
207
+ expression_statement: ($) =>
208
+ choice(
209
+ seq($._expression, ';'),
210
+ prec(1, $._expression_ending_with_block),
211
+ prec(1, alias($._block_statement_expression, $._expression))
212
+ ),
213
+
214
+ _block_statement_expression: ($) => alias($._attributed_block_statement, $.attributed_expression),
215
+
216
+ _outer_attributes: ($) => prec.right(seq($.attribute_item, repeat($.attribute_item))),
217
+
218
+ _attributed_block_statement: ($) => seq($._outer_attributes, field('value', $._expression_ending_with_block)),
200
219
 
201
220
  _declaration_statement: ($) =>
221
+ choice($.empty_statement, $.inner_attribute_item, $._attributable_declaration, $.attributed_declaration),
222
+
223
+ attributed_declaration: ($) => seq($._outer_attributes, field('declaration', $._attributable_declaration)),
224
+
225
+ _attributable_declaration: ($) =>
202
226
  choice(
203
227
  $.const_item,
204
228
  $.macro_invocation,
205
229
  $.macro_definition,
206
230
  $.decl_macro,
207
- $.empty_statement,
208
- $.attribute_item,
209
- $.inner_attribute_item,
210
231
  $.mod_item,
211
232
  $.foreign_mod_item,
212
233
  $.struct_item,
@@ -406,7 +427,31 @@ module.exports = grammar({
406
427
  // `_foreign_declaration_start` required by qualified extern items. Keep this context marker so `safe` remains
407
428
  // an identifier outside extern blocks while qualified items still participate in declaration supertype queries.
408
429
  _foreign_declaration_list: ($) =>
409
- seq('{', repeat(seq(optional(sym('_foreign_declaration_context')), $._declaration_statement)), '}'),
430
+ seq(
431
+ '{',
432
+ repeat(
433
+ seq(
434
+ optional(sym('_foreign_declaration_context')),
435
+ alias($._foreign_declaration_statement, $._declaration_statement)
436
+ )
437
+ ),
438
+ '}'
439
+ ),
440
+
441
+ _foreign_declaration_statement: ($) =>
442
+ choice(
443
+ $.empty_statement,
444
+ $.inner_attribute_item,
445
+ $._attributable_declaration,
446
+ alias($._foreign_attributed_declaration, $.attributed_declaration)
447
+ ),
448
+
449
+ _foreign_attributed_declaration: ($) =>
450
+ seq(
451
+ $._outer_attributes,
452
+ optional(sym('_foreign_declaration_context')),
453
+ field('declaration', $._attributable_declaration)
454
+ ),
410
455
 
411
456
  _safe_function_signature_item: ($) =>
412
457
  seq(
@@ -1009,7 +1054,7 @@ module.exports = grammar({
1009
1054
  _expression: ($) => choice($._expression_except_range, $.range_expression, $.attributed_expression),
1010
1055
 
1011
1056
  attributed_expression: ($) =>
1012
- prec.dynamic(-1, prec.right(PREC.unary, seq(repeat1($.attribute_item), field('value', $._expression)))),
1057
+ prec.dynamic(-1, seq($._outer_attributes, prec.right(PREC.unary, field('value', $._expression)))),
1013
1058
 
1014
1059
  _expression_ending_with_block: ($) =>
1015
1060
  choice(
@@ -1165,9 +1210,8 @@ module.exports = grammar({
1165
1210
  array_expression: ($) =>
1166
1211
  seq(
1167
1212
  '[',
1168
- repeat(prec(PREC.call, $.attribute_item)),
1169
1213
  choice(
1170
- seq($._expression, ';', field('length', $._expression)),
1214
+ seq(repeat(prec(PREC.call, $.attribute_item)), $._expression, ';', field('length', $._expression)),
1171
1215
  seq(sepBy(',', seq(repeat(prec(PREC.call, $.attribute_item)), $._expression)), optional(','))
1172
1216
  ),
1173
1217
  ']'
@@ -1210,11 +1254,11 @@ module.exports = grammar({
1210
1254
  ),
1211
1255
 
1212
1256
  shorthand_field_initializer: ($) =>
1213
- seq(repeat($.attribute_item), choice($.identifier, alias(choice(...fieldIdentifierKeywords), $.identifier))),
1257
+ seq(optional($._outer_attributes), choice($.identifier, alias(choice(...fieldIdentifierKeywords), $.identifier))),
1214
1258
 
1215
1259
  field_initializer: ($) =>
1216
1260
  seq(
1217
- repeat($.attribute_item),
1261
+ optional($._outer_attributes),
1218
1262
  field(
1219
1263
  'field',
1220
1264
  choice(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "3.2.0",
3
+ "version": "4.0.1",
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.24",
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
- ; function definitions
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
 
@@ -8,7 +8,7 @@
8
8
  "named": true
9
9
  },
10
10
  {
11
- "type": "attribute_item",
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,
Binary file
package/tree-sitter.json CHANGED
@@ -25,7 +25,7 @@
25
25
  }
26
26
  ],
27
27
  "metadata": {
28
- "version": "3.2.0",
28
+ "version": "4.0.1",
29
29
  "license": "MIT",
30
30
  "description": "Rust grammar for tree-sitter",
31
31
  "authors": [