@willbooster/tree-sitter-rust 14.0.4 → 14.0.6
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 +103 -47
- package/package.json +1 -1
- package/tree-sitter-rust.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -211,6 +211,7 @@ module.exports = grammar({
|
|
|
211
211
|
supertypes: ($) => [
|
|
212
212
|
$._declaration_statement,
|
|
213
213
|
$._foreign_declaration_statement,
|
|
214
|
+
$._associated_declaration_statement,
|
|
214
215
|
$._block_statement_expression,
|
|
215
216
|
$._expression,
|
|
216
217
|
$._type,
|
|
@@ -248,6 +249,7 @@ module.exports = grammar({
|
|
|
248
249
|
[$.function_modifiers, $.modified_trait_bound],
|
|
249
250
|
[$.function_modifiers, $.impl_item, $.modified_trait_bound],
|
|
250
251
|
[$.const_item, $.function_modifiers],
|
|
252
|
+
[$._associated_const_item, $.function_modifiers],
|
|
251
253
|
// Local ambiguity due to anonymous types:
|
|
252
254
|
// See https://internals.rust-lang.org/t/pre-rfc-deprecating-anonymous-parameters/3710
|
|
253
255
|
[$._type, $._pattern],
|
|
@@ -266,6 +268,7 @@ module.exports = grammar({
|
|
|
266
268
|
global: () => globalKeywords,
|
|
267
269
|
token_tree: () => [],
|
|
268
270
|
lifetime_declaration: () => [...globalKeywords, 'r#static', 'r#_'],
|
|
271
|
+
associated_const_name: () => [...globalKeywords, 'r#_'],
|
|
269
272
|
},
|
|
270
273
|
|
|
271
274
|
word: ($) => $.identifier,
|
|
@@ -296,32 +299,26 @@ module.exports = grammar({
|
|
|
296
299
|
|
|
297
300
|
attributed_declaration: ($) => seq($._outer_attributes, field('declaration', $._attributable_declaration)),
|
|
298
301
|
|
|
299
|
-
_attributable_declaration: ($) =>
|
|
302
|
+
_attributable_declaration: ($) => attributableDeclaration($, $.const_item),
|
|
303
|
+
|
|
304
|
+
_associated_declaration_statement: ($) =>
|
|
300
305
|
choice(
|
|
301
|
-
$.
|
|
302
|
-
$.
|
|
303
|
-
$.
|
|
304
|
-
$.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
$.
|
|
311
|
-
$.
|
|
312
|
-
$.function_signature_item,
|
|
313
|
-
$.impl_item,
|
|
314
|
-
$.trait_item,
|
|
315
|
-
$.trait_alias,
|
|
316
|
-
$.associated_type,
|
|
317
|
-
$.let_declaration,
|
|
318
|
-
$.use_declaration,
|
|
319
|
-
$.extern_crate_declaration,
|
|
320
|
-
$.static_item,
|
|
321
|
-
alias($._safe_function_signature_item, $.function_signature_item),
|
|
322
|
-
alias($._qualified_static_item, $.static_item)
|
|
306
|
+
$.empty_statement,
|
|
307
|
+
$.inner_attribute_item,
|
|
308
|
+
$._associated_attributable_declaration,
|
|
309
|
+
alias($._associated_attributed_declaration, $.attributed_declaration)
|
|
310
|
+
),
|
|
311
|
+
|
|
312
|
+
_associated_attributable_declaration: ($) =>
|
|
313
|
+
attributableDeclaration(
|
|
314
|
+
$,
|
|
315
|
+
alias($._associated_const_item, $.const_item),
|
|
316
|
+
alias($._associated_type_item, $.type_item)
|
|
323
317
|
),
|
|
324
318
|
|
|
319
|
+
_associated_attributed_declaration: ($) =>
|
|
320
|
+
seq($._outer_attributes, field('declaration', $._associated_attributable_declaration)),
|
|
321
|
+
|
|
325
322
|
macro_definition: ($) => {
|
|
326
323
|
const rules = seq(repeat(seq($.macro_rule, ';')), optional($.macro_rule));
|
|
327
324
|
|
|
@@ -519,6 +516,9 @@ module.exports = grammar({
|
|
|
519
516
|
|
|
520
517
|
declaration_list: ($) => seq('{', repeat($._declaration_statement), '}'),
|
|
521
518
|
|
|
519
|
+
_associated_declaration_list: ($) =>
|
|
520
|
+
seq('{', repeat(alias($._associated_declaration_statement, $._declaration_statement)), '}'),
|
|
521
|
+
|
|
522
522
|
// The scanner never emits `_foreign_declaration_context`: its validity enables the zero-width
|
|
523
523
|
// `_foreign_declaration_start` required by qualified extern items. Keep this context marker so `safe` remains
|
|
524
524
|
// an identifier outside extern blocks while qualified items still participate in declaration supertype queries.
|
|
@@ -635,16 +635,12 @@ module.exports = grammar({
|
|
|
635
635
|
';'
|
|
636
636
|
),
|
|
637
637
|
|
|
638
|
-
const_item: ($) =>
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
field('type', $._type),
|
|
645
|
-
optional(seq('=', field('value', $._expression))),
|
|
646
|
-
';'
|
|
647
|
-
),
|
|
638
|
+
const_item: ($) => constItem($, choice($.identifier, $._reserved_identifier, alias('_', $.identifier))),
|
|
639
|
+
|
|
640
|
+
_associated_const_item: ($) =>
|
|
641
|
+
constItem($, choice(reserved('associated_const_name', $.identifier), $._reserved_identifier), [
|
|
642
|
+
optional('default'),
|
|
643
|
+
]),
|
|
648
644
|
|
|
649
645
|
static_item: ($) => seq(optional($.visibility_modifier), $._static_declaration),
|
|
650
646
|
|
|
@@ -663,18 +659,9 @@ module.exports = grammar({
|
|
|
663
659
|
';'
|
|
664
660
|
),
|
|
665
661
|
|
|
666
|
-
type_item: ($) =>
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
'type',
|
|
670
|
-
field('name', $._type_identifier),
|
|
671
|
-
field('type_parameters', optional($.type_parameters)),
|
|
672
|
-
optional($.where_clause),
|
|
673
|
-
'=',
|
|
674
|
-
field('type', $._type),
|
|
675
|
-
optional($.where_clause),
|
|
676
|
-
';'
|
|
677
|
-
),
|
|
662
|
+
type_item: ($) => typeItem($),
|
|
663
|
+
|
|
664
|
+
_associated_type_item: ($) => typeItem($, [optional('default')]),
|
|
678
665
|
|
|
679
666
|
function_item: ($) =>
|
|
680
667
|
seq(
|
|
@@ -759,7 +746,7 @@ module.exports = grammar({
|
|
|
759
746
|
),
|
|
760
747
|
field('type', $._type),
|
|
761
748
|
optional($.where_clause),
|
|
762
|
-
choice(field('body', $.declaration_list), ';')
|
|
749
|
+
choice(field('body', alias($._associated_declaration_list, $.declaration_list)), ';')
|
|
763
750
|
),
|
|
764
751
|
|
|
765
752
|
trait_item: ($) =>
|
|
@@ -773,7 +760,7 @@ module.exports = grammar({
|
|
|
773
760
|
field('type_parameters', optional($.type_parameters)),
|
|
774
761
|
field('bounds', optional($.trait_bounds)),
|
|
775
762
|
optional($.where_clause),
|
|
776
|
-
field('body', $.declaration_list)
|
|
763
|
+
field('body', alias($._associated_declaration_list, $.declaration_list))
|
|
777
764
|
),
|
|
778
765
|
|
|
779
766
|
trait_alias: ($) =>
|
|
@@ -2007,6 +1994,75 @@ module.exports = grammar({
|
|
|
2007
1994
|
},
|
|
2008
1995
|
});
|
|
2009
1996
|
|
|
1997
|
+
/**
|
|
1998
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'empty_statement' | 'inner_attribute_item' | 'macro_invocation' | 'macro_definition' | 'decl_macro' | 'mod_item' | 'foreign_mod_item' | 'struct_item' | 'union_item' | 'enum_item' | 'type_item' | 'function_item' | 'function_signature_item' | 'impl_item' | 'trait_item' | 'trait_alias' | 'associated_type' | 'let_declaration' | 'use_declaration' | 'extern_crate_declaration' | 'static_item' | '_safe_function_signature_item' | '_qualified_static_item'>} $
|
|
1999
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} constant
|
|
2000
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} [typeAlias]
|
|
2001
|
+
*/
|
|
2002
|
+
function attributableDeclaration($, constant, typeAlias = $.type_item) {
|
|
2003
|
+
return choice(
|
|
2004
|
+
constant,
|
|
2005
|
+
$.macro_invocation,
|
|
2006
|
+
$.macro_definition,
|
|
2007
|
+
$.decl_macro,
|
|
2008
|
+
$.mod_item,
|
|
2009
|
+
$.foreign_mod_item,
|
|
2010
|
+
$.struct_item,
|
|
2011
|
+
$.union_item,
|
|
2012
|
+
$.enum_item,
|
|
2013
|
+
typeAlias,
|
|
2014
|
+
$.function_item,
|
|
2015
|
+
$.function_signature_item,
|
|
2016
|
+
$.impl_item,
|
|
2017
|
+
$.trait_item,
|
|
2018
|
+
$.trait_alias,
|
|
2019
|
+
$.associated_type,
|
|
2020
|
+
$.let_declaration,
|
|
2021
|
+
$.use_declaration,
|
|
2022
|
+
$.extern_crate_declaration,
|
|
2023
|
+
$.static_item,
|
|
2024
|
+
alias($._safe_function_signature_item, $.function_signature_item),
|
|
2025
|
+
alias($._qualified_static_item, $.static_item)
|
|
2026
|
+
);
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
/**
|
|
2030
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'visibility_modifier' | '_type' | '_expression'>} $
|
|
2031
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} name
|
|
2032
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral[]} [modifier]
|
|
2033
|
+
*/
|
|
2034
|
+
function constItem($, name, modifier = []) {
|
|
2035
|
+
return seq(
|
|
2036
|
+
optional($.visibility_modifier),
|
|
2037
|
+
...modifier,
|
|
2038
|
+
'const',
|
|
2039
|
+
field('name', name),
|
|
2040
|
+
':',
|
|
2041
|
+
field('type', $._type),
|
|
2042
|
+
optional(seq('=', field('value', $._expression))),
|
|
2043
|
+
';'
|
|
2044
|
+
);
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
/**
|
|
2048
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'visibility_modifier' | '_type_identifier' | 'type_parameters' | 'where_clause' | '_type'>} $
|
|
2049
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral[]} [modifier]
|
|
2050
|
+
*/
|
|
2051
|
+
function typeItem($, modifier = []) {
|
|
2052
|
+
return seq(
|
|
2053
|
+
optional($.visibility_modifier),
|
|
2054
|
+
...modifier,
|
|
2055
|
+
'type',
|
|
2056
|
+
field('name', $._type_identifier),
|
|
2057
|
+
field('type_parameters', optional($.type_parameters)),
|
|
2058
|
+
optional($.where_clause),
|
|
2059
|
+
'=',
|
|
2060
|
+
field('type', $._type),
|
|
2061
|
+
optional($.where_clause),
|
|
2062
|
+
';'
|
|
2063
|
+
);
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2010
2066
|
/**
|
|
2011
2067
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} start
|
|
2012
2068
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} content
|
package/package.json
CHANGED
package/tree-sitter-rust.wasm
CHANGED
|
Binary file
|