@willbooster/tree-sitter-rust 3.0.4 → 3.1.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/grammar.js CHANGED
@@ -139,6 +139,11 @@ module.exports = grammar({
139
139
  sym('_foreign_declaration_start'),
140
140
  sym('_macro_metavariable_name'),
141
141
  sym('_literal_suffix_start'),
142
+ sym('_frontmatter_start'),
143
+ sym('_frontmatter_header_end'),
144
+ sym('frontmatter_content'),
145
+ sym('_frontmatter_end'),
146
+ sym('_frontmatter_context'),
142
147
  ],
143
148
 
144
149
  supertypes: ($) => [$._declaration_statement, $._expression, $._type, $._literal, $._literal_pattern, $._pattern],
@@ -181,7 +186,8 @@ module.exports = grammar({
181
186
  word: ($) => $.identifier,
182
187
 
183
188
  rules: {
184
- source_file: ($) => seq(optional($.shebang), repeat($._statement)),
189
+ source_file: ($) =>
190
+ seq(sym('_frontmatter_context'), optional($.shebang), optional($.frontmatter), repeat($._statement)),
185
191
 
186
192
  _statement: ($) => choice($.expression_statement, $._declaration_statement),
187
193
 
@@ -569,6 +575,12 @@ module.exports = grammar({
569
575
  $.reference_type,
570
576
  $.pointer_type,
571
577
  $.tuple_type,
578
+ $.unit_type,
579
+ $.function_type,
580
+ $.dynamic_type,
581
+ $.bounded_type,
582
+ $.macro_invocation,
583
+ $.never_type,
572
584
  $.array_type,
573
585
  $.higher_ranked_trait_bound,
574
586
  alias(choice(...primitiveTypes), sym('primitive_type'))
@@ -644,7 +656,10 @@ module.exports = grammar({
644
656
  ';'
645
657
  ),
646
658
 
647
- trait_bounds: ($) => seq(':', sepBy1('+', choice($._type, $.lifetime, $.higher_ranked_trait_bound))),
659
+ trait_bounds: ($) =>
660
+ prec.right(
661
+ seq(':', optional(seq(sepBy1('+', choice($._type, $.lifetime, $.higher_ranked_trait_bound)), optional('+'))))
662
+ ),
648
663
 
649
664
  higher_ranked_trait_bound: ($) => seq('for', field('type_parameters', $.type_parameters), field('type', $._type)),
650
665
 
@@ -1602,6 +1617,17 @@ module.exports = grammar({
1602
1617
  _spaced_metavariable: () =>
1603
1618
  prec.dynamic(1, seq('$', choice(sym('_macro_metavariable_name'), token(prec(1, nonAsciiOrRawMacroName))))),
1604
1619
  metavariable: () => /\$(r#)?[_\p{XID_Start}][_\p{XID_Continue}]*/u,
1620
+
1621
+ frontmatter: ($) =>
1622
+ seq(
1623
+ sym('_frontmatter_start'),
1624
+ optional($.frontmatter_info_string),
1625
+ sym('_frontmatter_header_end'),
1626
+ sym('frontmatter_content'),
1627
+ sym('_frontmatter_end')
1628
+ ),
1629
+
1630
+ frontmatter_info_string: () => token.immediate(/[_\p{XID_Start}][_.\p{XID_Continue}-]*/u),
1605
1631
  },
1606
1632
  });
1607
1633
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "3.0.4",
3
+ "version": "3.1.1",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -67,6 +67,7 @@
67
67
 
68
68
  (line_comment) @comment
69
69
  (block_comment) @comment
70
+ (frontmatter) @comment
70
71
 
71
72
  (line_comment (doc_comment)) @comment.documentation
72
73
  (block_comment (doc_comment)) @comment.documentation
@@ -2143,6 +2143,25 @@
2143
2143
  "named": true,
2144
2144
  "fields": {}
2145
2145
  },
2146
+ {
2147
+ "type": "frontmatter",
2148
+ "named": true,
2149
+ "fields": {},
2150
+ "children": {
2151
+ "multiple": true,
2152
+ "required": true,
2153
+ "types": [
2154
+ {
2155
+ "type": "frontmatter_content",
2156
+ "named": true
2157
+ },
2158
+ {
2159
+ "type": "frontmatter_info_string",
2160
+ "named": true
2161
+ }
2162
+ ]
2163
+ }
2164
+ },
2146
2165
  {
2147
2166
  "type": "function_item",
2148
2167
  "named": true,
@@ -3849,6 +3868,10 @@
3849
3868
  "type": "expression_statement",
3850
3869
  "named": true
3851
3870
  },
3871
+ {
3872
+ "type": "frontmatter",
3873
+ "named": true
3874
+ },
3852
3875
  {
3853
3876
  "type": "shebang",
3854
3877
  "named": true
@@ -4368,7 +4391,7 @@
4368
4391
  "fields": {},
4369
4392
  "children": {
4370
4393
  "multiple": true,
4371
- "required": true,
4394
+ "required": false,
4372
4395
  "types": [
4373
4396
  {
4374
4397
  "type": "_type",
@@ -5177,6 +5200,18 @@
5177
5200
  "type": "array_type",
5178
5201
  "named": true
5179
5202
  },
5203
+ {
5204
+ "type": "bounded_type",
5205
+ "named": true
5206
+ },
5207
+ {
5208
+ "type": "dynamic_type",
5209
+ "named": true
5210
+ },
5211
+ {
5212
+ "type": "function_type",
5213
+ "named": true
5214
+ },
5180
5215
  {
5181
5216
  "type": "generic_type",
5182
5217
  "named": true
@@ -5189,6 +5224,14 @@
5189
5224
  "type": "lifetime",
5190
5225
  "named": true
5191
5226
  },
5227
+ {
5228
+ "type": "macro_invocation",
5229
+ "named": true
5230
+ },
5231
+ {
5232
+ "type": "never_type",
5233
+ "named": true
5234
+ },
5192
5235
  {
5193
5236
  "type": "pointer_type",
5194
5237
  "named": true
@@ -5212,6 +5255,10 @@
5212
5255
  {
5213
5256
  "type": "type_identifier",
5214
5257
  "named": true
5258
+ },
5259
+ {
5260
+ "type": "unit_type",
5261
+ "named": true
5215
5262
  }
5216
5263
  ]
5217
5264
  }
@@ -5576,6 +5623,14 @@
5576
5623
  "type": "for",
5577
5624
  "named": false
5578
5625
  },
5626
+ {
5627
+ "type": "frontmatter_content",
5628
+ "named": true
5629
+ },
5630
+ {
5631
+ "type": "frontmatter_info_string",
5632
+ "named": true
5633
+ },
5579
5634
  {
5580
5635
  "type": "gen",
5581
5636
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -18,11 +18,14 @@
18
18
  "tags": [
19
19
  "queries/tags.scm"
20
20
  ],
21
- "injection-regex": "rust"
21
+ "injection-regex": "rust",
22
+ "external-files": [
23
+ "src/frontmatter.h"
24
+ ]
22
25
  }
23
26
  ],
24
27
  "metadata": {
25
- "version": "3.0.4",
28
+ "version": "3.1.1",
26
29
  "license": "MIT",
27
30
  "description": "Rust grammar for tree-sitter",
28
31
  "authors": [