Skip to content

Commit 3d60faf

Browse files
committed
just go back to vendoring rust and typescript, not worth the trouble
1 parent 43b13f4 commit 3d60faf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+820177
-51
lines changed

src/test/suite/index.ts

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import * as Installer from "../../Installer";
2-
import * as fs from "fs/promises";
31
import * as path from "path";
42

53
import Mocha from "mocha";
64
import glob from "glob";
7-
import Parser from "tree-sitter";
85

96
export async function run(): Promise<void> {
107
// Create the mocha test
@@ -16,54 +13,6 @@ export async function run(): Promise<void> {
1613

1714
const testsRoot = path.resolve(__dirname, "..");
1815

19-
const parsersDir = path.resolve(testsRoot, "..", "..", "test-parsers");
20-
21-
// remove parsers dir
22-
let exists = false;
23-
try {
24-
await fs.access(parsersDir);
25-
exists = true;
26-
} catch {
27-
// do nothing
28-
}
29-
30-
if (exists) {
31-
await fs.rm(parsersDir, { recursive: true });
32-
}
33-
34-
// create parsers dir
35-
await fs.mkdir(parsersDir);
36-
37-
const testParser = new Parser();
38-
39-
// install tree-sitter-rust
40-
let result = await Installer.getLanguage("test-parsers", "rust", true);
41-
if (result.status === "err") {
42-
throw new Error(`Failed to install language: ${result.result}`);
43-
}
44-
45-
try {
46-
testParser.setLanguage(result.result);
47-
} catch (error) {
48-
throw new Error(`Failed to install language: ${result.result}`);
49-
}
50-
51-
console.log(`Installed language: ${JSON.stringify(result.result)}`);
52-
53-
// install tree-sitter-typescript
54-
result = await Installer.getLanguage("test-parsers", "typescript", true);
55-
if (result.status === "err") {
56-
throw new Error(`Failed to install language: ${result.result}`);
57-
}
58-
59-
try {
60-
testParser.setLanguage(result.result);
61-
} catch (error) {
62-
throw new Error(`Failed to install language: ${result.result}`);
63-
}
64-
65-
console.log(`Installed language: ${JSON.stringify(result.result)}`);
66-
6716
return new Promise((c, e) => {
6817
glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
6918
if (err) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Maxim Sokolov
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.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# tree-sitter-rust
2+
3+
[![CI][ci]](https://github.com/tree-sitter/tree-sitter-rust/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-rust)
7+
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-rust)
8+
[![pypi][pypi]](https://pypi.org/project/tree-sitter-rust)
9+
10+
Rust grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
11+
12+
## Features
13+
14+
- **Speed** — When initially parsing a file, `tree-sitter-rust` takes around two to three times
15+
as long as rustc's hand-written parser.
16+
17+
```sh
18+
$ wc -l examples/ast.rs
19+
2157 examples/ast.rs
20+
21+
$ rustc -Z unpretty=ast-tree -Z time-passes examples/ast.rs | head -n0
22+
time: 0.002; rss: 55MB -> 60MB ( +5MB) parse_crate
23+
24+
$ tree-sitter parse examples/ast.rs --quiet --time
25+
examples/ast.rs 6.48 ms 9908 bytes/ms
26+
```
27+
28+
But if you _edit_ the file after parsing it, tree-sitter can generally _update_
29+
the previous existing syntax tree to reflect your edit in less than a millisecond,
30+
thanks to its incremental parsing system.
31+
32+
## References
33+
34+
- [The Rust Reference](https://doc.rust-lang.org/reference/) — While Rust does
35+
not have a specification, the reference tries to describe its working in detail.
36+
It tends to be out of date.
37+
- [Keywords](https://doc.rust-lang.org/stable/book/appendix-01-keywords.html) and
38+
[Operators and Symbols](https://doc.rust-lang.org/stable/book/appendix-02-operators.html).
39+
40+
[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/tree-sitter-rust/ci.yml?logo=github&label=CI
41+
[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord
42+
[matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix&label=matrix
43+
[npm]: https://img.shields.io/npm/v/tree-sitter-rust?logo=npm
44+
[crates]: https://img.shields.io/crates/v/tree-sitter-rust?logo=rust
45+
[pypi]: https://img.shields.io/pypi/v/tree-sitter-rust?logo=pypi&logoColor=ffd242
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "tree_sitter_rust_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+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <napi.h>
2+
3+
typedef struct TSLanguage TSLanguage;
4+
5+
extern "C" TSLanguage *tree_sitter_rust();
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, "rust");
14+
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_rust());
15+
language.TypeTag(&LANGUAGE_TYPE_TAG);
16+
exports["language"] = language;
17+
return exports;
18+
}
19+
20+
NODE_API_MODULE(tree_sitter_rust_binding, Init)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference types="node" />
2+
3+
const assert = require("node:assert");
4+
const { test } = require("node:test");
5+
6+
test("can load grammar", () => {
7+
const parser = new (require("tree-sitter"))();
8+
assert.doesNotThrow(() => parser.setLanguage(require(".")));
9+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const root = require("path").join(__dirname, "..", "..");
2+
3+
module.exports = require("node-gyp-build")(root);
4+
5+
try {
6+
module.exports.nodeTypeInfo = require("../../src/node-types.json");
7+
} catch (_) {}

0 commit comments

Comments
 (0)