@willbooster/tree-sitter-rust 1.1.5 → 1.1.7
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 +24 -13
- package/grammar.js +1 -4
- package/package.json +8 -8
- package/queries/highlights.scm +162 -0
- package/queries/injections.scm +9 -0
- package/queries/tags.scm +60 -0
- package/tree-sitter-rust.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](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
|
|
@@ -57,7 +57,7 @@ const parser = new Parser();
|
|
|
57
57
|
parser.setLanguage(await Language.load(rust));
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
The package also ships the node types in `src/node-types.json`.
|
|
60
|
+
The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
|
|
61
61
|
|
|
62
62
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-rust) and on
|
|
63
63
|
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
|
|
@@ -86,24 +86,35 @@ script/parse-examples
|
|
|
86
86
|
cargo test
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
The scripts and tests generate, build, test, and parse with `script/tree-sitter`, the tree-sitter CLI of the
|
|
90
|
+
WillBooster/tree-sitter runtime version locked in `Cargo.lock`, since the generator and the runtime of upstream's CLI are
|
|
91
|
+
not the ones this package ships with. Its first run downloads that CLI from the runtime's GitHub Release, or builds it
|
|
92
|
+
with `cargo` (which needs CMake) when the download fails or the release has no binary that runs here. Run other CLI
|
|
93
|
+
commands through it as well (e.g. `script/tree-sitter parse file.rs`).
|
|
94
|
+
|
|
89
95
|
`bun run test` runs:
|
|
90
96
|
|
|
91
97
|
- the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
|
|
92
|
-
- an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz
|
|
93
|
-
reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
|
|
94
|
-
`TREE_SITTER_EDITS` run other or more edits;
|
|
98
|
+
- an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
|
|
99
|
+
edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
|
|
100
|
+
`TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
|
|
95
101
|
- a check that the real-world Rust files in `examples/`, the checked-in ones and those of the cloned repositories,
|
|
96
|
-
fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example
|
|
97
|
-
`script/parse-examples`. After a grammar change or a moved pin alters that list,
|
|
98
|
-
it; review its diff before committing;
|
|
99
|
-
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each line takes
|
|
100
|
-
|
|
101
|
-
@willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after
|
|
102
|
+
fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example
|
|
103
|
+
repositories are pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
|
|
104
|
+
`script/parse-examples` rewrites it; review its diff before committing;
|
|
105
|
+
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each line takes linear time
|
|
106
|
+
(ten times the lines take about ten times the CPU time, under a ceiling), since consumers parse files while they are
|
|
107
|
+
being edited. It loads the Wasm build through @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after
|
|
108
|
+
regenerating the parser;
|
|
109
|
+
- a check that `package.json` and `Cargo.lock` test the same runtime version (`test/unit/runtimeVersion.test.ts`);
|
|
102
110
|
- checks that the Wasm build parses in Chromium (`test/unit/browser/`) and in Cloudflare Workers with and without
|
|
103
111
|
Node.js compatibility (`test/unit/workerd.test.ts`). Run `bun run test/ci-setup` once to install Chromium.
|
|
104
112
|
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
|
|
114
|
+
by every checkout; `script/fuzz-corpus` builds a per-run parser in `.tmp/fuzz` and deletes it afterwards.
|
|
115
|
+
|
|
116
|
+
CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
|
|
117
|
+
parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
|
107
118
|
|
|
108
119
|
### References
|
|
109
120
|
|
package/grammar.js
CHANGED
|
@@ -6,9 +6,6 @@
|
|
|
6
6
|
* @license MIT
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
/// <reference types="tree-sitter-cli/dsl" />
|
|
10
|
-
// @ts-check
|
|
11
|
-
|
|
12
9
|
// https://doc.rust-lang.org/reference/expressions.html#expression-precedence
|
|
13
10
|
const PREC = {
|
|
14
11
|
call: 15,
|
|
@@ -117,7 +114,7 @@ module.exports = grammar({
|
|
|
117
114
|
$._error_sentinel,
|
|
118
115
|
],
|
|
119
116
|
|
|
120
|
-
supertypes: ($) => [$._expression, $._type, $._literal, $._literal_pattern, $.
|
|
117
|
+
supertypes: ($) => [$._expression, $._type, $._literal, $._literal_pattern, $._pattern],
|
|
121
118
|
|
|
122
119
|
inline: ($) => [
|
|
123
120
|
$._path,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-rust",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Rust grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
"author": "WillBooster Inc.",
|
|
17
17
|
"files": [
|
|
18
18
|
"grammar.js",
|
|
19
|
+
"queries/*.scm",
|
|
19
20
|
"tree-sitter.json",
|
|
20
21
|
"src/node-types.json",
|
|
21
22
|
"*.wasm"
|
|
22
23
|
],
|
|
23
24
|
"scripts": {
|
|
24
|
-
"build-wasm": "tree-sitter build --wasm",
|
|
25
|
-
"build/ci": "tree-sitter generate && tree-sitter build --wasm",
|
|
25
|
+
"build-wasm": "script/tree-sitter build --wasm",
|
|
26
|
+
"build/ci": "script/tree-sitter generate && script/tree-sitter build --wasm",
|
|
26
27
|
"cleanup": "bun wb lint --fix --format",
|
|
27
28
|
"format": "bun wb lint --format",
|
|
28
29
|
"lint": "bun wb lint",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
|
|
31
32
|
"release": "wb release",
|
|
32
33
|
"prestart": "bun run build-wasm",
|
|
33
|
-
"start": "tree-sitter playground",
|
|
34
|
+
"start": "script/tree-sitter playground",
|
|
34
35
|
"test": "bun wb test",
|
|
35
36
|
"test/ci": "bun wb test-on-ci",
|
|
36
37
|
"test/ci-setup": "playwright install chromium",
|
|
@@ -44,17 +45,16 @@
|
|
|
44
45
|
"@vitest/browser-playwright": "5.0.1",
|
|
45
46
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
46
47
|
"@willbooster/oxlint-config": "1.4.8",
|
|
47
|
-
"@willbooster/wb": "22.13.
|
|
48
|
-
"@willbooster/web-tree-sitter": "1.0.
|
|
48
|
+
"@willbooster/wb": "22.13.1",
|
|
49
|
+
"@willbooster/web-tree-sitter": "1.0.15",
|
|
49
50
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
50
51
|
"lefthook": "2.1.14",
|
|
51
52
|
"oxfmt": "0.70.0",
|
|
52
53
|
"oxlint": "1.85.0",
|
|
53
|
-
"oxlint-tsgolint": "7.0.
|
|
54
|
+
"oxlint-tsgolint": "7.0.2003",
|
|
54
55
|
"playwright": "1.63.0",
|
|
55
56
|
"semantic-release": "25.0.9",
|
|
56
57
|
"sort-package-json": "4.0.0",
|
|
57
|
-
"tree-sitter-cli": "0.27.0",
|
|
58
58
|
"typescript": "7.0.2",
|
|
59
59
|
"vite": "8.3.0",
|
|
60
60
|
"vitest": "5.0.1",
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
; Identifiers
|
|
2
|
+
|
|
3
|
+
(type_identifier) @type
|
|
4
|
+
(primitive_type) @type.builtin
|
|
5
|
+
(field_identifier) @property
|
|
6
|
+
|
|
7
|
+
; Identifier conventions
|
|
8
|
+
|
|
9
|
+
; Assume all-caps names are constants
|
|
10
|
+
((identifier) @constant
|
|
11
|
+
(#match? @constant "^[A-Z][A-Z\\d_]+$'"))
|
|
12
|
+
|
|
13
|
+
; Assume uppercase names are enum constructors
|
|
14
|
+
((identifier) @constructor
|
|
15
|
+
(#match? @constructor "^[A-Z]"))
|
|
16
|
+
|
|
17
|
+
; Assume that uppercase names in paths are types
|
|
18
|
+
((scoped_identifier
|
|
19
|
+
path: (identifier) @type)
|
|
20
|
+
(#match? @type "^[A-Z]"))
|
|
21
|
+
((scoped_identifier
|
|
22
|
+
path: (scoped_identifier
|
|
23
|
+
name: (identifier) @type))
|
|
24
|
+
(#match? @type "^[A-Z]"))
|
|
25
|
+
((scoped_type_identifier
|
|
26
|
+
path: (identifier) @type)
|
|
27
|
+
(#match? @type "^[A-Z]"))
|
|
28
|
+
((scoped_type_identifier
|
|
29
|
+
path: (scoped_identifier
|
|
30
|
+
name: (identifier) @type))
|
|
31
|
+
(#match? @type "^[A-Z]"))
|
|
32
|
+
|
|
33
|
+
; Assume all qualified names in struct patterns are enum constructors. (They're
|
|
34
|
+
; either that, or struct names; highlighting both as constructors seems to be
|
|
35
|
+
; the less glaring choice of error, visually.)
|
|
36
|
+
(struct_pattern
|
|
37
|
+
type: (scoped_type_identifier
|
|
38
|
+
name: (type_identifier) @constructor))
|
|
39
|
+
|
|
40
|
+
; Function calls
|
|
41
|
+
|
|
42
|
+
(call_expression
|
|
43
|
+
function: (identifier) @function)
|
|
44
|
+
(call_expression
|
|
45
|
+
function: (field_expression
|
|
46
|
+
field: (field_identifier) @function.method))
|
|
47
|
+
(call_expression
|
|
48
|
+
function: (scoped_identifier
|
|
49
|
+
"::"
|
|
50
|
+
name: (identifier) @function))
|
|
51
|
+
|
|
52
|
+
(generic_function
|
|
53
|
+
function: (identifier) @function)
|
|
54
|
+
(generic_function
|
|
55
|
+
function: (scoped_identifier
|
|
56
|
+
name: (identifier) @function))
|
|
57
|
+
(generic_function
|
|
58
|
+
function: (field_expression
|
|
59
|
+
field: (field_identifier) @function.method))
|
|
60
|
+
|
|
61
|
+
(macro_invocation
|
|
62
|
+
macro: (identifier) @function.macro
|
|
63
|
+
"!" @function.macro)
|
|
64
|
+
|
|
65
|
+
; Function definitions
|
|
66
|
+
|
|
67
|
+
(function_item (identifier) @function)
|
|
68
|
+
(function_signature_item (identifier) @function)
|
|
69
|
+
|
|
70
|
+
(line_comment) @comment
|
|
71
|
+
(block_comment) @comment
|
|
72
|
+
|
|
73
|
+
(line_comment (doc_comment)) @comment.documentation
|
|
74
|
+
(block_comment (doc_comment)) @comment.documentation
|
|
75
|
+
|
|
76
|
+
"(" @punctuation.bracket
|
|
77
|
+
")" @punctuation.bracket
|
|
78
|
+
"[" @punctuation.bracket
|
|
79
|
+
"]" @punctuation.bracket
|
|
80
|
+
"{" @punctuation.bracket
|
|
81
|
+
"}" @punctuation.bracket
|
|
82
|
+
|
|
83
|
+
(type_arguments
|
|
84
|
+
"<" @punctuation.bracket
|
|
85
|
+
">" @punctuation.bracket)
|
|
86
|
+
(type_parameters
|
|
87
|
+
"<" @punctuation.bracket
|
|
88
|
+
">" @punctuation.bracket)
|
|
89
|
+
|
|
90
|
+
"::" @punctuation.delimiter
|
|
91
|
+
":" @punctuation.delimiter
|
|
92
|
+
"." @punctuation.delimiter
|
|
93
|
+
"," @punctuation.delimiter
|
|
94
|
+
";" @punctuation.delimiter
|
|
95
|
+
|
|
96
|
+
(parameter (identifier) @variable.parameter)
|
|
97
|
+
|
|
98
|
+
(lifetime (identifier) @label)
|
|
99
|
+
|
|
100
|
+
"as" @keyword
|
|
101
|
+
"async" @keyword
|
|
102
|
+
"await" @keyword
|
|
103
|
+
"break" @keyword
|
|
104
|
+
"const" @keyword
|
|
105
|
+
"continue" @keyword
|
|
106
|
+
"default" @keyword
|
|
107
|
+
"dyn" @keyword
|
|
108
|
+
"else" @keyword
|
|
109
|
+
"enum" @keyword
|
|
110
|
+
"extern" @keyword
|
|
111
|
+
"fn" @keyword
|
|
112
|
+
"for" @keyword
|
|
113
|
+
"gen" @keyword
|
|
114
|
+
"if" @keyword
|
|
115
|
+
"impl" @keyword
|
|
116
|
+
"in" @keyword
|
|
117
|
+
"let" @keyword
|
|
118
|
+
"loop" @keyword
|
|
119
|
+
"macro_rules!" @keyword
|
|
120
|
+
"match" @keyword
|
|
121
|
+
"mod" @keyword
|
|
122
|
+
"move" @keyword
|
|
123
|
+
"pub" @keyword
|
|
124
|
+
"raw" @keyword
|
|
125
|
+
"ref" @keyword
|
|
126
|
+
"return" @keyword
|
|
127
|
+
"safe" @keyword
|
|
128
|
+
"static" @keyword
|
|
129
|
+
"struct" @keyword
|
|
130
|
+
"trait" @keyword
|
|
131
|
+
"type" @keyword
|
|
132
|
+
"union" @keyword
|
|
133
|
+
"unsafe" @keyword
|
|
134
|
+
"use" @keyword
|
|
135
|
+
"where" @keyword
|
|
136
|
+
"while" @keyword
|
|
137
|
+
"yield" @keyword
|
|
138
|
+
(crate) @keyword
|
|
139
|
+
(mutable_specifier) @keyword
|
|
140
|
+
(use_list (self) @keyword)
|
|
141
|
+
(scoped_use_list (self) @keyword)
|
|
142
|
+
(scoped_identifier (self) @keyword)
|
|
143
|
+
(super) @keyword
|
|
144
|
+
|
|
145
|
+
(self) @variable.builtin
|
|
146
|
+
|
|
147
|
+
(char_literal) @string
|
|
148
|
+
(string_literal) @string
|
|
149
|
+
(raw_string_literal) @string
|
|
150
|
+
|
|
151
|
+
(boolean_literal) @constant.builtin
|
|
152
|
+
(integer_literal) @constant.builtin
|
|
153
|
+
(float_literal) @constant.builtin
|
|
154
|
+
|
|
155
|
+
(escape_sequence) @escape
|
|
156
|
+
|
|
157
|
+
(attribute_item) @attribute
|
|
158
|
+
(inner_attribute_item) @attribute
|
|
159
|
+
|
|
160
|
+
"*" @operator
|
|
161
|
+
"&" @operator
|
|
162
|
+
"'" @operator
|
package/queries/tags.scm
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
; ADT definitions
|
|
2
|
+
|
|
3
|
+
(struct_item
|
|
4
|
+
name: (type_identifier) @name) @definition.class
|
|
5
|
+
|
|
6
|
+
(enum_item
|
|
7
|
+
name: (type_identifier) @name) @definition.class
|
|
8
|
+
|
|
9
|
+
(union_item
|
|
10
|
+
name: (type_identifier) @name) @definition.class
|
|
11
|
+
|
|
12
|
+
; type aliases
|
|
13
|
+
|
|
14
|
+
(type_item
|
|
15
|
+
name: (type_identifier) @name) @definition.class
|
|
16
|
+
|
|
17
|
+
; method definitions
|
|
18
|
+
|
|
19
|
+
(declaration_list
|
|
20
|
+
(function_item
|
|
21
|
+
name: (identifier) @name) @definition.method)
|
|
22
|
+
|
|
23
|
+
; function definitions
|
|
24
|
+
|
|
25
|
+
(function_item
|
|
26
|
+
name: (identifier) @name) @definition.function
|
|
27
|
+
|
|
28
|
+
; trait definitions
|
|
29
|
+
(trait_item
|
|
30
|
+
name: (type_identifier) @name) @definition.interface
|
|
31
|
+
|
|
32
|
+
; module definitions
|
|
33
|
+
(mod_item
|
|
34
|
+
name: (identifier) @name) @definition.module
|
|
35
|
+
|
|
36
|
+
; macro definitions
|
|
37
|
+
|
|
38
|
+
(macro_definition
|
|
39
|
+
name: (identifier) @name) @definition.macro
|
|
40
|
+
|
|
41
|
+
; references
|
|
42
|
+
|
|
43
|
+
(call_expression
|
|
44
|
+
function: (identifier) @name) @reference.call
|
|
45
|
+
|
|
46
|
+
(call_expression
|
|
47
|
+
function: (field_expression
|
|
48
|
+
field: (field_identifier) @name)) @reference.call
|
|
49
|
+
|
|
50
|
+
(macro_invocation
|
|
51
|
+
macro: (identifier) @name) @reference.call
|
|
52
|
+
|
|
53
|
+
; implementations
|
|
54
|
+
|
|
55
|
+
(impl_item
|
|
56
|
+
trait: (type_identifier) @name) @reference.implementation
|
|
57
|
+
|
|
58
|
+
(impl_item
|
|
59
|
+
type: (type_identifier) @name
|
|
60
|
+
!trait) @reference.implementation
|
package/tree-sitter-rust.wasm
CHANGED
|
Binary file
|