@willbooster/tree-sitter-kotlin 17.0.0 → 19.0.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 +51 -9
- package/package.json +1 -1
- package/tree-sitter-kotlin.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -5,7 +5,7 @@ const { grammar, alias, choice, field, optional, prec, repeat, repeat1, seq, sym
|
|
|
5
5
|
/** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
|
|
6
6
|
|
|
7
7
|
/** @typedef {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} RuleOrLiteral */
|
|
8
|
-
/** @typedef {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'value_argument'>} GrammarSymbols */
|
|
8
|
+
/** @typedef {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'value_argument' | 'expression' | '_when_condition' | 'block' | 'statement'>} GrammarSymbols */
|
|
9
9
|
|
|
10
10
|
const PREC = {
|
|
11
11
|
SPREAD: 1,
|
|
@@ -889,18 +889,37 @@ module.exports = grammar({
|
|
|
889
889
|
collection_literal: ($) => seq('[', optionalCommaSep1($.expression), ']'),
|
|
890
890
|
|
|
891
891
|
when_expression: ($) =>
|
|
892
|
-
seq(
|
|
892
|
+
seq(
|
|
893
|
+
'when',
|
|
894
|
+
optional($.when_subject),
|
|
895
|
+
'{',
|
|
896
|
+
sym('_open_entries'),
|
|
897
|
+
repeat(choice($.when_entry, seq(alias($._unseparated_when_entry, $.when_entry), $._else_when_entries))),
|
|
898
|
+
'}',
|
|
899
|
+
sym('_close_braces')
|
|
900
|
+
),
|
|
901
|
+
|
|
902
|
+
// The scanner puts no separator before an `else` other than `else ->`, since it cannot tell whether an `if` at the
|
|
903
|
+
// end of a statement body takes it. As in Kotlin, such an `if` takes it, `if_expression` being right-associative, and
|
|
904
|
+
// otherwise the `else` starts the next entry, so a statement body needs no separator before an entry that starts so.
|
|
905
|
+
_unseparated_when_entry: ($) => whenEntry($, whenEntryHead($), field('body', $.statement)),
|
|
906
|
+
|
|
907
|
+
// Unlike `repeat`, this right recursion lets a separator follow every statement body that `else` may follow, so the
|
|
908
|
+
// parse states of those bodies merge with those of other statements instead of duplicating every expression state.
|
|
909
|
+
_else_when_entries: ($) =>
|
|
910
|
+
choice(
|
|
911
|
+
alias($._else_when_entry, $.when_entry),
|
|
912
|
+
seq(alias($._unseparated_else_when_entry, $.when_entry), $._else_when_entries)
|
|
913
|
+
),
|
|
914
|
+
|
|
915
|
+
_unseparated_else_when_entry: ($) => whenEntry($, 'else', field('body', $.statement)),
|
|
916
|
+
|
|
917
|
+
_else_when_entry: ($) => whenEntry($, 'else', whenEntryBody($)),
|
|
893
918
|
|
|
894
919
|
when_subject: ($) =>
|
|
895
920
|
seq('(', optional(seq(repeat($.annotation), 'val', $.variable_declaration, '=')), $.expression, ')'),
|
|
896
921
|
|
|
897
|
-
when_entry: ($) =>
|
|
898
|
-
seq(
|
|
899
|
-
choice(seq(commaSep1(field('condition', $._when_condition)), optional(',')), 'else'),
|
|
900
|
-
optional(seq('if', field('guard', $.expression))),
|
|
901
|
-
'->',
|
|
902
|
-
choice(seq(field('body', $.block), optional(sym('_semi'))), seq(field('body', $.statement), sym('_semi')))
|
|
903
|
-
),
|
|
922
|
+
when_entry: ($) => whenEntry($, whenEntryHead($), whenEntryBody($)),
|
|
904
923
|
|
|
905
924
|
_when_condition: ($) => choice($.expression, $.range_test, $.type_test),
|
|
906
925
|
|
|
@@ -1156,3 +1175,26 @@ function optionalCommaSep1(rule) {
|
|
|
1156
1175
|
function valueArguments($, open) {
|
|
1157
1176
|
return seq(open, optionalCommaSep1($.value_argument), ')');
|
|
1158
1177
|
}
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* @param {GrammarSymbols} $
|
|
1181
|
+
* @param {RuleOrLiteral} head
|
|
1182
|
+
* @param {RuleOrLiteral} body
|
|
1183
|
+
*/
|
|
1184
|
+
function whenEntry($, head, body) {
|
|
1185
|
+
return seq(head, optional(seq('if', field('guard', $.expression))), '->', body);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
* @param {GrammarSymbols} $
|
|
1190
|
+
*/
|
|
1191
|
+
function whenEntryHead($) {
|
|
1192
|
+
return choice(seq(commaSep1(field('condition', $._when_condition)), optional(',')), 'else');
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* @param {GrammarSymbols} $
|
|
1197
|
+
*/
|
|
1198
|
+
function whenEntryBody($) {
|
|
1199
|
+
return choice(seq(field('body', $.block), optional(sym('_semi'))), seq(field('body', $.statement), sym('_semi')));
|
|
1200
|
+
}
|
package/package.json
CHANGED
package/tree-sitter-kotlin.wasm
CHANGED
|
Binary file
|