tree-sitter-java-orchard 0.5.8 → 0.5.10

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: $ => [
@@ -242,7 +242,7 @@ module.exports = grammar({
242
242
  $.switch_expression,
243
243
  ),
244
244
 
245
- cast_expression: $ => prec(PREC.CAST, choice(
245
+ cast_expression: $ => prec.right(PREC.CAST, choice(
246
246
  seq(
247
247
  '(',
248
248
  field('type', $._type),
@@ -352,12 +352,12 @@ module.exports = grammar({
352
352
  field('operand', $.expression),
353
353
  )),
354
354
 
355
- update_expression: $ => prec.left(PREC.UNARY, choice(
355
+ update_expression: $ => prec.right(PREC.UNARY, choice(
356
356
  // Post (in|de)crement is evaluated before pre (in|de)crement
357
- seq($.expression, '++'),
358
- seq($.expression, '--'),
359
- seq('++', $.expression),
360
- seq('--', $.expression),
357
+ seq($.primary_expression, '++'),
358
+ seq($.primary_expression, '--'),
359
+ seq('++', $.primary_expression),
360
+ seq('--', $.primary_expression),
361
361
  )),
362
362
 
363
363
  primary_expression: $ => choice(
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "tree-sitter-java-orchard",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
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
@@ -1362,7 +1362,7 @@
1362
1362
  ]
1363
1363
  },
1364
1364
  "cast_expression": {
1365
- "type": "PREC",
1365
+ "type": "PREC_RIGHT",
1366
1366
  "value": 14,
1367
1367
  "content": {
1368
1368
  "type": "CHOICE",
@@ -2520,7 +2520,7 @@
2520
2520
  }
2521
2521
  },
2522
2522
  "update_expression": {
2523
- "type": "PREC_LEFT",
2523
+ "type": "PREC_RIGHT",
2524
2524
  "value": 15,
2525
2525
  "content": {
2526
2526
  "type": "CHOICE",
@@ -2530,7 +2530,7 @@
2530
2530
  "members": [
2531
2531
  {
2532
2532
  "type": "SYMBOL",
2533
- "name": "expression"
2533
+ "name": "primary_expression"
2534
2534
  },
2535
2535
  {
2536
2536
  "type": "STRING",
@@ -2543,7 +2543,7 @@
2543
2543
  "members": [
2544
2544
  {
2545
2545
  "type": "SYMBOL",
2546
- "name": "expression"
2546
+ "name": "primary_expression"
2547
2547
  },
2548
2548
  {
2549
2549
  "type": "STRING",
@@ -2560,7 +2560,7 @@
2560
2560
  },
2561
2561
  {
2562
2562
  "type": "SYMBOL",
2563
- "name": "expression"
2563
+ "name": "primary_expression"
2564
2564
  }
2565
2565
  ]
2566
2566
  },
@@ -2573,7 +2573,7 @@
2573
2573
  },
2574
2574
  {
2575
2575
  "type": "SYMBOL",
2576
- "name": "expression"
2576
+ "name": "primary_expression"
2577
2577
  }
2578
2578
  ]
2579
2579
  }
@@ -4001,7 +4001,7 @@
4001
4001
  "required": true,
4002
4002
  "types": [
4003
4003
  {
4004
- "type": "expression",
4004
+ "type": "primary_expression",
4005
4005
  "named": true
4006
4006
  }
4007
4007
  ]