@xsrg2008/web-tree-sitter-cpp 0.0.1

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/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ type Parser = import("web-tree-sitter");
2
+ declare module "web-tree-sitter-cpp" {
3
+ function getCppParser(): Promise<Parser>;
4
+ }
package/index.js ADDED
@@ -0,0 +1,32 @@
1
+ const Parser = require("web-tree-sitter");
2
+ const fs = require("fs");
3
+
4
+ function getCppParser() {
5
+ return getParser(__dirname + "/tree-sitter-cpp.wasm");
6
+ }
7
+ /**
8
+ * @param {string} wasmLangFile
9
+ * @returns {Promise<Parser>}
10
+ */
11
+ async function getParser(wasmLangFile) {
12
+ return new Promise(async (resolve, reject) => {
13
+ await Parser.init();
14
+ const parser = new Parser();
15
+ fs.readFile(wasmLangFile, async (err, data) => {
16
+ if (err) {
17
+ reject(err);
18
+ }
19
+ try {
20
+ const lang = await Parser.Language.load(data);
21
+ parser.setLanguage(lang);
22
+ resolve(parser);
23
+ } catch (err2) {
24
+ reject(err2);
25
+ }
26
+ });
27
+ });
28
+ }
29
+
30
+ module.exports = {
31
+ getCppParser,
32
+ };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@xsrg2008/web-tree-sitter-cpp",
3
+ "version": "0.0.1",
4
+ "description": "tree-sitter-cpp WASM",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "index.d.ts",
13
+ "tree-sitter-cpp.wasm",
14
+ "package.json"
15
+ ],
16
+ "keywords": [
17
+ "tree-sitter",
18
+ "cpp",
19
+ "wasm"
20
+ ],
21
+ "author": "xsrg2008",
22
+ "license": "ISC",
23
+ "dependencies": {
24
+ "web-tree-sitter": "^0.22.6"
25
+ }
26
+ }
Binary file