@willbooster/tree-sitter-bash 1.1.3 → 2.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 +19 -8
- package/grammar.js +692 -550
- package/package.json +15 -20
- package/src/grammar.json +171 -14
- package/src/node-types.json +84 -13
- package/src/parser.c +170186 -133781
- package/src/scanner.c +466 -110
- package/tree-sitter-bash.wasm +0 -0
- package/tree-sitter.json +2 -2
- package/binding.gyp +0 -30
- package/bindings/node/binding.cc +0 -20
- package/bindings/node/binding_test.js +0 -9
- package/bindings/node/index.d.ts +0 -28
- package/bindings/node/index.js +0 -11
- package/prebuilds/darwin-arm64/tree-sitter-bash.node +0 -0
- package/prebuilds/darwin-x64/tree-sitter-bash.node +0 -0
- package/prebuilds/linux-arm64/tree-sitter-bash.node +0 -0
- package/prebuilds/linux-x64/tree-sitter-bash.node +0 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@willbooster/tree-sitter-bash)
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-bash/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/semantic-release/semantic-release)
|
|
7
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
8
8
|
|
|
9
9
|
Bash grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
10
10
|
[tree-sitter/tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash). We are grateful to its authors and
|
|
@@ -16,15 +16,21 @@ As a result, its syntax trees differ from the original grammar's; review your qu
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
+
The npm package ships `tree-sitter-bash.wasm` for [web-tree-sitter](https://www.npmjs.com/package/web-tree-sitter):
|
|
20
|
+
|
|
19
21
|
```js
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
import { fileURLToPath } from 'node:url';
|
|
23
|
+
import { Language, Parser } from 'web-tree-sitter';
|
|
22
24
|
|
|
25
|
+
await Parser.init();
|
|
23
26
|
const parser = new Parser();
|
|
24
|
-
|
|
27
|
+
const wasmPath = fileURLToPath(import.meta.resolve('@willbooster/tree-sitter-bash/tree-sitter-bash.wasm'));
|
|
28
|
+
parser.setLanguage(await Language.load(wasmPath));
|
|
25
29
|
const tree = parser.parse('cat <<EOF; echo done\n$(date)\nEOF\n');
|
|
26
30
|
```
|
|
27
31
|
|
|
32
|
+
The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
|
|
33
|
+
|
|
28
34
|
## Development
|
|
29
35
|
|
|
30
36
|
```sh
|
|
@@ -37,8 +43,10 @@ script/parse-examples
|
|
|
37
43
|
|
|
38
44
|
`bun run test` runs:
|
|
39
45
|
|
|
40
|
-
- the corpus in `test/corpus
|
|
41
|
-
-
|
|
46
|
+
- the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
|
|
47
|
+
- an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
|
|
48
|
+
reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
|
|
49
|
+
`TREE_SITTER_EDITS` run other or more edits;
|
|
42
50
|
- a check that real-world scripts cloned into `examples/` fail to parse exactly as listed in
|
|
43
51
|
`script/known-failures.txt`. The first run clones them, which takes a few minutes. The example repositories are
|
|
44
52
|
pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
|
|
@@ -47,11 +55,14 @@ script/parse-examples
|
|
|
47
55
|
scripts and runs them with the bash that `mise.toml` pins. It checks that the syntax tree shows exactly the commands
|
|
48
56
|
bash runs, with as many words and the same value for each word without expansions, and that the tree has no
|
|
49
57
|
`ERROR` or `MISSING` node for a script bash accepts. A failure prints the seed; `DIFFERENTIAL_SEED` and
|
|
50
|
-
`DIFFERENTIAL_CASES` run other or more scripts. It loads the
|
|
51
|
-
regenerating the parser;
|
|
58
|
+
`DIFFERENTIAL_CASES` run other or more scripts. It loads the Wasm build through web-tree-sitter, which `bun run build/ci`
|
|
59
|
+
rebuilds after regenerating the parser;
|
|
52
60
|
- a performance check (`test/unit/performance.test.ts`) that a 240 KB line parses in linear time, since consumers
|
|
53
61
|
parse untrusted scripts.
|
|
54
62
|
|
|
63
|
+
CI also runs these tests on Linux arm64 and macOS, and fuzzes the parser with libFuzzer and sanitizers
|
|
64
|
+
(`.github/workflows/robustness.yml`).
|
|
65
|
+
|
|
55
66
|
### References
|
|
56
67
|
|
|
57
68
|
- [Bash man page](http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_GRAMMAR)
|