Skip to content

Commit

Permalink
Improved grammar for kotlin based on official documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Per-Steinar Karlsen <per-steinar.karlsen@skatteetaten.no>
  • Loading branch information
Per-Steinar Karlsen committed Nov 30, 2023
1 parent 1b1d323 commit c8338dc
Showing 1 changed file with 135 additions and 11 deletions.
146 changes: 135 additions & 11 deletions language-support/kotlin/kotlin.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"information_for_contributors": [
"This file has been copied from https://github.com/eclipse/buildship/blob/b848d9a08283b68860671a73ceec3c99bdab27c2/org.eclipse.buildship.kotlindsl.provider/kotlin.tmLanguage.json"
],
"This file has been copied from https://github.com/eclipse/buildship/blob/b848d9a08283b68860671a73ceec3c99bdab27c2/org.eclipse.buildship.kotlindsl.provider/kotlin.tmLanguage.json"
],
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Kotlin",
"scopeName": "source.kotlin",
Expand All @@ -21,10 +21,13 @@
],
"repository": {
"import": {
"begin": "\\b(import)\\b\\s*",
"begin": "\\b(import)\\b\\s?([\\w+.]*\\w+)?\\s*",
"beginCaptures": {
"1": {
"name": "storage.type.import.kotlin"
},
"2": {
"name": "storage.modifier.import.kotlin"
}
},
"end": ";|$",
Expand Down Expand Up @@ -91,6 +94,15 @@
{
"include": "#variable-declaration"
},
{
"include": "#constant-declaration"
},
{
"include": "#variable"
},
{
"include": "#object"
},
{
"include": "#type-constraint"
},
Expand All @@ -100,6 +112,9 @@
{
"include": "#function-call"
},
{
"include": "#property.reference"
},
{
"include": "#method-reference"
},
Expand Down Expand Up @@ -141,6 +156,18 @@
},
{
"include": "#null-literal"
},
{
"match": ",",
"name": "punctuation.separator.delimiter.kotlin"
},
{
"match": "\\.",
"name": "punctuation.separator.period.kotlin"
},
{
"match": "\\?\\.",
"name": "punctuation.accessor.optional.kotlin"
}
]
},
Expand Down Expand Up @@ -257,6 +284,10 @@
"match": "\\b(if|else|while|do|when|try|throw|break|continue|return|for)\\b",
"name": "keyword.control.kotlin"
},
"map-keywords": {
"match": "\\b(to)\\b",
"name": "keyword.map.kotlin"
},
"annotation-simple": {
"match": "(?<!\\w)@[\\w\\.]+\\b(?!:)",
"name": "entity.name.type.annotation.kotlin"
Expand Down Expand Up @@ -341,8 +372,8 @@
}
},
"function-declaration": {
"match": "\\b(fun)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?:(\\w+)\\.)?(\\b\\w+\\b|`[^`]+`)",
"captures": {
"begin": "\\b(fun)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?:(\\w+)\\.)?(\\b\\w+\\b|`[^`]+`)\\(",
"beginCaptures": {
"1": {
"name": "storage.type.function.kotlin"
},
Expand All @@ -359,10 +390,38 @@
"5": {
"name": "entity.name.function.declaration.kotlin"
}
},
"end": "\\)",
"endCaptures": {
"1": {
"name": "keyword.operator.assignment.type.kotlin"
}
},
"patterns": [
{
"include": "#parameter-declaration"
}
]
},
"parameter-declaration": {
"match": "\\b(\\w+)\\s*(:)\\s*(\\w+)(\\?)?",
"captures": {
"1": {
"name": "variable.parameter.kotlin"
},
"2": {
"name": "keyword.operator.assignment.type.kotlin"
},
"3": {
"name": "entity.name.type.kotlin"
},
"4": {
"name": "keyword.operator.optional"
}
}
},
"variable-declaration": {
"match": "\\b(val|var)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?",
"match": "\\b(var)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?",
"captures": {
"1": {
"name": "storage.type.variable.kotlin"
Expand All @@ -376,11 +435,52 @@
}
}
},
"constant-declaration": {
"match": "\\b(val)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?",
"captures": {
"1": {
"name": "storage.type.variable.readonly.kotlin"
},
"2": {
"patterns": [
{
"include": "#type-parameter"
}
]
}
}
},
"variable" : {
"match": "\\b(\\w+)(?=\\s*[:=])",
"captures": {
"1": {
"name": "variable.other.definition.kotlin"
}
}
},
"object" : {
"match": "\\b(\\w+)(?=\\.)",
"captures": {
"1": {
"name": "variable.other.object.kotlin"
}
}
},
"type-parameter": {
"patterns": [
{
"match": "\\b\\w+\\b",
"name": "entity.name.type.kotlin"
"match": "(:)?\\s*(\\b\\w+\\b)(\\?)?",
"captures": {
"1": {
"name": "keyword.operator.assignment.kotlin"
},
"2": {
"name": "entity.name.type.kotlin"
},
"3": {
"name": "keyword.operator.optional"
}
}
},
{
"match": "\\b(in|out)\\b",
Expand All @@ -401,12 +501,18 @@
}
},
"function-call": {
"match": "\\??\\.?(\\b\\w+\\b|`[^`]+`)\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?=[({])",
"match": "(?:(\\?\\.)|(\\.))?(\\b\\w+\\b|`[^`]+`)\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?=[({])",
"captures": {
"1": {
"name": "entity.name.function.call.kotlin"
"name": "punctuation.accessor.optional.kotlin"
},
"2": {
"name": "punctuation.separator.period.kotlin"
},
"3": {
"name": "entity.name.function.call.kotlin"
},
"4": {
"patterns": [
{
"include": "#type-parameter"
Expand All @@ -415,6 +521,20 @@
}
}
},
"property.reference": {
"match": "(?:(\\?\\.)|(\\.))(\\w+)\\b",
"captures": {
"1": {
"name": "punctuation.accessor.optional.kotlin"
},
"2": {
"name": "punctuation.separator.period.kotlin"
},
"3": {
"name": "variable.other.property.kotlin"
}
}
},
"method-reference": {
"match": "\\??::(\\b\\w+\\b|`[^`]+`)",
"captures": {
Expand Down Expand Up @@ -537,6 +657,10 @@
"match": "(===?|\\!==?|<=|>=|<|>)",
"name": "keyword.operator.comparison.kotlin"
},
{
"match": "(\\?:)",
"name": "keyword.operator.elvis.kotlin"
},
{
"match": "([+*/%-]=)",
"name": "keyword.operator.assignment.arithmetic.kotlin"
Expand Down Expand Up @@ -568,4 +692,4 @@
"name": "variable.language.this.kotlin"
}
}
}
}

0 comments on commit c8338dc

Please sign in to comment.