@willbooster/web-tree-sitter 1.0.12 → 1.0.14
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 +25 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,20 +72,17 @@ console.log(tree.rootNode.toString());
|
|
|
72
72
|
|
|
73
73
|
// (program
|
|
74
74
|
// (lexical_declaration
|
|
75
|
-
// (variable_declarator (identifier) (number)))
|
|
75
|
+
// (variable_declarator name: (identifier) value: (number)))
|
|
76
76
|
// (expression_statement
|
|
77
77
|
// (call_expression
|
|
78
|
-
// (member_expression (identifier) (property_identifier))
|
|
79
|
-
// (arguments (identifier)))))
|
|
78
|
+
// function: (member_expression object: (identifier) property: (property_identifier))
|
|
79
|
+
// arguments: (arguments (identifier)))))
|
|
80
|
+
// (printed on one line)
|
|
80
81
|
|
|
81
82
|
const callExpression = tree.rootNode.child(1).firstChild;
|
|
82
|
-
console.log(callExpression);
|
|
83
|
+
console.log(callExpression.type, callExpression.startPosition, callExpression.endPosition);
|
|
83
84
|
|
|
84
|
-
// {
|
|
85
|
-
// startPosition: {row: 0, column: 16},
|
|
86
|
-
// endPosition: {row: 0, column: 30},
|
|
87
|
-
// startIndex: 0,
|
|
88
|
-
// endIndex: 30 }
|
|
85
|
+
// call_expression { row: 0, column: 11 } { row: 0, column: 25 }
|
|
89
86
|
```
|
|
90
87
|
|
|
91
88
|
### Editing
|
|
@@ -131,53 +128,42 @@ There are several options on how to get the `.wasm` files for the languages you
|
|
|
131
128
|
|
|
132
129
|
#### From npmjs.com
|
|
133
130
|
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
WillBooster's grammar packages ship their `.wasm` files: `@willbooster/tree-sitter-bash`, `-c`, `-cpp`, `-c-sharp`,
|
|
132
|
+
`-javascript`, `-kotlin`, `-rust`, and `-typescript`. For example, to parse JavaScript:
|
|
136
133
|
|
|
137
134
|
```sh
|
|
138
|
-
npm install tree-sitter-javascript
|
|
135
|
+
npm install @willbooster/tree-sitter-javascript
|
|
139
136
|
```
|
|
140
137
|
|
|
141
|
-
Then you can find
|
|
138
|
+
Then you can find `tree-sitter-javascript.wasm` in the `node_modules/@willbooster/tree-sitter-javascript` directory.
|
|
139
|
+
Other grammar packages on npm, such as `tree-sitter-javascript`, may ship a `.wasm` file as well.
|
|
142
140
|
|
|
143
141
|
#### From GitHub
|
|
144
142
|
|
|
145
|
-
You can also download the `.wasm` files from GitHub releases
|
|
146
|
-
|
|
147
|
-
For example, you can download the JavaScript `.wasm` file from the tree-sitter-javascript [releases page][gh release js].
|
|
143
|
+
You can also download the `.wasm` files from the GitHub releases of grammars that publish them with Tree-sitter's
|
|
144
|
+
reusable workflow, such as the tree-sitter-javascript [releases page][gh release js].
|
|
148
145
|
|
|
149
146
|
#### Generating `.wasm` files
|
|
150
147
|
|
|
151
|
-
You can also generate the `.wasm` file for your desired grammar
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
> No additional tools need to be installed.
|
|
157
|
-
|
|
158
|
-
First install `tree-sitter-cli`, and the tree-sitter language for which to generate `.wasm`
|
|
159
|
-
(`tree-sitter-javascript` in this example):
|
|
148
|
+
You can also generate the `.wasm` file for your desired grammar with the CLI that the [releases of this
|
|
149
|
+
repository][releases] from v1.0.7 on carry as `tree-sitter-cli-<platform>.tar.gz` (`linux-x64`, `linux-arm64`,
|
|
150
|
+
`macos-arm64`, or `macos-x64`), which extracts to an executable `tree-sitter`; a workflow builds and attaches the
|
|
151
|
+
archives after a release is published, so the newest release lacks them for a while. `tree-sitter build --wasm`
|
|
152
|
+
downloads [wasi-sdk][] on first use, so no other tools need to be installed. For example, for the JavaScript grammar:
|
|
160
153
|
|
|
161
154
|
```sh
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
```sh
|
|
168
|
-
npx tree-sitter build --wasm node_modules/tree-sitter-javascript
|
|
155
|
+
platform=macos-arm64 # or linux-x64, linux-arm64, macos-x64
|
|
156
|
+
tag=v1.0.9 # a release that lists tree-sitter-cli-$platform.tar.gz among its assets
|
|
157
|
+
curl -fsSL "https://github.com/WillBooster/tree-sitter/releases/download/$tag/tree-sitter-cli-$platform.tar.gz" | tar -xz
|
|
158
|
+
npm install tree-sitter-javascript
|
|
159
|
+
./tree-sitter build --wasm node_modules/tree-sitter-javascript
|
|
169
160
|
```
|
|
170
161
|
|
|
171
162
|
If everything is fine, file `tree-sitter-javascript.wasm` should be generated in current directory.
|
|
172
163
|
|
|
173
164
|
### Wasm compatibility
|
|
174
165
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
| web-tree-sitter version | Min parser ABI version | Max parser ABI version |
|
|
178
|
-
|-------------------------|------------------------|------------------------|
|
|
179
|
-
| 0.24.x | 13 | 14 |
|
|
180
|
-
| >= 0.25.0 | 13 | 15 |
|
|
166
|
+
`@willbooster/web-tree-sitter` loads parsers of ABI versions 13 to 15.
|
|
181
167
|
|
|
182
168
|
> [!WARNING]
|
|
183
169
|
> Some prebuilt `.wasm` files use an older dynamic-linking format that newer versions of `web-tree-sitter` cannot
|
|
@@ -241,10 +227,8 @@ and not `http://localhost:3000/_next/static/chunks/pages/web-tree-sitter.wasm`.
|
|
|
241
227
|
|
|
242
228
|
For more information on the module options you can pass in, see the [emscripten documentation][emscripten-module-options].
|
|
243
229
|
|
|
244
|
-
[docker]: https://www.docker.com
|
|
245
|
-
[emscripten]: https://emscripten.org
|
|
246
230
|
[emscripten-module-options]: https://emscripten.org/docs/api_reference/module.html#affecting-execution
|
|
247
231
|
[gh release js]: https://github.com/tree-sitter/tree-sitter-javascript/releases/latest
|
|
232
|
+
[releases]: https://github.com/WillBooster/tree-sitter/releases
|
|
248
233
|
[node bindings]: https://github.com/tree-sitter/node-tree-sitter
|
|
249
|
-
[podman]: https://podman.io
|
|
250
234
|
[wasi-sdk]: https://github.com/WebAssembly/wasi-sdk
|