tree-sitter-java-orchard 0.5.7 → 0.5.9

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 CHANGED
@@ -4,11 +4,28 @@
4
4
  [![pypi][pypi]](https://pypi.org/project/tree-sitter-java-orchard)
5
5
  [![npm][npm]](https://www.npmjs.com/package/tree-sitter-java-orchard)
6
6
 
7
- Java grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
8
- Forked from https://github.com/tree-sitter/tree-sitter-java to integrate valuable unreviewed PRs.
7
+ This is a tree-sitter grammar for Java.
8
+
9
+ ### Using it
10
+
11
+ You can obtain this parser in various formats:
12
+ * as an archive from [the Releases page](/grammar-orchard/tree-sitter-java-orchard/releases), which contains all the generated files (bindings, parser code)
13
+ * as a Rust crate: `cargo add tree-sitter-java-orchard`
14
+ * as a Python package: `pip install tree-sitter-java-orchard`
15
+ * as an NPM package: `npm install tree-sitter-java-orchard`
16
+
17
+ ### Contributing
9
18
 
10
19
  Contributions are welcome, so are co-maintainers.
11
20
 
21
+ Unlike many grammar repositories, this one does not track generated files.
22
+ After cloning this repository, you'll need to run `tree-sitter generate` to obtain the parser.
23
+ If you want to use it via bindings, you'll also need to run `tree-sitter init`.
24
+
25
+ ### Origin
26
+
27
+ This project was forked from https://github.com/tree-sitter/tree-sitter-java, to [ease the use of and collaboration on this grammar](https://codeberg.org/grammar-orchard#for-contributors).
28
+
12
29
  [crates]: https://img.shields.io/crates/v/tree-sitter-java-orchard?logo=rust
13
30
  [pypi]: https://img.shields.io/pypi/v/tree-sitter-java-orchard?logo=pypi&logoColor=ffd242
14
31
  [npm]: https://img.shields.io/npm/v/tree-sitter-java-orchard?logo=npm
@@ -1,9 +1,11 @@
1
- const assert = require("node:assert");
2
- const { test } = require("node:test");
3
-
4
- const Parser = require("tree-sitter");
1
+ import assert from "node:assert";
2
+ import { test } from "node:test";
3
+ import Parser from "tree-sitter";
5
4
 
6
5
  test("can load grammar", () => {
7
6
  const parser = new Parser();
8
- assert.doesNotThrow(() => parser.setLanguage(require(".")));
7
+ assert.doesNotReject(async () => {
8
+ const { default: language } = await import("./index.js");
9
+ parser.setLanguage(language);
10
+ });
9
11
  });
@@ -18,10 +18,43 @@ type NodeInfo =
18
18
  children: ChildNode[];
19
19
  });
20
20
 
21
- type Language = {
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 JavaOrchard from "tree-sitter-java-orchard";
29
+ *
30
+ * const parser = new Parser();
31
+ * parser.setLanguage(JavaOrchard);
32
+ */
33
+ declare const binding: {
34
+ /**
35
+ * The inner language object.
36
+ * @private
37
+ */
22
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
+ */
23
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;
24
58
  };
25
59
 
26
- declare const language: Language;
27
- export = language;
60
+ export default binding;
@@ -1,11 +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 =
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-java-orchard.node`)
7
- : 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-java-orchard.node`)
9
+ : (await import("node-gyp-build")).default(root);
8
10
 
9
11
  try {
10
- module.exports.nodeTypeInfo = require("../../src/node-types.json");
11
- } 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;
package/grammar.js CHANGED
@@ -44,7 +44,7 @@ const PREC = {
44
44
 
45
45
  /* eslint-enable no-multi-spaces */
46
46
 
47
- module.exports = grammar({
47
+ export default grammar({
48
48
  name: 'java_orchard',
49
49
 
50
50
  extras: $ => [
@@ -603,7 +603,7 @@ module.exports = grammar({
603
603
  ),
604
604
 
605
605
  labeled_statement: $ => seq(
606
- $.identifier, ':', $.statement,
606
+ choice($.identifier, $._reserved_identifier), ':', $.statement,
607
607
  ),
608
608
 
609
609
  assert_statement: $ => choice(
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "tree-sitter-java-orchard",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "description": "Java grammar for tree-sitter",
5
- "repository": "https://codeberg.org/grammar-orchard/tree-sitter-java-orchard",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://codeberg.org/grammar-orchard/tree-sitter-java-orchard.git"
9
+ },
6
10
  "license": "MIT",
7
11
  "author": {
8
12
  "name": "Ayman Nadeem",
@@ -27,13 +31,13 @@
27
31
  "*.wasm"
28
32
  ],
29
33
  "dependencies": {
30
- "node-addon-api": "^8.3.1",
34
+ "node-addon-api": "^8.5.0",
31
35
  "node-gyp-build": "^4.8.4"
32
36
  },
33
37
  "devDependencies": {
34
38
  "prebuildify": "^6.0.1",
35
39
  "tree-sitter": "^0.25.0",
36
- "tree-sitter-cli": "^0.25.5"
40
+ "tree-sitter-cli": "^0.26.11"
37
41
  },
38
42
  "peerDependencies": {
39
43
  "tree-sitter": "^0.25.0"
package/src/grammar.json CHANGED
@@ -3993,8 +3993,17 @@
3993
3993
  "type": "SEQ",
3994
3994
  "members": [
3995
3995
  {
3996
- "type": "SYMBOL",
3997
- "name": "identifier"
3996
+ "type": "CHOICE",
3997
+ "members": [
3998
+ {
3999
+ "type": "SYMBOL",
4000
+ "name": "identifier"
4001
+ },
4002
+ {
4003
+ "type": "SYMBOL",
4004
+ "name": "_reserved_identifier"
4005
+ }
4006
+ ]
3998
4007
  },
3999
4008
  {
4000
4009
  "type": "STRING",