@willbooster/tree-sitter-kotlin 1.4.1 → 1.5.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/README.md CHANGED
@@ -60,12 +60,15 @@ parser.setLanguage(await Language.load(kotlin));
60
60
 
61
61
  The package also ships the node types in `src/node-types.json`.
62
62
 
63
- In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-kotlin):
63
+ In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-kotlin) and on
64
+ [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
65
+ fuzzed with (the grammar also loads in the upstream `tree-sitter` crate 0.27, whose error recovery never ends on some
66
+ malformed input):
64
67
 
65
68
  ```toml
66
69
  [dependencies]
67
- tree-sitter = "0.27"
68
- tree-sitter-kotlin = { package = "willbooster-tree-sitter-kotlin", version = "1.2" }
70
+ tree-sitter = { package = "willbooster-tree-sitter", version = "1" }
71
+ tree-sitter-kotlin = { package = "willbooster-tree-sitter-kotlin", version = "1" }
69
72
  ```
70
73
 
71
74
  ```rust
package/grammar.js CHANGED
@@ -86,6 +86,11 @@ module.exports = grammar({
86
86
  $._in,
87
87
  $._q_dot,
88
88
  $._multiline_string_content,
89
+ $._multi_dollar_string_start,
90
+ $._multi_dollar_multiline_string_start,
91
+ $._multi_dollar_string_content,
92
+ $._multi_dollar_interpolation_start,
93
+ $._multi_dollar_string_end,
89
94
  // used to check if a preceding annoation should not have an automatic _semi inserted
90
95
  'constructor',
91
96
  'get',
@@ -94,6 +99,8 @@ module.exports = grammar({
94
99
  '$',
95
100
  // used to check if a modifier alone on its line belongs to a declaration on the next line
96
101
  'val',
102
+ // never scanned: it tells the scanner where a primary constructor may start
103
+ $._primary_constructor_position,
97
104
  ],
98
105
 
99
106
  inline: ($) => [$._statements, $._identifier, $._control_structure_body],
@@ -143,7 +150,7 @@ module.exports = grammar({
143
150
  choice('class', seq(optional('fun'), 'interface')),
144
151
  field('name', $.identifier),
145
152
  optional($.type_parameters),
146
- optional($.primary_constructor),
153
+ optional(seq(optional($._primary_constructor_position), $.primary_constructor)),
147
154
  optional(seq(':', $.delegation_specifiers)),
148
155
  optional($.type_constraints),
149
156
  optional(choice($.class_body, $.enum_class_body))
@@ -681,26 +688,51 @@ module.exports = grammar({
681
688
  object_literal: ($) => seq('object', optional(seq(':', $.delegation_specifiers)), $.class_body),
682
689
 
683
690
  string_literal: ($) =>
684
- seq(
685
- '"',
686
- repeat(
687
- choice(
688
- alias(
689
- choice(token.immediate(prec(2, seq('\\', /[^bnrt'"\\$]/))), token.immediate(prec(1, /[^"\\$]+/)), '$'),
690
- $.string_content
691
- ),
692
- $.escape_sequence,
693
- $.interpolation
694
- )
691
+ choice(
692
+ seq(
693
+ '"',
694
+ repeat(
695
+ choice(
696
+ alias(
697
+ choice(token.immediate(prec(2, seq('\\', /[^bnrt'"\\$]/))), token.immediate(prec(1, /[^"\\$]+/)), '$'),
698
+ $.string_content
699
+ ),
700
+ $.escape_sequence,
701
+ $.interpolation
702
+ )
703
+ ),
704
+ '"'
695
705
  ),
696
- '"'
706
+ seq(
707
+ $._multi_dollar_string_start,
708
+ repeat(
709
+ choice(
710
+ alias($._multi_dollar_string_content, $.string_content),
711
+ $.escape_sequence,
712
+ alias($._multi_dollar_interpolation, $.interpolation)
713
+ )
714
+ ),
715
+ $._multi_dollar_string_end
716
+ )
697
717
  ),
698
718
 
699
719
  multiline_string_literal: ($) =>
700
- seq(
701
- '"""',
702
- repeat(choice(alias($._multiline_string_content, $.string_content), $.interpolation)),
703
- choice('"""', '""""')
720
+ choice(
721
+ seq(
722
+ '"""',
723
+ repeat(choice(alias($._multiline_string_content, $.string_content), $.interpolation)),
724
+ choice('"""', '""""')
725
+ ),
726
+ seq(
727
+ $._multi_dollar_multiline_string_start,
728
+ repeat(
729
+ choice(
730
+ alias($._multi_dollar_string_content, $.string_content),
731
+ alias($._multi_dollar_interpolation, $.interpolation)
732
+ )
733
+ ),
734
+ $._multi_dollar_string_end
735
+ )
704
736
  ),
705
737
 
706
738
  interpolation: ($) =>
@@ -710,6 +742,17 @@ module.exports = grammar({
710
742
  seq('${', $.expression, '}')
711
743
  ),
712
744
 
745
+ // In a string prefixed with n dollars (Kotlin 2.1), exactly n dollars start an interpolation; the scanner
746
+ // returns them as one token only where they do.
747
+ _multi_dollar_interpolation: ($) =>
748
+ seq(
749
+ $._multi_dollar_interpolation_start,
750
+ choice(
751
+ alias(token.immediate(prec(2, /[\p{L}_][\p{L}_\p{Nd}]*/u)), $.identifier),
752
+ seq(token.immediate('{'), $.expression, '}')
753
+ )
754
+ ),
755
+
713
756
  character_literal: ($) => seq("'", choice(token.immediate(prec(1, /[^'\\\r\n]/)), $.escape_sequence), "'"),
714
757
 
715
758
  escape_sequence: () => token.immediate(prec(1, seq('\\', choice(/[^xu0-7]/, /u[0-9a-fA-F]{4}/)))),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-kotlin",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Kotlin grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "build-wasm": "tree-sitter build --wasm",
25
- "build/ci": "tree-sitter generate && tree-sitter build --wasm",
25
+ "build/ci": "tree-sitter generate && script/generate-letter-ranges && tree-sitter build --wasm",
26
26
  "cleanup": "bun wb lint --fix --format",
27
27
  "format": "bun wb lint --format",
28
28
  "lint": "bun wb lint",
Binary file
package/tree-sitter.json CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
  ],
15
15
  "metadata": {
16
- "version": "1.4.1",
16
+ "version": "1.5.0",
17
17
  "license": "MIT",
18
18
  "description": "Kotlin grammar for tree-sitter",
19
19
  "authors": [