tree-sitter-zsh 0.31.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/LICENSE +21 -0
- package/README.md +78 -0
- package/binding.gyp +30 -0
- package/bindings/node/binding.cc +20 -0
- package/bindings/node/binding_test.js +9 -0
- package/bindings/node/index.d.ts +28 -0
- package/bindings/node/index.js +11 -0
- package/grammar.js +1904 -0
- package/package.json +54 -0
- package/prebuilds/darwin-arm64/tree-sitter-zsh.node +0 -0
- package/prebuilds/darwin-x64/tree-sitter-zsh.node +0 -0
- package/prebuilds/linux-arm64/tree-sitter-zsh.node +0 -0
- package/prebuilds/linux-x64/tree-sitter-zsh.node +0 -0
- package/prebuilds/win32-arm64/tree-sitter-zsh.node +0 -0
- package/prebuilds/win32-x64/tree-sitter-zsh.node +0 -0
- package/queries/highlights.scm +59 -0
- package/src/grammar.json +11444 -0
- package/src/node-types.json +4386 -0
- package/src/parser.c +929980 -0
- package/src/scanner.c +2416 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +291 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tree-sitter-zsh.wasm +0 -0
- package/tree-sitter.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Max Brunsfeld
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# tree-sitter-zsh
|
|
2
|
+
|
|
3
|
+
[![CI][ci]](https://github.com/tree-sitter/tree-sitter-zsh/actions/workflows/ci.yml)
|
|
4
|
+
[![discord][discord]](https://discord.gg/w7nTvsVJhm)
|
|
5
|
+
[![matrix][matrix]](https://matrix.to/#/#tree-sitter-chat:matrix.org)
|
|
6
|
+
[![crates][crates]](https://crates.io/crates/tree-sitter-zsh)
|
|
7
|
+
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-zsh)
|
|
8
|
+
[![pypi][pypi]](https://pypi.org/project/tree-sitter-zsh)
|
|
9
|
+
|
|
10
|
+
Zsh grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
|
11
|
+
|
|
12
|
+
> [!NOTE]
|
|
13
|
+
> this is not the same as [tree-sitter/tree-sitter-zsh](https://github.com/tree-sitter-grammars/tree-sitter-zsh)
|
|
14
|
+
> which has been archived, but rather a complete reworking starting
|
|
15
|
+
> from the bash grammar.
|
|
16
|
+
|
|
17
|
+
### Known issues:
|
|
18
|
+
|
|
19
|
+
Glob qualifier delimeters for 's::' and 'n::' and 'b::' must be ':' rather
|
|
20
|
+
than arbitrary paired chars.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
For neovim, add the following to your config
|
|
25
|
+
|
|
26
|
+
```lua
|
|
27
|
+
vim.api.nvim_create_autocmd("User", {
|
|
28
|
+
pattern = "TSUpdate",
|
|
29
|
+
callback = function()
|
|
30
|
+
require("nvim-treesitter.parsers").zsh = {
|
|
31
|
+
install_info = {
|
|
32
|
+
"https://github.com/georgeharker/tree-sitter-zsh",
|
|
33
|
+
generate_from_json = false, -- only needed if repo does not contain `src/grammar.json` either
|
|
34
|
+
queries = 'nvim-queries', -- also install queries from given directory
|
|
35
|
+
},
|
|
36
|
+
tier = 3,
|
|
37
|
+
}
|
|
38
|
+
end,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
In addition to enabling treesitter for zsh files.
|
|
44
|
+
|
|
45
|
+
## Development
|
|
46
|
+
|
|
47
|
+
Install the dependencies:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npm install
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Build and run the tests:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
npm run build
|
|
57
|
+
npm run test
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Run the build and tests in watch mode:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
npm run test:watch
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### References
|
|
67
|
+
|
|
68
|
+
- [Zsh reference docs](https://zsh.sourceforge.io/Doc/Release/zsh_toc.html)
|
|
69
|
+
- [Shell command language specification](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)
|
|
70
|
+
- [mvdnan/sh - a shell parser in go](https://github.com/mvdan/sh)
|
|
71
|
+
- [tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash)
|
|
72
|
+
|
|
73
|
+
[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/tree-sitter-zsh/ci.yml?logo=github&label=CI
|
|
74
|
+
[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord
|
|
75
|
+
[matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix&label=matrix
|
|
76
|
+
[npm]: https://img.shields.io/npm/v/tree-sitter-zsh?logo=npm
|
|
77
|
+
[crates]: https://img.shields.io/crates/v/tree-sitter-zsh?logo=rust
|
|
78
|
+
[pypi]: https://img.shields.io/pypi/v/tree-sitter-zsh?logo=pypi&logoColor=ffd242
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "tree_sitter_zsh_binding",
|
|
5
|
+
"dependencies": [
|
|
6
|
+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
|
7
|
+
],
|
|
8
|
+
"include_dirs": [
|
|
9
|
+
"src",
|
|
10
|
+
],
|
|
11
|
+
"sources": [
|
|
12
|
+
"bindings/node/binding.cc",
|
|
13
|
+
"src/parser.c",
|
|
14
|
+
"src/scanner.c",
|
|
15
|
+
],
|
|
16
|
+
"conditions": [
|
|
17
|
+
["OS!='win'", {
|
|
18
|
+
"cflags_c": [
|
|
19
|
+
"-std=c11",
|
|
20
|
+
],
|
|
21
|
+
}, { # OS == "win"
|
|
22
|
+
"cflags_c": [
|
|
23
|
+
"/std:c11",
|
|
24
|
+
"/utf-8",
|
|
25
|
+
],
|
|
26
|
+
}],
|
|
27
|
+
],
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#include <napi.h>
|
|
2
|
+
|
|
3
|
+
typedef struct TSLanguage TSLanguage;
|
|
4
|
+
|
|
5
|
+
extern "C" TSLanguage *tree_sitter_zsh();
|
|
6
|
+
|
|
7
|
+
// "tree-sitter", "language" hashed with BLAKE2
|
|
8
|
+
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
|
9
|
+
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
13
|
+
exports["name"] = Napi::String::New(env, "zsh");
|
|
14
|
+
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_zsh());
|
|
15
|
+
language.TypeTag(&LANGUAGE_TYPE_TAG);
|
|
16
|
+
exports["language"] = language;
|
|
17
|
+
return exports;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
NODE_API_MODULE(tree_sitter_zsh_binding, Init)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type BaseNode = {
|
|
2
|
+
type: string;
|
|
3
|
+
named: boolean;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
type ChildNode = {
|
|
7
|
+
multiple: boolean;
|
|
8
|
+
required: boolean;
|
|
9
|
+
types: BaseNode[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type NodeInfo =
|
|
13
|
+
| (BaseNode & {
|
|
14
|
+
subtypes: BaseNode[];
|
|
15
|
+
})
|
|
16
|
+
| (BaseNode & {
|
|
17
|
+
fields: { [name: string]: ChildNode };
|
|
18
|
+
children: ChildNode[];
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
type Language = {
|
|
22
|
+
name: string;
|
|
23
|
+
language: unknown;
|
|
24
|
+
nodeTypeInfo: NodeInfo[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare const language: Language;
|
|
28
|
+
export = language;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const root = require("path").join(__dirname, "..", "..");
|
|
2
|
+
|
|
3
|
+
module.exports =
|
|
4
|
+
typeof process.versions.bun === "string"
|
|
5
|
+
// Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
|
|
6
|
+
? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-zsh.node`)
|
|
7
|
+
: require("node-gyp-build")(root);
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
|
11
|
+
} catch (_) {}
|