@willbooster/tree-sitter-rust 1.1.5 → 1.1.6
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 +15 -10
- package/package.json +5 -4
- 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
|
|
@@ -93,17 +93,22 @@ cargo test
|
|
|
93
93
|
reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
|
|
94
94
|
`TREE_SITTER_EDITS` run other or more edits;
|
|
95
95
|
- 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
|
|
96
|
+
fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example
|
|
97
|
+
repositories are pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
|
|
98
|
+
`script/parse-examples` rewrites it; review its diff before committing;
|
|
99
|
+
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each line takes linear time
|
|
100
|
+
(ten times the lines take about ten times the CPU time, under a ceiling), since consumers parse files while they are
|
|
101
|
+
being edited. It loads the Wasm build through @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after
|
|
102
|
+
regenerating the parser;
|
|
103
|
+
- a check that `package.json` and `Cargo.lock` test the same runtime version (`test/unit/runtimeVersion.test.ts`);
|
|
102
104
|
- checks that the Wasm build parses in Chromium (`test/unit/browser/`) and in Cloudflare Workers with and without
|
|
103
105
|
Node.js compatibility (`test/unit/workerd.test.ts`). Run `bun run test/ci-setup` once to install Chromium.
|
|
104
106
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
|
|
108
|
+
by every checkout.
|
|
109
|
+
|
|
110
|
+
CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
|
|
111
|
+
parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
|
107
112
|
|
|
108
113
|
### References
|
|
109
114
|
|
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.6",
|
|
4
4
|
"description": "Rust grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -16,6 +16,7 @@
|
|
|
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"
|
|
@@ -44,13 +45,13 @@
|
|
|
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.12",
|
|
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",
|
|
@@ -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
|