@willbooster/tree-sitter-kotlin 1.6.2 → 1.6.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
@@ -413,10 +413,7 @@ module.exports = grammar({
413
413
  optional($.class_body)
414
414
  ),
415
415
 
416
- // Whether a call takes a trailing lambda depends on the token after its arguments, which the lookahead of the
417
- // scanned `)` reaches, so an edit there makes incremental parsing reparse the call instead of reusing a call without
418
- // the lambda.
419
- value_arguments: ($) => seq('(', optionalCommaSep1($.value_argument), alias($._arguments_end, ')')),
416
+ value_arguments: ($) => valueArguments($, '('),
420
417
 
421
418
  value_argument: ($) => seq(optional(seq($._identifier, '=')), optional('*'), $.expression),
422
419
 
@@ -480,7 +477,15 @@ module.exports = grammar({
480
477
  use_site_target: () =>
481
478
  seq(choice('field', 'property', 'get', 'set', 'receiver', 'param', 'setparam', 'delegate'), ':'),
482
479
 
483
- _unescaped_annotation: ($) => choice($.constructor_invocation, $.type),
480
+ // As in Kotlin, a `(` right after an annotation's name always starts its arguments; lexing it as a separate immediate
481
+ // token keeps an annotated parenthesized expression from being read there. After whitespace, Kotlin's reading
482
+ // depends on the context, so both readings remain.
483
+ _unescaped_annotation: ($) =>
484
+ choice($.constructor_invocation, alias($._annotation_invocation, $.constructor_invocation), $.type),
485
+
486
+ _annotation_invocation: ($) => seq($.type, alias($._annotation_arguments, $.value_arguments)),
487
+
488
+ _annotation_arguments: ($) => valueArguments($, alias(token.immediate('('), '(')),
484
489
 
485
490
  type: ($) =>
486
491
  choice($.user_type, $.nullable_type, $.function_type, $.non_nullable_type, $.parenthesized_type, 'dynamic'),
@@ -964,3 +969,17 @@ function commaSep1(rule) {
964
969
  function optionalCommaSep1(rule) {
965
970
  return optional(seq(rule, repeat(seq(',', rule)), optional(',')));
966
971
  }
972
+
973
+ /**
974
+ * Creates the arguments of a call or an annotation. Whether a call takes a trailing lambda depends on the token after
975
+ * its arguments, which the lookahead of the scanned `)` reaches, so an edit there makes incremental parsing reparse the
976
+ * call instead of reusing a call without the lambda.
977
+ *
978
+ * @param {GrammarSymbols<string>} $
979
+ * @param {RuleOrLiteral} open
980
+ *
981
+ * @returns {SeqRule}
982
+ */
983
+ function valueArguments($, open) {
984
+ return seq(open, optionalCommaSep1($.value_argument), alias($._arguments_end, ')'));
985
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-kotlin",
3
- "version": "1.6.2",
3
+ "version": "1.6.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.6.2",
16
+ "version": "1.6.3",
17
17
  "license": "MIT",
18
18
  "description": "Kotlin grammar for tree-sitter",
19
19
  "authors": [