@willbooster/tree-sitter-rust 14.0.3 → 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 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],
@@ -265,6 +267,8 @@ module.exports = grammar({
265
267
  reserved: {
266
268
  global: () => globalKeywords,
267
269
  token_tree: () => [],
270
+ lifetime_declaration: () => [...globalKeywords, 'r#static', 'r#_'],
271
+ associated_const_name: () => [...globalKeywords, 'r#_'],
268
272
  },
269
273
 
270
274
  word: ($) => $.identifier,
@@ -295,32 +299,22 @@ module.exports = grammar({
295
299
 
296
300
  attributed_declaration: ($) => seq($._outer_attributes, field('declaration', $._attributable_declaration)),
297
301
 
298
- _attributable_declaration: ($) =>
302
+ _attributable_declaration: ($) => attributableDeclaration($, $.const_item),
303
+
304
+ _associated_declaration_statement: ($) =>
299
305
  choice(
300
- $.const_item,
301
- $.macro_invocation,
302
- $.macro_definition,
303
- $.decl_macro,
304
- $.mod_item,
305
- $.foreign_mod_item,
306
- $.struct_item,
307
- $.union_item,
308
- $.enum_item,
309
- $.type_item,
310
- $.function_item,
311
- $.function_signature_item,
312
- $.impl_item,
313
- $.trait_item,
314
- $.trait_alias,
315
- $.associated_type,
316
- $.let_declaration,
317
- $.use_declaration,
318
- $.extern_crate_declaration,
319
- $.static_item,
320
- alias($._safe_function_signature_item, $.function_signature_item),
321
- alias($._qualified_static_item, $.static_item)
306
+ $.empty_statement,
307
+ $.inner_attribute_item,
308
+ $._associated_attributable_declaration,
309
+ alias($._associated_attributed_declaration, $.attributed_declaration)
322
310
  ),
323
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
+
324
318
  macro_definition: ($) => {
325
319
  const rules = seq(repeat(seq($.macro_rule, ';')), optional($.macro_rule));
326
320
 
@@ -518,6 +512,9 @@ module.exports = grammar({
518
512
 
519
513
  declaration_list: ($) => seq('{', repeat($._declaration_statement), '}'),
520
514
 
515
+ _associated_declaration_list: ($) =>
516
+ seq('{', repeat(alias($._associated_declaration_statement, $._declaration_statement)), '}'),
517
+
521
518
  // The scanner never emits `_foreign_declaration_context`: its validity enables the zero-width
522
519
  // `_foreign_declaration_start` required by qualified extern items. Keep this context marker so `safe` remains
523
520
  // an identifier outside extern blocks while qualified items still participate in declaration supertype queries.
@@ -634,16 +631,10 @@ module.exports = grammar({
634
631
  ';'
635
632
  ),
636
633
 
637
- const_item: ($) =>
638
- seq(
639
- optional($.visibility_modifier),
640
- 'const',
641
- field('name', choice($.identifier, $._reserved_identifier, alias('_', $.identifier))),
642
- ':',
643
- field('type', $._type),
644
- optional(seq('=', field('value', $._expression))),
645
- ';'
646
- ),
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)),
647
638
 
648
639
  static_item: ($) => seq(optional($.visibility_modifier), $._static_declaration),
649
640
 
@@ -758,7 +749,7 @@ module.exports = grammar({
758
749
  ),
759
750
  field('type', $._type),
760
751
  optional($.where_clause),
761
- choice(field('body', $.declaration_list), ';')
752
+ choice(field('body', alias($._associated_declaration_list, $.declaration_list)), ';')
762
753
  ),
763
754
 
764
755
  trait_item: ($) =>
@@ -772,7 +763,7 @@ module.exports = grammar({
772
763
  field('type_parameters', optional($.type_parameters)),
773
764
  field('bounds', optional($.trait_bounds)),
774
765
  optional($.where_clause),
775
- field('body', $.declaration_list)
766
+ field('body', alias($._associated_declaration_list, $.declaration_list))
776
767
  ),
777
768
 
778
769
  trait_alias: ($) =>
@@ -858,7 +849,11 @@ module.exports = grammar({
858
849
  )
859
850
  ),
860
851
 
861
- lifetime_parameter: ($) => prec(1, seq(field('name', $.lifetime), optional(field('bounds', $.trait_bounds)))),
852
+ lifetime_parameter: ($) =>
853
+ prec(
854
+ 1,
855
+ seq(field('name', alias($._lifetime_declaration, $.lifetime)), optional(field('bounds', $.trait_bounds)))
856
+ ),
862
857
 
863
858
  let_declaration: ($) =>
864
859
  seq(
@@ -935,11 +930,23 @@ module.exports = grammar({
935
930
 
936
931
  qualified_type: ($) => seq(field('type', $._type), 'as', field('alias', $._type)),
937
932
 
938
- lifetime: ($) => prec(1, seq("'", choice($.identifier, alias(choice('static', '_'), $.identifier)))),
933
+ lifetime: ($) =>
934
+ prec(1, seq("'", choice($.identifier, alias(choice('static', '_', 'r#static', 'r#_'), $.identifier)))),
935
+
936
+ _lifetime_declaration: ($) => prec(1, seq("'", reserved('lifetime_declaration', $.identifier))),
939
937
 
940
938
  array_type: ($) => seq('[', field('element', $._type), optional(seq(';', field('length', $._expression))), ']'),
941
939
 
942
- for_lifetimes: ($) => prec(1, seq('for', '<', optional(seq(sepBy1(',', prec(1, $.lifetime)), optional(','))), '>')),
940
+ for_lifetimes: ($) =>
941
+ prec(
942
+ 1,
943
+ seq(
944
+ 'for',
945
+ '<',
946
+ optional(seq(sepBy1(',', prec(1, alias($._lifetime_declaration, $.lifetime))), optional(','))),
947
+ '>'
948
+ )
949
+ ),
943
950
 
944
951
  function_type: ($) =>
945
952
  seq(
@@ -1990,6 +1997,53 @@ module.exports = grammar({
1990
1997
  },
1991
1998
  });
1992
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
+
1993
2047
  /**
1994
2048
  * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} start
1995
2049
  * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} content
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "14.0.3",
3
+ "version": "14.0.5",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
package/tree-sitter.json CHANGED
@@ -25,7 +25,7 @@
25
25
  }
26
26
  ],
27
27
  "metadata": {
28
- "version": "14.0.3",
28
+ "version": "14.0.5",
29
29
  "license": "MIT",
30
30
  "description": "Rust grammar for tree-sitter",
31
31
  "authors": [