@willbooster/tree-sitter-rust 1.1.15 → 1.2.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
@@ -166,6 +166,7 @@ module.exports = grammar({
166
166
  $.const_item,
167
167
  $.macro_invocation,
168
168
  $.macro_definition,
169
+ $.decl_macro,
169
170
  $.empty_statement,
170
171
  $.attribute_item,
171
172
  $.inner_attribute_item,
@@ -179,6 +180,7 @@ module.exports = grammar({
179
180
  $.function_signature_item,
180
181
  $.impl_item,
181
182
  $.trait_item,
183
+ $.trait_alias,
182
184
  $.associated_type,
183
185
  $.let_declaration,
184
186
  $.use_declaration,
@@ -186,8 +188,6 @@ module.exports = grammar({
186
188
  $.static_item
187
189
  ),
188
190
 
189
- // Section - Macro definitions
190
-
191
191
  macro_definition: ($) => {
192
192
  const rules = seq(repeat(seq($.macro_rule, ';')), optional($.macro_rule));
193
193
 
@@ -198,6 +198,15 @@ module.exports = grammar({
198
198
  );
199
199
  },
200
200
 
201
+ decl_macro: ($) =>
202
+ seq(
203
+ optional($.visibility_modifier),
204
+ 'macro',
205
+ field('name', choice($.identifier, $._reserved_identifier)),
206
+ field('parameters', optional(alias($._parenthesized_token_tree, $.token_tree))),
207
+ field('body', alias($._braced_token_tree, $.token_tree))
208
+ ),
209
+
201
210
  macro_rule: ($) => seq(field('left', $.token_tree_pattern), '=>', field('right', $.token_tree)),
202
211
 
203
212
  _token_pattern: ($) =>
@@ -247,9 +256,6 @@ module.exports = grammar({
247
256
 
248
257
  token_repetition: ($) => seq('$', '(', repeat($._tokens), ')', optional(/[^+*?]+/), choice('+', '*', '?')),
249
258
 
250
- // Matches non-delimiter tokens common to both macro invocations and
251
- // definitions. This is everything except $ and metavariables (which begin
252
- // with $).
253
259
  _non_special_token: ($) =>
254
260
  choice(
255
261
  $._literal,
@@ -291,8 +297,6 @@ module.exports = grammar({
291
297
  'while'
292
298
  ),
293
299
 
294
- // Section - Declarations
295
-
296
300
  attribute_item: ($) => seq('#', '[', $.attribute, ']'),
297
301
 
298
302
  inner_attribute_item: ($) => seq('#', '!', '[', $.attribute, ']'),
@@ -536,6 +540,22 @@ module.exports = grammar({
536
540
  field('body', $.declaration_list)
537
541
  ),
538
542
 
543
+ trait_alias: ($) =>
544
+ seq(
545
+ optional($.visibility_modifier),
546
+ optional('const'),
547
+ 'trait',
548
+ field('name', $._type_identifier),
549
+ field('type_parameters', optional($.type_parameters)),
550
+ '=',
551
+ field('bounds', optional($.trait_alias_bounds)),
552
+ optional($.where_clause),
553
+ ';'
554
+ ),
555
+
556
+ trait_alias_bounds: ($) =>
557
+ seq(sepBy1('+', choice($._type, $.lifetime, $.higher_ranked_trait_bound)), optional('+')),
558
+
539
559
  associated_type: ($) =>
540
560
  seq(
541
561
  'type',
@@ -637,8 +657,6 @@ module.exports = grammar({
637
657
  visibility_modifier: ($) =>
638
658
  choice($.crate, seq('pub', optional(seq('(', choice($.self, $.super, $.crate, seq('in', $._path)), ')')))),
639
659
 
640
- // Section - Types
641
-
642
660
  _type: ($) =>
643
661
  choice(
644
662
  $.abstract_type,
@@ -783,8 +801,6 @@ module.exports = grammar({
783
801
 
784
802
  mutable_specifier: () => 'mut',
785
803
 
786
- // Section - Expressions
787
-
788
804
  _expression_except_range: ($) =>
789
805
  choice(
790
806
  $.unary_expression,
@@ -853,15 +869,14 @@ module.exports = grammar({
853
869
  ),
854
870
 
855
871
  delim_token_tree: ($) =>
856
- choice(
857
- seq('(', repeat($._delim_tokens), ')'),
858
- seq('[', repeat($._delim_tokens), ']'),
859
- seq('{', repeat($._delim_tokens), '}')
860
- ),
872
+ choice($._parenthesized_token_tree, seq('[', repeat($._delim_tokens), ']'), $._braced_token_tree),
873
+
874
+ _parenthesized_token_tree: ($) => seq('(', repeat($._delim_tokens), ')'),
875
+
876
+ _braced_token_tree: ($) => seq('{', repeat($._delim_tokens), '}'),
861
877
 
862
878
  _delim_tokens: ($) => choice($._non_delim_token, alias($.delim_token_tree, $.token_tree)),
863
879
 
864
- // Should match any token other than a delimiter.
865
880
  _non_delim_token: ($) => choice($._non_special_token, '$'),
866
881
 
867
882
  scoped_identifier: ($) =>
@@ -1144,8 +1159,6 @@ module.exports = grammar({
1144
1159
 
1145
1160
  block: ($) => seq(optional(seq($.label, ':')), '{', repeat($._statement), optional($._expression), '}'),
1146
1161
 
1147
- // Section - Patterns
1148
-
1149
1162
  _pattern: ($) =>
1150
1163
  choice(
1151
1164
  $._literal_pattern,
@@ -1226,8 +1239,6 @@ module.exports = grammar({
1226
1239
 
1227
1240
  or_pattern: ($) => prec.left(-2, choice(seq($._pattern, '|', $._pattern), seq('|', $._pattern))),
1228
1241
 
1229
- // Section - Literals
1230
-
1231
1242
  _literal: ($) =>
1232
1243
  choice(
1233
1244
  $.string_literal,
@@ -1315,16 +1326,9 @@ module.exports = grammar({
1315
1326
 
1316
1327
  line_comment: ($) =>
1317
1328
  seq(
1318
- // All line comments start with two //
1319
1329
  '//',
1320
- // Then are followed by:
1321
- // - 2 or more slashes making it a regular comment
1322
- // - 1 slash or 1 or more bang operators making it a doc comment
1323
- // - or just content for the comment
1324
1330
  choice(
1325
- // A tricky edge case where what looks like a doc comment is not
1326
1331
  seq(token.immediate(prec(2, /\/\//)), /.*/),
1327
- // A regular doc comment
1328
1332
  seq($._line_doc_comment_marker, field('doc', alias($._line_doc_content, $.doc_comment))),
1329
1333
  token.immediate(prec(1, /.*/))
1330
1334
  )
@@ -1332,9 +1336,7 @@ module.exports = grammar({
1332
1336
 
1333
1337
  _line_doc_comment_marker: ($) =>
1334
1338
  choice(
1335
- // An outer line doc comment applies to the element that it is outside of
1336
1339
  field('outer', alias($._outer_line_doc_comment_marker, $.outer_doc_comment_marker)),
1337
- // An inner line doc comment applies to the element it is inside of
1338
1340
  field('inner', alias($._inner_line_doc_comment_marker, $.inner_doc_comment_marker))
1339
1341
  ),
1340
1342
 
@@ -1346,9 +1348,7 @@ module.exports = grammar({
1346
1348
  '/*',
1347
1349
  optional(
1348
1350
  choice(
1349
- // Documentation block comments: /** docs */ or /*! docs */
1350
1351
  seq($._block_doc_comment_marker, optional(field('doc', alias($._block_comment_content, $.doc_comment)))),
1351
- // Non-doc block comments
1352
1352
  $._block_comment_content
1353
1353
  )
1354
1354
  ),
@@ -1392,9 +1392,7 @@ module.exports = grammar({
1392
1392
  });
1393
1393
 
1394
1394
  /**
1395
- * Creates a rule to match one or more of the rules separated by the separator.
1396
- *
1397
- * @param {RuleOrLiteral} sep - The separator to use.
1395
+ * @param {RuleOrLiteral} sep
1398
1396
  * @param {RuleOrLiteral} rule
1399
1397
  *
1400
1398
  * @returns {SeqRule}
@@ -1404,9 +1402,7 @@ function sepBy1(sep, rule) {
1404
1402
  }
1405
1403
 
1406
1404
  /**
1407
- * Creates a rule to optionally match one or more of the rules separated by the separator.
1408
- *
1409
- * @param {RuleOrLiteral} sep - The separator to use.
1405
+ * @param {RuleOrLiteral} sep
1410
1406
  * @param {RuleOrLiteral} rule
1411
1407
  *
1412
1408
  * @returns {ChoiceRule}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "1.1.15",
3
+ "version": "1.2.0",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -62,6 +62,8 @@
62
62
  macro: (identifier) @function.macro
63
63
  "!" @function.macro)
64
64
 
65
+ (decl_macro name: (identifier) @function.macro)
66
+
65
67
  ; Function definitions
66
68
 
67
69
  (function_item (identifier) @function)
@@ -117,6 +119,7 @@
117
119
  "let" @keyword
118
120
  "loop" @keyword
119
121
  "macro_rules!" @keyword
122
+ "macro" @keyword
120
123
  "match" @keyword
121
124
  "mod" @keyword
122
125
  "move" @keyword
@@ -7,3 +7,9 @@
7
7
  (token_tree) @injection.content)
8
8
  (#set! injection.language "rust")
9
9
  (#set! injection.include-children))
10
+
11
+ ((decl_macro
12
+ parameters: (token_tree)
13
+ body: (token_tree) @injection.content)
14
+ (#set! injection.language "rust")
15
+ (#set! injection.include-children))
package/queries/tags.scm CHANGED
@@ -29,6 +29,9 @@
29
29
  (trait_item
30
30
  name: (type_identifier) @name) @definition.interface
31
31
 
32
+ (trait_alias
33
+ name: (type_identifier) @name) @definition.interface
34
+
32
35
  ; module definitions
33
36
  (mod_item
34
37
  name: (identifier) @name) @definition.module
@@ -38,6 +41,9 @@
38
41
  (macro_definition
39
42
  name: (identifier) @name) @definition.macro
40
43
 
44
+ (decl_macro
45
+ name: (identifier) @name) @definition.macro
46
+
41
47
  ; references
42
48
 
43
49
  (call_expression
@@ -822,6 +822,10 @@
822
822
  "type": "const_item",
823
823
  "named": true
824
824
  },
825
+ {
826
+ "type": "decl_macro",
827
+ "named": true
828
+ },
825
829
  {
826
830
  "type": "empty_statement",
827
831
  "named": true
@@ -882,6 +886,10 @@
882
886
  "type": "struct_item",
883
887
  "named": true
884
888
  },
889
+ {
890
+ "type": "trait_alias",
891
+ "named": true
892
+ },
885
893
  {
886
894
  "type": "trait_item",
887
895
  "named": true
@@ -1453,6 +1461,52 @@
1453
1461
  ]
1454
1462
  }
1455
1463
  },
1464
+ {
1465
+ "type": "decl_macro",
1466
+ "named": true,
1467
+ "fields": {
1468
+ "body": {
1469
+ "multiple": false,
1470
+ "required": true,
1471
+ "types": [
1472
+ {
1473
+ "type": "token_tree",
1474
+ "named": true
1475
+ }
1476
+ ]
1477
+ },
1478
+ "name": {
1479
+ "multiple": false,
1480
+ "required": true,
1481
+ "types": [
1482
+ {
1483
+ "type": "identifier",
1484
+ "named": true
1485
+ }
1486
+ ]
1487
+ },
1488
+ "parameters": {
1489
+ "multiple": false,
1490
+ "required": false,
1491
+ "types": [
1492
+ {
1493
+ "type": "token_tree",
1494
+ "named": true
1495
+ }
1496
+ ]
1497
+ }
1498
+ },
1499
+ "children": {
1500
+ "multiple": false,
1501
+ "required": false,
1502
+ "types": [
1503
+ {
1504
+ "type": "visibility_modifier",
1505
+ "named": true
1506
+ }
1507
+ ]
1508
+ }
1509
+ },
1456
1510
  {
1457
1511
  "type": "declaration_list",
1458
1512
  "named": true,
@@ -1473,6 +1527,10 @@
1473
1527
  "type": "const_item",
1474
1528
  "named": true
1475
1529
  },
1530
+ {
1531
+ "type": "decl_macro",
1532
+ "named": true
1533
+ },
1476
1534
  {
1477
1535
  "type": "empty_statement",
1478
1536
  "named": true
@@ -1529,6 +1587,10 @@
1529
1587
  "type": "struct_item",
1530
1588
  "named": true
1531
1589
  },
1590
+ {
1591
+ "type": "trait_alias",
1592
+ "named": true
1593
+ },
1532
1594
  {
1533
1595
  "type": "trait_item",
1534
1596
  "named": true
@@ -3762,6 +3824,10 @@
3762
3824
  "type": "const_item",
3763
3825
  "named": true
3764
3826
  },
3827
+ {
3828
+ "type": "decl_macro",
3829
+ "named": true
3830
+ },
3765
3831
  {
3766
3832
  "type": "empty_statement",
3767
3833
  "named": true
@@ -3826,6 +3892,10 @@
3826
3892
  "type": "struct_item",
3827
3893
  "named": true
3828
3894
  },
3895
+ {
3896
+ "type": "trait_alias",
3897
+ "named": true
3898
+ },
3829
3899
  {
3830
3900
  "type": "trait_item",
3831
3901
  "named": true
@@ -4274,6 +4344,79 @@
4274
4344
  ]
4275
4345
  }
4276
4346
  },
4347
+ {
4348
+ "type": "trait_alias",
4349
+ "named": true,
4350
+ "fields": {
4351
+ "bounds": {
4352
+ "multiple": false,
4353
+ "required": false,
4354
+ "types": [
4355
+ {
4356
+ "type": "trait_alias_bounds",
4357
+ "named": true
4358
+ }
4359
+ ]
4360
+ },
4361
+ "name": {
4362
+ "multiple": false,
4363
+ "required": true,
4364
+ "types": [
4365
+ {
4366
+ "type": "type_identifier",
4367
+ "named": true
4368
+ }
4369
+ ]
4370
+ },
4371
+ "type_parameters": {
4372
+ "multiple": false,
4373
+ "required": false,
4374
+ "types": [
4375
+ {
4376
+ "type": "type_parameters",
4377
+ "named": true
4378
+ }
4379
+ ]
4380
+ }
4381
+ },
4382
+ "children": {
4383
+ "multiple": true,
4384
+ "required": false,
4385
+ "types": [
4386
+ {
4387
+ "type": "visibility_modifier",
4388
+ "named": true
4389
+ },
4390
+ {
4391
+ "type": "where_clause",
4392
+ "named": true
4393
+ }
4394
+ ]
4395
+ }
4396
+ },
4397
+ {
4398
+ "type": "trait_alias_bounds",
4399
+ "named": true,
4400
+ "fields": {},
4401
+ "children": {
4402
+ "multiple": true,
4403
+ "required": true,
4404
+ "types": [
4405
+ {
4406
+ "type": "_type",
4407
+ "named": true
4408
+ },
4409
+ {
4410
+ "type": "higher_ranked_trait_bound",
4411
+ "named": true
4412
+ },
4413
+ {
4414
+ "type": "lifetime",
4415
+ "named": true
4416
+ }
4417
+ ]
4418
+ }
4419
+ },
4277
4420
  {
4278
4421
  "type": "trait_bounds",
4279
4422
  "named": true,
@@ -5528,6 +5671,10 @@
5528
5671
  "type": "loop",
5529
5672
  "named": false
5530
5673
  },
5674
+ {
5675
+ "type": "macro",
5676
+ "named": false
5677
+ },
5531
5678
  {
5532
5679
  "type": "macro_rules!",
5533
5680
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -22,7 +22,7 @@
22
22
  }
23
23
  ],
24
24
  "metadata": {
25
- "version": "1.1.15",
25
+ "version": "1.2.0",
26
26
  "license": "MIT",
27
27
  "description": "Rust grammar for tree-sitter",
28
28
  "authors": [