@willbooster/tree-sitter-rust 14.0.2 → 14.0.4
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 +109 -19
- 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,9 @@ module.exports = grammar({
|
|
|
213
263
|
],
|
|
214
264
|
|
|
215
265
|
reserved: {
|
|
216
|
-
global: () =>
|
|
217
|
-
|
|
266
|
+
global: () => globalKeywords,
|
|
267
|
+
token_tree: () => [],
|
|
268
|
+
lifetime_declaration: () => [...globalKeywords, 'r#static', 'r#_'],
|
|
218
269
|
},
|
|
219
270
|
|
|
220
271
|
word: ($) => $.identifier,
|
|
@@ -380,7 +431,7 @@ module.exports = grammar({
|
|
|
380
431
|
alias($._outer_line_comment, $.line_comment),
|
|
381
432
|
alias($._outer_block_comment, $.block_comment),
|
|
382
433
|
$._literal,
|
|
383
|
-
$.identifier,
|
|
434
|
+
reserved('token_tree', $.identifier),
|
|
384
435
|
$.mutable_specifier,
|
|
385
436
|
$.self,
|
|
386
437
|
$.super,
|
|
@@ -389,6 +440,7 @@ module.exports = grammar({
|
|
|
389
440
|
alias(choice(...extendedFloatTypes), $.identifier),
|
|
390
441
|
prec.right(repeat1(choice(...TOKEN_TREE_NON_SPECIAL_PUNCTUATION))),
|
|
391
442
|
"'",
|
|
443
|
+
alias(choice('abstract', 'do', 'final', 'override', 'priv', 'typeof', 'unsized', 'virtual'), $.identifier),
|
|
392
444
|
'as',
|
|
393
445
|
'async',
|
|
394
446
|
'await',
|
|
@@ -440,11 +492,14 @@ module.exports = grammar({
|
|
|
440
492
|
inner_attribute_item: ($) => seq('#', '!', '[', $.attribute, ']'),
|
|
441
493
|
|
|
442
494
|
attribute: ($) =>
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
495
|
+
choice(
|
|
496
|
+
seq(
|
|
497
|
+
$._path,
|
|
498
|
+
optional(
|
|
499
|
+
choice(seq('=', field('value', $._expression)), field('arguments', alias($.delim_token_tree, $.token_tree)))
|
|
500
|
+
)
|
|
501
|
+
),
|
|
502
|
+
seq(alias('unsafe', $.identifier), field('arguments', alias($._parenthesized_token_tree, $.token_tree)))
|
|
448
503
|
),
|
|
449
504
|
|
|
450
505
|
mod_item: ($) =>
|
|
@@ -575,8 +630,8 @@ module.exports = grammar({
|
|
|
575
630
|
optional($.visibility_modifier),
|
|
576
631
|
'extern',
|
|
577
632
|
$.crate,
|
|
578
|
-
field('name', $.identifier),
|
|
579
|
-
optional(seq('as', field('alias', $.identifier))),
|
|
633
|
+
field('name', choice($.identifier, alias($.self, $.identifier))),
|
|
634
|
+
optional(seq('as', field('alias', choice($.identifier, alias('_', $.identifier))))),
|
|
580
635
|
';'
|
|
581
636
|
),
|
|
582
637
|
|
|
@@ -584,7 +639,7 @@ module.exports = grammar({
|
|
|
584
639
|
seq(
|
|
585
640
|
optional($.visibility_modifier),
|
|
586
641
|
'const',
|
|
587
|
-
field('name', choice($.identifier, $._reserved_identifier)),
|
|
642
|
+
field('name', choice($.identifier, $._reserved_identifier, alias('_', $.identifier))),
|
|
588
643
|
':',
|
|
589
644
|
field('type', $._type),
|
|
590
645
|
optional(seq('=', field('value', $._expression))),
|
|
@@ -804,7 +859,11 @@ module.exports = grammar({
|
|
|
804
859
|
)
|
|
805
860
|
),
|
|
806
861
|
|
|
807
|
-
lifetime_parameter: ($) =>
|
|
862
|
+
lifetime_parameter: ($) =>
|
|
863
|
+
prec(
|
|
864
|
+
1,
|
|
865
|
+
seq(field('name', alias($._lifetime_declaration, $.lifetime)), optional(field('bounds', $.trait_bounds)))
|
|
866
|
+
),
|
|
808
867
|
|
|
809
868
|
let_declaration: ($) =>
|
|
810
869
|
seq(
|
|
@@ -825,7 +884,8 @@ module.exports = grammar({
|
|
|
825
884
|
|
|
826
885
|
use_list: ($) => seq('{', sepBy(',', choice($._use_clause)), optional(','), '}'),
|
|
827
886
|
|
|
828
|
-
use_as_clause: ($) =>
|
|
887
|
+
use_as_clause: ($) =>
|
|
888
|
+
seq(field('path', $._path), 'as', field('alias', choice($.identifier, alias('_', $.identifier)))),
|
|
829
889
|
|
|
830
890
|
use_wildcard: ($) => seq(optional(seq(optional($._path), '::')), '*'),
|
|
831
891
|
|
|
@@ -880,11 +940,23 @@ module.exports = grammar({
|
|
|
880
940
|
|
|
881
941
|
qualified_type: ($) => seq(field('type', $._type), 'as', field('alias', $._type)),
|
|
882
942
|
|
|
883
|
-
lifetime: ($) =>
|
|
943
|
+
lifetime: ($) =>
|
|
944
|
+
prec(1, seq("'", choice($.identifier, alias(choice('static', '_', 'r#static', 'r#_'), $.identifier)))),
|
|
945
|
+
|
|
946
|
+
_lifetime_declaration: ($) => prec(1, seq("'", reserved('lifetime_declaration', $.identifier))),
|
|
884
947
|
|
|
885
948
|
array_type: ($) => seq('[', field('element', $._type), optional(seq(';', field('length', $._expression))), ']'),
|
|
886
949
|
|
|
887
|
-
for_lifetimes: ($) =>
|
|
950
|
+
for_lifetimes: ($) =>
|
|
951
|
+
prec(
|
|
952
|
+
1,
|
|
953
|
+
seq(
|
|
954
|
+
'for',
|
|
955
|
+
'<',
|
|
956
|
+
optional(seq(sepBy1(',', prec(1, alias($._lifetime_declaration, $.lifetime))), optional(','))),
|
|
957
|
+
'>'
|
|
958
|
+
)
|
|
959
|
+
),
|
|
888
960
|
|
|
889
961
|
function_type: ($) =>
|
|
890
962
|
seq(
|
|
@@ -921,6 +993,7 @@ module.exports = grammar({
|
|
|
921
993
|
'function',
|
|
922
994
|
choice(
|
|
923
995
|
$.identifier,
|
|
996
|
+
alias('Self', $.identifier),
|
|
924
997
|
$._reserved_identifier,
|
|
925
998
|
alias(choice(...primitiveTypes), $.identifier),
|
|
926
999
|
$.scoped_identifier,
|
|
@@ -940,6 +1013,7 @@ module.exports = grammar({
|
|
|
940
1013
|
'type',
|
|
941
1014
|
choice(
|
|
942
1015
|
$._type_identifier,
|
|
1016
|
+
alias('Self', sym('type_identifier')),
|
|
943
1017
|
alias(choice(...primitiveTypes), sym('type_identifier')),
|
|
944
1018
|
alias(choice(...reservedIdentifiers), $.identifier),
|
|
945
1019
|
$.scoped_type_identifier
|
|
@@ -955,6 +1029,7 @@ module.exports = grammar({
|
|
|
955
1029
|
'type',
|
|
956
1030
|
choice(
|
|
957
1031
|
$._type_identifier,
|
|
1032
|
+
alias('Self', sym('type_identifier')),
|
|
958
1033
|
alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
|
|
959
1034
|
$.scoped_identifier
|
|
960
1035
|
)
|
|
@@ -981,7 +1056,13 @@ module.exports = grammar({
|
|
|
981
1056
|
),
|
|
982
1057
|
|
|
983
1058
|
use_bounds: ($) =>
|
|
984
|
-
seq(
|
|
1059
|
+
seq(
|
|
1060
|
+
'use',
|
|
1061
|
+
token(prec(1, '<')),
|
|
1062
|
+
sepBy(',', choice($.lifetime, $._type_identifier, alias('Self', sym('type_identifier')))),
|
|
1063
|
+
optional(','),
|
|
1064
|
+
'>'
|
|
1065
|
+
),
|
|
985
1066
|
|
|
986
1067
|
type_arguments: ($) =>
|
|
987
1068
|
seq(
|
|
@@ -1080,6 +1161,7 @@ module.exports = grammar({
|
|
|
1080
1161
|
$.yield_expression,
|
|
1081
1162
|
$._literal,
|
|
1082
1163
|
prec.left($.identifier),
|
|
1164
|
+
alias(choice('_', 'Self'), $.identifier),
|
|
1083
1165
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1084
1166
|
prec.left($._reserved_identifier),
|
|
1085
1167
|
$.self,
|
|
@@ -1154,7 +1236,7 @@ module.exports = grammar({
|
|
|
1154
1236
|
optional(choice($._path, $.bracketed_type, alias($.generic_type_with_turbofish, $.generic_type)))
|
|
1155
1237
|
),
|
|
1156
1238
|
'::',
|
|
1157
|
-
field('name', choice($.identifier, $._reserved_identifier, $.super))
|
|
1239
|
+
field('name', choice($.identifier, $._reserved_identifier, $.super, alias($.self, $.identifier)))
|
|
1158
1240
|
),
|
|
1159
1241
|
|
|
1160
1242
|
scoped_type_identifier_in_expression_position: ($) =>
|
|
@@ -1368,7 +1450,8 @@ module.exports = grammar({
|
|
|
1368
1450
|
|
|
1369
1451
|
_struct_expression_name: ($) =>
|
|
1370
1452
|
choice(
|
|
1371
|
-
|
|
1453
|
+
$._type_identifier,
|
|
1454
|
+
alias('Self', sym('type_identifier')),
|
|
1372
1455
|
prec.dynamic(-1, alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier'))),
|
|
1373
1456
|
alias($.scoped_type_identifier_in_expression_position, $.scoped_type_identifier),
|
|
1374
1457
|
$.generic_type_with_turbofish
|
|
@@ -1581,6 +1664,7 @@ module.exports = grammar({
|
|
|
1581
1664
|
$._literal_pattern,
|
|
1582
1665
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1583
1666
|
$.identifier,
|
|
1667
|
+
alias('Self', $.identifier),
|
|
1584
1668
|
$.scoped_identifier,
|
|
1585
1669
|
$.generic_pattern,
|
|
1586
1670
|
$.tuple_pattern,
|
|
@@ -1605,6 +1689,7 @@ module.exports = grammar({
|
|
|
1605
1689
|
seq(
|
|
1606
1690
|
choice(
|
|
1607
1691
|
$.identifier,
|
|
1692
|
+
alias('Self', $.identifier),
|
|
1608
1693
|
$._reserved_identifier,
|
|
1609
1694
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1610
1695
|
$.scoped_identifier
|
|
@@ -1624,6 +1709,7 @@ module.exports = grammar({
|
|
|
1624
1709
|
'type',
|
|
1625
1710
|
choice(
|
|
1626
1711
|
$.identifier,
|
|
1712
|
+
alias('Self', $.identifier),
|
|
1627
1713
|
$._reserved_identifier,
|
|
1628
1714
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1629
1715
|
$.scoped_identifier,
|
|
@@ -1642,6 +1728,7 @@ module.exports = grammar({
|
|
|
1642
1728
|
'type',
|
|
1643
1729
|
choice(
|
|
1644
1730
|
$._type_identifier,
|
|
1731
|
+
alias('Self', sym('type_identifier')),
|
|
1645
1732
|
alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
|
|
1646
1733
|
$.scoped_type_identifier,
|
|
1647
1734
|
alias($._generic_struct_pattern_type, $.generic_type)
|
|
@@ -1659,6 +1746,7 @@ module.exports = grammar({
|
|
|
1659
1746
|
'type',
|
|
1660
1747
|
choice(
|
|
1661
1748
|
$._type_identifier,
|
|
1749
|
+
alias('Self', sym('type_identifier')),
|
|
1662
1750
|
alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier')),
|
|
1663
1751
|
$.scoped_type_identifier
|
|
1664
1752
|
)
|
|
@@ -1860,6 +1948,7 @@ module.exports = grammar({
|
|
|
1860
1948
|
_path: ($) =>
|
|
1861
1949
|
choice(
|
|
1862
1950
|
$.self,
|
|
1951
|
+
alias('Self', $.identifier),
|
|
1863
1952
|
alias(choice(...primitiveTypes), $.identifier),
|
|
1864
1953
|
$.metavariable,
|
|
1865
1954
|
$.super,
|
|
@@ -1875,7 +1964,7 @@ module.exports = grammar({
|
|
|
1875
1964
|
|
|
1876
1965
|
_type_identifier: ($) => alias(choice($.identifier, 'auto', 'macro_rules'), sym('type_identifier')),
|
|
1877
1966
|
_type_identifier_in_type_position: ($) =>
|
|
1878
|
-
choice($._type_identifier, alias(choice(...reservedIdentifiers), sym('type_identifier'))),
|
|
1967
|
+
choice($._type_identifier, alias(choice(...reservedIdentifiers, 'Self'), sym('type_identifier'))),
|
|
1879
1968
|
_field_identifier: ($) => alias($.identifier, sym('field_identifier')),
|
|
1880
1969
|
|
|
1881
1970
|
self: () => 'self',
|
|
@@ -1905,6 +1994,7 @@ module.exports = grammar({
|
|
|
1905
1994
|
'type',
|
|
1906
1995
|
choice(
|
|
1907
1996
|
$._type_identifier,
|
|
1997
|
+
alias('Self', sym('type_identifier')),
|
|
1908
1998
|
alias(choice(...primitiveTypes), sym('type_identifier')),
|
|
1909
1999
|
alias(choice(...reservedIdentifiers), $.identifier),
|
|
1910
2000
|
$.scoped_type_identifier
|
package/package.json
CHANGED
package/tree-sitter-rust.wasm
CHANGED
|
Binary file
|