@willbooster/tree-sitter-rust 14.0.6 → 16.0.0

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
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.48.9-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-21.3.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-rust.svg)](https://crates.io/crates/willbooster-tree-sitter-rust)
10
10
 
11
11
  Rust grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
@@ -14,6 +14,13 @@ to its authors and contributors. This is not an official release of that project
14
14
 
15
15
  This fork fixes parsing bugs and raises conformance with [The Rust Reference](https://doc.rust-lang.org/reference/).
16
16
 
17
+ ## Support Scope
18
+
19
+ This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
20
+ nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
21
+ but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
22
+ the trees that error recovery produces may change; such changes are released as new major versions.
23
+
17
24
  ## Usage
18
25
 
19
26
  The npm package ships `tree-sitter-rust.wasm` for
@@ -59,13 +66,7 @@ const parser = new Parser();
59
66
  parser.setLanguage(await Language.load(rust));
60
67
  ```
61
68
 
62
- The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
63
-
64
- Documentation-comment injections require a host with Markdown parsing and fenced-language injections.
65
- Line documentation is combined across the syntax tree; an unclosed fence can affect later comments.
66
- Each block comment is a separate Markdown document. Its content is passed through unchanged, including
67
- leading `*` gutters, which remain Markdown text and can prevent fence recognition. Use unguttered block
68
- documentation or line documentation for fenced examples with these queries.
69
+ The package also ships the node types in `src/node-types.json`.
69
70
 
70
71
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-rust) and on
71
72
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
@@ -110,7 +111,7 @@ For a joint token, an optional lifetime and mutability describe the inner refere
110
111
 
111
112
  An attribute in an expression position can produce an `attributed_expression` node with a `value` field.
112
113
  For example, in `let x = #[allow(unused)] 1 + 2;`, that field contains `1`; the enclosing binary expression
113
- still contains `+ 2`. Consecutive attributes share one wrapper. Queries matching `_expression` include
114
+ still contains `+ 2`. Consecutive attributes share one wrapper. The `_expression` supertype includes
114
115
  these wrappers, including attributed block statements. The `value` field identifies the operand.
115
116
 
116
117
  Outer declaration attributes belong to an `attributed_declaration` node whose `declaration` field identifies
@@ -127,8 +128,8 @@ errors may return larger `ERROR` subtrees. Ordinary line comments are leaf nodes
127
128
  than an anonymous `//` child.
128
129
 
129
130
  Parameter and list attributes retain their sibling nodes. Attributes inside parentheses also precede
130
- the operand as siblings. List and parenthesized operands remain queryable through
131
- `_expression`. Compiler feature gates and attribute-placement diagnostics remain the compiler's responsibility.
131
+ the operand as siblings. List and parenthesized operands remain in the
132
+ `_expression` supertype. Compiler feature gates and attribute-placement diagnostics remain the compiler's responsibility.
132
133
 
133
134
  ## Development
134
135
 
@@ -157,9 +158,6 @@ and the release build regenerate the parsers before compiling them.
157
158
  `bun run test` runs:
158
159
 
159
160
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
160
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
161
- edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
162
- `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
163
161
  - a check that the real-world Rust files in `examples/`, the checked-in ones and those of the cloned repositories,
164
162
  fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example
165
163
  repositories are pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
@@ -173,7 +171,7 @@ and the release build regenerate the parsers before compiling them.
173
171
  Node.js compatibility (`test/unit/workerd.test.ts`). Run `bun run test/ci-setup` once to install Chromium.
174
172
 
175
173
  The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
176
- by every checkout; `script/fuzz-corpus` builds a per-run parser in `.tmp/fuzz` and deletes it afterwards.
174
+ by every checkout.
177
175
 
178
176
  CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
179
177
  parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
package/grammar.js CHANGED
@@ -313,7 +313,8 @@ module.exports = grammar({
313
313
  attributableDeclaration(
314
314
  $,
315
315
  alias($._associated_const_item, $.const_item),
316
- alias($._associated_type_item, $.type_item)
316
+ alias($._associated_type_item, $.type_item),
317
+ alias($._associated_type_declaration, $.associated_type)
317
318
  ),
318
319
 
319
320
  _associated_attributed_declaration: ($) =>
@@ -779,16 +780,9 @@ module.exports = grammar({
779
780
  trait_alias_bounds: ($) =>
780
781
  seq(sepBy1('+', choice($._type, $.lifetime, $.higher_ranked_trait_bound)), optional('+')),
781
782
 
782
- associated_type: ($) =>
783
- seq(
784
- optional($.visibility_modifier),
785
- 'type',
786
- field('name', $._type_identifier),
787
- field('type_parameters', optional($.type_parameters)),
788
- field('bounds', optional($.trait_bounds)),
789
- optional($.where_clause),
790
- ';'
791
- ),
783
+ associated_type: ($) => associatedType($),
784
+
785
+ _associated_type_declaration: ($) => associatedType($, [optional('default')]),
792
786
 
793
787
  trait_bounds: ($) =>
794
788
  prec.right(
@@ -1998,8 +1992,9 @@ module.exports = grammar({
1998
1992
  * @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
1993
  * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} constant
2000
1994
  * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} [typeAlias]
1995
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} [typeDeclaration]
2001
1996
  */
2002
- function attributableDeclaration($, constant, typeAlias = $.type_item) {
1997
+ function attributableDeclaration($, constant, typeAlias = $.type_item, typeDeclaration = $.associated_type) {
2003
1998
  return choice(
2004
1999
  constant,
2005
2000
  $.macro_invocation,
@@ -2016,7 +2011,7 @@ function attributableDeclaration($, constant, typeAlias = $.type_item) {
2016
2011
  $.impl_item,
2017
2012
  $.trait_item,
2018
2013
  $.trait_alias,
2019
- $.associated_type,
2014
+ typeDeclaration,
2020
2015
  $.let_declaration,
2021
2016
  $.use_declaration,
2022
2017
  $.extern_crate_declaration,
@@ -2026,6 +2021,23 @@ function attributableDeclaration($, constant, typeAlias = $.type_item) {
2026
2021
  );
2027
2022
  }
2028
2023
 
2024
+ /**
2025
+ * @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'visibility_modifier' | '_type_identifier' | 'type_parameters' | 'trait_bounds' | 'where_clause'>} $
2026
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral[]} [modifier]
2027
+ */
2028
+ function associatedType($, modifier = []) {
2029
+ return seq(
2030
+ optional($.visibility_modifier),
2031
+ ...modifier,
2032
+ 'type',
2033
+ field('name', $._type_identifier),
2034
+ field('type_parameters', optional($.type_parameters)),
2035
+ field('bounds', optional($.trait_bounds)),
2036
+ optional($.where_clause),
2037
+ ';'
2038
+ );
2039
+ }
2040
+
2029
2041
  /**
2030
2042
  * @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'visibility_modifier' | '_type' | '_expression'>} $
2031
2043
  * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "14.0.6",
3
+ "version": "16.0.0",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -16,7 +16,6 @@
16
16
  },
17
17
  "files": [
18
18
  "grammar.js",
19
- "queries/*.scm",
20
19
  "tree-sitter.json",
21
20
  "src/node-types.json",
22
21
  "*.wasm"
@@ -46,20 +45,20 @@
46
45
  },
47
46
  "devDependencies": {
48
47
  "@tsconfig/bun": "1.0.11",
49
- "@types/bun": "1.4.3",
48
+ "@types/bun": "1.4.4",
50
49
  "@vitest/browser-playwright": "5.0.5",
51
50
  "@willbooster/oxlint-config": "1.4.9",
52
- "@willbooster/wb": "22.29.3",
53
- "@willbooster/web-tree-sitter": "15.0.0",
51
+ "@willbooster/wb": "23.0.2",
52
+ "@willbooster/web-tree-sitter": "15.5.4",
54
53
  "conventional-changelog-conventionalcommits": "10.4.1",
55
54
  "lefthook": "2.2.2",
56
- "oxlint": "1.88.0",
57
- "oxlint-tsgolint": "7.0.2004",
55
+ "oxlint": "1.89.0",
56
+ "oxlint-tsgolint": "7.0.2005",
58
57
  "playwright": "1.64.1",
59
58
  "semantic-release": "25.0.9",
60
- "vite": "8.3.4",
59
+ "vite": "8.3.5",
61
60
  "vitest": "5.0.5",
62
- "wrangler": "4.151.1"
61
+ "wrangler": "4.152.0"
63
62
  },
64
63
  "peerDependencies": {
65
64
  "@willbooster/web-tree-sitter": "^15.0.0"
Binary file
package/tree-sitter.json CHANGED
@@ -9,15 +9,6 @@
9
9
  "file-types": [
10
10
  "rs"
11
11
  ],
12
- "highlights": [
13
- "queries/highlights.scm"
14
- ],
15
- "injections": [
16
- "queries/injections.scm"
17
- ],
18
- "tags": [
19
- "queries/tags.scm"
20
- ],
21
12
  "injection-regex": "rust",
22
13
  "external-files": [
23
14
  "src/frontmatter.h"
@@ -25,7 +16,7 @@
25
16
  }
26
17
  ],
27
18
  "metadata": {
28
- "version": "14.0.6",
19
+ "version": "16.0.0",
29
20
  "license": "MIT",
30
21
  "description": "Rust grammar for tree-sitter",
31
22
  "authors": [
@@ -1,168 +0,0 @@
1
- (type_identifier) @type
2
- (primitive_type) @type.builtin
3
- (field_identifier) @property
4
-
5
-
6
- ((identifier) @constant
7
- (#match? @constant "^[A-Z][A-Z\\d_]+$'"))
8
-
9
- ((identifier) @constructor
10
- (#match? @constructor "^[A-Z]"))
11
-
12
- ((scoped_identifier
13
- path: (identifier) @type)
14
- (#match? @type "^[A-Z]"))
15
- ((scoped_identifier
16
- path: (scoped_identifier
17
- name: (identifier) @type))
18
- (#match? @type "^[A-Z]"))
19
- ((scoped_type_identifier
20
- path: (identifier) @type)
21
- (#match? @type "^[A-Z]"))
22
- ((scoped_type_identifier
23
- path: (scoped_identifier
24
- name: (identifier) @type))
25
- (#match? @type "^[A-Z]"))
26
-
27
- ; Assume all qualified names in struct patterns are enum constructors. (They're
28
- ; either that, or struct names; highlighting both as constructors seems to be
29
- ; the less glaring choice of error, visually.)
30
- (struct_pattern
31
- type: (scoped_type_identifier
32
- name: (type_identifier) @constructor))
33
- (struct_pattern
34
- type: (generic_type
35
- type: (scoped_type_identifier
36
- name: (type_identifier) @constructor)))
37
-
38
-
39
- (call_expression
40
- function: (identifier) @function)
41
- (call_expression
42
- function: (field_expression
43
- field: (field_identifier) @function.method))
44
- (call_expression
45
- function: (scoped_identifier
46
- "::"
47
- name: (identifier) @function))
48
-
49
- (generic_function
50
- function: (identifier) @function)
51
- (generic_function
52
- function: (scoped_identifier
53
- name: (identifier) @function))
54
- (generic_function
55
- function: (field_expression
56
- field: (field_identifier) @function.method))
57
-
58
- (macro_invocation
59
- macro: (identifier) @function.macro
60
- "!" @function.macro)
61
-
62
- (decl_macro name: (identifier) @function.macro)
63
-
64
-
65
- (function_item (identifier) @function)
66
- (function_signature_item (identifier) @function)
67
-
68
- (line_comment) @comment
69
- (block_comment) @comment
70
- (frontmatter) @comment
71
-
72
- (line_comment (doc_comment)) @comment.documentation
73
- (block_comment (doc_comment)) @comment.documentation
74
-
75
- "(" @punctuation.bracket
76
- ")" @punctuation.bracket
77
- "[" @punctuation.bracket
78
- "]" @punctuation.bracket
79
- "{" @punctuation.bracket
80
- "}" @punctuation.bracket
81
-
82
- (type_arguments
83
- "<" @punctuation.bracket
84
- ">" @punctuation.bracket)
85
- (type_parameters
86
- "<" @punctuation.bracket
87
- ">" @punctuation.bracket)
88
-
89
- "::" @punctuation.delimiter
90
- ":" @punctuation.delimiter
91
- "." @punctuation.delimiter
92
- "," @punctuation.delimiter
93
- ";" @punctuation.delimiter
94
-
95
- (parameter (identifier) @variable.parameter)
96
-
97
- (lifetime (identifier) @label)
98
-
99
- "as" @keyword
100
- "async" @keyword
101
- "auto" @keyword
102
- "await" @keyword
103
- "become" @keyword
104
- "box" @keyword
105
- "break" @keyword
106
- "const" @keyword
107
- "continue" @keyword
108
- "default" @keyword
109
- "dyn" @keyword
110
- "else" @keyword
111
- "enum" @keyword
112
- "extern" @keyword
113
- "fn" @keyword
114
- "for" @keyword
115
- "gen" @keyword
116
- "if" @keyword
117
- "impl" @keyword
118
- "in" @keyword
119
- "let" @keyword
120
- "loop" @keyword
121
- "macro_rules!" @keyword
122
- (macro_definition "!" @keyword)
123
- "macro" @keyword
124
- "match" @keyword
125
- "mod" @keyword
126
- "move" @keyword
127
- "pub" @keyword
128
- "raw" @keyword
129
- "ref" @keyword
130
- "return" @keyword
131
- "safe" @keyword
132
- "static" @keyword
133
- "struct" @keyword
134
- "trait" @keyword
135
- "type" @keyword
136
- "union" @keyword
137
- "unsafe" @keyword
138
- "use" @keyword
139
- "where" @keyword
140
- "while" @keyword
141
- "yield" @keyword
142
- (crate) @keyword
143
- (mutable_specifier) @keyword
144
- (use_list (self) @keyword)
145
- (scoped_use_list (self) @keyword)
146
- (scoped_identifier (self) @keyword)
147
- (super) @keyword
148
-
149
- (self) @variable.builtin
150
-
151
- (char_literal) @string
152
- (string_literal) @string
153
- (raw_string_literal) @string
154
-
155
- (boolean_literal) @constant.builtin
156
- (integer_literal) @constant.builtin
157
- (float_literal) @constant.builtin
158
-
159
- (escape_sequence) @escape
160
-
161
- (attribute_item (attribute)) @attribute
162
- (inner_attribute_item) @attribute
163
-
164
- "*" @operator
165
- "&" @operator
166
- (reference_type "&&" @operator)
167
- (reference_pattern "&&" @operator)
168
- "'" @operator
@@ -1,24 +0,0 @@
1
- ((macro_invocation
2
- (token_tree) @injection.content)
3
- (#set! injection.language "rust")
4
- (#set! injection.include-children))
5
-
6
- ((macro_rule
7
- (token_tree) @injection.content)
8
- (#set! injection.language "rust")
9
- (#set! injection.include-children))
10
-
11
- ((decl_macro
12
- parameters: (token_tree)
13
- body: (token_tree) @injection.content)
14
- (#set! injection.language "rust")
15
- (#set! injection.include-children))
16
-
17
- ((line_comment
18
- doc: (doc_comment) @injection.content)
19
- (#set! injection.language "markdown")
20
- (#set! injection.combined))
21
-
22
- ((block_comment
23
- doc: (doc_comment) @injection.content)
24
- (#set! injection.language "markdown"))
package/queries/tags.scm DELETED
@@ -1,55 +0,0 @@
1
- (struct_item
2
- name: (type_identifier) @name) @definition.class
3
-
4
- (enum_item
5
- name: (type_identifier) @name) @definition.class
6
-
7
- (union_item
8
- name: (type_identifier) @name) @definition.class
9
-
10
- (type_item
11
- name: (type_identifier) @name) @definition.class
12
-
13
- (declaration_list
14
- (function_item
15
- name: (identifier) @name) @definition.method)
16
-
17
- (declaration_list
18
- (attributed_declaration
19
- declaration: (function_item
20
- name: (identifier) @name) @definition.method))
21
-
22
- (function_item
23
- name: (identifier) @name) @definition.function
24
-
25
- (trait_item
26
- name: (type_identifier) @name) @definition.interface
27
-
28
- (trait_alias
29
- name: (type_identifier) @name) @definition.interface
30
-
31
- (mod_item
32
- name: (identifier) @name) @definition.module
33
-
34
- (macro_definition
35
- name: (identifier) @name) @definition.macro
36
-
37
- (decl_macro
38
- name: (identifier) @name) @definition.macro
39
-
40
- (call_expression
41
- function: (identifier) @name) @reference.call
42
-
43
- (call_expression
44
- function: (field_expression
45
- field: (field_identifier) @name)) @reference.call
46
-
47
- (macro_invocation
48
- macro: (identifier) @name) @reference.call
49
-
50
- (impl_item
51
- trait: (type_identifier) @name) @reference.implementation
52
-
53
- (impl_item
54
- type: (type_identifier) @name
55
- !trait) @reference.implementation