Skip to content

Commit

Permalink
Improved grammar for kotlin (#1273)
Browse files Browse the repository at this point in the history
* Improved grammar for kotlin

* Fixed map-keyword and parameter-declaration
  • Loading branch information
per-steinar authored Jan 11, 2024
1 parent 5a51b88 commit fb1a6c7
Showing 1 changed file with 138 additions and 8 deletions.
146 changes: 138 additions & 8 deletions org.eclipse.buildship.kotlindsl.provider/kotlin.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,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 @@ -88,6 +91,15 @@
{
"include": "#variable-declaration"
},
{
"include": "#constant-declaration"
},
{
"include": "#variable"
},
{
"include": "#object"
},
{
"include": "#type-constraint"
},
Expand All @@ -97,6 +109,9 @@
{
"include": "#function-call"
},
{
"include": "#property.reference"
},
{
"include": "#method-reference"
},
Expand Down Expand Up @@ -138,6 +153,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 @@ -231,6 +258,9 @@
},
{
"include": "#control-keywords"
},
{
"include": "#map-keywords"
}
]
},
Expand All @@ -254,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 @@ -338,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 @@ -356,10 +390,41 @@
"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"
},
"5": {
"name": "punctuation.separator.delimiter.kotlin"
}
}
},
"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 @@ -373,11 +438,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 @@ -398,12 +504,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 @@ -412,6 +524,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 @@ -534,6 +660,10 @@
"match": "(===?|\\!==?|<=|>=|<|>)",
"name": "keyword.operator.comparison.kotlin"
},
{
"match": "(\\?:)",
"name": "keyword.operator.elvis.kotlin"
},
{
"match": "([+*/%-]=)",
"name": "keyword.operator.assignment.arithmetic.kotlin"
Expand Down

0 comments on commit fb1a6c7

Please sign in to comment.