@willbooster/tree-sitter-kotlin 1.3.0 → 1.3.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/grammar.js CHANGED
@@ -41,6 +41,11 @@ module.exports = grammar({
41
41
  [$.annotated_expression, $.type_modifiers],
42
42
  [$.annotated_expression, $.type_modifiers, $.when_subject],
43
43
  [$.annotated_expression, $.type_modifiers, $.modifiers],
44
+ [$.variable_declaration, $._loop_prefix, $.modifiers, $.type_modifiers, $.annotated_expression],
45
+ [$._loop_prefix, $.annotated_expression],
46
+ [$._loop_prefix, $.modifiers, $.type_modifiers, $.annotated_expression],
47
+ [$._loop_prefix, $.labeled_expression],
48
+ [$._loop_prefix, $.type_modifiers, $.annotated_expression],
44
49
  [$.parameter_modifiers, $.type_modifiers],
45
50
  [$.function_modifier, $.type_modifiers],
46
51
  [$.function_modifier, $._reserved_identifier],
@@ -84,7 +89,7 @@ module.exports = grammar({
84
89
  '$',
85
90
  ],
86
91
 
87
- inline: ($) => [$._statements, $._identifier],
92
+ inline: ($) => [$._statements, $._identifier, $._control_structure_body],
88
93
 
89
94
  precedences: ($) => [
90
95
  [$.block, $.lambda_literal],
@@ -286,7 +291,7 @@ module.exports = grammar({
286
291
  for_statement: ($) =>
287
292
  prec.right(
288
293
  seq(
289
- optional($.label),
294
+ optional($._loop_prefix),
290
295
  'for',
291
296
  '(',
292
297
  repeat($.annotation),
@@ -294,28 +299,28 @@ module.exports = grammar({
294
299
  'in',
295
300
  $.expression,
296
301
  ')',
297
- optional(field('body', choice($.block, $.statement)))
302
+ optional(field('body', $._control_structure_body))
298
303
  )
299
304
  ),
300
305
 
301
306
  while_statement: ($) =>
302
307
  prec.right(
303
308
  seq(
304
- optional($.label),
309
+ optional($._loop_prefix),
305
310
  'while',
306
311
  '(',
307
312
  field('condition', $.expression),
308
313
  ')',
309
- optional(choice(field('body', choice($.block, $.statement)), ';'))
314
+ optional(choice(field('body', $._control_structure_body), ';'))
310
315
  )
311
316
  ),
312
317
 
313
318
  do_while_statement: ($) =>
314
319
  prec.right(
315
320
  seq(
316
- optional($.label),
321
+ optional($._loop_prefix),
317
322
  'do',
318
- optional(choice(field('body', choice($.block, $.statement)), ';')),
323
+ optional(choice(field('body', $._control_structure_body), ';')),
319
324
  'while',
320
325
  '(',
321
326
  field('condition', $.expression),
@@ -323,6 +328,8 @@ module.exports = grammar({
323
328
  )
324
329
  ),
325
330
 
331
+ _loop_prefix: ($) => prec.dynamic(1, repeat1(choice($.annotation, $.label))),
332
+
326
333
  class_body: ($) => seq('{', repeat(seq($.class_member_declaration, $._class_member_semi)), '}'),
327
334
 
328
335
  class_member_declaration: ($) =>
@@ -592,18 +599,23 @@ module.exports = grammar({
592
599
  field('condition', $.expression),
593
600
  ')',
594
601
  choice(
595
- field('consequence', choice($.block, $.expression, $.assignment)),
602
+ field('consequence', $._control_structure_body),
596
603
  ';',
597
604
  seq(
598
- optional(field('consequence', choice($.block, $.expression, $.assignment))),
605
+ optional(field('consequence', $._control_structure_body)),
599
606
  optional(';'),
600
607
  'else',
601
- choice(field('alternative', choice($.block, $.expression, $.assignment)), ';')
608
+ choice(field('alternative', $._control_structure_body), ';')
602
609
  )
603
610
  )
604
611
  )
605
612
  ),
606
613
 
614
+ // Unlike Kotlin's grammar, this excludes declarations, which the compiler rejects here anyway: allowing them
615
+ // lets declarations nest in every expression context and exceeds tree-sitter's limit of 65535 parse states.
616
+ _control_structure_body: ($) =>
617
+ choice($.block, $.expression, $.assignment, $.for_statement, $.while_statement, $.do_while_statement),
618
+
607
619
  parenthesized_expression: ($) => seq('(', $.expression, ')'),
608
620
 
609
621
  collection_literal: ($) => seq('[', commaSep1($.expression), optional(','), ']'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-kotlin",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Kotlin grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -936,12 +936,28 @@
936
936
  "multiple": false,
937
937
  "required": false,
938
938
  "types": [
939
+ {
940
+ "type": "assignment",
941
+ "named": true
942
+ },
939
943
  {
940
944
  "type": "block",
941
945
  "named": true
942
946
  },
943
947
  {
944
- "type": "statement",
948
+ "type": "do_while_statement",
949
+ "named": true
950
+ },
951
+ {
952
+ "type": "expression",
953
+ "named": true
954
+ },
955
+ {
956
+ "type": "for_statement",
957
+ "named": true
958
+ },
959
+ {
960
+ "type": "while_statement",
945
961
  "named": true
946
962
  }
947
963
  ]
@@ -958,9 +974,13 @@
958
974
  }
959
975
  },
960
976
  "children": {
961
- "multiple": false,
977
+ "multiple": true,
962
978
  "required": false,
963
979
  "types": [
980
+ {
981
+ "type": "annotation",
982
+ "named": true
983
+ },
964
984
  {
965
985
  "type": "label",
966
986
  "named": true
@@ -1075,12 +1095,28 @@
1075
1095
  "multiple": false,
1076
1096
  "required": false,
1077
1097
  "types": [
1098
+ {
1099
+ "type": "assignment",
1100
+ "named": true
1101
+ },
1078
1102
  {
1079
1103
  "type": "block",
1080
1104
  "named": true
1081
1105
  },
1082
1106
  {
1083
- "type": "statement",
1107
+ "type": "do_while_statement",
1108
+ "named": true
1109
+ },
1110
+ {
1111
+ "type": "expression",
1112
+ "named": true
1113
+ },
1114
+ {
1115
+ "type": "for_statement",
1116
+ "named": true
1117
+ },
1118
+ {
1119
+ "type": "while_statement",
1084
1120
  "named": true
1085
1121
  }
1086
1122
  ]
@@ -1291,9 +1327,21 @@
1291
1327
  "type": "block",
1292
1328
  "named": true
1293
1329
  },
1330
+ {
1331
+ "type": "do_while_statement",
1332
+ "named": true
1333
+ },
1294
1334
  {
1295
1335
  "type": "expression",
1296
1336
  "named": true
1337
+ },
1338
+ {
1339
+ "type": "for_statement",
1340
+ "named": true
1341
+ },
1342
+ {
1343
+ "type": "while_statement",
1344
+ "named": true
1297
1345
  }
1298
1346
  ]
1299
1347
  },
@@ -1319,9 +1367,21 @@
1319
1367
  "type": "block",
1320
1368
  "named": true
1321
1369
  },
1370
+ {
1371
+ "type": "do_while_statement",
1372
+ "named": true
1373
+ },
1322
1374
  {
1323
1375
  "type": "expression",
1324
1376
  "named": true
1377
+ },
1378
+ {
1379
+ "type": "for_statement",
1380
+ "named": true
1381
+ },
1382
+ {
1383
+ "type": "while_statement",
1384
+ "named": true
1325
1385
  }
1326
1386
  ]
1327
1387
  }
@@ -2601,12 +2661,28 @@
2601
2661
  "multiple": false,
2602
2662
  "required": false,
2603
2663
  "types": [
2664
+ {
2665
+ "type": "assignment",
2666
+ "named": true
2667
+ },
2604
2668
  {
2605
2669
  "type": "block",
2606
2670
  "named": true
2607
2671
  },
2608
2672
  {
2609
- "type": "statement",
2673
+ "type": "do_while_statement",
2674
+ "named": true
2675
+ },
2676
+ {
2677
+ "type": "expression",
2678
+ "named": true
2679
+ },
2680
+ {
2681
+ "type": "for_statement",
2682
+ "named": true
2683
+ },
2684
+ {
2685
+ "type": "while_statement",
2610
2686
  "named": true
2611
2687
  }
2612
2688
  ]
@@ -2623,9 +2699,13 @@
2623
2699
  }
2624
2700
  },
2625
2701
  "children": {
2626
- "multiple": false,
2702
+ "multiple": true,
2627
2703
  "required": false,
2628
2704
  "types": [
2705
+ {
2706
+ "type": "annotation",
2707
+ "named": true
2708
+ },
2629
2709
  {
2630
2710
  "type": "label",
2631
2711
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
  ],
15
15
  "metadata": {
16
- "version": "1.3.0",
16
+ "version": "1.3.2",
17
17
  "license": "MIT",
18
18
  "description": "Kotlin grammar for tree-sitter",
19
19
  "authors": [