@willbooster/tree-sitter-rust 14.0.4 → 14.0.5
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 +72 -35
- 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,22 @@ 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
|
-
$.mod_item,
|
|
306
|
-
$.foreign_mod_item,
|
|
307
|
-
$.struct_item,
|
|
308
|
-
$.union_item,
|
|
309
|
-
$.enum_item,
|
|
310
|
-
$.type_item,
|
|
311
|
-
$.function_item,
|
|
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)
|
|
323
310
|
),
|
|
324
311
|
|
|
312
|
+
_associated_attributable_declaration: ($) =>
|
|
313
|
+
attributableDeclaration($, alias($._associated_const_item, $.const_item)),
|
|
314
|
+
|
|
315
|
+
_associated_attributed_declaration: ($) =>
|
|
316
|
+
seq($._outer_attributes, field('declaration', $._associated_attributable_declaration)),
|
|
317
|
+
|
|
325
318
|
macro_definition: ($) => {
|
|
326
319
|
const rules = seq(repeat(seq($.macro_rule, ';')), optional($.macro_rule));
|
|
327
320
|
|
|
@@ -519,6 +512,9 @@ module.exports = grammar({
|
|
|
519
512
|
|
|
520
513
|
declaration_list: ($) => seq('{', repeat($._declaration_statement), '}'),
|
|
521
514
|
|
|
515
|
+
_associated_declaration_list: ($) =>
|
|
516
|
+
seq('{', repeat(alias($._associated_declaration_statement, $._declaration_statement)), '}'),
|
|
517
|
+
|
|
522
518
|
// The scanner never emits `_foreign_declaration_context`: its validity enables the zero-width
|
|
523
519
|
// `_foreign_declaration_start` required by qualified extern items. Keep this context marker so `safe` remains
|
|
524
520
|
// an identifier outside extern blocks while qualified items still participate in declaration supertype queries.
|
|
@@ -635,16 +631,10 @@ module.exports = grammar({
|
|
|
635
631
|
';'
|
|
636
632
|
),
|
|
637
633
|
|
|
638
|
-
const_item: ($) =>
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
field('name', choice($.identifier, $._reserved_identifier, alias('_', $.identifier))),
|
|
643
|
-
':',
|
|
644
|
-
field('type', $._type),
|
|
645
|
-
optional(seq('=', field('value', $._expression))),
|
|
646
|
-
';'
|
|
647
|
-
),
|
|
634
|
+
const_item: ($) => constItem($, choice($.identifier, $._reserved_identifier, alias('_', $.identifier))),
|
|
635
|
+
|
|
636
|
+
_associated_const_item: ($) =>
|
|
637
|
+
constItem($, choice(reserved('associated_const_name', $.identifier), $._reserved_identifier)),
|
|
648
638
|
|
|
649
639
|
static_item: ($) => seq(optional($.visibility_modifier), $._static_declaration),
|
|
650
640
|
|
|
@@ -759,7 +749,7 @@ module.exports = grammar({
|
|
|
759
749
|
),
|
|
760
750
|
field('type', $._type),
|
|
761
751
|
optional($.where_clause),
|
|
762
|
-
choice(field('body', $.declaration_list), ';')
|
|
752
|
+
choice(field('body', alias($._associated_declaration_list, $.declaration_list)), ';')
|
|
763
753
|
),
|
|
764
754
|
|
|
765
755
|
trait_item: ($) =>
|
|
@@ -773,7 +763,7 @@ module.exports = grammar({
|
|
|
773
763
|
field('type_parameters', optional($.type_parameters)),
|
|
774
764
|
field('bounds', optional($.trait_bounds)),
|
|
775
765
|
optional($.where_clause),
|
|
776
|
-
field('body', $.declaration_list)
|
|
766
|
+
field('body', alias($._associated_declaration_list, $.declaration_list))
|
|
777
767
|
),
|
|
778
768
|
|
|
779
769
|
trait_alias: ($) =>
|
|
@@ -2007,6 +1997,53 @@ module.exports = grammar({
|
|
|
2007
1997
|
},
|
|
2008
1998
|
});
|
|
2009
1999
|
|
|
2000
|
+
/**
|
|
2001
|
+
* @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'>} $
|
|
2002
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} constant
|
|
2003
|
+
*/
|
|
2004
|
+
function attributableDeclaration($, constant) {
|
|
2005
|
+
return choice(
|
|
2006
|
+
constant,
|
|
2007
|
+
$.macro_invocation,
|
|
2008
|
+
$.macro_definition,
|
|
2009
|
+
$.decl_macro,
|
|
2010
|
+
$.mod_item,
|
|
2011
|
+
$.foreign_mod_item,
|
|
2012
|
+
$.struct_item,
|
|
2013
|
+
$.union_item,
|
|
2014
|
+
$.enum_item,
|
|
2015
|
+
$.type_item,
|
|
2016
|
+
$.function_item,
|
|
2017
|
+
$.function_signature_item,
|
|
2018
|
+
$.impl_item,
|
|
2019
|
+
$.trait_item,
|
|
2020
|
+
$.trait_alias,
|
|
2021
|
+
$.associated_type,
|
|
2022
|
+
$.let_declaration,
|
|
2023
|
+
$.use_declaration,
|
|
2024
|
+
$.extern_crate_declaration,
|
|
2025
|
+
$.static_item,
|
|
2026
|
+
alias($._safe_function_signature_item, $.function_signature_item),
|
|
2027
|
+
alias($._qualified_static_item, $.static_item)
|
|
2028
|
+
);
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
/**
|
|
2032
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'visibility_modifier' | '_type' | '_expression'>} $
|
|
2033
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} name
|
|
2034
|
+
*/
|
|
2035
|
+
function constItem($, name) {
|
|
2036
|
+
return seq(
|
|
2037
|
+
optional($.visibility_modifier),
|
|
2038
|
+
'const',
|
|
2039
|
+
field('name', name),
|
|
2040
|
+
':',
|
|
2041
|
+
field('type', $._type),
|
|
2042
|
+
optional(seq('=', field('value', $._expression))),
|
|
2043
|
+
';'
|
|
2044
|
+
);
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2010
2047
|
/**
|
|
2011
2048
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} start
|
|
2012
2049
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} content
|
package/package.json
CHANGED
package/tree-sitter-rust.wasm
CHANGED
|
Binary file
|