@willbooster/tree-sitter-kotlin 1.7.1 → 1.7.3

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/grammar.js CHANGED
@@ -14,8 +14,9 @@ const PREC = {
14
14
  ADD: 10,
15
15
  MULTIPLY: 11,
16
16
  AS: 12,
17
- CALL: 13,
18
- UNARY: 14,
17
+ PREFIX: 13,
18
+ CALL: 14,
19
+ POSTFIX: 14,
19
20
  };
20
21
 
21
22
  // oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
@@ -27,6 +28,7 @@ module.exports = grammar({
27
28
  [$.class_body, $.enum_class_body],
28
29
 
29
30
  [$.binary_expression, $.call_expression],
31
+ [$.unary_expression, $.binary_expression, $.call_expression],
30
32
  [$.binary_expression, $.in_expression, $.call_expression],
31
33
  [$.binary_expression, $.infix_expression, $.call_expression],
32
34
  [$.binary_expression, $.range_expression, $.call_expression],
@@ -88,6 +90,8 @@ module.exports = grammar({
88
90
  externals: ($) => [
89
91
  $._semi,
90
92
  $._class_member_semi,
93
+ // Unlike properties, these declarations can end before another member on the same line.
94
+ $._same_line_member_end,
91
95
  $.block_comment,
92
96
  // also lexed by the scanner, since the generated lexer stops at a NUL character
93
97
  $.line_comment,
@@ -127,6 +131,8 @@ module.exports = grammar({
127
131
  // never scanned: see `_template_name`
128
132
  $._keyword_reference_end,
129
133
  'where',
134
+ $._separated_member_start,
135
+ $._unseparated_member_start,
130
136
  ],
131
137
 
132
138
  inline: ($) => [$._statements, $._identifier, $._control_structure_body],
@@ -206,7 +212,8 @@ module.exports = grammar({
206
212
  prec.right(
207
213
  seq(
208
214
  optional($.modifiers),
209
- choice('class', seq(optional('fun'), 'interface')),
215
+ choice('class', seq(optional(seq('fun', optional($._unseparated_member_start))), 'interface')),
216
+ optional($._unseparated_member_start),
210
217
  field('name', $.identifier),
211
218
  optional($.type_parameters),
212
219
  optional(seq(optional($._primary_constructor_position), $.primary_constructor)),
@@ -221,6 +228,7 @@ module.exports = grammar({
221
228
  seq(
222
229
  optional($.modifiers),
223
230
  'object',
231
+ optional($._unseparated_member_start),
224
232
  field('name', $.identifier),
225
233
  optional(seq(':', $.delegation_specifiers)),
226
234
  optional($.class_body)
@@ -232,6 +240,7 @@ module.exports = grammar({
232
240
  seq(
233
241
  optional($.modifiers),
234
242
  choice('val', 'var'),
243
+ optional($._separated_member_start),
235
244
  optional($.type_parameters),
236
245
  optional(seq($._receiver_type, optional('.'))),
237
246
  choice($.variable_declaration, $.multi_variable_declaration),
@@ -244,7 +253,15 @@ module.exports = grammar({
244
253
 
245
254
  type_alias: ($) =>
246
255
  prec.right(
247
- seq(optional($.modifiers), 'typealias', field('type', $.identifier), optional($.type_parameters), '=', $.type)
256
+ seq(
257
+ optional($.modifiers),
258
+ 'typealias',
259
+ optional($._separated_member_start),
260
+ field('type', $.identifier),
261
+ optional($.type_parameters),
262
+ '=',
263
+ $.type
264
+ )
248
265
  ),
249
266
 
250
267
  companion_object: ($) =>
@@ -252,17 +269,19 @@ module.exports = grammar({
252
269
  optional($.modifiers),
253
270
  'companion',
254
271
  'object',
272
+ optional($._unseparated_member_start),
255
273
  optional(field('name', $.identifier)),
256
274
  optional(seq(':', $.delegation_specifiers)),
257
275
  optional($.class_body)
258
276
  ),
259
277
 
260
- anonymous_initializer: ($) => seq('init', $.block),
278
+ anonymous_initializer: ($) => seq('init', optional($._unseparated_member_start), $.block),
261
279
 
262
280
  secondary_constructor: ($) =>
263
281
  seq(
264
282
  optional($.modifiers),
265
283
  'constructor',
284
+ optional($._unseparated_member_start),
266
285
  $.function_value_parameters,
267
286
  optional(seq(':', $.constructor_delegation_call)),
268
287
  optional($.block)
@@ -300,6 +319,7 @@ module.exports = grammar({
300
319
  seq(
301
320
  optional($.modifiers),
302
321
  'fun',
322
+ optional($._unseparated_member_start),
303
323
  optional($.type_parameters),
304
324
  optional(seq($._receiver_type, optional('.'))),
305
325
  field('name', $._identifier),
@@ -406,8 +426,10 @@ module.exports = grammar({
406
426
 
407
427
  _loop_prefix: ($) => prec.dynamic(1, repeat1(choice($.annotation, $.label))),
408
428
 
409
- class_body: ($) =>
410
- seq('{', $._open_members, repeat(seq($.class_member_declaration, $._class_member_semi)), '}', $._close_braces),
429
+ class_body: ($) => seq('{', $._open_members, repeat($._class_member_with_separator), '}', $._close_braces),
430
+
431
+ _class_member_with_separator: ($) =>
432
+ seq($.class_member_declaration, optional($._same_line_member_end), $._class_member_semi),
411
433
 
412
434
  class_member_declaration: ($) =>
413
435
  choice($.declaration, $.companion_object, $.anonymous_initializer, $.secondary_constructor),
@@ -419,7 +441,7 @@ module.exports = grammar({
419
441
  '{',
420
442
  $._open_members,
421
443
  optionalCommaSep1($.enum_entry),
422
- optional(seq(';', repeat(seq($.class_member_declaration, $._class_member_semi)))),
444
+ optional(seq(';', repeat($._class_member_with_separator))),
423
445
  '}',
424
446
  $._close_braces
425
447
  ),
@@ -617,12 +639,12 @@ module.exports = grammar({
617
639
  ),
618
640
 
619
641
  unary_expression: ($) =>
620
- prec.left(
621
- PREC.UNARY,
622
- choice(
623
- seq(field('operator', choice('++', '--', '+', '-', '!')), field('argument', $.expression)),
624
- seq(field('argument', $.expression), field('operator', choice('++', '--', '!!')))
625
- )
642
+ choice(
643
+ prec.right(
644
+ PREC.PREFIX,
645
+ seq(field('operator', choice('++', '--', '+', '-', '!')), field('argument', $.expression))
646
+ ),
647
+ prec.left(PREC.POSTFIX, seq(field('argument', $.expression), field('operator', choice('++', '--', '!!'))))
626
648
  ),
627
649
 
628
650
  annotated_expression: ($) => seq($.annotation, $.expression),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-kotlin",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
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.7.1",
16
+ "version": "1.7.3",
17
17
  "license": "MIT",
18
18
  "description": "Kotlin grammar for tree-sitter",
19
19
  "authors": [