@danielblomma/cortex-mcp 1.3.2 → 1.4.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 +62 -14
- package/package.json +2 -2
- package/scaffold/mcp/package-lock.json +3 -7
- package/scaffold/mcp/package.json +1 -1
- package/scaffold/scripts/dashboard.mjs +15 -1
- package/scaffold/scripts/ingest.mjs +323 -50
- package/scaffold/scripts/parsers/bash-treesitter.mjs +229 -0
- package/scaffold/scripts/parsers/cpp-dispatch.mjs +56 -0
- package/scaffold/scripts/parsers/cpp-treesitter.mjs +333 -0
- package/scaffold/scripts/parsers/csharp.mjs +197 -10
- package/scaffold/scripts/parsers/dotnet/CSharpParser/CSharpParser.csproj +1 -0
- package/scaffold/scripts/parsers/dotnet/CSharpParser/Program.cs +126 -21
- package/scaffold/scripts/parsers/go-treesitter.mjs +283 -0
- package/scaffold/scripts/parsers/java-treesitter.mjs +250 -0
- package/scaffold/scripts/parsers/javascript/ast.mjs +118 -12
- package/scaffold/scripts/parsers/javascript/chunks.mjs +4 -0
- package/scaffold/scripts/parsers/javascript/patterns.mjs +6 -0
- package/scaffold/scripts/parsers/javascript.mjs +4 -19
- package/scaffold/scripts/parsers/node_modules/.package-lock.json +57 -0
- package/scaffold/scripts/parsers/node_modules/acorn/CHANGELOG.md +972 -0
- package/scaffold/scripts/parsers/node_modules/acorn/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/acorn/README.md +301 -0
- package/scaffold/scripts/parsers/node_modules/acorn/bin/acorn +4 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.d.mts +883 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.d.ts +883 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.js +6295 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.mjs +6266 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/bin.js +90 -0
- package/scaffold/scripts/parsers/node_modules/acorn/package.json +50 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/CHANGELOG.md +421 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/README.md +81 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.d.ts +103 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.js +78 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.d.ts +167 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.js +75 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.d.ts +177 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.js +56 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.d.ts +198 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.js +327 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.d.ts +256 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.js +256 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.d.ts +472 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.js +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.mjs +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.d.ts +159 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.js +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.d.ts +10 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.js +38 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.d.ts +12 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.js +29 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.d.ts +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.js +118 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.d.ts +60 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.js +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.d.ts +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.js +19 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/package.json +53 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/tsconfig.json +19 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/CHANGELOG.md +209 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/README.md +124 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.d.mts +152 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.d.ts +152 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.js +485 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.mjs +467 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/package.json +50 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/LICENSE +24 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/README.md +23 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-bash.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-c.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-c_sharp.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-cpp.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-css.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-dart.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elisp.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elixir.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elm.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-embedded_template.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-go.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-html.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-java.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-javascript.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-json.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-kotlin.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-lua.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-objc.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ocaml.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-php.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-python.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ql.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-rescript.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ruby.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-rust.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-scala.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-solidity.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-swift.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-systemrdl.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-tlaplus.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-toml.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-tsx.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-typescript.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-vue.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-yaml.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-zig.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/package.json +64 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/README.md +198 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/package.json +37 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter-web.d.ts +242 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter.js +1 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter.wasm +0 -0
- package/scaffold/scripts/parsers/package-lock.json +19 -1
- package/scaffold/scripts/parsers/package.json +3 -1
- package/scaffold/scripts/parsers/python-treesitter.mjs +271 -0
- package/scaffold/scripts/parsers/ruby-treesitter.mjs +271 -0
- package/scaffold/scripts/parsers/rust-dispatch.mjs +43 -0
- package/scaffold/scripts/parsers/rust-treesitter.mjs +291 -0
- package/scaffold/scripts/parsers/tree-sitter/base.mjs +163 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/bash.calls.scm +7 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/bash.chunks.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/bash.imports.scm +5 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/cpp.calls.scm +17 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/cpp.chunks.scm +30 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/cpp.imports.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/go.calls.scm +11 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/go.chunks.scm +19 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/go.imports.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/java.calls.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/java.chunks.scm +23 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/java.imports.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/python.calls.scm +11 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/python.chunks.scm +11 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/python.imports.scm +13 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/ruby.calls.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/ruby.chunks.scm +16 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/ruby.imports.scm +8 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/rust.calls.scm +31 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/rust.chunks.scm +29 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/rust.imports.scm +5 -0
- package/scaffold/scripts/parsers/vb6.mjs +395 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tree-sitter-wasms",
|
|
3
|
+
"version": "0.1.13",
|
|
4
|
+
"description": "Prebuilt WASM binaries for tree-sitter's language parsers.",
|
|
5
|
+
"repository": "https://github.com/Gregoor/tree-sitter-wasms",
|
|
6
|
+
"author": "Gregor <gregorwbr@gmail.com>, Menci <huanghaorui301@gmail.com>",
|
|
7
|
+
"license": "Unlicense",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "ts-node build.ts"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@supercharge/promise-pool": "^3.1.1",
|
|
13
|
+
"@tlaplus/tree-sitter-tlaplus": "^1.2.4",
|
|
14
|
+
"@tree-sitter-grammars/tree-sitter-zig": "^1.0.0",
|
|
15
|
+
"@types/find-root": "^1.1.4",
|
|
16
|
+
"@types/node": "^20.11.17",
|
|
17
|
+
"@willjouo/tree-sitter-r": "^0.0.1",
|
|
18
|
+
"find-root": "^1.1.0",
|
|
19
|
+
"tree-sitter-bash": "^0.20.5",
|
|
20
|
+
"tree-sitter-c": "^0.20.7",
|
|
21
|
+
"tree-sitter-c-sharp": "^0.20.0",
|
|
22
|
+
"tree-sitter-cli": "^0.20.8",
|
|
23
|
+
"tree-sitter-cpp": "^0.20.4",
|
|
24
|
+
"tree-sitter-css": "^0.20.0",
|
|
25
|
+
"tree-sitter-dart": "github:UserNobody14/tree-sitter-dart",
|
|
26
|
+
"tree-sitter-elisp": "^1.3.0",
|
|
27
|
+
"tree-sitter-elixir": "^0.1.1",
|
|
28
|
+
"tree-sitter-elm": "^4.5.0",
|
|
29
|
+
"tree-sitter-embedded-template": "^0.20.0",
|
|
30
|
+
"tree-sitter-go": "^0.20.0",
|
|
31
|
+
"tree-sitter-html": "^0.20.0",
|
|
32
|
+
"tree-sitter-java": "^0.20.2",
|
|
33
|
+
"tree-sitter-javascript": "^0.20.3",
|
|
34
|
+
"tree-sitter-json": "^0.20.2",
|
|
35
|
+
"tree-sitter-kotlin": "^0.3.1",
|
|
36
|
+
"tree-sitter-lua": "^2.1.3",
|
|
37
|
+
"tree-sitter-objc": "^2.1.0",
|
|
38
|
+
"tree-sitter-ocaml": "^0.20.4",
|
|
39
|
+
"tree-sitter-php": "^0.22.0",
|
|
40
|
+
"tree-sitter-python": "^0.21.0",
|
|
41
|
+
"tree-sitter-ql": "^1.0.0",
|
|
42
|
+
"tree-sitter-rescript": "github:rescript-lang/tree-sitter-rescript#6376fa028f31aa4e26ca2c8f007e322cd2a5eb4a",
|
|
43
|
+
"tree-sitter-ruby": "^0.20.1",
|
|
44
|
+
"tree-sitter-rust": "^0.20.4",
|
|
45
|
+
"tree-sitter-scala": "^0.19.0",
|
|
46
|
+
"tree-sitter-solidity": "github:JoranHonig/tree-sitter-solidity#b239a95f94cfcc6e7b3e961bc73a28d55e214f02",
|
|
47
|
+
"tree-sitter-swift": "^0.4.0",
|
|
48
|
+
"tree-sitter-systemrdl": "^0.7.0",
|
|
49
|
+
"tree-sitter-toml": "^0.5.1",
|
|
50
|
+
"tree-sitter-typescript": "^0.20.5",
|
|
51
|
+
"tree-sitter-vue": "https://github.com/tree-sitter-grammars/tree-sitter-vue#7e48557b903a9db9c38cea3b7839ef7e1f36c693",
|
|
52
|
+
"tree-sitter-yaml": "^0.5.0",
|
|
53
|
+
"ts-node": "^10.9.2",
|
|
54
|
+
"typescript": "5.3.3"
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"/out"
|
|
58
|
+
],
|
|
59
|
+
"packageManager": "pnpm@8.10.5",
|
|
60
|
+
"main": "bindings/node",
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"tree-sitter-wasms": "^0.1.11"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-2024 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.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Web Tree-sitter
|
|
2
|
+
|
|
3
|
+
[![npmjs.com badge]][npmjs.com]
|
|
4
|
+
|
|
5
|
+
[npmjs.com]: https://www.npmjs.org/package/web-tree-sitter
|
|
6
|
+
[npmjs.com badge]: https://img.shields.io/npm/v/web-tree-sitter.svg?color=%23BF4A4A
|
|
7
|
+
|
|
8
|
+
WebAssembly bindings to the [Tree-sitter](https://github.com/tree-sitter/tree-sitter) parsing library.
|
|
9
|
+
|
|
10
|
+
### Setup
|
|
11
|
+
|
|
12
|
+
You can download the `tree-sitter.js` and `tree-sitter.wasm` files from [the latest GitHub release](https://github.com/tree-sitter/tree-sitter/releases/latest) and load them using a standalone script:
|
|
13
|
+
|
|
14
|
+
```html
|
|
15
|
+
<script src="/the/path/to/tree-sitter.js"></script>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
const Parser = window.TreeSitter;
|
|
19
|
+
Parser.init().then(() => { /* the library is ready */ });
|
|
20
|
+
</script>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
You can also install [the `web-tree-sitter` module](https://www.npmjs.com/package/web-tree-sitter) from NPM and load it using a system like Webpack:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
const Parser = require('web-tree-sitter');
|
|
27
|
+
Parser.init().then(() => { /* the library is ready */ });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
You can use this module with [deno](https://deno.land/):
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import Parser from "npm:web-tree-sitter";
|
|
34
|
+
await Parser.init();
|
|
35
|
+
// the library is ready
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Basic Usage
|
|
39
|
+
|
|
40
|
+
First, create a parser:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
const parser = new Parser;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Then assign a language to the parser. Tree-sitter languages are packaged as individual `.wasm` files (more on this below):
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
const JavaScript = await Parser.Language.load('/path/to/tree-sitter-javascript.wasm');
|
|
50
|
+
parser.setLanguage(JavaScript);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Now you can parse source code:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
const sourceCode = 'let x = 1; console.log(x);';
|
|
57
|
+
const tree = parser.parse(sourceCode);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
and inspect the syntax tree.
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
console.log(tree.rootNode.toString());
|
|
64
|
+
|
|
65
|
+
// (program
|
|
66
|
+
// (lexical_declaration
|
|
67
|
+
// (variable_declarator (identifier) (number)))
|
|
68
|
+
// (expression_statement
|
|
69
|
+
// (call_expression
|
|
70
|
+
// (member_expression (identifier) (property_identifier))
|
|
71
|
+
// (arguments (identifier)))))
|
|
72
|
+
|
|
73
|
+
const callExpression = tree.rootNode.child(1).firstChild;
|
|
74
|
+
console.log(callExpression);
|
|
75
|
+
|
|
76
|
+
// { type: 'call_expression',
|
|
77
|
+
// startPosition: {row: 0, column: 16},
|
|
78
|
+
// endPosition: {row: 0, column: 30},
|
|
79
|
+
// startIndex: 0,
|
|
80
|
+
// endIndex: 30 }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Editing
|
|
84
|
+
|
|
85
|
+
If your source code *changes*, you can update the syntax tree. This will take less time than the first parse.
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
// Replace 'let' with 'const'
|
|
89
|
+
const newSourceCode = 'const x = 1; console.log(x);';
|
|
90
|
+
|
|
91
|
+
tree.edit({
|
|
92
|
+
startIndex: 0,
|
|
93
|
+
oldEndIndex: 3,
|
|
94
|
+
newEndIndex: 5,
|
|
95
|
+
startPosition: {row: 0, column: 0},
|
|
96
|
+
oldEndPosition: {row: 0, column: 3},
|
|
97
|
+
newEndPosition: {row: 0, column: 5},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const newTree = parser.parse(newSourceCode, tree);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Parsing Text From a Custom Data Structure
|
|
104
|
+
|
|
105
|
+
If your text is stored in a data structure other than a single string, you can parse it by supplying a callback to `parse` instead of a string:
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
const sourceLines = [
|
|
109
|
+
'let x = 1;',
|
|
110
|
+
'console.log(x);'
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
const tree = parser.parse((index, position) => {
|
|
114
|
+
let line = sourceLines[position.row];
|
|
115
|
+
if (line) return line.slice(position.column);
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Generate .wasm language files
|
|
120
|
+
|
|
121
|
+
The following example shows how to generate `.wasm` file for tree-sitter JavaScript grammar.
|
|
122
|
+
|
|
123
|
+
**IMPORTANT**: [emscripten](https://emscripten.org/docs/getting_started/downloads.html), [docker](https://www.docker.com/), or [podman](https://podman.io) need to be installed.
|
|
124
|
+
|
|
125
|
+
First install `tree-sitter-cli` and the tree-sitter language for which to generate `.wasm` (`tree-sitter-javascript` in this example):
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
npm install --save-dev tree-sitter-cli tree-sitter-javascript
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Then just use tree-sitter cli tool to generate the `.wasm`.
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
npx tree-sitter build --wasm node_modules/tree-sitter-javascript
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
If everything is fine, file `tree-sitter-javascript.wasm` should be generated in current directory.
|
|
138
|
+
|
|
139
|
+
#### Running .wasm in Node.js
|
|
140
|
+
|
|
141
|
+
Notice that executing `.wasm` files in node.js is considerably slower than running [node.js bindings](https://github.com/tree-sitter/node-tree-sitter). However could be useful for testing purposes:
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
const Parser = require('web-tree-sitter');
|
|
145
|
+
|
|
146
|
+
(async () => {
|
|
147
|
+
await Parser.init();
|
|
148
|
+
const parser = new Parser();
|
|
149
|
+
const Lang = await Parser.Language.load('tree-sitter-javascript.wasm');
|
|
150
|
+
parser.setLanguage(Lang);
|
|
151
|
+
const tree = parser.parse('let x = 1;');
|
|
152
|
+
console.log(tree.rootNode.toString());
|
|
153
|
+
})();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### Running .wasm in browser
|
|
157
|
+
|
|
158
|
+
`web-tree-sitter` can run in the browser, but there are some common pitfalls.
|
|
159
|
+
|
|
160
|
+
##### Loading the .wasm file
|
|
161
|
+
|
|
162
|
+
`web-tree-sitter` needs to load the `tree-sitter.wasm` file. By default, it assumes that this file is available in the
|
|
163
|
+
same path as the JavaScript code. Therefore, if the code is being served from `http://localhost:3000/bundle.js`, then
|
|
164
|
+
the wasm file should be at `http://localhost:3000/tree-sitter.wasm`.
|
|
165
|
+
|
|
166
|
+
For server side frameworks like NextJS, this can be tricky as pages are often served from a path such as
|
|
167
|
+
`http://localhost:3000/_next/static/chunks/pages/index.js`. The loader will therefore look for the wasm file at
|
|
168
|
+
`http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`. The solution is to pass a `locateFile` function in
|
|
169
|
+
the `moduleOptions` argument to `Parser.init()`:
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
await Parser.init({
|
|
173
|
+
locateFile(scriptName: string, scriptDirectory: string) {
|
|
174
|
+
return scriptName;
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`locateFile` takes in two parameters, `scriptName`, i.e. the wasm file name, and `scriptDirectory`, i.e. the directory
|
|
180
|
+
where the loader expects the script to be. It returns the path where the loader will look for the wasm file. In the NextJS
|
|
181
|
+
case, we want to return just the `scriptName` so that the loader will look at `http://localhost:3000/tree-sitter.wasm`
|
|
182
|
+
and not `http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`.
|
|
183
|
+
|
|
184
|
+
##### `Can't resolve 'fs' in 'node_modules/web-tree-sitter'`
|
|
185
|
+
|
|
186
|
+
Most bundlers will notice that the `tree-sitter.js` file is attempting to import `fs`, i.e. node's file system library.
|
|
187
|
+
Since this doesn't exist in the browser, the bundlers will get confused. For webpack you can fix this by adding the
|
|
188
|
+
following to your webpack config:
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
{
|
|
192
|
+
resolve: {
|
|
193
|
+
fallback: {
|
|
194
|
+
fs: false
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "web-tree-sitter",
|
|
3
|
+
"version": "0.22.6",
|
|
4
|
+
"description": "Tree-sitter bindings for the web",
|
|
5
|
+
"main": "tree-sitter.js",
|
|
6
|
+
"types": "tree-sitter-web.d.ts",
|
|
7
|
+
"directories": {
|
|
8
|
+
"test": "test"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "mocha",
|
|
12
|
+
"prepack": "cp ../../LICENSE .",
|
|
13
|
+
"prepublishOnly": "node check-artifacts-fresh.js"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/tree-sitter/tree-sitter.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"incremental",
|
|
21
|
+
"parsing"
|
|
22
|
+
],
|
|
23
|
+
"author": "Max Brunsfeld",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/tree-sitter/tree-sitter/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/tree-sitter/tree-sitter/tree/master/lib/binding_web",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/emscripten": "^1.39.10",
|
|
31
|
+
"chai": "^4.3.7",
|
|
32
|
+
"eslint": ">=8.56.0",
|
|
33
|
+
"eslint-config-google": "^0.14.0",
|
|
34
|
+
"mocha": "^10.2.0",
|
|
35
|
+
"terser": "^5.16.6"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
declare module 'web-tree-sitter' {
|
|
2
|
+
class Parser {
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param moduleOptions Optional emscripten module-object, see https://emscripten.org/docs/api_reference/module.html
|
|
6
|
+
*/
|
|
7
|
+
static init(moduleOptions?: object): Promise<void>;
|
|
8
|
+
delete(): void;
|
|
9
|
+
parse(input: string | Parser.Input, oldTree?: Parser.Tree, options?: Parser.Options): Parser.Tree;
|
|
10
|
+
getIncludedRanges(): Parser.Range[];
|
|
11
|
+
getTimeoutMicros(): number;
|
|
12
|
+
setTimeoutMicros(timeout: number): void;
|
|
13
|
+
reset(): void;
|
|
14
|
+
getLanguage(): Parser.Language;
|
|
15
|
+
setLanguage(language?: Parser.Language | null): void;
|
|
16
|
+
getLogger(): Parser.Logger;
|
|
17
|
+
setLogger(logFunc?: Parser.Logger | false | null): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
namespace Parser {
|
|
21
|
+
export type Options = {
|
|
22
|
+
includedRanges?: Range[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type Point = {
|
|
26
|
+
row: number;
|
|
27
|
+
column: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type Range = {
|
|
31
|
+
startIndex: number,
|
|
32
|
+
endIndex: number,
|
|
33
|
+
startPosition: Point,
|
|
34
|
+
endPosition: Point
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type Edit = {
|
|
38
|
+
startIndex: number;
|
|
39
|
+
oldEndIndex: number;
|
|
40
|
+
newEndIndex: number;
|
|
41
|
+
startPosition: Point;
|
|
42
|
+
oldEndPosition: Point;
|
|
43
|
+
newEndPosition: Point;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type Logger = (
|
|
47
|
+
message: string,
|
|
48
|
+
params: { [param: string]: string },
|
|
49
|
+
type: "parse" | "lex"
|
|
50
|
+
) => void;
|
|
51
|
+
|
|
52
|
+
export interface Input {
|
|
53
|
+
(index: number, position?: Point): string | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SyntaxNode {
|
|
57
|
+
tree: Tree;
|
|
58
|
+
id: number;
|
|
59
|
+
typeId: number;
|
|
60
|
+
grammarId: number;
|
|
61
|
+
type: string;
|
|
62
|
+
grammarType: string;
|
|
63
|
+
isNamed: boolean;
|
|
64
|
+
isMissing: boolean;
|
|
65
|
+
isExtra: boolean;
|
|
66
|
+
hasChanges: boolean;
|
|
67
|
+
hasError: boolean;
|
|
68
|
+
isError: boolean;
|
|
69
|
+
text: string;
|
|
70
|
+
parseState: number;
|
|
71
|
+
nextParseState: number;
|
|
72
|
+
startPosition: Point;
|
|
73
|
+
endPosition: Point;
|
|
74
|
+
startIndex: number;
|
|
75
|
+
endIndex: number;
|
|
76
|
+
parent: SyntaxNode | null;
|
|
77
|
+
children: Array<SyntaxNode>;
|
|
78
|
+
namedChildren: Array<SyntaxNode>;
|
|
79
|
+
childCount: number;
|
|
80
|
+
namedChildCount: number;
|
|
81
|
+
firstChild: SyntaxNode | null;
|
|
82
|
+
firstNamedChild: SyntaxNode | null;
|
|
83
|
+
lastChild: SyntaxNode | null;
|
|
84
|
+
lastNamedChild: SyntaxNode | null;
|
|
85
|
+
nextSibling: SyntaxNode | null;
|
|
86
|
+
nextNamedSibling: SyntaxNode | null;
|
|
87
|
+
previousSibling: SyntaxNode | null;
|
|
88
|
+
previousNamedSibling: SyntaxNode | null;
|
|
89
|
+
descendantCount: number;
|
|
90
|
+
|
|
91
|
+
equals(other: SyntaxNode): boolean;
|
|
92
|
+
toString(): string;
|
|
93
|
+
child(index: number): SyntaxNode | null;
|
|
94
|
+
namedChild(index: number): SyntaxNode | null;
|
|
95
|
+
childForFieldName(fieldName: string): SyntaxNode | null;
|
|
96
|
+
childForFieldId(fieldId: number): SyntaxNode | null;
|
|
97
|
+
fieldNameForChild(childIndex: number): string | null;
|
|
98
|
+
childrenForFieldName(fieldName: string): Array<SyntaxNode>;
|
|
99
|
+
childrenForFieldId(fieldId: number): Array<SyntaxNode>;
|
|
100
|
+
firstChildForIndex(index: number): SyntaxNode | null;
|
|
101
|
+
firstNamedChildForIndex(index: number): SyntaxNode | null;
|
|
102
|
+
|
|
103
|
+
descendantForIndex(index: number): SyntaxNode;
|
|
104
|
+
descendantForIndex(startIndex: number, endIndex: number): SyntaxNode;
|
|
105
|
+
namedDescendantForIndex(index: number): SyntaxNode;
|
|
106
|
+
namedDescendantForIndex(startIndex: number, endIndex: number): SyntaxNode;
|
|
107
|
+
descendantForPosition(position: Point): SyntaxNode;
|
|
108
|
+
descendantForPosition(startPosition: Point, endPosition: Point): SyntaxNode;
|
|
109
|
+
namedDescendantForPosition(position: Point): SyntaxNode;
|
|
110
|
+
namedDescendantForPosition(startPosition: Point, endPosition: Point): SyntaxNode;
|
|
111
|
+
descendantsOfType(types: String | Array<String>, startPosition?: Point, endPosition?: Point): Array<SyntaxNode>;
|
|
112
|
+
|
|
113
|
+
walk(): TreeCursor;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface TreeCursor {
|
|
117
|
+
nodeType: string;
|
|
118
|
+
nodeTypeId: number;
|
|
119
|
+
nodeStateId: number;
|
|
120
|
+
nodeText: string;
|
|
121
|
+
nodeId: number;
|
|
122
|
+
nodeIsNamed: boolean;
|
|
123
|
+
nodeIsMissing: boolean;
|
|
124
|
+
startPosition: Point;
|
|
125
|
+
endPosition: Point;
|
|
126
|
+
startIndex: number;
|
|
127
|
+
endIndex: number;
|
|
128
|
+
readonly currentNode: SyntaxNode;
|
|
129
|
+
readonly currentFieldName: string;
|
|
130
|
+
readonly currentFieldId: number;
|
|
131
|
+
readonly currentDepth: number;
|
|
132
|
+
readonly currentDescendantIndex: number;
|
|
133
|
+
|
|
134
|
+
reset(node: SyntaxNode): void;
|
|
135
|
+
resetTo(cursor: TreeCursor): void;
|
|
136
|
+
delete(): void;
|
|
137
|
+
gotoParent(): boolean;
|
|
138
|
+
gotoFirstChild(): boolean;
|
|
139
|
+
gotoLastChild(): boolean;
|
|
140
|
+
gotoFirstChildForIndex(goalIndex: number): boolean;
|
|
141
|
+
gotoFirstChildForPosition(goalPosition: Point): boolean;
|
|
142
|
+
gotoNextSibling(): boolean;
|
|
143
|
+
gotoPreviousSibling(): boolean;
|
|
144
|
+
gotoDescendant(goalDescendantIndex: number): void;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface Tree {
|
|
148
|
+
readonly rootNode: SyntaxNode;
|
|
149
|
+
|
|
150
|
+
rootNodeWithOffset(offsetBytes: number, offsetExtent: Point): SyntaxNode;
|
|
151
|
+
copy(): Tree;
|
|
152
|
+
delete(): void;
|
|
153
|
+
edit(edit: Edit): Tree;
|
|
154
|
+
walk(): TreeCursor;
|
|
155
|
+
getChangedRanges(other: Tree): Range[];
|
|
156
|
+
getIncludedRanges(): Range[];
|
|
157
|
+
getEditedRange(other: Tree): Range;
|
|
158
|
+
getLanguage(): Language;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface QueryCapture {
|
|
162
|
+
name: string;
|
|
163
|
+
text?: string;
|
|
164
|
+
node: SyntaxNode;
|
|
165
|
+
setProperties?: { [prop: string]: string | null };
|
|
166
|
+
assertedProperties?: { [prop: string]: string | null };
|
|
167
|
+
refutedProperties?: { [prop: string]: string | null };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface QueryMatch {
|
|
171
|
+
pattern: number;
|
|
172
|
+
captures: QueryCapture[];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export type QueryOptions = {
|
|
176
|
+
startPosition?: Point;
|
|
177
|
+
endPosition?: Point;
|
|
178
|
+
startIndex?: number;
|
|
179
|
+
endIndex?: number;
|
|
180
|
+
matchLimit?: number;
|
|
181
|
+
maxStartDepth?: number;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export interface PredicateResult {
|
|
185
|
+
operator: string;
|
|
186
|
+
operands: { name: string; type: string }[];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export class Query {
|
|
190
|
+
captureNames: string[];
|
|
191
|
+
readonly predicates: { [name: string]: Function }[];
|
|
192
|
+
readonly setProperties: any[];
|
|
193
|
+
readonly assertedProperties: any[];
|
|
194
|
+
readonly refutedProperties: any[];
|
|
195
|
+
readonly matchLimit: number;
|
|
196
|
+
|
|
197
|
+
delete(): void;
|
|
198
|
+
captures(node: SyntaxNode, options?: QueryOptions): QueryCapture[];
|
|
199
|
+
matches(node: SyntaxNode, options?: QueryOptions): QueryMatch[];
|
|
200
|
+
predicatesForPattern(patternIndex: number): PredicateResult[];
|
|
201
|
+
disableCapture(captureName: string): void;
|
|
202
|
+
disablePattern(patternIndex: number): void;
|
|
203
|
+
isPatternGuaranteedAtStep(byteOffset: number): boolean;
|
|
204
|
+
isPatternRooted(patternIndex: number): boolean;
|
|
205
|
+
isPatternNonLocal(patternIndex: number): boolean;
|
|
206
|
+
startIndexForPattern(patternIndex: number): number;
|
|
207
|
+
didExceedMatchLimit(): boolean;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
class Language {
|
|
211
|
+
static load(input: string | Uint8Array): Promise<Language>;
|
|
212
|
+
|
|
213
|
+
readonly version: number;
|
|
214
|
+
readonly fieldCount: number;
|
|
215
|
+
readonly stateCount: number;
|
|
216
|
+
readonly nodeTypeCount: number;
|
|
217
|
+
|
|
218
|
+
fieldNameForId(fieldId: number): string | null;
|
|
219
|
+
fieldIdForName(fieldName: string): number | null;
|
|
220
|
+
idForNodeType(type: string, named: boolean): number;
|
|
221
|
+
nodeTypeForId(typeId: number): string | null;
|
|
222
|
+
nodeTypeIsNamed(typeId: number): boolean;
|
|
223
|
+
nodeTypeIsVisible(typeId: number): boolean;
|
|
224
|
+
nextState(stateId: number, typeId: number): number;
|
|
225
|
+
query(source: string): Query;
|
|
226
|
+
lookaheadIterator(stateId: number): LookaheadIterable | null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export class LookaheadIterable {
|
|
230
|
+
readonly language: Language;
|
|
231
|
+
readonly currentTypeId: number;
|
|
232
|
+
readonly currentType: string;
|
|
233
|
+
|
|
234
|
+
delete(): void;
|
|
235
|
+
reset(language: Language, stateId: number): boolean;
|
|
236
|
+
resetState(stateId: number): boolean;
|
|
237
|
+
[Symbol.iterator](): Iterator<string>;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export = Parser
|
|
242
|
+
}
|