@willbooster/tree-sitter-rust 14.0.2 → 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 +90 -17
- 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.
|
|
@@ -213,8 +263,8 @@ module.exports = grammar({
|
|
|
213
263
|
],
|
|
214
264
|
|
|
215
265
|
reserved: {
|
|
216
|
-
global: () =>
|
|
217
|
-
|
|
266
|
+
global: () => globalKeywords,
|
|
267
|
+
token_tree: () => [],
|
|
218
268
|
},
|
|
219
269
|
|
|
220
270
|
word: ($) => $.identifier,
|
|
@@ -380,7 +430,7 @@ module.exports = grammar({
|
|
|
380
430
|
alias($._outer_line_comment, $.line_comment),
|
|
381
431
|
alias($._outer_block_comment, $.block_comment),
|
|
382
432
|
$._literal,
|
|
383
|
-
$.identifier,
|
|
433
|
+
reserved('token_tree', $.identifier),
|
|
384
434
|
$.mutable_specifier,
|
|
385
435
|
$.self,
|
|
386
436
|
$.super,
|
|
@@ -389,6 +439,7 @@ module.exports = grammar({
|
|
|
389
439
|
alias(choice(...extendedFloatTypes), $.identifier),
|
|
390
440
|
prec.right(repeat1(choice(...TOKEN_TREE_NON_SPECIAL_PUNCTUATION))),
|
|
391
441
|
"'",
|
|
442
|
+
alias(choice('abstract', 'do', 'final', 'override', 'priv', 'typeof', 'unsized', 'virtual'), $.identifier),
|
|
392
443
|
'as',
|
|
393
444
|
'async',
|
|
394
445
|
'await',
|
|
@@ -440,11 +491,14 @@ module.exports = grammar({
|
|
|
440
491
|
inner_attribute_item: ($) => seq('#', '!', '[', $.attribute, ']'),
|
|
441
492
|
|
|
442
493
|
attribute: ($) =>
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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)))
|
|
448
502
|
),
|
|
449
503
|
|
|
450
504
|
mod_item: ($) =>
|
|
@@ -575,8 +629,8 @@ module.exports = grammar({
|
|
|
575
629
|
optional($.visibility_modifier),
|
|
576
630
|
'extern',
|
|
577
631
|
$.crate,
|
|
578
|
-
field('name', $.identifier),
|
|
579
|
-
optional(seq('as', field('alias', $.identifier))),
|
|
632
|
+
field('name', choice($.identifier, alias($.self, $.identifier))),
|
|
633
|
+
optional(seq('as', field('alias', choice($.identifier, alias('_', $.identifier))))),
|
|
580
634
|
';'
|
|
581
635
|
),
|
|
582
636
|
|
|
@@ -584,7 +638,7 @@ module.exports = grammar({
|
|
|
584
638
|
seq(
|
|
585
639
|
optional($.visibility_modifier),
|
|
586
640
|
'const',
|
|
587
|
-
field('name', choice($.identifier, $._reserved_identifier)),
|
|
641
|
+
field('name', choice($.identifier, $._reserved_identifier, alias('_', $.identifier))),
|
|
588
642
|
':',
|
|
589
643
|
field('type', $._type),
|
|
590
644
|
optional(seq('=', field('value', $._expression))),
|
|
@@ -825,7 +879,8 @@ module.exports = grammar({
|
|
|
825
879
|
|
|
826
880
|
use_list: ($) => seq('{', sepBy(',', choice($._use_clause)), optional(','), '}'),
|
|
827
881
|
|
|
828
|
-
use_as_clause: ($) =>
|
|
882
|
+
use_as_clause: ($) =>
|
|
883
|
+
seq(field('path', $._path), 'as', field('alias', choice($.identifier, alias('_', $.identifier)))),
|
|
829
884
|
|
|
830
885
|
use_wildcard: ($) => seq(optional(seq(optional($._path), '::')), '*'),
|
|
831
886
|
|
|
@@ -880,7 +935,7 @@ module.exports = grammar({
|
|
|
880
935
|
|
|
881
936
|
qualified_type: ($) => seq(field('type', $._type), 'as', field('alias', $._type)),
|
|
882
937
|
|
|
883
|
-
lifetime: ($) => prec(1, seq("'", $.identifier)),
|
|
938
|
+
lifetime: ($) => prec(1, seq("'", choice($.identifier, alias(choice('static', '_'), $.identifier)))),
|
|
884
939
|
|
|
885
940
|
array_type: ($) => seq('[', field('element', $._type), optional(seq(';', field('length', $._expression))), ']'),
|
|
886
941
|
|
|
@@ -921,6 +976,7 @@ module.exports = grammar({
|
|
|
921
976
|
'function',
|
|
922
977
|
choice(
|
|
923
978
|
$.identifier,
|
|
979
|
+
alias('Self', $.identifier),
|
|
924
980
|
$._reserved_identifier,
|
|
925
981
|
alias(choice(...primitiveTypes), $.identifier),
|
|
926
982
|
$.scoped_identifier,
|
|
@@ -940,6 +996,7 @@ module.exports = grammar({
|
|
|
940
996
|
'type',
|
|
941
997
|
choice(
|
|
942
998
|
$._type_identifier,
|
|
999
|
+
alias('Self', sym('type_identifier')),
|
|
943
1000
|
alias(choice(...primitiveTypes), sym('type_identifier')),
|
|
944
1001
|
alias(choice(...reservedIdentifiers), $.identifier),
|
|
945
1002
|
$.scoped_type_identifier
|
|
@@ -955,6 +1012,7 @@ module.exports = grammar({
|
|
|
955
1012
|
'type',
|
|
956
1013
|
choice(
|
|
957
1014
|
$._type_identifier,
|
|
1015
|
+
alias('Self', sym('type_identifier')),
|
|
958
1016
|
alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
|
|
959
1017
|
$.scoped_identifier
|
|
960
1018
|
)
|
|
@@ -981,7 +1039,13 @@ module.exports = grammar({
|
|
|
981
1039
|
),
|
|
982
1040
|
|
|
983
1041
|
use_bounds: ($) =>
|
|
984
|
-
seq(
|
|
1042
|
+
seq(
|
|
1043
|
+
'use',
|
|
1044
|
+
token(prec(1, '<')),
|
|
1045
|
+
sepBy(',', choice($.lifetime, $._type_identifier, alias('Self', sym('type_identifier')))),
|
|
1046
|
+
optional(','),
|
|
1047
|
+
'>'
|
|
1048
|
+
),
|
|
985
1049
|
|
|
986
1050
|
type_arguments: ($) =>
|
|
987
1051
|
seq(
|
|
@@ -1080,6 +1144,7 @@ module.exports = grammar({
|
|
|
1080
1144
|
$.yield_expression,
|
|
1081
1145
|
$._literal,
|
|
1082
1146
|
prec.left($.identifier),
|
|
1147
|
+
alias(choice('_', 'Self'), $.identifier),
|
|
1083
1148
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1084
1149
|
prec.left($._reserved_identifier),
|
|
1085
1150
|
$.self,
|
|
@@ -1154,7 +1219,7 @@ module.exports = grammar({
|
|
|
1154
1219
|
optional(choice($._path, $.bracketed_type, alias($.generic_type_with_turbofish, $.generic_type)))
|
|
1155
1220
|
),
|
|
1156
1221
|
'::',
|
|
1157
|
-
field('name', choice($.identifier, $._reserved_identifier, $.super))
|
|
1222
|
+
field('name', choice($.identifier, $._reserved_identifier, $.super, alias($.self, $.identifier)))
|
|
1158
1223
|
),
|
|
1159
1224
|
|
|
1160
1225
|
scoped_type_identifier_in_expression_position: ($) =>
|
|
@@ -1368,7 +1433,8 @@ module.exports = grammar({
|
|
|
1368
1433
|
|
|
1369
1434
|
_struct_expression_name: ($) =>
|
|
1370
1435
|
choice(
|
|
1371
|
-
|
|
1436
|
+
$._type_identifier,
|
|
1437
|
+
alias('Self', sym('type_identifier')),
|
|
1372
1438
|
prec.dynamic(-1, alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier'))),
|
|
1373
1439
|
alias($.scoped_type_identifier_in_expression_position, $.scoped_type_identifier),
|
|
1374
1440
|
$.generic_type_with_turbofish
|
|
@@ -1581,6 +1647,7 @@ module.exports = grammar({
|
|
|
1581
1647
|
$._literal_pattern,
|
|
1582
1648
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1583
1649
|
$.identifier,
|
|
1650
|
+
alias('Self', $.identifier),
|
|
1584
1651
|
$.scoped_identifier,
|
|
1585
1652
|
$.generic_pattern,
|
|
1586
1653
|
$.tuple_pattern,
|
|
@@ -1605,6 +1672,7 @@ module.exports = grammar({
|
|
|
1605
1672
|
seq(
|
|
1606
1673
|
choice(
|
|
1607
1674
|
$.identifier,
|
|
1675
|
+
alias('Self', $.identifier),
|
|
1608
1676
|
$._reserved_identifier,
|
|
1609
1677
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1610
1678
|
$.scoped_identifier
|
|
@@ -1624,6 +1692,7 @@ module.exports = grammar({
|
|
|
1624
1692
|
'type',
|
|
1625
1693
|
choice(
|
|
1626
1694
|
$.identifier,
|
|
1695
|
+
alias('Self', $.identifier),
|
|
1627
1696
|
$._reserved_identifier,
|
|
1628
1697
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1629
1698
|
$.scoped_identifier,
|
|
@@ -1642,6 +1711,7 @@ module.exports = grammar({
|
|
|
1642
1711
|
'type',
|
|
1643
1712
|
choice(
|
|
1644
1713
|
$._type_identifier,
|
|
1714
|
+
alias('Self', sym('type_identifier')),
|
|
1645
1715
|
alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
|
|
1646
1716
|
$.scoped_type_identifier,
|
|
1647
1717
|
alias($._generic_struct_pattern_type, $.generic_type)
|
|
@@ -1659,6 +1729,7 @@ module.exports = grammar({
|
|
|
1659
1729
|
'type',
|
|
1660
1730
|
choice(
|
|
1661
1731
|
$._type_identifier,
|
|
1732
|
+
alias('Self', sym('type_identifier')),
|
|
1662
1733
|
alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
|
|
1663
1734
|
$.scoped_type_identifier
|
|
1664
1735
|
)
|
|
@@ -1860,6 +1931,7 @@ module.exports = grammar({
|
|
|
1860
1931
|
_path: ($) =>
|
|
1861
1932
|
choice(
|
|
1862
1933
|
$.self,
|
|
1934
|
+
alias('Self', $.identifier),
|
|
1863
1935
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1864
1936
|
$.metavariable,
|
|
1865
1937
|
$.super,
|
|
@@ -1875,7 +1947,7 @@ module.exports = grammar({
|
|
|
1875
1947
|
|
|
1876
1948
|
_type_identifier: ($) => alias(choice($.identifier, 'auto', 'macro_rules'), sym('type_identifier')),
|
|
1877
1949
|
_type_identifier_in_type_position: ($) =>
|
|
1878
|
-
choice($._type_identifier, alias(choice(...reservedIdentifiers), sym('type_identifier'))),
|
|
1950
|
+
choice($._type_identifier, alias(choice(...reservedIdentifiers, 'Self'), sym('type_identifier'))),
|
|
1879
1951
|
_field_identifier: ($) => alias($.identifier, sym('field_identifier')),
|
|
1880
1952
|
|
|
1881
1953
|
self: () => 'self',
|
|
@@ -1905,6 +1977,7 @@ module.exports = grammar({
|
|
|
1905
1977
|
'type',
|
|
1906
1978
|
choice(
|
|
1907
1979
|
$._type_identifier,
|
|
1980
|
+
alias('Self', sym('type_identifier')),
|
|
1908
1981
|
alias(choice(...primitiveTypes), sym('type_identifier')),
|
|
1909
1982
|
alias(choice(...reservedIdentifiers), $.identifier),
|
|
1910
1983
|
$.scoped_type_identifier
|
package/package.json
CHANGED
package/tree-sitter-rust.wasm
CHANGED
|
Binary file
|