@willbooster/tree-sitter-rust 1.8.0 → 1.9.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/grammar.js CHANGED
@@ -34,6 +34,8 @@ const numericSuffixWithoutExponent = new RegExp(String.raw`[\p{XID_Start}--[eE]]
34
34
  const zeroNumericSuffix = new RegExp(String.raw`[\p{XID_Start}--[eEbox]][_\p{XID_Continue}]*`, 'v');
35
35
  const hexadecimalSuffix = new RegExp(String.raw`[\p{XID_Start}--[a-fA-F]][_\p{XID_Continue}]*`, 'v');
36
36
 
37
+ const extendedFloatTypes = ['f16', 'f128'];
38
+
37
39
  const numericTypes = [
38
40
  'u8',
39
41
  'i8',
@@ -49,6 +51,7 @@ const numericTypes = [
49
51
  'usize',
50
52
  'f32',
51
53
  'f64',
54
+ ...extendedFloatTypes,
52
55
  ];
53
56
 
54
57
  // https://doc.rust-lang.org/reference/tokens.html#punctuation
@@ -101,6 +104,7 @@ const TOKEN_TREE_NON_SPECIAL_PUNCTUATION = [
101
104
  ];
102
105
 
103
106
  const primitiveTypes = [...numericTypes, 'bool', 'str', 'char'];
107
+ const reservedIdentifiers = ['default', 'union', 'gen', 'raw'];
104
108
 
105
109
  // oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
106
110
  module.exports = grammar({
@@ -138,6 +142,7 @@ module.exports = grammar({
138
142
  ],
139
143
 
140
144
  conflicts: ($) => [
145
+ [$._expression_except_range, $.struct_expression],
141
146
  [$.function_modifiers, $.modified_trait_bound],
142
147
  [$.function_modifiers, $.impl_item, $.modified_trait_bound],
143
148
  [$.const_item, $.function_modifiers],
@@ -272,7 +277,8 @@ module.exports = grammar({
272
277
  $.self,
273
278
  $.super,
274
279
  $.crate,
275
- alias(choice(...primitiveTypes), $.primitive_type),
280
+ alias(choice(...primitiveTypes.filter((type) => !extendedFloatTypes.includes(type))), $.primitive_type),
281
+ alias(choice(...extendedFloatTypes), $.identifier),
276
282
  prec.right(repeat1(choice(...TOKEN_TREE_NON_SPECIAL_PUNCTUATION))),
277
283
  "'",
278
284
  'as',
@@ -529,7 +535,15 @@ module.exports = grammar({
529
535
  optional(
530
536
  seq(
531
537
  optional(choice('!', 'const', seq('~', 'const'))),
532
- field('trait', choice($._type_identifier, $.scoped_type_identifier, $.generic_type)),
538
+ field(
539
+ 'trait',
540
+ choice(
541
+ $._type_identifier,
542
+ alias(choice(...primitiveTypes), $.type_identifier),
543
+ $.scoped_type_identifier,
544
+ $.generic_type
545
+ )
546
+ ),
533
547
  'for'
534
548
  )
535
549
  ),
@@ -543,6 +557,7 @@ module.exports = grammar({
543
557
  optional($.visibility_modifier),
544
558
  optional('const'),
545
559
  optional('unsafe'),
560
+ optional('auto'),
546
561
  'trait',
547
562
  field('name', $._type_identifier),
548
563
  field('type_parameters', optional($.type_parameters)),
@@ -620,7 +635,7 @@ module.exports = grammar({
620
635
  prec(
621
636
  1,
622
637
  seq(
623
- field('name', $._type_identifier),
638
+ field('name', choice($._type_identifier, alias(choice(...primitiveTypes), $.type_identifier))),
624
639
  optional(field('bounds', $.trait_bounds)),
625
640
  optional(seq('=', field('default_type', $._type)))
626
641
  )
@@ -714,7 +729,14 @@ module.exports = grammar({
714
729
  PREC.call,
715
730
  seq(
716
731
  choice(
717
- field('trait', choice($._type_identifier, $.scoped_type_identifier)),
732
+ field(
733
+ 'trait',
734
+ choice(
735
+ $._type_identifier,
736
+ $.scoped_type_identifier,
737
+ alias(choice(...primitiveTypes), $.type_identifier)
738
+ )
739
+ ),
718
740
  seq(optional($.function_modifiers), 'fn')
719
741
  ),
720
742
  field('parameters', $.parameters)
@@ -731,7 +753,16 @@ module.exports = grammar({
731
753
  prec(
732
754
  1,
733
755
  seq(
734
- field('function', choice($.identifier, $.scoped_identifier, $.field_expression)),
756
+ field(
757
+ 'function',
758
+ choice(
759
+ $.identifier,
760
+ $._reserved_identifier,
761
+ alias(choice(...primitiveTypes), $.identifier),
762
+ $.scoped_identifier,
763
+ $.field_expression
764
+ )
765
+ ),
735
766
  '::',
736
767
  field('type_arguments', $.type_arguments)
737
768
  )
@@ -741,14 +772,25 @@ module.exports = grammar({
741
772
  prec(
742
773
  1,
743
774
  seq(
744
- field('type', choice($._type_identifier, $._reserved_identifier, $.scoped_type_identifier)),
775
+ field(
776
+ 'type',
777
+ choice(
778
+ $._type_identifier,
779
+ alias(choice(...primitiveTypes), $.type_identifier),
780
+ alias(choice(...reservedIdentifiers), $.identifier),
781
+ $.scoped_type_identifier
782
+ )
783
+ ),
745
784
  field('type_arguments', $.type_arguments)
746
785
  )
747
786
  ),
748
787
 
749
788
  generic_type_with_turbofish: ($) =>
750
789
  seq(
751
- field('type', choice($._type_identifier, $.scoped_identifier)),
790
+ field(
791
+ 'type',
792
+ choice($._type_identifier, alias(choice(...primitiveTypes), $.type_identifier), $.scoped_identifier)
793
+ ),
752
794
  '::',
753
795
  field('type_arguments', $.type_arguments)
754
796
  ),
@@ -762,14 +804,20 @@ module.exports = grammar({
762
804
  type_arguments: ($) =>
763
805
  seq(
764
806
  token(prec(1, '<')),
765
- sepBy1(',', seq(choice($._type, $.type_binding, $.lifetime, $._literal, $.block), optional($.trait_bounds))),
807
+ sepBy1(
808
+ ',',
809
+ choice(
810
+ seq(choice($._type, $.type_binding, $.lifetime, $._literal, $.block), optional($.trait_bounds)),
811
+ prec(1, seq(alias(choice(...primitiveTypes), $.type_identifier), $.trait_bounds))
812
+ )
813
+ ),
766
814
  optional(','),
767
815
  '>'
768
816
  ),
769
817
 
770
818
  type_binding: ($) =>
771
819
  seq(
772
- field('name', $._type_identifier),
820
+ field('name', choice($._type_identifier, alias(choice(...primitiveTypes), $.type_identifier))),
773
821
  field('type_arguments', optional($.type_arguments)),
774
822
  '=',
775
823
  field('type', $._type)
@@ -791,6 +839,7 @@ module.exports = grammar({
791
839
  1,
792
840
  choice(
793
841
  $._type_identifier,
842
+ alias(choice(...primitiveTypes), $.type_identifier),
794
843
  $.scoped_type_identifier,
795
844
  $.removed_trait_bound,
796
845
  $.modified_trait_bound,
@@ -812,6 +861,7 @@ module.exports = grammar({
812
861
  $.higher_ranked_trait_bound,
813
862
  $.modified_trait_bound,
814
863
  $._type_identifier,
864
+ alias(choice(...primitiveTypes), $.type_identifier),
815
865
  $.scoped_type_identifier,
816
866
  $.generic_type,
817
867
  $.function_type,
@@ -908,7 +958,7 @@ module.exports = grammar({
908
958
  optional(choice($._path, $.bracketed_type, alias($.generic_type_with_turbofish, $.generic_type)))
909
959
  ),
910
960
  '::',
911
- field('name', choice($.identifier, $.super))
961
+ field('name', choice($.identifier, $._reserved_identifier, $.super))
912
962
  ),
913
963
 
914
964
  scoped_type_identifier_in_expression_position: ($) =>
@@ -917,7 +967,7 @@ module.exports = grammar({
917
967
  seq(
918
968
  field('path', optional(choice($._path, alias($.generic_type_with_turbofish, $.generic_type)))),
919
969
  '::',
920
- field('name', $._type_identifier)
970
+ field('name', choice($._type_identifier, alias(choice(...reservedIdentifiers), $.type_identifier)))
921
971
  )
922
972
  ),
923
973
 
@@ -930,7 +980,7 @@ module.exports = grammar({
930
980
  )
931
981
  ),
932
982
  '::',
933
- field('name', $._type_identifier)
983
+ field('name', choice($._type_identifier, alias(choice(...reservedIdentifiers), $.type_identifier)))
934
984
  ),
935
985
 
936
986
  range_expression: ($) =>
@@ -1037,6 +1087,7 @@ module.exports = grammar({
1037
1087
  'name',
1038
1088
  choice(
1039
1089
  $._type_identifier,
1090
+ prec.dynamic(-1, alias(choice(...primitiveTypes), $.type_identifier)),
1040
1091
  alias($.scoped_type_identifier_in_expression_position, $.scoped_type_identifier),
1041
1092
  $.generic_type_with_turbofish
1042
1093
  )
@@ -1208,7 +1259,17 @@ module.exports = grammar({
1208
1259
  ),
1209
1260
 
1210
1261
  generic_pattern: ($) =>
1211
- seq(choice($.identifier, $.scoped_identifier), '::', field('type_arguments', $.type_arguments)),
1262
+ seq(
1263
+ choice(
1264
+ $.identifier,
1265
+ $._reserved_identifier,
1266
+ alias(choice(...primitiveTypes), $.identifier),
1267
+ $.scoped_identifier
1268
+ ),
1269
+
1270
+ '::',
1271
+ field('type_arguments', $.type_arguments)
1272
+ ),
1212
1273
 
1213
1274
  tuple_pattern: ($) => seq('(', sepBy(',', choice($._pattern, $.closure_expression)), optional(','), ')'),
1214
1275
 
@@ -1216,7 +1277,16 @@ module.exports = grammar({
1216
1277
 
1217
1278
  tuple_struct_pattern: ($) =>
1218
1279
  seq(
1219
- field('type', choice($.identifier, $.scoped_identifier, alias($.generic_type_with_turbofish, $.generic_type))),
1280
+ field(
1281
+ 'type',
1282
+ choice(
1283
+ $.identifier,
1284
+ $._reserved_identifier,
1285
+ alias(choice(...primitiveTypes), $.identifier),
1286
+ $.scoped_identifier,
1287
+ alias($.generic_type_with_turbofish, $.generic_type)
1288
+ )
1289
+ ),
1220
1290
  '(',
1221
1291
  sepBy(',', $._pattern),
1222
1292
  optional(','),
@@ -1227,7 +1297,12 @@ module.exports = grammar({
1227
1297
  seq(
1228
1298
  field(
1229
1299
  'type',
1230
- choice($._type_identifier, $.scoped_type_identifier, alias($._generic_struct_pattern_type, $.generic_type))
1300
+ choice(
1301
+ $._type_identifier,
1302
+ alias(choice(...primitiveTypes), $.type_identifier),
1303
+ $.scoped_type_identifier,
1304
+ alias($._generic_struct_pattern_type, $.generic_type)
1305
+ )
1231
1306
  ),
1232
1307
  '{',
1233
1308
  sepBy(',', choice($.field_pattern, $.remaining_field_pattern)),
@@ -1237,7 +1312,10 @@ module.exports = grammar({
1237
1312
 
1238
1313
  _generic_struct_pattern_type: ($) =>
1239
1314
  seq(
1240
- field('type', choice($._type_identifier, $.scoped_type_identifier)),
1315
+ field(
1316
+ 'type',
1317
+ choice($._type_identifier, alias(choice(...primitiveTypes), $.type_identifier), $.scoped_type_identifier)
1318
+ ),
1241
1319
  '::',
1242
1320
  field('type_arguments', $.type_arguments)
1243
1321
  ),
@@ -1268,7 +1346,12 @@ module.exports = grammar({
1268
1346
 
1269
1347
  ref_pattern: ($) => seq('ref', $._pattern),
1270
1348
 
1271
- captured_pattern: ($) => seq($.identifier, '@', $._pattern),
1349
+ captured_pattern: ($) =>
1350
+ seq(
1351
+ choice($.identifier, $._reserved_identifier, alias(choice(...primitiveTypes), $.identifier)),
1352
+ '@',
1353
+ $._pattern
1354
+ ),
1272
1355
 
1273
1356
  reference_pattern: ($) => seq('&', optional($.mutable_specifier), $._pattern),
1274
1357
 
@@ -1413,9 +1496,9 @@ module.exports = grammar({
1413
1496
  // oxlint-disable-next-line no-useless-escape -- tree-sitter's regex parser rejects an unescaped `[` in a character class.
1414
1497
  shebang: () => /#![\r\f\t\v ]*([^\[\n].*)?\n/,
1415
1498
 
1416
- _reserved_identifier: ($) => alias(choice('default', 'union', 'gen', 'raw'), $.identifier),
1499
+ _reserved_identifier: ($) => alias(choice(...reservedIdentifiers, 'auto'), $.identifier),
1417
1500
 
1418
- _type_identifier: ($) => alias($.identifier, $.type_identifier),
1501
+ _type_identifier: ($) => alias(choice($.identifier, 'auto'), $.type_identifier),
1419
1502
  _field_identifier: ($) => alias($.identifier, $.field_identifier),
1420
1503
 
1421
1504
  self: () => 'self',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -97,6 +97,7 @@
97
97
 
98
98
  "as" @keyword
99
99
  "async" @keyword
100
+ "auto" @keyword
100
101
  "await" @keyword
101
102
  "become" @keyword
102
103
  "break" @keyword
@@ -5444,6 +5444,10 @@
5444
5444
  "type": "async",
5445
5445
  "named": false
5446
5446
  },
5447
+ {
5448
+ "type": "auto",
5449
+ "named": false
5450
+ },
5447
5451
  {
5448
5452
  "type": "await",
5449
5453
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -22,7 +22,7 @@
22
22
  }
23
23
  ],
24
24
  "metadata": {
25
- "version": "1.8.0",
25
+ "version": "1.9.0",
26
26
  "license": "MIT",
27
27
  "description": "Rust grammar for tree-sitter",
28
28
  "authors": [