@willbooster/tree-sitter-rust 3.0.0 → 3.0.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/grammar.js CHANGED
@@ -6,9 +6,11 @@
6
6
  * @license MIT
7
7
  */
8
8
 
9
- /// <reference types="tree-sitter-cli/dsl" />
10
9
  // @ts-check
11
10
 
11
+ const { alias, choice, field, grammar, optional, prec, repeat, repeat1, seq, sym, token } =
12
+ /** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
13
+
12
14
  // https://doc.rust-lang.org/reference/expressions.html#expression-precedence
13
15
  const PREC = {
14
16
  call: 15,
@@ -118,22 +120,22 @@ module.exports = grammar({
118
120
 
119
121
  extras: ($) => [/\s/, $.line_comment, $.block_comment],
120
122
 
121
- externals: ($) => [
122
- $.string_content,
123
- $.string_close,
124
- $._raw_string_literal_start,
125
- $._raw_string_literal_content,
126
- $._raw_string_literal_end,
127
- $._trailing_dot_float_literal,
128
- $._outer_block_doc_comment_marker,
129
- $._inner_block_doc_comment_marker,
130
- $._block_comment_content,
131
- $._line_doc_content,
132
- $._range_unary_endpoint_start,
133
- $._error_sentinel,
134
- $._foreign_declaration_context,
135
- $._foreign_declaration_start,
136
- $._macro_metavariable_name,
123
+ externals: () => [
124
+ sym('string_content'),
125
+ sym('string_close'),
126
+ sym('_raw_string_literal_start'),
127
+ sym('_raw_string_literal_content'),
128
+ sym('_raw_string_literal_end'),
129
+ sym('_trailing_dot_float_literal'),
130
+ sym('_outer_block_doc_comment_marker'),
131
+ sym('_inner_block_doc_comment_marker'),
132
+ sym('_block_comment_content'),
133
+ sym('_line_doc_content'),
134
+ sym('_range_unary_endpoint_start'),
135
+ sym('_error_sentinel'),
136
+ sym('_foreign_declaration_context'),
137
+ sym('_foreign_declaration_start'),
138
+ sym('_macro_metavariable_name'),
137
139
  ],
138
140
 
139
141
  supertypes: ($) => [$._declaration_statement, $._expression, $._type, $._literal, $._literal_pattern, $._pattern],
@@ -264,9 +266,9 @@ module.exports = grammar({
264
266
  ')',
265
267
  optional(
266
268
  macroRepetitionSeparator(
267
- $._raw_string_literal_start,
268
- $._raw_string_literal_content,
269
- $._raw_string_literal_end
269
+ sym('_raw_string_literal_start'),
270
+ sym('_raw_string_literal_content'),
271
+ sym('_raw_string_literal_end')
270
272
  )
271
273
  ),
272
274
  choice('+', '*', '?')
@@ -307,9 +309,9 @@ module.exports = grammar({
307
309
  ')',
308
310
  optional(
309
311
  macroRepetitionSeparator(
310
- $._raw_string_literal_start,
311
- $._raw_string_literal_content,
312
- $._raw_string_literal_end
312
+ sym('_raw_string_literal_start'),
313
+ sym('_raw_string_literal_content'),
314
+ sym('_raw_string_literal_end')
313
315
  )
314
316
  ),
315
317
  choice('+', '*', '?')
@@ -324,7 +326,7 @@ module.exports = grammar({
324
326
  $.self,
325
327
  $.super,
326
328
  $.crate,
327
- alias(choice(...primitiveTypes.filter((type) => !extendedFloatTypes.includes(type))), $.primitive_type),
329
+ alias(choice(...primitiveTypes.filter((type) => !extendedFloatTypes.includes(type))), sym('primitive_type')),
328
330
  alias(choice(...extendedFloatTypes), $.identifier),
329
331
  prec.right(repeat1(choice(...TOKEN_TREE_NON_SPECIAL_PUNCTUATION))),
330
332
  "'",
@@ -392,11 +394,11 @@ module.exports = grammar({
392
394
  // `_foreign_declaration_start` required by qualified extern items. Keep this context marker so `safe` remains
393
395
  // an identifier outside extern blocks while qualified items still participate in declaration supertype queries.
394
396
  _foreign_declaration_list: ($) =>
395
- seq('{', repeat(seq(optional($._foreign_declaration_context), $._declaration_statement)), '}'),
397
+ seq('{', repeat(seq(optional(sym('_foreign_declaration_context')), $._declaration_statement)), '}'),
396
398
 
397
399
  _safe_function_signature_item: ($) =>
398
400
  seq(
399
- $._foreign_declaration_start,
401
+ sym('_foreign_declaration_start'),
400
402
  optional($.visibility_modifier),
401
403
  alias($._safe_modifier, $.function_modifiers),
402
404
  $._function_signature
@@ -408,7 +410,7 @@ module.exports = grammar({
408
410
 
409
411
  _qualified_static_item: ($) =>
410
412
  seq(
411
- $._foreign_declaration_start,
413
+ sym('_foreign_declaration_start'),
412
414
  optional($.visibility_modifier),
413
415
  choice('safe', 'unsafe'),
414
416
  $._static_declaration
@@ -421,9 +423,8 @@ module.exports = grammar({
421
423
  field('name', $._type_identifier),
422
424
  field('type_parameters', optional($.type_parameters)),
423
425
  choice(
424
- seq(optional($.where_clause), field('body', $.field_declaration_list)),
425
- seq(field('body', $.ordered_field_declaration_list), optional($.where_clause), ';'),
426
- ';'
426
+ seq(optional($.where_clause), choice(field('body', $.field_declaration_list), ';')),
427
+ seq(field('body', $.ordered_field_declaration_list), optional($.where_clause), ';')
427
428
  )
428
429
  ),
429
430
 
@@ -567,7 +568,7 @@ module.exports = grammar({
567
568
  $.tuple_type,
568
569
  $.array_type,
569
570
  $.higher_ranked_trait_bound,
570
- alias(choice(...primitiveTypes), $.primitive_type)
571
+ alias(choice(...primitiveTypes), sym('primitive_type'))
571
572
  )
572
573
  ),
573
574
  field('bounds', $.trait_bounds)
@@ -586,7 +587,7 @@ module.exports = grammar({
586
587
  'trait',
587
588
  choice(
588
589
  $._type_identifier,
589
- alias(choice(...primitiveTypes), $.type_identifier),
590
+ alias(choice(...primitiveTypes), sym('type_identifier')),
590
591
  $.scoped_type_identifier,
591
592
  $.generic_type
592
593
  )
@@ -682,7 +683,7 @@ module.exports = grammar({
682
683
  prec(
683
684
  1,
684
685
  seq(
685
- field('name', choice($._type_identifier, alias(choice(...primitiveTypes), $.type_identifier))),
686
+ field('name', choice($._type_identifier, alias(choice(...primitiveTypes), sym('type_identifier')))),
686
687
  optional(field('bounds', $.trait_bounds)),
687
688
  optional(seq('=', field('default_type', $._type)))
688
689
  )
@@ -756,7 +757,7 @@ module.exports = grammar({
756
757
  $.bounded_type,
757
758
  $.removed_trait_bound,
758
759
  $.modified_trait_bound,
759
- alias(choice(...primitiveTypes), $.primitive_type)
760
+ alias(choice(...primitiveTypes), sym('primitive_type'))
760
761
  ),
761
762
 
762
763
  bracketed_type: ($) => seq('<', choice($._type, $.qualified_type), '>'),
@@ -781,7 +782,7 @@ module.exports = grammar({
781
782
  choice(
782
783
  $._type_identifier,
783
784
  $.scoped_type_identifier,
784
- alias(choice(...primitiveTypes), $.type_identifier)
785
+ alias(choice(...primitiveTypes), sym('type_identifier'))
785
786
  )
786
787
  ),
787
788
  seq(optional($.function_modifiers), 'fn')
@@ -823,7 +824,7 @@ module.exports = grammar({
823
824
  'type',
824
825
  choice(
825
826
  $._type_identifier,
826
- alias(choice(...primitiveTypes), $.type_identifier),
827
+ alias(choice(...primitiveTypes), sym('type_identifier')),
827
828
  alias(choice(...reservedIdentifiers), $.identifier),
828
829
  $.scoped_type_identifier
829
830
  )
@@ -838,7 +839,7 @@ module.exports = grammar({
838
839
  'type',
839
840
  choice(
840
841
  $._type_identifier,
841
- alias(choice(...primitiveTypes, ...reservedIdentifiers), $.type_identifier),
842
+ alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
842
843
  $.scoped_identifier
843
844
  )
844
845
  ),
@@ -859,7 +860,7 @@ module.exports = grammar({
859
860
  ',',
860
861
  choice(
861
862
  seq(choice($._type, $.type_binding, $.lifetime, $._literal, $.block), optional($.trait_bounds)),
862
- prec(1, seq(alias(choice(...primitiveTypes), $.type_identifier), $.trait_bounds))
863
+ prec(1, seq(alias(choice(...primitiveTypes), sym('type_identifier')), $.trait_bounds))
863
864
  )
864
865
  ),
865
866
  optional(','),
@@ -868,7 +869,7 @@ module.exports = grammar({
868
869
 
869
870
  type_binding: ($) =>
870
871
  seq(
871
- field('name', choice($._type_identifier, alias(choice(...primitiveTypes), $.type_identifier))),
872
+ field('name', choice($._type_identifier, alias(choice(...primitiveTypes), sym('type_identifier')))),
872
873
  field('type_arguments', optional($.type_arguments)),
873
874
  '=',
874
875
  field('type', $._type)
@@ -890,7 +891,7 @@ module.exports = grammar({
890
891
  1,
891
892
  choice(
892
893
  $._type_identifier,
893
- alias(choice(...primitiveTypes), $.type_identifier),
894
+ alias(choice(...primitiveTypes), sym('type_identifier')),
894
895
  $.scoped_type_identifier,
895
896
  $.removed_trait_bound,
896
897
  $.modified_trait_bound,
@@ -912,7 +913,7 @@ module.exports = grammar({
912
913
  $.higher_ranked_trait_bound,
913
914
  $.modified_trait_bound,
914
915
  $._type_identifier,
915
- alias(choice(...primitiveTypes), $.type_identifier),
916
+ alias(choice(...primitiveTypes), sym('type_identifier')),
916
917
  $.scoped_type_identifier,
917
918
  $.generic_type,
918
919
  $.function_type,
@@ -1021,7 +1022,7 @@ module.exports = grammar({
1021
1022
  seq(
1022
1023
  field('path', optional(choice($._path, alias($.generic_type_with_turbofish, $.generic_type)))),
1023
1024
  '::',
1024
- field('name', choice($._type_identifier, alias(choice(...reservedIdentifiers), $.type_identifier)))
1025
+ field('name', choice($._type_identifier, alias(choice(...reservedIdentifiers), sym('type_identifier'))))
1025
1026
  )
1026
1027
  ),
1027
1028
 
@@ -1034,7 +1035,7 @@ module.exports = grammar({
1034
1035
  )
1035
1036
  ),
1036
1037
  '::',
1037
- field('name', choice($._type_identifier, alias(choice(...reservedIdentifiers), $.type_identifier)))
1038
+ field('name', choice($._type_identifier, alias(choice(...reservedIdentifiers), sym('type_identifier'))))
1038
1039
  ),
1039
1040
 
1040
1041
  range_expression: ($) =>
@@ -1044,9 +1045,9 @@ module.exports = grammar({
1044
1045
  prec.left(PREC.range, seq(choice('..', '..='), $._expression)),
1045
1046
  prec.right(
1046
1047
  PREC.range + 1,
1047
- seq($._expression, choice('..', '..='), $._range_unary_endpoint_start, $._expression)
1048
+ seq($._expression, choice('..', '..='), sym('_range_unary_endpoint_start'), $._expression)
1048
1049
  ),
1049
- prec.right(PREC.range + 1, seq(choice('..', '..='), $._range_unary_endpoint_start, $._expression)),
1050
+ prec.right(PREC.range + 1, seq(choice('..', '..='), sym('_range_unary_endpoint_start'), $._expression)),
1050
1051
  prec.left(PREC.range, '..')
1051
1052
  ),
1052
1053
 
@@ -1065,7 +1066,7 @@ module.exports = grammar({
1065
1066
  ),
1066
1067
 
1067
1068
  binary_expression: ($) => {
1068
- /** @type {[number, RuleOrLiteral][]} */
1069
+ /** @type {[number, import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral][]} */
1069
1070
  const table = [
1070
1071
  [PREC.and, '&&'],
1071
1072
  [PREC.or, '||'],
@@ -1146,7 +1147,7 @@ module.exports = grammar({
1146
1147
  'name',
1147
1148
  choice(
1148
1149
  $._type_identifier,
1149
- prec.dynamic(-1, alias(choice(...primitiveTypes, ...reservedIdentifiers), $.type_identifier)),
1150
+ prec.dynamic(-1, alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier'))),
1150
1151
  alias($.scoped_type_identifier_in_expression_position, $.scoped_type_identifier),
1151
1152
  $.generic_type_with_turbofish
1152
1153
  )
@@ -1172,7 +1173,7 @@ module.exports = grammar({
1172
1173
  'field',
1173
1174
  choice(
1174
1175
  $._field_identifier,
1175
- alias(choice(...fieldIdentifierKeywords), $.field_identifier),
1176
+ alias(choice(...fieldIdentifierKeywords), sym('field_identifier')),
1176
1177
  alias(/[0-9][0-9_]*/, $.integer_literal)
1177
1178
  )
1178
1179
  ),
@@ -1207,7 +1208,7 @@ module.exports = grammar({
1207
1208
  )
1208
1209
  ),
1209
1210
 
1210
- _condition: ($) => choice($._expression, $.let_condition, alias($._let_chain, $.let_chain)),
1211
+ _condition: ($) => choice($._expression, $.let_condition, alias($._let_chain, sym('let_chain'))),
1211
1212
 
1212
1213
  else_clause: ($) => seq('else', choice($.block, $.if_expression)),
1213
1214
 
@@ -1366,7 +1367,7 @@ module.exports = grammar({
1366
1367
  'type',
1367
1368
  choice(
1368
1369
  $._type_identifier,
1369
- alias(choice(...primitiveTypes, ...reservedIdentifiers), $.type_identifier),
1370
+ alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
1370
1371
  $.scoped_type_identifier,
1371
1372
  alias($._generic_struct_pattern_type, $.generic_type)
1372
1373
  )
@@ -1383,7 +1384,7 @@ module.exports = grammar({
1383
1384
  'type',
1384
1385
  choice(
1385
1386
  $._type_identifier,
1386
- alias(choice(...primitiveTypes, ...reservedIdentifiers), $.type_identifier),
1387
+ alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
1387
1388
  $.scoped_type_identifier
1388
1389
  )
1389
1390
  ),
@@ -1397,7 +1398,7 @@ module.exports = grammar({
1397
1398
  optional('ref'),
1398
1399
  optional($.mutable_specifier),
1399
1400
  choice(
1400
- field('name', alias($.identifier, $.shorthand_field_identifier)),
1401
+ field('name', alias($.identifier, sym('shorthand_field_identifier'))),
1401
1402
  seq(field('name', $._field_identifier), ':', field('pattern', $._pattern))
1402
1403
  )
1403
1404
  ),
@@ -1467,9 +1468,9 @@ module.exports = grammar({
1467
1468
  )
1468
1469
  ),
1469
1470
 
1470
- float_literal: ($) =>
1471
+ float_literal: () =>
1471
1472
  choice(
1472
- $._trailing_dot_float_literal,
1473
+ sym('_trailing_dot_float_literal'),
1473
1474
  token(
1474
1475
  prec(
1475
1476
  1,
@@ -1488,13 +1489,17 @@ module.exports = grammar({
1488
1489
  ),
1489
1490
 
1490
1491
  string_literal: ($) =>
1491
- seq(alias(/[bc]?"/, '"'), repeat(choice($.escape_sequence, $.string_content)), alias($.string_close, '"')),
1492
+ seq(
1493
+ alias(/[bc]?"/, '"'),
1494
+ repeat(choice($.escape_sequence, sym('string_content'))),
1495
+ alias(sym('string_close'), '"')
1496
+ ),
1492
1497
 
1493
- raw_string_literal: ($) =>
1498
+ raw_string_literal: () =>
1494
1499
  seq(
1495
- $._raw_string_literal_start,
1496
- alias($._raw_string_literal_content, $.string_content),
1497
- $._raw_string_literal_end
1500
+ sym('_raw_string_literal_start'),
1501
+ alias(sym('_raw_string_literal_content'), sym('string_content')),
1502
+ sym('_raw_string_literal_end')
1498
1503
  ),
1499
1504
 
1500
1505
  char_literal: () =>
@@ -1521,15 +1526,15 @@ module.exports = grammar({
1521
1526
  '//',
1522
1527
  choice(
1523
1528
  seq(token.immediate(prec(2, /\/\//)), /.*/),
1524
- seq($._line_doc_comment_marker, field('doc', alias($._line_doc_content, $.doc_comment))),
1529
+ seq($._line_doc_comment_marker, field('doc', alias(sym('_line_doc_content'), sym('doc_comment')))),
1525
1530
  token.immediate(prec(1, /.*/))
1526
1531
  )
1527
1532
  ),
1528
1533
 
1529
1534
  _line_doc_comment_marker: ($) =>
1530
1535
  choice(
1531
- field('outer', alias($._outer_line_doc_comment_marker, $.outer_doc_comment_marker)),
1532
- field('inner', alias($._inner_line_doc_comment_marker, $.inner_doc_comment_marker))
1536
+ field('outer', alias($._outer_line_doc_comment_marker, sym('outer_doc_comment_marker'))),
1537
+ field('inner', alias($._inner_line_doc_comment_marker, sym('inner_doc_comment_marker')))
1533
1538
  ),
1534
1539
 
1535
1540
  _inner_line_doc_comment_marker: () => token.immediate(prec(2, '!')),
@@ -1540,17 +1545,20 @@ module.exports = grammar({
1540
1545
  '/*',
1541
1546
  optional(
1542
1547
  choice(
1543
- seq($._block_doc_comment_marker, optional(field('doc', alias($._block_comment_content, $.doc_comment)))),
1544
- $._block_comment_content
1548
+ seq(
1549
+ $._block_doc_comment_marker,
1550
+ optional(field('doc', alias(sym('_block_comment_content'), sym('doc_comment'))))
1551
+ ),
1552
+ sym('_block_comment_content')
1545
1553
  )
1546
1554
  ),
1547
1555
  '*/'
1548
1556
  ),
1549
1557
 
1550
- _block_doc_comment_marker: ($) =>
1558
+ _block_doc_comment_marker: () =>
1551
1559
  choice(
1552
- field('outer', alias($._outer_block_doc_comment_marker, $.outer_doc_comment_marker)),
1553
- field('inner', alias($._inner_block_doc_comment_marker, $.inner_doc_comment_marker))
1560
+ field('outer', alias(sym('_outer_block_doc_comment_marker'), sym('outer_doc_comment_marker'))),
1561
+ field('inner', alias(sym('_inner_block_doc_comment_marker'), sym('inner_doc_comment_marker')))
1554
1562
  ),
1555
1563
 
1556
1564
  _path: ($) =>
@@ -1572,24 +1580,24 @@ module.exports = grammar({
1572
1580
 
1573
1581
  _reserved_identifier: ($) => alias(choice(...reservedIdentifiers, 'auto', 'macro_rules'), $.identifier),
1574
1582
 
1575
- _type_identifier: ($) => alias(choice($.identifier, 'auto', 'macro_rules'), $.type_identifier),
1576
- _field_identifier: ($) => alias($.identifier, $.field_identifier),
1583
+ _type_identifier: ($) => alias(choice($.identifier, 'auto', 'macro_rules'), sym('type_identifier')),
1584
+ _field_identifier: ($) => alias($.identifier, sym('field_identifier')),
1577
1585
 
1578
1586
  self: () => 'self',
1579
1587
  super: () => 'super',
1580
1588
  crate: () => 'crate',
1581
1589
 
1582
1590
  _macro_metavariable: ($) => choice($.metavariable, alias($._spaced_metavariable, $.metavariable)),
1583
- _spaced_metavariable: ($) =>
1584
- prec.dynamic(1, seq('$', choice($._macro_metavariable_name, token(prec(1, nonAsciiOrRawMacroName))))),
1591
+ _spaced_metavariable: () =>
1592
+ prec.dynamic(1, seq('$', choice(sym('_macro_metavariable_name'), token(prec(1, nonAsciiOrRawMacroName))))),
1585
1593
  metavariable: () => /\$(r#)?[_\p{XID_Start}][_\p{XID_Continue}]*/u,
1586
1594
  },
1587
1595
  });
1588
1596
 
1589
1597
  /**
1590
- * @param {RuleOrLiteral} start
1591
- * @param {RuleOrLiteral} content
1592
- * @param {RuleOrLiteral} end
1598
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} start
1599
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} content
1600
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} end
1593
1601
  */
1594
1602
  function macroRepetitionSeparator(start, content, end) {
1595
1603
  return choice(
@@ -1601,20 +1609,20 @@ function macroRepetitionSeparator(start, content, end) {
1601
1609
  }
1602
1610
 
1603
1611
  /**
1604
- * @param {RuleOrLiteral} sep
1605
- * @param {RuleOrLiteral} rule
1612
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} sep
1613
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
1606
1614
  *
1607
- * @returns {SeqRule}
1615
+ * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
1608
1616
  */
1609
1617
  function sepBy1(sep, rule) {
1610
1618
  return seq(rule, repeat(seq(sep, rule)));
1611
1619
  }
1612
1620
 
1613
1621
  /**
1614
- * @param {RuleOrLiteral} sep
1615
- * @param {RuleOrLiteral} rule
1622
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} sep
1623
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
1616
1624
  *
1617
- * @returns {ChoiceRule}
1625
+ * @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
1618
1626
  */
1619
1627
  function sepBy(sep, rule) {
1620
1628
  return optional(sepBy1(sep, rule));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -56,7 +56,6 @@
56
56
  "playwright": "1.63.0",
57
57
  "semantic-release": "25.0.9",
58
58
  "sort-package-json": "4.0.0",
59
- "tree-sitter-cli": "0.27.0",
60
59
  "typescript": "7.0.2",
61
60
  "vite": "8.3.2",
62
61
  "vitest": "5.0.3",
Binary file
package/tree-sitter.json CHANGED
@@ -22,7 +22,7 @@
22
22
  }
23
23
  ],
24
24
  "metadata": {
25
- "version": "3.0.0",
25
+ "version": "3.0.2",
26
26
  "license": "MIT",
27
27
  "description": "Rust grammar for tree-sitter",
28
28
  "authors": [