@willbooster/tree-sitter-rust 1.9.1 → 1.10.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
@@ -75,6 +75,17 @@ let mut parser = tree_sitter::Parser::new();
75
75
  parser.set_language(&tree_sitter_rust::LANGUAGE.into())?;
76
76
  ```
77
77
 
78
+ ## Expression attributes
79
+
80
+ An attribute in an expression position can produce an `attributed_expression` node with a `value` field.
81
+ For example, in `let x = #[allow(unused)] 1 + 2;`, that field contains `1`; the enclosing binary expression
82
+ still contains `+ 2`. Multiple attributes can form nested wrappers. Queries matching `_expression` include
83
+ these wrappers. Follow each wrapper's `value` field until reaching the operand.
84
+
85
+ Existing item, parameter and list attributes retain their sibling nodes. Attributes inside parentheses also precede
86
+ the operand as siblings. List and parenthesized operands remain queryable through
87
+ `_expression`. Compiler feature gates and attribute-placement diagnostics remain the compiler's responsibility.
88
+
78
89
  ## Development
79
90
 
80
91
  ```sh
package/grammar.js CHANGED
@@ -105,6 +105,7 @@ const TOKEN_TREE_NON_SPECIAL_PUNCTUATION = [
105
105
 
106
106
  const primitiveTypes = [...numericTypes, 'bool', 'str', 'char'];
107
107
  const reservedIdentifiers = ['default', 'union', 'gen', 'raw'];
108
+ const fieldIdentifierKeywords = [...reservedIdentifiers, ...primitiveTypes, 'auto'];
108
109
 
109
110
  // oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
110
111
  module.exports = grammar({
@@ -142,6 +143,10 @@ module.exports = grammar({
142
143
  ],
143
144
 
144
145
  conflicts: ($) => [
146
+ [$.field_initializer_list, $.block],
147
+ [$._declaration_statement, $.shorthand_field_initializer, $.field_initializer],
148
+ [$._expression_except_range, $.shorthand_field_initializer],
149
+ [$._declaration_statement, $.attributed_expression],
145
150
  [$._expression_except_range, $.struct_expression],
146
151
  [$.function_modifiers, $.modified_trait_bound],
147
152
  [$.function_modifiers, $.impl_item, $.modified_trait_bound],
@@ -912,7 +917,10 @@ module.exports = grammar({
912
917
  $._expression_ending_with_block
913
918
  ),
914
919
 
915
- _expression: ($) => choice($._expression_except_range, $.range_expression),
920
+ _expression: ($) => choice($._expression_except_range, $.range_expression, $.attributed_expression),
921
+
922
+ attributed_expression: ($) =>
923
+ prec.dynamic(-1, prec.right(PREC.unary, seq(repeat1($.attribute_item), field('value', $._expression)))),
916
924
 
917
925
  _expression_ending_with_block: ($) =>
918
926
  choice(
@@ -1058,28 +1066,29 @@ module.exports = grammar({
1058
1066
  call_expression: ($) =>
1059
1067
  prec(PREC.call, seq(field('function', $._expression_except_range), field('arguments', $.arguments))),
1060
1068
 
1061
- arguments: ($) => seq('(', sepBy(',', seq(repeat($.attribute_item), $._expression)), optional(','), ')'),
1069
+ arguments: ($) =>
1070
+ seq('(', sepBy(',', seq(repeat(prec(PREC.call, $.attribute_item)), $._expression)), optional(','), ')'),
1062
1071
 
1063
1072
  array_expression: ($) =>
1064
1073
  seq(
1065
1074
  '[',
1066
- repeat($.attribute_item),
1075
+ repeat(prec(PREC.call, $.attribute_item)),
1067
1076
  choice(
1068
1077
  seq($._expression, ';', field('length', $._expression)),
1069
- seq(sepBy(',', seq(repeat($.attribute_item), $._expression)), optional(','))
1078
+ seq(sepBy(',', seq(repeat(prec(PREC.call, $.attribute_item)), $._expression)), optional(','))
1070
1079
  ),
1071
1080
  ']'
1072
1081
  ),
1073
1082
 
1074
- parenthesized_expression: ($) => seq('(', $._expression, ')'),
1083
+ parenthesized_expression: ($) => seq('(', repeat(prec(PREC.call, $.attribute_item)), $._expression, ')'),
1075
1084
 
1076
1085
  tuple_expression: ($) =>
1077
1086
  seq(
1078
1087
  '(',
1079
- repeat($.attribute_item),
1088
+ repeat(prec(PREC.call, $.attribute_item)),
1080
1089
  seq($._expression, ','),
1081
- repeat(seq($._expression, ',')),
1082
- optional($._expression),
1090
+ repeat(seq(repeat(prec(PREC.call, $.attribute_item)), $._expression, ',')),
1091
+ optional(seq(repeat(prec(PREC.call, $.attribute_item)), $._expression)),
1083
1092
  ')'
1084
1093
  ),
1085
1094
 
@@ -1091,7 +1100,7 @@ module.exports = grammar({
1091
1100
  'name',
1092
1101
  choice(
1093
1102
  $._type_identifier,
1094
- prec.dynamic(-1, alias(choice(...primitiveTypes), $.type_identifier)),
1103
+ prec.dynamic(-1, alias(choice(...primitiveTypes, ...reservedIdentifiers), $.type_identifier)),
1095
1104
  alias($.scoped_type_identifier_in_expression_position, $.scoped_type_identifier),
1096
1105
  $.generic_type_with_turbofish
1097
1106
  )
@@ -1107,12 +1116,20 @@ module.exports = grammar({
1107
1116
  '}'
1108
1117
  ),
1109
1118
 
1110
- shorthand_field_initializer: ($) => seq(repeat($.attribute_item), $.identifier),
1119
+ shorthand_field_initializer: ($) =>
1120
+ seq(repeat($.attribute_item), choice($.identifier, alias(choice(...fieldIdentifierKeywords), $.identifier))),
1111
1121
 
1112
1122
  field_initializer: ($) =>
1113
1123
  seq(
1114
1124
  repeat($.attribute_item),
1115
- field('field', choice($._field_identifier, alias(/[0-9][0-9_]*/, $.integer_literal))),
1125
+ field(
1126
+ 'field',
1127
+ choice(
1128
+ $._field_identifier,
1129
+ alias(choice(...fieldIdentifierKeywords), $.field_identifier),
1130
+ alias(/[0-9][0-9_]*/, $.integer_literal)
1131
+ )
1132
+ ),
1116
1133
  ':',
1117
1134
  field('value', $._expression)
1118
1135
  ),
@@ -1389,15 +1406,18 @@ module.exports = grammar({
1389
1406
  negative_literal: ($) => seq('-', choice($.integer_literal, $.float_literal)),
1390
1407
 
1391
1408
  integer_literal: () =>
1392
- token(
1393
- choice(
1394
- seq(
1395
- choice(/[1-9][0-9_]*/, /0[0-9_]+/, /0b_*[01][01_]*/, /0o_*[0-7][0-7_]*/),
1396
- optional(numericSuffixWithoutExponent)
1397
- ),
1398
- /0[box]_+/,
1399
- seq('0', optional(zeroNumericSuffix)),
1400
- seq(/0x_*[0-9a-fA-F][0-9a-fA-F_]*/, optional(hexadecimalSuffix))
1409
+ choice(
1410
+ /[0-9][0-9_]*/,
1411
+ token(
1412
+ choice(
1413
+ seq(
1414
+ choice(/[1-9][0-9_]*/, /0[0-9_]+/, /0b_*[01][01_]*/, /0o_*[0-7][0-7_]*/),
1415
+ optional(numericSuffixWithoutExponent)
1416
+ ),
1417
+ /0[box]_+/,
1418
+ seq('0', optional(zeroNumericSuffix)),
1419
+ seq(/0x_*[0-9a-fA-F][0-9a-fA-F_]*/, optional(hexadecimalSuffix))
1420
+ )
1401
1421
  )
1402
1422
  ),
1403
1423
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "1.9.1",
3
+ "version": "1.10.1",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -117,6 +117,10 @@
117
117
  "type": "async_block",
118
118
  "named": true
119
119
  },
120
+ {
121
+ "type": "attributed_expression",
122
+ "named": true
123
+ },
120
124
  {
121
125
  "type": "await_expression",
122
126
  "named": true
@@ -778,6 +782,32 @@
778
782
  ]
779
783
  }
780
784
  },
785
+ {
786
+ "type": "attributed_expression",
787
+ "named": true,
788
+ "fields": {
789
+ "value": {
790
+ "multiple": false,
791
+ "required": true,
792
+ "types": [
793
+ {
794
+ "type": "_expression",
795
+ "named": true
796
+ }
797
+ ]
798
+ }
799
+ },
800
+ "children": {
801
+ "multiple": true,
802
+ "required": true,
803
+ "types": [
804
+ {
805
+ "type": "attribute_item",
806
+ "named": true
807
+ }
808
+ ]
809
+ }
810
+ },
781
811
  {
782
812
  "type": "await_expression",
783
813
  "named": true,
@@ -2644,6 +2674,11 @@
2644
2674
  "named": true,
2645
2675
  "fields": {}
2646
2676
  },
2677
+ {
2678
+ "type": "integer_literal",
2679
+ "named": true,
2680
+ "fields": {}
2681
+ },
2647
2682
  {
2648
2683
  "type": "label",
2649
2684
  "named": true,
@@ -3282,12 +3317,16 @@
3282
3317
  "named": true,
3283
3318
  "fields": {},
3284
3319
  "children": {
3285
- "multiple": false,
3320
+ "multiple": true,
3286
3321
  "required": true,
3287
3322
  "types": [
3288
3323
  {
3289
3324
  "type": "_expression",
3290
3325
  "named": true
3326
+ },
3327
+ {
3328
+ "type": "attribute_item",
3329
+ "named": true
3291
3330
  }
3292
3331
  ]
3293
3332
  }
@@ -5556,10 +5595,6 @@
5556
5595
  "type": "in",
5557
5596
  "named": false
5558
5597
  },
5559
- {
5560
- "type": "integer_literal",
5561
- "named": true
5562
- },
5563
5598
  {
5564
5599
  "type": "item",
5565
5600
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -22,7 +22,7 @@
22
22
  }
23
23
  ],
24
24
  "metadata": {
25
- "version": "1.9.1",
25
+ "version": "1.10.1",
26
26
  "license": "MIT",
27
27
  "description": "Rust grammar for tree-sitter",
28
28
  "authors": [