@willbooster/tree-sitter-rust 14.0.0 → 14.0.2
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 +147 -32
- package/package.json +1 -1
- package/src/node-types.json +4 -0
- package/tree-sitter-rust.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -155,6 +155,7 @@ module.exports = grammar({
|
|
|
155
155
|
sym('_orphan_block_doc_comment_start'),
|
|
156
156
|
sym('_orphan_doc_missing_owner'),
|
|
157
157
|
sym('_trailing_type_bound_plus'),
|
|
158
|
+
sym('shebang'),
|
|
158
159
|
],
|
|
159
160
|
|
|
160
161
|
supertypes: ($) => [
|
|
@@ -170,6 +171,10 @@ module.exports = grammar({
|
|
|
170
171
|
|
|
171
172
|
inline: ($) => [
|
|
172
173
|
$._path,
|
|
174
|
+
$._struct_expression_name,
|
|
175
|
+
$._field_initializer_name,
|
|
176
|
+
$._assignee_expression,
|
|
177
|
+
$._rest_assignee_expression,
|
|
173
178
|
$._type_identifier,
|
|
174
179
|
$._type_identifier_in_type_position,
|
|
175
180
|
$._tokens,
|
|
@@ -180,6 +185,9 @@ module.exports = grammar({
|
|
|
180
185
|
],
|
|
181
186
|
|
|
182
187
|
conflicts: ($) => [
|
|
188
|
+
[$.array_expression, $._array_assignee_expression],
|
|
189
|
+
[$.tuple_expression, $._tuple_assignee_expression],
|
|
190
|
+
[$.arguments, $._assignee_arguments],
|
|
183
191
|
[$._attributed_block_statement, $._expression_except_range],
|
|
184
192
|
[$.type_parameters, $.for_lifetimes],
|
|
185
193
|
[$.lifetime_parameter, $.for_lifetimes],
|
|
@@ -187,7 +195,6 @@ module.exports = grammar({
|
|
|
187
195
|
[$.token_tree, $.token_repetition],
|
|
188
196
|
[$.field_initializer_list, $.block],
|
|
189
197
|
[$._expression_except_range, $.shorthand_field_initializer],
|
|
190
|
-
[$._expression_except_range, $.struct_expression],
|
|
191
198
|
[$.function_modifiers, $.modified_trait_bound],
|
|
192
199
|
[$.function_modifiers, $.impl_item, $.modified_trait_bound],
|
|
193
200
|
[$.const_item, $.function_modifiers],
|
|
@@ -214,7 +221,7 @@ module.exports = grammar({
|
|
|
214
221
|
|
|
215
222
|
rules: {
|
|
216
223
|
source_file: ($) =>
|
|
217
|
-
seq(sym('_frontmatter_context'), optional(
|
|
224
|
+
seq(sym('_frontmatter_context'), optional(sym('shebang')), optional($.frontmatter), repeat($._statement)),
|
|
218
225
|
|
|
219
226
|
_statement: ($) => choice($.expression_statement, $._declaration_statement),
|
|
220
227
|
|
|
@@ -1224,7 +1231,7 @@ module.exports = grammar({
|
|
|
1224
1231
|
},
|
|
1225
1232
|
|
|
1226
1233
|
assignment_expression: ($) =>
|
|
1227
|
-
prec.left(PREC.assign, seq(field('left', $.
|
|
1234
|
+
prec.left(PREC.assign, seq(field('left', $._assignee_expression), '=', field('right', $._expression))),
|
|
1228
1235
|
|
|
1229
1236
|
compound_assignment_expr: ($) =>
|
|
1230
1237
|
prec.left(
|
|
@@ -1282,44 +1289,147 @@ module.exports = grammar({
|
|
|
1282
1289
|
|
|
1283
1290
|
unit_expression: () => seq('(', ')'),
|
|
1284
1291
|
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1292
|
+
_assignee_expression: ($) => choice($._expression, $._rest_assignee_expression),
|
|
1293
|
+
|
|
1294
|
+
_rest_assignee_expression: ($) =>
|
|
1295
|
+
choice(
|
|
1296
|
+
alias($._struct_assignee_expression, $.struct_expression),
|
|
1297
|
+
alias($._parenthesized_assignee_expression, $.parenthesized_expression),
|
|
1298
|
+
alias($._tuple_assignee_expression, $.tuple_expression),
|
|
1299
|
+
alias($._array_assignee_expression, $.array_expression),
|
|
1300
|
+
alias($._call_assignee_expression, $.call_expression)
|
|
1301
|
+
),
|
|
1302
|
+
|
|
1303
|
+
_struct_assignee_expression: ($) =>
|
|
1304
|
+
prec(
|
|
1305
|
+
-1,
|
|
1306
|
+
seq(
|
|
1307
|
+
field('name', $._struct_expression_name),
|
|
1308
|
+
field('body', alias($._assignee_field_initializer_list, $.field_initializer_list))
|
|
1309
|
+
)
|
|
1310
|
+
),
|
|
1311
|
+
|
|
1312
|
+
_parenthesized_assignee_expression: ($) =>
|
|
1313
|
+
prec(-1, seq('(', repeat(prec(PREC.call, $.attribute_item)), $._rest_assignee_expression, ')')),
|
|
1314
|
+
|
|
1315
|
+
_tuple_assignee_expression: ($) => {
|
|
1316
|
+
const ordinary = seq(repeat(prec(PREC.call, $.attribute_item)), $._expression);
|
|
1317
|
+
const rest = seq(repeat(prec(PREC.call, $.attribute_item)), $._rest_assignee_expression);
|
|
1318
|
+
const assignee = seq(repeat(prec(PREC.call, $.attribute_item)), $._assignee_expression);
|
|
1319
|
+
return prec(
|
|
1320
|
+
-1,
|
|
1321
|
+
seq(
|
|
1322
|
+
'(',
|
|
1289
1323
|
choice(
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1324
|
+
seq(rest, ',', repeat(seq(assignee, ',')), optional(assignee)),
|
|
1325
|
+
seq(repeat1(seq(ordinary, ',')), rest, repeat(seq(',', assignee)), optional(','))
|
|
1326
|
+
),
|
|
1327
|
+
')'
|
|
1328
|
+
)
|
|
1329
|
+
);
|
|
1330
|
+
},
|
|
1331
|
+
|
|
1332
|
+
_array_assignee_expression: ($) =>
|
|
1333
|
+
prec(
|
|
1334
|
+
-1,
|
|
1335
|
+
seq(
|
|
1336
|
+
'[',
|
|
1337
|
+
commaListWithRest(
|
|
1338
|
+
seq(repeat(prec(PREC.call, $.attribute_item)), $._expression),
|
|
1339
|
+
seq(repeat(prec(PREC.call, $.attribute_item)), $._rest_assignee_expression)
|
|
1340
|
+
),
|
|
1341
|
+
']'
|
|
1342
|
+
)
|
|
1343
|
+
),
|
|
1344
|
+
|
|
1345
|
+
_call_assignee_expression: ($) =>
|
|
1346
|
+
prec(
|
|
1347
|
+
PREC.call - 1,
|
|
1348
|
+
seq(
|
|
1349
|
+
field('function', $._expression_except_range),
|
|
1350
|
+
field('arguments', alias($._assignee_arguments, $.arguments))
|
|
1351
|
+
)
|
|
1352
|
+
),
|
|
1353
|
+
|
|
1354
|
+
_assignee_arguments: ($) =>
|
|
1355
|
+
prec(
|
|
1356
|
+
-1,
|
|
1357
|
+
seq(
|
|
1358
|
+
'(',
|
|
1359
|
+
commaListWithRest(
|
|
1360
|
+
seq(repeat(prec(PREC.call, $.attribute_item)), $._expression),
|
|
1361
|
+
seq(repeat(prec(PREC.call, $.attribute_item)), $._rest_assignee_expression)
|
|
1362
|
+
),
|
|
1363
|
+
')'
|
|
1364
|
+
)
|
|
1365
|
+
),
|
|
1366
|
+
|
|
1367
|
+
struct_expression: ($) => seq(field('name', $._struct_expression_name), field('body', $.field_initializer_list)),
|
|
1368
|
+
|
|
1369
|
+
_struct_expression_name: ($) =>
|
|
1370
|
+
choice(
|
|
1371
|
+
reserved('struct_name', $._type_identifier),
|
|
1372
|
+
prec.dynamic(-1, alias(choice(...primitiveTypes, ...reservedIdentifiers), sym('type_identifier'))),
|
|
1373
|
+
alias($.scoped_type_identifier_in_expression_position, $.scoped_type_identifier),
|
|
1374
|
+
$.generic_type_with_turbofish
|
|
1375
|
+
),
|
|
1376
|
+
|
|
1377
|
+
field_initializer_list: ($) => {
|
|
1378
|
+
const ordinary = choice($.shorthand_field_initializer, $.field_initializer);
|
|
1379
|
+
return seq(
|
|
1380
|
+
'{',
|
|
1381
|
+
choice(
|
|
1382
|
+
seq(optional($._ordinary_field_initializer_prefix), optional(ordinary)),
|
|
1383
|
+
seq(
|
|
1384
|
+
optional($._ordinary_field_initializer_prefix),
|
|
1385
|
+
$.base_field_initializer,
|
|
1386
|
+
repeat(seq(',', choice(ordinary, $.base_field_initializer))),
|
|
1387
|
+
optional(',')
|
|
1294
1388
|
)
|
|
1295
1389
|
),
|
|
1296
|
-
|
|
1297
|
-
)
|
|
1390
|
+
'}'
|
|
1391
|
+
);
|
|
1392
|
+
},
|
|
1298
1393
|
|
|
1299
|
-
|
|
1300
|
-
seq(
|
|
1394
|
+
_ordinary_field_initializer_prefix: ($) =>
|
|
1395
|
+
repeat1(seq(choice($.shorthand_field_initializer, $.field_initializer), ',')),
|
|
1396
|
+
|
|
1397
|
+
_assignee_field_initializer_list: ($) => {
|
|
1398
|
+
const ordinary = choice($.shorthand_field_initializer, $.field_initializer);
|
|
1399
|
+
const rest = alias($._assignee_field_initializer, $.field_initializer);
|
|
1400
|
+
return seq(
|
|
1301
1401
|
'{',
|
|
1302
|
-
|
|
1303
|
-
|
|
1402
|
+
optional($._ordinary_field_initializer_prefix),
|
|
1403
|
+
choice(
|
|
1404
|
+
$.remaining_field_pattern,
|
|
1405
|
+
seq(rest, repeat(seq(',', choice(ordinary, rest))), optional(seq(',', optional($.remaining_field_pattern))))
|
|
1406
|
+
),
|
|
1304
1407
|
'}'
|
|
1408
|
+
);
|
|
1409
|
+
},
|
|
1410
|
+
|
|
1411
|
+
_assignee_field_initializer: ($) =>
|
|
1412
|
+
prec(
|
|
1413
|
+
-1,
|
|
1414
|
+
seq(
|
|
1415
|
+
optional($._outer_attributes),
|
|
1416
|
+
field('field', $._field_initializer_name),
|
|
1417
|
+
':',
|
|
1418
|
+
field('value', $._rest_assignee_expression)
|
|
1419
|
+
)
|
|
1305
1420
|
),
|
|
1306
1421
|
|
|
1307
1422
|
shorthand_field_initializer: ($) =>
|
|
1308
1423
|
seq(optional($._outer_attributes), choice($.identifier, alias(choice(...fieldIdentifierKeywords), $.identifier))),
|
|
1309
1424
|
|
|
1310
1425
|
field_initializer: ($) =>
|
|
1311
|
-
seq(
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
alias(/[0-9][0-9_]*/, $.integer_literal)
|
|
1319
|
-
)
|
|
1320
|
-
),
|
|
1321
|
-
':',
|
|
1322
|
-
field('value', $._expression)
|
|
1426
|
+
seq(optional($._outer_attributes), field('field', $._field_initializer_name), ':', field('value', $._expression)),
|
|
1427
|
+
|
|
1428
|
+
_field_initializer_name: ($) =>
|
|
1429
|
+
choice(
|
|
1430
|
+
$._field_identifier,
|
|
1431
|
+
alias(choice(...fieldIdentifierKeywords), sym('field_identifier')),
|
|
1432
|
+
alias(/[0-9][0-9_]*/, $.integer_literal)
|
|
1323
1433
|
),
|
|
1324
1434
|
|
|
1325
1435
|
base_field_initializer: ($) => seq('..', $._expression),
|
|
@@ -1761,9 +1871,6 @@ module.exports = grammar({
|
|
|
1761
1871
|
|
|
1762
1872
|
identifier: () => /(r#)?[_\p{XID_Start}][_\p{XID_Continue}]*/u,
|
|
1763
1873
|
|
|
1764
|
-
// oxlint-disable-next-line no-useless-escape -- tree-sitter's regex parser rejects an unescaped `[` in a character class.
|
|
1765
|
-
shebang: () => /#![\r\f\t\v ]*([^\[\n].*)?\n/,
|
|
1766
|
-
|
|
1767
1874
|
_reserved_identifier: ($) => alias(choice(...reservedIdentifiers, 'auto', 'macro_rules'), $.identifier),
|
|
1768
1875
|
|
|
1769
1876
|
_type_identifier: ($) => alias(choice($.identifier, 'auto', 'macro_rules'), sym('type_identifier')),
|
|
@@ -1824,6 +1931,14 @@ function macroRepetitionSeparator(start, content, end) {
|
|
|
1824
1931
|
);
|
|
1825
1932
|
}
|
|
1826
1933
|
|
|
1934
|
+
/**
|
|
1935
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} ordinary
|
|
1936
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rest
|
|
1937
|
+
*/
|
|
1938
|
+
function commaListWithRest(ordinary, rest) {
|
|
1939
|
+
return seq(repeat(seq(ordinary, ',')), rest, repeat(seq(',', choice(ordinary, rest))), optional(','));
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1827
1942
|
/**
|
|
1828
1943
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} sep
|
|
1829
1944
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
package/package.json
CHANGED
package/src/node-types.json
CHANGED
package/tree-sitter-rust.wasm
CHANGED
|
Binary file
|