Skip to content

Commit d186e12

Browse files
per-steinarPer-Steinar Karlsen
andauthored
Improved grammar for kotlin based on official documentation (#3407)
Signed-off-by: Per-Steinar Karlsen <[email protected]> Co-authored-by: Per-Steinar Karlsen <[email protected]>
1 parent 5e4d93a commit d186e12

File tree

1 file changed

+140
-10
lines changed

1 file changed

+140
-10
lines changed

language-support/kotlin/kotlin.tmLanguage.json

Lines changed: 140 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"information_for_contributors": [
3-
"This file has been copied from https://github.com/eclipse/buildship/blob/b848d9a08283b68860671a73ceec3c99bdab27c2/org.eclipse.buildship.kotlindsl.provider/kotlin.tmLanguage.json"
4-
],
3+
"This file has been copied from https://github.com/eclipse/buildship/blob/b848d9a08283b68860671a73ceec3c99bdab27c2/org.eclipse.buildship.kotlindsl.provider/kotlin.tmLanguage.json"
4+
],
55
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
66
"name": "Kotlin",
77
"scopeName": "source.kotlin",
@@ -21,10 +21,13 @@
2121
],
2222
"repository": {
2323
"import": {
24-
"begin": "\\b(import)\\b\\s*",
24+
"begin": "\\b(import)\\b\\s?([\\w+.]*\\w+)?\\s*",
2525
"beginCaptures": {
2626
"1": {
2727
"name": "storage.type.import.kotlin"
28+
},
29+
"2": {
30+
"name": "storage.modifier.import.kotlin"
2831
}
2932
},
3033
"end": ";|$",
@@ -91,6 +94,15 @@
9194
{
9295
"include": "#variable-declaration"
9396
},
97+
{
98+
"include": "#constant-declaration"
99+
},
100+
{
101+
"include": "#variable"
102+
},
103+
{
104+
"include": "#object"
105+
},
94106
{
95107
"include": "#type-constraint"
96108
},
@@ -100,6 +112,9 @@
100112
{
101113
"include": "#function-call"
102114
},
115+
{
116+
"include": "#property.reference"
117+
},
103118
{
104119
"include": "#method-reference"
105120
},
@@ -141,6 +156,18 @@
141156
},
142157
{
143158
"include": "#null-literal"
159+
},
160+
{
161+
"match": ",",
162+
"name": "punctuation.separator.delimiter.kotlin"
163+
},
164+
{
165+
"match": "\\.",
166+
"name": "punctuation.separator.period.kotlin"
167+
},
168+
{
169+
"match": "\\?\\.",
170+
"name": "punctuation.accessor.optional.kotlin"
144171
}
145172
]
146173
},
@@ -234,6 +261,9 @@
234261
},
235262
{
236263
"include": "#control-keywords"
264+
},
265+
{
266+
"include": "#map-keywords"
237267
}
238268
]
239269
},
@@ -257,6 +287,10 @@
257287
"match": "\\b(if|else|while|do|when|try|throw|break|continue|return|for)\\b",
258288
"name": "keyword.control.kotlin"
259289
},
290+
"map-keywords": {
291+
"match": "\\b(to)\\b",
292+
"name": "keyword.map.kotlin"
293+
},
260294
"annotation-simple": {
261295
"match": "(?<!\\w)@[\\w\\.]+\\b(?!:)",
262296
"name": "entity.name.type.annotation.kotlin"
@@ -341,8 +375,8 @@
341375
}
342376
},
343377
"function-declaration": {
344-
"match": "\\b(fun)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?:(\\w+)\\.)?(\\b\\w+\\b|`[^`]+`)",
345-
"captures": {
378+
"begin": "\\b(fun)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?:(\\w+)\\.)?(\\b\\w+\\b|`[^`]+`)\\(",
379+
"beginCaptures": {
346380
"1": {
347381
"name": "storage.type.function.kotlin"
348382
},
@@ -359,10 +393,41 @@
359393
"5": {
360394
"name": "entity.name.function.declaration.kotlin"
361395
}
396+
},
397+
"end": "\\)",
398+
"endCaptures": {
399+
"1": {
400+
"name": "keyword.operator.assignment.type.kotlin"
401+
}
402+
},
403+
"patterns": [
404+
{
405+
"include": "#parameter-declaration"
406+
}
407+
]
408+
},
409+
"parameter-declaration": {
410+
"match": "\\b(\\w+)\\s*(:)\\s*(\\w+)(\\?)?(,)?",
411+
"captures": {
412+
"1": {
413+
"name": "variable.parameter.kotlin"
414+
},
415+
"2": {
416+
"name": "keyword.operator.assignment.type.kotlin"
417+
},
418+
"3": {
419+
"name": "entity.name.type.kotlin"
420+
},
421+
"4": {
422+
"name": "keyword.operator.optional"
423+
},
424+
"5": {
425+
"name": "punctuation.separator.delimiter.kotlin"
426+
}
362427
}
363428
},
364429
"variable-declaration": {
365-
"match": "\\b(val|var)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?",
430+
"match": "\\b(var)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?",
366431
"captures": {
367432
"1": {
368433
"name": "storage.type.variable.kotlin"
@@ -376,11 +441,52 @@
376441
}
377442
}
378443
},
444+
"constant-declaration": {
445+
"match": "\\b(val)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?",
446+
"captures": {
447+
"1": {
448+
"name": "storage.type.variable.readonly.kotlin"
449+
},
450+
"2": {
451+
"patterns": [
452+
{
453+
"include": "#type-parameter"
454+
}
455+
]
456+
}
457+
}
458+
},
459+
"variable" : {
460+
"match": "\\b(\\w+)(?=\\s*[:=])",
461+
"captures": {
462+
"1": {
463+
"name": "variable.other.definition.kotlin"
464+
}
465+
}
466+
},
467+
"object" : {
468+
"match": "\\b(\\w+)(?=\\.)",
469+
"captures": {
470+
"1": {
471+
"name": "variable.other.object.kotlin"
472+
}
473+
}
474+
},
379475
"type-parameter": {
380476
"patterns": [
381477
{
382-
"match": "\\b\\w+\\b",
383-
"name": "entity.name.type.kotlin"
478+
"match": "(:)?\\s*(\\b\\w+\\b)(\\?)?",
479+
"captures": {
480+
"1": {
481+
"name": "keyword.operator.assignment.kotlin"
482+
},
483+
"2": {
484+
"name": "entity.name.type.kotlin"
485+
},
486+
"3": {
487+
"name": "keyword.operator.optional"
488+
}
489+
}
384490
},
385491
{
386492
"match": "\\b(in|out)\\b",
@@ -401,12 +507,18 @@
401507
}
402508
},
403509
"function-call": {
404-
"match": "\\??\\.?(\\b\\w+\\b|`[^`]+`)\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?=[({])",
510+
"match": "(?:(\\?\\.)|(\\.))?(\\b\\w+\\b|`[^`]+`)\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?=[({])",
405511
"captures": {
406512
"1": {
407-
"name": "entity.name.function.call.kotlin"
513+
"name": "punctuation.accessor.optional.kotlin"
408514
},
409515
"2": {
516+
"name": "punctuation.separator.period.kotlin"
517+
},
518+
"3": {
519+
"name": "entity.name.function.call.kotlin"
520+
},
521+
"4": {
410522
"patterns": [
411523
{
412524
"include": "#type-parameter"
@@ -415,6 +527,20 @@
415527
}
416528
}
417529
},
530+
"property.reference": {
531+
"match": "(?:(\\?\\.)|(\\.))(\\w+)\\b",
532+
"captures": {
533+
"1": {
534+
"name": "punctuation.accessor.optional.kotlin"
535+
},
536+
"2": {
537+
"name": "punctuation.separator.period.kotlin"
538+
},
539+
"3": {
540+
"name": "variable.other.property.kotlin"
541+
}
542+
}
543+
},
418544
"method-reference": {
419545
"match": "\\??::(\\b\\w+\\b|`[^`]+`)",
420546
"captures": {
@@ -537,6 +663,10 @@
537663
"match": "(===?|\\!==?|<=|>=|<|>)",
538664
"name": "keyword.operator.comparison.kotlin"
539665
},
666+
{
667+
"match": "(\\?:)",
668+
"name": "keyword.operator.elvis.kotlin"
669+
},
540670
{
541671
"match": "([+*/%-]=)",
542672
"name": "keyword.operator.assignment.arithmetic.kotlin"

0 commit comments

Comments
 (0)