tree-sitter-muttrc 0.0.5 → 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Neorocks
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 CHANGED
@@ -78,6 +78,18 @@ It can be used by:
78
78
  - [tree-sitter-languages](https://github.com/grantjenks/py-tree-sitter-languages):
79
79
  for python
80
80
 
81
+ ## Optional Dependencies
82
+
83
+ - [tree-sitter-expando](https://github.com/neomutt/tree-sitter-expando)
84
+
85
+ Before:
86
+
87
+ ![before](https://github.com/user-attachments/assets/f6d79eef-3281-4be6-8697-83f15f6d1c91)
88
+
89
+ After:
90
+
91
+ ![after](https://github.com/user-attachments/assets/5bc78d28-b944-455b-a68e-36f2ceccdb81)
92
+
81
93
  ## Related Projects
82
94
 
83
95
  - [neomutt.vim](https://github.com/neomutt/neomutt.vim): vim syntax
package/binding.gyp CHANGED
@@ -11,10 +11,24 @@
11
11
  "sources": [
12
12
  "bindings/node/binding.cc",
13
13
  "src/parser.c",
14
- # NOTE: if your language has an external scanner, add it here.
15
14
  ],
16
- "cflags_c": [
17
- "-std=c11",
15
+ "variables": {
16
+ "has_scanner": "<!(node -p \"fs.existsSync('src/scanner.c')\")"
17
+ },
18
+ "conditions": [
19
+ ["has_scanner=='true'", {
20
+ "sources+": ["src/scanner.c"],
21
+ }],
22
+ ["OS!='win'", {
23
+ "cflags_c": [
24
+ "-std=c11",
25
+ ],
26
+ }, { # OS == "win"
27
+ "cflags_c": [
28
+ "/std:c11",
29
+ "/utf-8",
30
+ ],
31
+ }],
18
32
  ],
19
33
  }
20
34
  ]
@@ -6,11 +6,10 @@ extern "C" TSLanguage *tree_sitter_muttrc();
6
6
 
7
7
  // "tree-sitter", "language" hashed with BLAKE2
8
8
  const napi_type_tag LANGUAGE_TYPE_TAG = {
9
- 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
9
+ 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
10
10
  };
11
11
 
12
12
  Napi::Object Init(Napi::Env env, Napi::Object exports) {
13
- exports["name"] = Napi::String::New(env, "muttrc");
14
13
  auto language = Napi::External<TSLanguage>::New(env, tree_sitter_muttrc());
15
14
  language.TypeTag(&LANGUAGE_TYPE_TAG);
16
15
  exports["language"] = language;
@@ -0,0 +1,11 @@
1
+ import assert from "node:assert";
2
+ import { test } from "node:test";
3
+ import Parser from "tree-sitter";
4
+
5
+ test("can load grammar", () => {
6
+ const parser = new Parser();
7
+ assert.doesNotReject(async () => {
8
+ const { default: language } = await import("./index.js");
9
+ parser.setLanguage(language);
10
+ });
11
+ });
@@ -18,11 +18,43 @@ type NodeInfo =
18
18
  children: ChildNode[];
19
19
  });
20
20
 
21
- type Language = {
22
- name: string;
21
+ /**
22
+ * The tree-sitter language object for this grammar.
23
+ *
24
+ * @see {@linkcode https://tree-sitter.github.io/node-tree-sitter/interfaces/Parser.Language.html Parser.Language}
25
+ *
26
+ * @example
27
+ * import Parser from "tree-sitter";
28
+ * import Muttrc from "tree-sitter-muttrc";
29
+ *
30
+ * const parser = new Parser();
31
+ * parser.setLanguage(Muttrc);
32
+ */
33
+ declare const binding: {
34
+ /**
35
+ * The inner language object.
36
+ * @private
37
+ */
23
38
  language: unknown;
39
+
40
+ /**
41
+ * The content of the `node-types.json` file for this grammar.
42
+ *
43
+ * @see {@linkplain https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types Static Node Types}
44
+ */
24
45
  nodeTypeInfo: NodeInfo[];
46
+
47
+ /** The syntax highlighting query for this grammar. */
48
+ HIGHLIGHTS_QUERY?: string;
49
+
50
+ /** The language injection query for this grammar. */
51
+ INJECTIONS_QUERY?: string;
52
+
53
+ /** The local variable query for this grammar. */
54
+ LOCALS_QUERY?: string;
55
+
56
+ /** The symbol tagging query for this grammar. */
57
+ TAGS_QUERY?: string;
25
58
  };
26
59
 
27
- declare const language: Language;
28
- export = language;
60
+ export default binding;
@@ -1,7 +1,37 @@
1
- const root = require("path").join(__dirname, "..", "..");
1
+ import { readFileSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
2
3
 
3
- module.exports = require("node-gyp-build")(root);
4
+ const root = fileURLToPath(new URL("../..", import.meta.url));
5
+
6
+ const binding = typeof process.versions.bun === "string"
7
+ // Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
8
+ ? await import(`${root}/prebuilds/${process.platform}-${process.arch}/tree-sitter-muttrc.node`)
9
+ : (await import("node-gyp-build")).default(root);
4
10
 
5
11
  try {
6
- module.exports.nodeTypeInfo = require("../../src/node-types.json");
7
- } catch (_) {}
12
+ const nodeTypes = await import(`${root}/src/node-types.json`, { with: { type: "json" } });
13
+ binding.nodeTypeInfo = nodeTypes.default;
14
+ } catch { }
15
+
16
+ const queries = [
17
+ ["HIGHLIGHTS_QUERY", `${root}/queries/highlights.scm`],
18
+ ["INJECTIONS_QUERY", `${root}/queries/injections.scm`],
19
+ ["LOCALS_QUERY", `${root}/queries/locals.scm`],
20
+ ["TAGS_QUERY", `${root}/queries/tags.scm`],
21
+ ];
22
+
23
+ for (const [prop, path] of queries) {
24
+ Object.defineProperty(binding, prop, {
25
+ configurable: true,
26
+ enumerable: true,
27
+ get() {
28
+ delete binding[prop];
29
+ try {
30
+ binding[prop] = readFileSync(path, "utf8");
31
+ } catch { }
32
+ return binding[prop];
33
+ }
34
+ });
35
+ }
36
+
37
+ export default binding;