@willbooster/tree-sitter-rust 1.0.0 → 1.1.1

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/README.md CHANGED
@@ -93,7 +93,7 @@ cargo test
93
93
  fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example repositories are pinned to commits in
94
94
  `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
95
95
  it; review its diff before committing;
96
- - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
96
+ - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each line takes
97
97
  linear time, since consumers parse files while they are being edited. It loads the Wasm build through
98
98
  @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parser;
99
99
  - checks that the Wasm build parses in Chromium (`test/unit/browser/`) and in Cloudflare Workers with and without
package/grammar.js CHANGED
@@ -307,10 +307,41 @@ module.exports = grammar({
307
307
  choice(';', field('body', $.declaration_list))
308
308
  ),
309
309
 
310
- foreign_mod_item: ($) => seq(optional('unsafe'), $.extern_modifier, choice(';', field('body', $.declaration_list))),
310
+ foreign_mod_item: ($) =>
311
+ seq(
312
+ optional('unsafe'),
313
+ $.extern_modifier,
314
+ choice(';', field('body', alias($._foreign_declaration_list, $.declaration_list)))
315
+ ),
311
316
 
312
317
  declaration_list: ($) => seq('{', repeat($._declaration_statement), '}'),
313
318
 
319
+ // Items in `extern` blocks may be `safe` functions and `safe` or `unsafe` statics. `safe` is a keyword only where
320
+ // such an item starts: accepting it on every item would make it one wherever an item can start, breaking its uses as
321
+ // an identifier (`let safe = …; safe = …;`).
322
+ _foreign_declaration_list: ($) =>
323
+ seq(
324
+ '{',
325
+ repeat(
326
+ choice(
327
+ $._declaration_statement,
328
+ alias($._safe_function_signature_item, $.function_signature_item),
329
+ alias($._qualified_static_item, $.static_item)
330
+ )
331
+ ),
332
+ '}'
333
+ ),
334
+
335
+ _safe_function_signature_item: ($) =>
336
+ seq(optional($.visibility_modifier), alias($._safe_modifier, $.function_modifiers), $._function_signature),
337
+
338
+ // Aliasing the bare token instead would make `function_modifiers` a leaf without the `safe` child that other
339
+ // modifiers have.
340
+ _safe_modifier: () => 'safe',
341
+
342
+ _qualified_static_item: ($) =>
343
+ seq(optional($.visibility_modifier), choice('safe', 'unsafe'), $._static_declaration),
344
+
314
345
  struct_item: ($) =>
315
346
  seq(
316
347
  optional($.visibility_modifier),
@@ -389,9 +420,10 @@ module.exports = grammar({
389
420
  ';'
390
421
  ),
391
422
 
392
- static_item: ($) =>
423
+ static_item: ($) => seq(optional($.visibility_modifier), $._static_declaration),
424
+
425
+ _static_declaration: ($) =>
393
426
  seq(
394
- optional($.visibility_modifier),
395
427
  'static',
396
428
 
397
429
  // Not actual rust syntax, but made popular by the lazy_static crate.
@@ -432,9 +464,10 @@ module.exports = grammar({
432
464
  ),
433
465
 
434
466
  function_signature_item: ($) =>
467
+ seq(optional($.visibility_modifier), optional($.function_modifiers), $._function_signature),
468
+
469
+ _function_signature: ($) =>
435
470
  seq(
436
- optional($.visibility_modifier),
437
- optional($.function_modifiers),
438
471
  'fn',
439
472
  field('name', choice($.identifier, $.metavariable)),
440
473
  field('type_parameters', optional($.type_parameters)),
@@ -800,7 +833,15 @@ module.exports = grammar({
800
833
 
801
834
  macro_invocation: ($) =>
802
835
  seq(
803
- field('macro', choice($.scoped_identifier, $.identifier, $._reserved_identifier)),
836
+ field(
837
+ 'macro',
838
+ choice(
839
+ $.scoped_identifier,
840
+ $.identifier,
841
+ alias(choice(...primitiveTypes), $.identifier),
842
+ $._reserved_identifier
843
+ )
844
+ ),
804
845
  '!',
805
846
  alias($.delim_token_tree, $.token_tree)
806
847
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -5587,6 +5587,10 @@
5587
5587
  "type": "return",
5588
5588
  "named": false
5589
5589
  },
5590
+ {
5591
+ "type": "safe",
5592
+ "named": false
5593
+ },
5590
5594
  {
5591
5595
  "type": "self",
5592
5596
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -22,7 +22,7 @@
22
22
  }
23
23
  ],
24
24
  "metadata": {
25
- "version": "1.0.0",
25
+ "version": "1.1.1",
26
26
  "license": "MIT",
27
27
  "description": "Rust grammar for tree-sitter",
28
28
  "authors": [