@willbooster/tree-sitter-java 5.0.0 → 6.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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-java/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-java/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-java/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-java/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.41.8-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.43.2-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-java.svg)](https://crates.io/crates/willbooster-tree-sitter-java)
10
10
 
11
11
  Java grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
@@ -16,13 +16,13 @@ This fork is based on tree-sitter-java 0.23.5 and accepts `final` modifiers on s
16
16
  and typed record-pattern components, plus qualified names in record patterns. Unnamed variables in switch and
17
17
  `instanceof` type patterns, including typed record-pattern components, use `underscore_pattern` nodes. It ships the
18
18
  parser as the compact tables that the [WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator
19
- emits under that fork's own ABI number (`0x57420006`), so the parser loads only with that runtime, version 7.0.5 or
20
- later within major version 7, and not with upstream's tree-sitter.
19
+ emits under that fork's own ABI number (`0x57420007`), so the parser loads only with that runtime, version 9.0.0 or
20
+ later within major version 9, and not with upstream's tree-sitter.
21
21
 
22
22
  ## Usage
23
23
 
24
24
  The npm package ships `tree-sitter-java.wasm` for
25
- [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 7.0.5 or later within major version 7, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
25
+ [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 9.0.0 or later within major version 9, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
26
26
 
27
27
  ```js
28
28
  import { fileURLToPath } from 'node:url';
@@ -80,8 +80,8 @@ fuzzed with:
80
80
 
81
81
  ```toml
82
82
  [dependencies]
83
- tree-sitter = { package = "willbooster-tree-sitter", version = "7.0.5" }
84
- tree-sitter-java = { package = "willbooster-tree-sitter-java", version = "5" }
83
+ tree-sitter = { package = "willbooster-tree-sitter", version = "9.0.0" }
84
+ tree-sitter-java = { package = "willbooster-tree-sitter-java", version = "6" }
85
85
  ```
86
86
 
87
87
  ```rust
@@ -107,8 +107,8 @@ not the ones this package ships with. Its first run downloads that CLI from the
107
107
  with `cargo` (whose build runs the CMake that `mise.toml` pins) when the download fails or the release has no binary that runs here. Run other CLI commands through it as
108
108
  well (e.g. `script/tree-sitter parse File.java`).
109
109
 
110
- `grammar.js` stays as upstream wrote and formatted it, apart from rule changes, so that it can be compared with
111
- upstream's grammar; the linter and the formatter skip it.
110
+ `grammar.js` keeps upstream's code layout so changes can be compared with upstream's grammar; the linter and formatter
111
+ skip it.
112
112
 
113
113
  `bun run generate` records a fresh generation profile from the applicable `test/corpus` cases and any Git-tracked
114
114
  files in `examples/`, then generates compact parser tables. The parser also embeds metadata from `tree-sitter.json`. After changing a grammar,
package/grammar.js CHANGED
@@ -13,37 +13,33 @@ const DECIMAL_DIGITS = token(sep1(/[0-9]+/, /_+/));
13
13
  const DIGITS = token(choice('0', seq(/[1-9]/, optional(seq(optional(/_+/), DECIMAL_DIGITS)))));
14
14
  const HEX_DIGITS = token(sep1(/[A-Fa-f0-9]+/, /_+/));
15
15
 
16
- /* eslint-disable no-multi-spaces */
17
-
18
16
  const PREC = {
19
17
  // https://introcs.cs.princeton.edu/java/11precedence/
20
- COMMENT: 0, // // /* */
21
- ASSIGN: 1, // = += -= *= /= %= &= ^= |= <<= >>= >>>=
18
+ COMMENT: 0,
19
+ ASSIGN: 1,
22
20
  DECL: 2,
23
21
  ELEMENT_VAL: 2,
24
- TERNARY: 3, // ?:
25
- OR: 4, // ||
26
- AND: 5, // &&
27
- BIT_OR: 6, // |
28
- BIT_XOR: 7, // ^
29
- BIT_AND: 8, // &
30
- EQUALITY: 9, // == !=
22
+ TERNARY: 3,
23
+ OR: 4,
24
+ AND: 5,
25
+ BIT_OR: 6,
26
+ BIT_XOR: 7,
27
+ BIT_AND: 8,
28
+ EQUALITY: 9,
31
29
  GENERIC: 10,
32
- REL: 10, // < <= > >= instanceof
33
- SHIFT: 11, // << >> >>>
34
- ADD: 12, // + -
35
- MULT: 13, // * / %
36
- CAST: 14, // (Type)
37
- OBJ_INST: 14, // new
38
- UNARY: 15, // ++a --a a++ a-- + - ! ~
39
- ARRAY: 16, // [Index]
40
- OBJ_ACCESS: 16, // .
41
- PARENS: 16, // (Expression)
42
- CLASS_LITERAL: 17, // .
30
+ REL: 10,
31
+ SHIFT: 11,
32
+ ADD: 12,
33
+ MULT: 13,
34
+ CAST: 14,
35
+ OBJ_INST: 14,
36
+ UNARY: 15,
37
+ ARRAY: 16,
38
+ OBJ_ACCESS: 16,
39
+ PARENS: 16,
40
+ CLASS_LITERAL: 17,
43
41
  };
44
42
 
45
- /* eslint-enable no-multi-spaces */
46
-
47
43
  module.exports = grammar({
48
44
  name: 'java',
49
45
 
@@ -77,6 +73,7 @@ module.exports = grammar({
77
73
  [$.array_type, $._unannotated_type],
78
74
  [$.array_type, $.primary_expression],
79
75
  [$.modifiers, $.annotated_type, $.receiver_parameter],
76
+ [$.type_pattern, $.annotated_type],
80
77
  [$.modifiers, $.annotated_type, $.module_declaration, $.package_declaration],
81
78
  [$._unannotated_type, $.primary_expression, $.inferred_parameters],
82
79
  [$._unannotated_type, $.primary_expression],
@@ -84,7 +81,6 @@ module.exports = grammar({
84
81
  [$._unannotated_type, $.generic_type],
85
82
  [$.generic_type, $.primary_expression],
86
83
  [$.expression, $.statement],
87
- // Only conflicts in switch expressions
88
84
  [$.lambda_expression, $.primary_expression],
89
85
  [$.inferred_parameters, $.primary_expression],
90
86
  [$.argument_list, $.record_pattern_body],
@@ -280,10 +276,6 @@ module.exports = grammar({
280
276
  )),
281
277
  '"""',
282
278
  ),
283
- // Workaround to https://github.com/tree-sitter/tree-sitter/issues/1156
284
- // We give names to the token() constructs containing a regexp
285
- // so as to obtain a node in the CST.
286
-
287
279
  string_fragment: _ => token.immediate(prec(1, /[^"\\]+/)),
288
280
  _multiline_string_fragment: _ => choice(
289
281
  /[^"\\]+/,
@@ -438,7 +430,6 @@ module.exports = grammar({
438
430
  )),
439
431
 
440
432
  update_expression: $ => prec.left(PREC.UNARY, choice(
441
- // Post (in|de)crement is evaluated before pre (in|de)crement
442
433
  seq($.expression, '++'),
443
434
  seq($.expression, '--'),
444
435
  seq('++', $.expression),
@@ -623,7 +614,7 @@ module.exports = grammar({
623
614
  $.type_pattern,
624
615
  $.record_pattern,
625
616
  ),
626
- type_pattern: $ => seq(optional('final'), $._unannotated_type, choice($.identifier, $._reserved_identifier, $.underscore_pattern)),
617
+ type_pattern: $ => seq(repeat(choice($._annotation, 'final')), $._unannotated_type, choice($.identifier, $._reserved_identifier, $.underscore_pattern)),
627
618
  record_pattern: $ => seq(choice($.identifier, $._reserved_identifier, $.generic_type, $.scoped_type_identifier), $.record_pattern_body),
628
619
  record_pattern_body: $ => seq('(', commaSep(choice($.record_pattern_component, $.record_pattern)), ')'),
629
620
  record_pattern_component: $ => choice(
@@ -655,7 +646,7 @@ module.exports = grammar({
655
646
  $.continue_statement,
656
647
  $.return_statement,
657
648
  $.yield_statement,
658
- $.switch_expression, // switch statements and expressions are identical
649
+ $.switch_expression,
659
650
  $.synchronized_statement,
660
651
  $.local_variable_declaration,
661
652
  $.throw_statement,
@@ -1053,7 +1044,7 @@ module.exports = grammar({
1053
1044
  $.field_declaration,
1054
1045
  $.record_declaration,
1055
1046
  $.method_declaration,
1056
- $.compact_constructor_declaration, // For records.
1047
+ $.compact_constructor_declaration,
1057
1048
  $.class_declaration,
1058
1049
  $.interface_declaration,
1059
1050
  $.annotation_type_declaration,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-java",
3
- "version": "5.0.0",
3
+ "version": "6.0.1",
4
4
  "description": "Java grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -42,16 +42,16 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@tsconfig/bun": "1.0.11",
45
- "@types/bun": "1.4.2",
45
+ "@types/bun": "1.4.3",
46
46
  "@vitest/browser-playwright": "5.0.3",
47
47
  "@willbooster/oxfmt-config": "1.2.2",
48
48
  "@willbooster/oxlint-config": "1.4.8",
49
- "@willbooster/wb": "22.26.1",
50
- "@willbooster/web-tree-sitter": "7.0.5",
49
+ "@willbooster/wb": "22.26.2",
50
+ "@willbooster/web-tree-sitter": "9.0.0",
51
51
  "conventional-changelog-conventionalcommits": "10.4.0",
52
- "lefthook": "2.2.1",
53
- "oxfmt": "0.72.0",
54
- "oxlint": "1.87.0",
52
+ "lefthook": "2.2.2",
53
+ "oxfmt": "0.73.0",
54
+ "oxlint": "1.88.0",
55
55
  "oxlint-tsgolint": "7.0.2004",
56
56
  "playwright": "1.63.0",
57
57
  "semantic-release": "25.0.9",
@@ -60,7 +60,7 @@
60
60
  "wrangler": "4.147.0"
61
61
  },
62
62
  "peerDependencies": {
63
- "@willbooster/web-tree-sitter": "^7.0.5"
63
+ "@willbooster/web-tree-sitter": "^9.0.0"
64
64
  },
65
65
  "peerDependenciesMeta": {
66
66
  "@willbooster/web-tree-sitter": {
@@ -3950,10 +3950,18 @@
3950
3950
  "type": "_unannotated_type",
3951
3951
  "named": true
3952
3952
  },
3953
+ {
3954
+ "type": "annotation",
3955
+ "named": true
3956
+ },
3953
3957
  {
3954
3958
  "type": "identifier",
3955
3959
  "named": true
3956
3960
  },
3961
+ {
3962
+ "type": "marker_annotation",
3963
+ "named": true
3964
+ },
3957
3965
  {
3958
3966
  "type": "underscore_pattern",
3959
3967
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -14,7 +14,7 @@
14
14
  }
15
15
  ],
16
16
  "metadata": {
17
- "version": "5.0.0",
17
+ "version": "6.0.1",
18
18
  "license": "MIT",
19
19
  "description": "Java grammar for tree-sitter",
20
20
  "authors": [