@willbooster/tree-sitter-kotlin 1.4.0 → 1.4.2

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
@@ -49,6 +49,8 @@ module.exports = grammar({
49
49
  [$.parameter_modifiers, $.type_modifiers],
50
50
  [$.function_modifier, $.type_modifiers],
51
51
  [$.function_modifier, $._reserved_identifier],
52
+ [$.function_modifier, $.type_modifiers, $._reserved_identifier],
53
+ [$.type_modifiers, $._reserved_identifier],
52
54
  [$.variable_declaration, $.type_modifiers],
53
55
  [$.variable_declaration, $.type_modifiers, $.modifiers, $.annotated_expression],
54
56
  [$.variable_declaration, $.type_modifiers, $.annotated_expression],
@@ -61,6 +63,9 @@ module.exports = grammar({
61
63
  [$.class_modifier, $._reserved_identifier],
62
64
  [$.platform_modifier, $._reserved_identifier],
63
65
  [$.property_modifier, $._reserved_identifier],
66
+ [$.inheritance_modifier, $._reserved_identifier],
67
+ [$.visibility_modifier, $._reserved_identifier],
68
+ [$.member_modifier, $._reserved_identifier],
64
69
 
65
70
  [$.explicit_delegation, $.expression],
66
71
  [$.qualified_identifier],
@@ -87,6 +92,10 @@ module.exports = grammar({
87
92
  'set',
88
93
  // used to check if we can parse a comment
89
94
  '$',
95
+ // used to check if a modifier alone on its line belongs to a declaration on the next line
96
+ 'val',
97
+ // never scanned: it tells the scanner where a primary constructor may start
98
+ $._primary_constructor_position,
90
99
  ],
91
100
 
92
101
  inline: ($) => [$._statements, $._identifier, $._control_structure_body],
@@ -136,7 +145,7 @@ module.exports = grammar({
136
145
  choice('class', seq(optional('fun'), 'interface')),
137
146
  field('name', $.identifier),
138
147
  optional($.type_parameters),
139
- optional($.primary_constructor),
148
+ optional(seq(optional($._primary_constructor_position), $.primary_constructor)),
140
149
  optional(seq(':', $.delegation_specifiers)),
141
150
  optional($.type_constraints),
142
151
  optional(choice($.class_body, $.enum_class_body))
@@ -371,17 +380,22 @@ module.exports = grammar({
371
380
  )
372
381
  ),
373
382
 
374
- class_modifier: () => choice('enum', 'sealed', 'annotation', 'data', 'inner', 'value'),
383
+ // A modifier keyword that `_reserved_identifier` also accepts as a name makes `@A\nsealed interface B` parse as
384
+ // an infix call as well, since `interface` lexes as an identifier where no keyword is valid, so the modifier
385
+ // reading takes dynamic precedence. The name takes none: it would outweigh the modifiers again wherever a
386
+ // reading has more names, such as `get` calls in a class body misread as a trailing lambda.
387
+ class_modifier: () => prec.dynamic(1, choice('enum', 'sealed', 'annotation', 'data', 'inner', 'value')),
375
388
 
376
- function_modifier: () => prec.right(choice('tailrec', 'operator', 'infix', 'inline', 'external', 'suspend')),
389
+ function_modifier: () =>
390
+ prec.dynamic(1, prec.right(choice('tailrec', 'operator', 'infix', 'inline', 'external', 'suspend'))),
377
391
 
378
- property_modifier: () => 'const',
392
+ property_modifier: () => prec.dynamic(1, 'const'),
379
393
 
380
- visibility_modifier: () => choice('public', 'private', 'protected', 'internal'),
394
+ visibility_modifier: () => prec.dynamic(1, choice('public', 'private', 'protected', 'internal')),
381
395
 
382
- inheritance_modifier: () => choice('abstract', 'final', 'open'),
396
+ inheritance_modifier: () => prec.dynamic(1, choice('abstract', 'final', 'open')),
383
397
 
384
- member_modifier: () => choice('override', 'lateinit'),
398
+ member_modifier: () => prec.dynamic(1, choice('override', 'lateinit')),
385
399
 
386
400
  parameter_modifiers: ($) => repeat1(choice($.annotation, $.parameter_modifier)),
387
401
 
@@ -389,7 +403,7 @@ module.exports = grammar({
389
403
 
390
404
  reification_modifier: () => 'reified',
391
405
 
392
- platform_modifier: () => choice('expect', 'actual'),
406
+ platform_modifier: () => prec.dynamic(1, choice('expect', 'actual')),
393
407
 
394
408
  type_modifiers: ($) => prec.right(repeat1(choice($.annotation, 'suspend'))),
395
409
 
@@ -746,25 +760,37 @@ module.exports = grammar({
746
760
  identifier: () => token(choice(/[\p{L}_][\p{L}_\p{Nd}]*/u, /`[^\r\n`]+`/)),
747
761
 
748
762
  _reserved_identifier: ($) =>
749
- prec.dynamic(
750
- 1,
751
- alias(
752
- choice(
753
- 'actual',
754
- 'annotation',
755
- 'constructor',
756
- 'const',
757
- 'data',
758
- 'enum',
759
- 'expect',
760
- 'inner',
761
- 'get',
762
- 'set',
763
- 'operator',
764
- 'value'
765
- ),
766
- $.identifier
767
- )
763
+ alias(
764
+ choice(
765
+ 'abstract',
766
+ 'actual',
767
+ 'annotation',
768
+ 'const',
769
+ 'constructor',
770
+ 'data',
771
+ 'enum',
772
+ 'expect',
773
+ 'external',
774
+ 'final',
775
+ 'get',
776
+ 'infix',
777
+ 'inline',
778
+ 'inner',
779
+ 'internal',
780
+ 'lateinit',
781
+ 'open',
782
+ 'operator',
783
+ 'override',
784
+ 'private',
785
+ 'protected',
786
+ 'public',
787
+ 'sealed',
788
+ 'set',
789
+ 'suspend',
790
+ 'tailrec',
791
+ 'value'
792
+ ),
793
+ $.identifier
768
794
  ),
769
795
 
770
796
  shebang: () => /#!.*/,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-kotlin",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Kotlin grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
package/tree-sitter.json CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
  ],
15
15
  "metadata": {
16
- "version": "1.4.0",
16
+ "version": "1.4.2",
17
17
  "license": "MIT",
18
18
  "description": "Kotlin grammar for tree-sitter",
19
19
  "authors": [