@willbooster/tree-sitter-rust 3.0.3 → 3.1.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
@@ -32,6 +32,8 @@ const PREC = {
32
32
  closure: -1,
33
33
  };
34
34
 
35
+ const literalSuffix = /[_\p{XID_Start}][_\p{XID_Continue}]*/u;
36
+
35
37
  const numericSuffixWithoutExponent = new RegExp(String.raw`[\p{XID_Start}--[eE]][_\p{XID_Continue}]*`, 'v');
36
38
  const zeroNumericSuffix = new RegExp(String.raw`[\p{XID_Start}--[eEbox]][_\p{XID_Continue}]*`, 'v');
37
39
  const hexadecimalSuffix = new RegExp(String.raw`[\p{XID_Start}--[a-fA-F]][_\p{XID_Continue}]*`, 'v');
@@ -136,6 +138,12 @@ module.exports = grammar({
136
138
  sym('_foreign_declaration_context'),
137
139
  sym('_foreign_declaration_start'),
138
140
  sym('_macro_metavariable_name'),
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'),
139
147
  ],
140
148
 
141
149
  supertypes: ($) => [$._declaration_statement, $._expression, $._type, $._literal, $._literal_pattern, $._pattern],
@@ -178,7 +186,8 @@ module.exports = grammar({
178
186
  word: ($) => $.identifier,
179
187
 
180
188
  rules: {
181
- source_file: ($) => seq(optional($.shebang), repeat($._statement)),
189
+ source_file: ($) =>
190
+ seq(sym('_frontmatter_context'), optional($.shebang), optional($.frontmatter), repeat($._statement)),
182
191
 
183
192
  _statement: ($) => choice($.expression_statement, $._declaration_statement),
184
193
 
@@ -1492,14 +1501,16 @@ module.exports = grammar({
1492
1501
  seq(
1493
1502
  alias(/[bc]?"/, '"'),
1494
1503
  repeat(choice($.escape_sequence, sym('string_content'))),
1495
- alias(sym('string_close'), '"')
1504
+ alias(sym('string_close'), '"'),
1505
+ optional(seq(sym('_literal_suffix_start'), token.immediate(prec(1, literalSuffix))))
1496
1506
  ),
1497
1507
 
1498
1508
  raw_string_literal: () =>
1499
1509
  seq(
1500
1510
  sym('_raw_string_literal_start'),
1501
1511
  alias(sym('_raw_string_literal_content'), sym('string_content')),
1502
- sym('_raw_string_literal_end')
1512
+ sym('_raw_string_literal_end'),
1513
+ optional(seq(sym('_literal_suffix_start'), token.immediate(prec(1, literalSuffix))))
1503
1514
  ),
1504
1515
 
1505
1516
  char_literal: () =>
@@ -1513,7 +1524,8 @@ module.exports = grammar({
1513
1524
  /[^\\']/
1514
1525
  )
1515
1526
  ),
1516
- "'"
1527
+ "'",
1528
+ optional(literalSuffix)
1517
1529
  )
1518
1530
  ),
1519
1531
 
@@ -1596,6 +1608,17 @@ module.exports = grammar({
1596
1608
  _spaced_metavariable: () =>
1597
1609
  prec.dynamic(1, seq('$', choice(sym('_macro_metavariable_name'), token(prec(1, nonAsciiOrRawMacroName))))),
1598
1610
  metavariable: () => /\$(r#)?[_\p{XID_Start}][_\p{XID_Continue}]*/u,
1611
+
1612
+ frontmatter: ($) =>
1613
+ seq(
1614
+ sym('_frontmatter_start'),
1615
+ optional($.frontmatter_info_string),
1616
+ sym('_frontmatter_header_end'),
1617
+ sym('frontmatter_content'),
1618
+ sym('_frontmatter_end')
1619
+ ),
1620
+
1621
+ frontmatter_info_string: () => token.immediate(/[_\p{XID_Start}][_.\p{XID_Continue}-]*/u),
1599
1622
  },
1600
1623
  });
1601
1624
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "3.0.3",
3
+ "version": "3.1.0",
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
@@ -5576,6 +5599,14 @@
5576
5599
  "type": "for",
5577
5600
  "named": false
5578
5601
  },
5602
+ {
5603
+ "type": "frontmatter_content",
5604
+ "named": true
5605
+ },
5606
+ {
5607
+ "type": "frontmatter_info_string",
5608
+ "named": true
5609
+ },
5579
5610
  {
5580
5611
  "type": "gen",
5581
5612
  "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.3",
28
+ "version": "3.1.0",
26
29
  "license": "MIT",
27
30
  "description": "Rust grammar for tree-sitter",
28
31
  "authors": [