@willbooster/tree-sitter-rust 14.0.1 → 14.0.3
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 +92 -21
- package/package.json +1 -1
- package/tree-sitter-rust.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -114,6 +114,56 @@ const TOKEN_TREE_NON_SPECIAL_PUNCTUATION = [
|
|
|
114
114
|
|
|
115
115
|
const primitiveTypes = [...numericTypes, 'bool', 'str', 'char'];
|
|
116
116
|
const reservedIdentifiers = ['default', 'union', 'gen', 'raw'];
|
|
117
|
+
const globalKeywords = [
|
|
118
|
+
'_',
|
|
119
|
+
'as',
|
|
120
|
+
'break',
|
|
121
|
+
'const',
|
|
122
|
+
'continue',
|
|
123
|
+
'crate',
|
|
124
|
+
'else',
|
|
125
|
+
'enum',
|
|
126
|
+
'extern',
|
|
127
|
+
'false',
|
|
128
|
+
'fn',
|
|
129
|
+
'for',
|
|
130
|
+
'if',
|
|
131
|
+
'impl',
|
|
132
|
+
'in',
|
|
133
|
+
'let',
|
|
134
|
+
'loop',
|
|
135
|
+
'match',
|
|
136
|
+
'mod',
|
|
137
|
+
'move',
|
|
138
|
+
'mut',
|
|
139
|
+
'pub',
|
|
140
|
+
'ref',
|
|
141
|
+
'return',
|
|
142
|
+
'self',
|
|
143
|
+
'Self',
|
|
144
|
+
'static',
|
|
145
|
+
'struct',
|
|
146
|
+
'super',
|
|
147
|
+
'trait',
|
|
148
|
+
'true',
|
|
149
|
+
'type',
|
|
150
|
+
'unsafe',
|
|
151
|
+
'use',
|
|
152
|
+
'where',
|
|
153
|
+
'while',
|
|
154
|
+
'abstract',
|
|
155
|
+
'become',
|
|
156
|
+
'box',
|
|
157
|
+
'do',
|
|
158
|
+
'final',
|
|
159
|
+
'macro',
|
|
160
|
+
'override',
|
|
161
|
+
'priv',
|
|
162
|
+
'typeof',
|
|
163
|
+
'unsized',
|
|
164
|
+
'virtual',
|
|
165
|
+
'yield',
|
|
166
|
+
];
|
|
117
167
|
const fieldIdentifierKeywords = [...reservedIdentifiers, ...primitiveTypes, 'auto'];
|
|
118
168
|
|
|
119
169
|
// oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
|
|
@@ -155,6 +205,7 @@ module.exports = grammar({
|
|
|
155
205
|
sym('_orphan_block_doc_comment_start'),
|
|
156
206
|
sym('_orphan_doc_missing_owner'),
|
|
157
207
|
sym('_trailing_type_bound_plus'),
|
|
208
|
+
sym('shebang'),
|
|
158
209
|
],
|
|
159
210
|
|
|
160
211
|
supertypes: ($) => [
|
|
@@ -212,15 +263,15 @@ module.exports = grammar({
|
|
|
212
263
|
],
|
|
213
264
|
|
|
214
265
|
reserved: {
|
|
215
|
-
global: () =>
|
|
216
|
-
|
|
266
|
+
global: () => globalKeywords,
|
|
267
|
+
token_tree: () => [],
|
|
217
268
|
},
|
|
218
269
|
|
|
219
270
|
word: ($) => $.identifier,
|
|
220
271
|
|
|
221
272
|
rules: {
|
|
222
273
|
source_file: ($) =>
|
|
223
|
-
seq(sym('_frontmatter_context'), optional(
|
|
274
|
+
seq(sym('_frontmatter_context'), optional(sym('shebang')), optional($.frontmatter), repeat($._statement)),
|
|
224
275
|
|
|
225
276
|
_statement: ($) => choice($.expression_statement, $._declaration_statement),
|
|
226
277
|
|
|
@@ -379,7 +430,7 @@ module.exports = grammar({
|
|
|
379
430
|
alias($._outer_line_comment, $.line_comment),
|
|
380
431
|
alias($._outer_block_comment, $.block_comment),
|
|
381
432
|
$._literal,
|
|
382
|
-
$.identifier,
|
|
433
|
+
reserved('token_tree', $.identifier),
|
|
383
434
|
$.mutable_specifier,
|
|
384
435
|
$.self,
|
|
385
436
|
$.super,
|
|
@@ -388,6 +439,7 @@ module.exports = grammar({
|
|
|
388
439
|
alias(choice(...extendedFloatTypes), $.identifier),
|
|
389
440
|
prec.right(repeat1(choice(...TOKEN_TREE_NON_SPECIAL_PUNCTUATION))),
|
|
390
441
|
"'",
|
|
442
|
+
alias(choice('abstract', 'do', 'final', 'override', 'priv', 'typeof', 'unsized', 'virtual'), $.identifier),
|
|
391
443
|
'as',
|
|
392
444
|
'async',
|
|
393
445
|
'await',
|
|
@@ -439,11 +491,14 @@ module.exports = grammar({
|
|
|
439
491
|
inner_attribute_item: ($) => seq('#', '!', '[', $.attribute, ']'),
|
|
440
492
|
|
|
441
493
|
attribute: ($) =>
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
494
|
+
choice(
|
|
495
|
+
seq(
|
|
496
|
+
$._path,
|
|
497
|
+
optional(
|
|
498
|
+
choice(seq('=', field('value', $._expression)), field('arguments', alias($.delim_token_tree, $.token_tree)))
|
|
499
|
+
)
|
|
500
|
+
),
|
|
501
|
+
seq(alias('unsafe', $.identifier), field('arguments', alias($._parenthesized_token_tree, $.token_tree)))
|
|
447
502
|
),
|
|
448
503
|
|
|
449
504
|
mod_item: ($) =>
|
|
@@ -574,8 +629,8 @@ module.exports = grammar({
|
|
|
574
629
|
optional($.visibility_modifier),
|
|
575
630
|
'extern',
|
|
576
631
|
$.crate,
|
|
577
|
-
field('name', $.identifier),
|
|
578
|
-
optional(seq('as', field('alias', $.identifier))),
|
|
632
|
+
field('name', choice($.identifier, alias($.self, $.identifier))),
|
|
633
|
+
optional(seq('as', field('alias', choice($.identifier, alias('_', $.identifier))))),
|
|
579
634
|
';'
|
|
580
635
|
),
|
|
581
636
|
|
|
@@ -583,7 +638,7 @@ module.exports = grammar({
|
|
|
583
638
|
seq(
|
|
584
639
|
optional($.visibility_modifier),
|
|
585
640
|
'const',
|
|
586
|
-
field('name', choice($.identifier, $._reserved_identifier)),
|
|
641
|
+
field('name', choice($.identifier, $._reserved_identifier, alias('_', $.identifier))),
|
|
587
642
|
':',
|
|
588
643
|
field('type', $._type),
|
|
589
644
|
optional(seq('=', field('value', $._expression))),
|
|
@@ -824,7 +879,8 @@ module.exports = grammar({
|
|
|
824
879
|
|
|
825
880
|
use_list: ($) => seq('{', sepBy(',', choice($._use_clause)), optional(','), '}'),
|
|
826
881
|
|
|
827
|
-
use_as_clause: ($) =>
|
|
882
|
+
use_as_clause: ($) =>
|
|
883
|
+
seq(field('path', $._path), 'as', field('alias', choice($.identifier, alias('_', $.identifier)))),
|
|
828
884
|
|
|
829
885
|
use_wildcard: ($) => seq(optional(seq(optional($._path), '::')), '*'),
|
|
830
886
|
|
|
@@ -879,7 +935,7 @@ module.exports = grammar({
|
|
|
879
935
|
|
|
880
936
|
qualified_type: ($) => seq(field('type', $._type), 'as', field('alias', $._type)),
|
|
881
937
|
|
|
882
|
-
lifetime: ($) => prec(1, seq("'", $.identifier)),
|
|
938
|
+
lifetime: ($) => prec(1, seq("'", choice($.identifier, alias(choice('static', '_'), $.identifier)))),
|
|
883
939
|
|
|
884
940
|
array_type: ($) => seq('[', field('element', $._type), optional(seq(';', field('length', $._expression))), ']'),
|
|
885
941
|
|
|
@@ -920,6 +976,7 @@ module.exports = grammar({
|
|
|
920
976
|
'function',
|
|
921
977
|
choice(
|
|
922
978
|
$.identifier,
|
|
979
|
+
alias('Self', $.identifier),
|
|
923
980
|
$._reserved_identifier,
|
|
924
981
|
alias(choice(...primitiveTypes), $.identifier),
|
|
925
982
|
$.scoped_identifier,
|
|
@@ -939,6 +996,7 @@ module.exports = grammar({
|
|
|
939
996
|
'type',
|
|
940
997
|
choice(
|
|
941
998
|
$._type_identifier,
|
|
999
|
+
alias('Self', sym('type_identifier')),
|
|
942
1000
|
alias(choice(...primitiveTypes), sym('type_identifier')),
|
|
943
1001
|
alias(choice(...reservedIdentifiers), $.identifier),
|
|
944
1002
|
$.scoped_type_identifier
|
|
@@ -954,6 +1012,7 @@ module.exports = grammar({
|
|
|
954
1012
|
'type',
|
|
955
1013
|
choice(
|
|
956
1014
|
$._type_identifier,
|
|
1015
|
+
alias('Self', sym('type_identifier')),
|
|
957
1016
|
alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
|
|
958
1017
|
$.scoped_identifier
|
|
959
1018
|
)
|
|
@@ -980,7 +1039,13 @@ module.exports = grammar({
|
|
|
980
1039
|
),
|
|
981
1040
|
|
|
982
1041
|
use_bounds: ($) =>
|
|
983
|
-
seq(
|
|
1042
|
+
seq(
|
|
1043
|
+
'use',
|
|
1044
|
+
token(prec(1, '<')),
|
|
1045
|
+
sepBy(',', choice($.lifetime, $._type_identifier, alias('Self', sym('type_identifier')))),
|
|
1046
|
+
optional(','),
|
|
1047
|
+
'>'
|
|
1048
|
+
),
|
|
984
1049
|
|
|
985
1050
|
type_arguments: ($) =>
|
|
986
1051
|
seq(
|
|
@@ -1079,6 +1144,7 @@ module.exports = grammar({
|
|
|
1079
1144
|
$.yield_expression,
|
|
1080
1145
|
$._literal,
|
|
1081
1146
|
prec.left($.identifier),
|
|
1147
|
+
alias(choice('_', 'Self'), $.identifier),
|
|
1082
1148
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1083
1149
|
prec.left($._reserved_identifier),
|
|
1084
1150
|
$.self,
|
|
@@ -1153,7 +1219,7 @@ module.exports = grammar({
|
|
|
1153
1219
|
optional(choice($._path, $.bracketed_type, alias($.generic_type_with_turbofish, $.generic_type)))
|
|
1154
1220
|
),
|
|
1155
1221
|
'::',
|
|
1156
|
-
field('name', choice($.identifier, $._reserved_identifier, $.super))
|
|
1222
|
+
field('name', choice($.identifier, $._reserved_identifier, $.super, alias($.self, $.identifier)))
|
|
1157
1223
|
),
|
|
1158
1224
|
|
|
1159
1225
|
scoped_type_identifier_in_expression_position: ($) =>
|
|
@@ -1367,7 +1433,8 @@ module.exports = grammar({
|
|
|
1367
1433
|
|
|
1368
1434
|
_struct_expression_name: ($) =>
|
|
1369
1435
|
choice(
|
|
1370
|
-
|
|
1436
|
+
$._type_identifier,
|
|
1437
|
+
alias('Self', sym('type_identifier')),
|
|
1371
1438
|
prec.dynamic(-1, alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier'))),
|
|
1372
1439
|
alias($.scoped_type_identifier_in_expression_position, $.scoped_type_identifier),
|
|
1373
1440
|
$.generic_type_with_turbofish
|
|
@@ -1580,6 +1647,7 @@ module.exports = grammar({
|
|
|
1580
1647
|
$._literal_pattern,
|
|
1581
1648
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1582
1649
|
$.identifier,
|
|
1650
|
+
alias('Self', $.identifier),
|
|
1583
1651
|
$.scoped_identifier,
|
|
1584
1652
|
$.generic_pattern,
|
|
1585
1653
|
$.tuple_pattern,
|
|
@@ -1604,6 +1672,7 @@ module.exports = grammar({
|
|
|
1604
1672
|
seq(
|
|
1605
1673
|
choice(
|
|
1606
1674
|
$.identifier,
|
|
1675
|
+
alias('Self', $.identifier),
|
|
1607
1676
|
$._reserved_identifier,
|
|
1608
1677
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1609
1678
|
$.scoped_identifier
|
|
@@ -1623,6 +1692,7 @@ module.exports = grammar({
|
|
|
1623
1692
|
'type',
|
|
1624
1693
|
choice(
|
|
1625
1694
|
$.identifier,
|
|
1695
|
+
alias('Self', $.identifier),
|
|
1626
1696
|
$._reserved_identifier,
|
|
1627
1697
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1628
1698
|
$.scoped_identifier,
|
|
@@ -1641,6 +1711,7 @@ module.exports = grammar({
|
|
|
1641
1711
|
'type',
|
|
1642
1712
|
choice(
|
|
1643
1713
|
$._type_identifier,
|
|
1714
|
+
alias('Self', sym('type_identifier')),
|
|
1644
1715
|
alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
|
|
1645
1716
|
$.scoped_type_identifier,
|
|
1646
1717
|
alias($._generic_struct_pattern_type, $.generic_type)
|
|
@@ -1658,6 +1729,7 @@ module.exports = grammar({
|
|
|
1658
1729
|
'type',
|
|
1659
1730
|
choice(
|
|
1660
1731
|
$._type_identifier,
|
|
1732
|
+
alias('Self', sym('type_identifier')),
|
|
1661
1733
|
alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
|
|
1662
1734
|
$.scoped_type_identifier
|
|
1663
1735
|
)
|
|
@@ -1859,6 +1931,7 @@ module.exports = grammar({
|
|
|
1859
1931
|
_path: ($) =>
|
|
1860
1932
|
choice(
|
|
1861
1933
|
$.self,
|
|
1934
|
+
alias('Self', $.identifier),
|
|
1862
1935
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1863
1936
|
$.metavariable,
|
|
1864
1937
|
$.super,
|
|
@@ -1870,14 +1943,11 @@ module.exports = grammar({
|
|
|
1870
1943
|
|
|
1871
1944
|
identifier: () => /(r#)?[_\p{XID_Start}][_\p{XID_Continue}]*/u,
|
|
1872
1945
|
|
|
1873
|
-
// oxlint-disable-next-line no-useless-escape -- tree-sitter's regex parser rejects an unescaped `[` in a character class.
|
|
1874
|
-
shebang: () => /#![\r\f\t\v ]*([^\[\n].*)?\n/,
|
|
1875
|
-
|
|
1876
1946
|
_reserved_identifier: ($) => alias(choice(...reservedIdentifiers, 'auto', 'macro_rules'), $.identifier),
|
|
1877
1947
|
|
|
1878
1948
|
_type_identifier: ($) => alias(choice($.identifier, 'auto', 'macro_rules'), sym('type_identifier')),
|
|
1879
1949
|
_type_identifier_in_type_position: ($) =>
|
|
1880
|
-
choice($._type_identifier, alias(choice(...reservedIdentifiers), sym('type_identifier'))),
|
|
1950
|
+
choice($._type_identifier, alias(choice(...reservedIdentifiers, 'Self'), sym('type_identifier'))),
|
|
1881
1951
|
_field_identifier: ($) => alias($.identifier, sym('field_identifier')),
|
|
1882
1952
|
|
|
1883
1953
|
self: () => 'self',
|
|
@@ -1907,6 +1977,7 @@ module.exports = grammar({
|
|
|
1907
1977
|
'type',
|
|
1908
1978
|
choice(
|
|
1909
1979
|
$._type_identifier,
|
|
1980
|
+
alias('Self', sym('type_identifier')),
|
|
1910
1981
|
alias(choice(...primitiveTypes), sym('type_identifier')),
|
|
1911
1982
|
alias(choice(...reservedIdentifiers), $.identifier),
|
|
1912
1983
|
$.scoped_type_identifier
|
package/package.json
CHANGED
package/tree-sitter-rust.wasm
CHANGED
|
Binary file
|