@willbooster/tree-sitter-kotlin 1.5.9 → 1.6.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/grammar.js CHANGED
@@ -68,6 +68,11 @@ module.exports = grammar({
68
68
  [$.visibility_modifier, $._reserved_identifier],
69
69
  [$.member_modifier, $._reserved_identifier],
70
70
 
71
+ [$.context_parameters, $._reserved_identifier],
72
+ [$.modifiers, $.function_type],
73
+ [$.secondary_constructor, $._reserved_identifier],
74
+ [$.enum_entry, $.modifiers],
75
+ [$.modifiers, $.anonymous_function],
71
76
  [$.qualified_identifier],
72
77
  [$.constructor_invocation, $._unescaped_annotation],
73
78
  [$.nullable_type],
@@ -385,6 +390,8 @@ module.exports = grammar({
385
390
  class_member_declaration: ($) =>
386
391
  choice($.declaration, $.companion_object, $.anonymous_initializer, $.secondary_constructor),
387
392
 
393
+ _annotations: ($) => repeat1($.annotation),
394
+
388
395
  enum_class_body: ($) =>
389
396
  seq(
390
397
  '{',
@@ -393,7 +400,15 @@ module.exports = grammar({
393
400
  '}'
394
401
  ),
395
402
 
396
- enum_entry: ($) => seq(optional($.modifiers), $.identifier, optional($.value_arguments), optional($.class_body)),
403
+ // Only annotations can modify an enum entry, and with the full modifier list a `context` after an annotation would
404
+ // start a context parameter list instead of naming the entry.
405
+ enum_entry: ($) =>
406
+ seq(
407
+ optional(alias($._annotations, $.modifiers)),
408
+ $._identifier,
409
+ optional($.value_arguments),
410
+ optional($.class_body)
411
+ ),
397
412
 
398
413
  value_arguments: ($) => seq('(', optionalCommaSep1($.value_argument), ')'),
399
414
 
@@ -421,7 +436,8 @@ module.exports = grammar({
421
436
  $.visibility_modifier,
422
437
  $.inheritance_modifier,
423
438
  $.parameter_modifier,
424
- $.platform_modifier
439
+ $.platform_modifier,
440
+ $.context_parameters
425
441
  )
426
442
  )
427
443
  )
@@ -481,7 +497,24 @@ module.exports = grammar({
481
497
  type_projection: ($) => choice(seq(repeat($.variance_modifier), $.type), '*'),
482
498
 
483
499
  function_type: ($) =>
484
- seq(optional($.type_modifiers), optional(seq($._receiver_type, '.')), $.function_type_parameters, '->', $.type),
500
+ seq(
501
+ optional($.type_modifiers),
502
+ optional($.context_parameters),
503
+ optional(seq($._receiver_type, '.')),
504
+ $.function_type_parameters,
505
+ '->',
506
+ $.type
507
+ ),
508
+
509
+ // Context parameters (`context(scope: Scope)`, Kotlin 2.2) and the older context receivers (`context(Scope)`).
510
+ context_parameters: ($) =>
511
+ seq(
512
+ 'context',
513
+ '(',
514
+ commaSep1(choice(seq(optional($.parameter_modifiers), $.parameter), $.type)),
515
+ optional(','),
516
+ ')'
517
+ ),
485
518
 
486
519
  function_type_parameters: ($) => seq('(', optionalCommaSep1(choice($.parameter, $.type)), ')'),
487
520
 
@@ -625,6 +658,7 @@ module.exports = grammar({
625
658
  anonymous_function: ($) =>
626
659
  prec.right(
627
660
  seq(
661
+ optional($.context_parameters),
628
662
  'fun',
629
663
  optional(seq($.type, '.')),
630
664
  $.function_value_parameters,
@@ -861,7 +895,8 @@ module.exports = grammar({
861
895
  'set',
862
896
  'suspend',
863
897
  'tailrec',
864
- 'value'
898
+ 'value',
899
+ 'context'
865
900
  ),
866
901
  $.identifier
867
902
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-kotlin",
3
- "version": "1.5.9",
3
+ "version": "1.6.0",
4
4
  "description": "Kotlin grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -332,6 +332,10 @@
332
332
  "multiple": true,
333
333
  "required": true,
334
334
  "types": [
335
+ {
336
+ "type": "context_parameters",
337
+ "named": true
338
+ },
335
339
  {
336
340
  "type": "function_body",
337
341
  "named": true
@@ -870,6 +874,29 @@
870
874
  ]
871
875
  }
872
876
  },
877
+ {
878
+ "type": "context_parameters",
879
+ "named": true,
880
+ "fields": {},
881
+ "children": {
882
+ "multiple": true,
883
+ "required": true,
884
+ "types": [
885
+ {
886
+ "type": "parameter",
887
+ "named": true
888
+ },
889
+ {
890
+ "type": "parameter_modifiers",
891
+ "named": true
892
+ },
893
+ {
894
+ "type": "type",
895
+ "named": true
896
+ }
897
+ ]
898
+ }
899
+ },
873
900
  {
874
901
  "type": "continue_expression",
875
902
  "named": true,
@@ -1231,6 +1258,10 @@
1231
1258
  "multiple": true,
1232
1259
  "required": true,
1233
1260
  "types": [
1261
+ {
1262
+ "type": "context_parameters",
1263
+ "named": true
1264
+ },
1234
1265
  {
1235
1266
  "type": "function_type_parameters",
1236
1267
  "named": true
@@ -1598,6 +1629,10 @@
1598
1629
  "type": "class_modifier",
1599
1630
  "named": true
1600
1631
  },
1632
+ {
1633
+ "type": "context_parameters",
1634
+ "named": true
1635
+ },
1601
1636
  {
1602
1637
  "type": "function_modifier",
1603
1638
  "named": true
@@ -2966,6 +3001,10 @@
2966
3001
  "type": "constructor",
2967
3002
  "named": false
2968
3003
  },
3004
+ {
3005
+ "type": "context",
3006
+ "named": false
3007
+ },
2969
3008
  {
2970
3009
  "type": "continue",
2971
3010
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
  ],
15
15
  "metadata": {
16
- "version": "1.5.9",
16
+ "version": "1.6.0",
17
17
  "license": "MIT",
18
18
  "description": "Kotlin grammar for tree-sitter",
19
19
  "authors": [