Skip to content

Commit

Permalink
Match generics even in deep nested contexts. Match inherited contexts…
Browse files Browse the repository at this point in the history
… correctly (#41)

Fixes #19 and #40.
  • Loading branch information
Animeshz committed Feb 8, 2021
1 parent e2b7595 commit e968288
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 24 deletions.
67 changes: 65 additions & 2 deletions dist/Kotlin.JSON-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"name": "entity.name.class.kotlin"
}
},
"end": "(?=\\(|\\{|:|$)",
"end": "(?=\\(|\\{|$)",
"patterns": [
{
"include": "#comments"
Expand Down Expand Up @@ -125,6 +125,9 @@
"repository": {
"class-parameter-list": {
"patterns": [
{
"include": "#generic"
},
{
"include": "#annotations"
},
Expand Down Expand Up @@ -249,6 +252,9 @@
},
"end": "(?=\\()",
"patterns": [
{
"include": "#generic"
},
{
"match": "(`[^`]*`)",
"comment": "Backtick quoted function names",
Expand Down Expand Up @@ -374,10 +380,64 @@
}
}
},
"generic": {
"patterns": [
{
"begin": "(?=\\<(?:[A-Z_]|\\*|in|out))",
"end": "(?<=\\>)(?!\\>)",
"patterns": [
{
"match": "<",
"name": "punctuation.bracket.angle.begin.kotlin"
},
{
"match": ">",
"name": "punctuation.bracket.angle.end.kotlin"
},
{
"match": "\\*",
"name": "entity.name.type.generic.wildcard.kotlin"
},
{
"include": "#generic-parameter-list"
},
{
"match": ",",
"name": "punctuation.seperator.kotlin"
}
]
}
],
"repository": {
"generic-parameter-list": {
"patterns": [
{
"include": "#annotations"
},
{
"match": "\\b(in|out)\\b",
"name": "storage.modifier.generic.variance.kotlin"
},
{
"include": "#built-in-types"
},
{
"include": "#class-ident"
},
{
"include": "#generic"
},
{
"include": "#operators"
}
]
}
}
},
"class-ident": {
"patterns": [
{
"match": "\\b[A-Z]\\w+\\b",
"match": "\\b[A-Z_]\\w*\\b",
"name": "entity.name.type.class.kotlin",
"comment": "Classes generally start with an Uppercase Char"
}
Expand Down Expand Up @@ -957,6 +1017,9 @@
{
"include": "#class-ident"
},
{
"include": "#generic"
},
{
"match": "(?<![/=\\-+!*%<>&|\\^~.])(->)(?![/=\\-+!*%<>&|\\^~.])",
"captures": {
Expand Down
29 changes: 26 additions & 3 deletions dist/Kotlin.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ repository:
name: meta.class.kotlin
patterns:
- {include: '#keyword'}
- {begin: \b(class|interface)\b\s+(\w+), beginCaptures: {'1': {name: storage.modifier.kotlin}, '2': {name: entity.name.class.kotlin}}, end: '(?=\(|\{|:|$)', patterns: [{include: '#comments'}, {include: '#annotations'}, {include: '#types'}]}
- {begin: \b(class|interface)\b\s+(\w+), beginCaptures: {'1': {name: storage.modifier.kotlin}, '2': {name: entity.name.class.kotlin}}, end: '(?=\(|\{|$)', patterns: [{include: '#comments'}, {include: '#annotations'}, {include: '#types'}]}
- {begin: (\(), beginCaptures: {'0': {name: punctuation.section.group.begin.kotlin}, '1': {name: punctuation.definition.parameters.begin.kotlin}}, end: (\)), endCaptures: {'0': {name: punctuation.section.group.end.kotlin}, '1': {name: punctuation.definition.parameters.end.kotlin}}, name: meta.parameters.kotlin, patterns: [{include: '#comments'}, {include: '#class-parameter-list'}]}
- {begin: '\{', beginCaptures: {'0': {name: punctuation.section.group.begin.kotlin}}, end: '\}', endCaptures: {'0': {name: punctuation.section.group.end.kotlin}}, name: meta.block.kotlin, patterns: [{include: '#code'}]}
repository:
class-parameter-list:
patterns:
- {include: '#generic'}
- {include: '#annotations'}
- {include: '#keywords'}
- {match: '(\w+)\s*(:)', captures: {'1': {name: variable.parameter.function.kotlin}, '2': {name: keyword.operator.declaration.kotlin}}}
Expand Down Expand Up @@ -77,7 +78,7 @@ repository:
name: meta.function.kotlin
patterns:
- {include: '#keywords'}
- {begin: \bfun\b, beginCaptures: {'0': {name: keyword.other.kotlin}}, end: '(?=\()', patterns: [{match: '(`[^`]*`)', comment: 'Backtick quoted function names', captures: {'0': {name: entity.name.function.kotlin}, '1': {name: string.quoted.backtick.kotlin}}}, {match: '([\.<\?>\w]+\.)?(\w+)', captures: {'2': {name: entity.name.function.kotlin}}}, {include: '#types'}]}
- {begin: \bfun\b, beginCaptures: {'0': {name: keyword.other.kotlin}}, end: '(?=\()', patterns: [{include: '#generic'}, {match: '(`[^`]*`)', comment: 'Backtick quoted function names', captures: {'0': {name: entity.name.function.kotlin}, '1': {name: string.quoted.backtick.kotlin}}}, {match: '([\.<\?>\w]+\.)?(\w+)', captures: {'2': {name: entity.name.function.kotlin}}}, {include: '#types'}]}
- {begin: (\(), beginCaptures: {'0': {name: punctuation.section.group.begin.kotlin}, '1': {name: punctuation.definition.parameters.begin.kotlin}}, end: (\)), endCaptures: {'0': {name: punctuation.section.group.end.kotlin}, '1': {name: punctuation.definition.parameters.end.kotlin}}, name: meta.parameters.kotlin, patterns: [{include: '#function-parameter-list'}]}
- {begin: '\{', beginCaptures: {'0': {name: punctuation.section.group.begin.kotlin}}, end: '\}', endCaptures: {'0': {name: punctuation.section.group.end.kotlin}}, name: meta.block.kotlin, patterns: [{include: '#code'}]}
- {include: '#return-type'}
Expand All @@ -93,10 +94,30 @@ repository:
return-type:
patterns:
- {name: meta.return.type.kotlin, begin: '(?<=\))\s*(:)(?=\s*\S)', end: '(?<![:|&])(?=$|^|[{};,]|//)', patterns: [{include: '#types'}]}
generic:
patterns:
-
begin: '(?=\<(?:[A-Z_]|\*|in|out))'
end: '(?<=\>)(?!\>)'
patterns:
- {match: '<', name: punctuation.bracket.angle.begin.kotlin}
- {match: '>', name: punctuation.bracket.angle.end.kotlin}
- {match: '\*', name: entity.name.type.generic.wildcard.kotlin}
- {include: '#generic-parameter-list'}
- {match: ',', name: punctuation.seperator.kotlin}
repository:
generic-parameter-list:
patterns:
- {include: '#annotations'}
- {match: \b(in|out)\b, name: storage.modifier.generic.variance.kotlin}
- {include: '#built-in-types'}
- {include: '#class-ident'}
- {include: '#generic'}
- {include: '#operators'}
class-ident:
patterns:
-
match: '\b[A-Z]\w+\b'
match: '\b[A-Z_]\w*\b'
name: entity.name.type.class.kotlin
comment: 'Classes generally start with an Uppercase Char'
imports:
Expand Down Expand Up @@ -336,6 +357,8 @@ repository:
include: '#built-in-types'
-
include: '#class-ident'
-
include: '#generic'
-
match: '(?<![/=\-+!*%<>&|\^~.])(->)(?![/=\-+!*%<>&|\^~.])'
captures:
Expand Down
94 changes: 92 additions & 2 deletions dist/Kotlin.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</dict>
</dict>
<key>end</key>
<string>(?=\(|\{|:|$)</string>
<string>(?=\(|\{|$)</string>
<key>patterns</key>
<array>
<dict>
Expand Down Expand Up @@ -197,6 +197,10 @@
<dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#generic</string>
</dict>
<dict>
<key>include</key>
<string>#annotations</string>
Expand Down Expand Up @@ -384,6 +388,10 @@
<string>(?=\()</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#generic</string>
</dict>
<dict>
<key>match</key>
<string>(`[^`]*`)</string>
Expand Down Expand Up @@ -570,13 +578,91 @@
</dict>
</dict>
</dict>
<key>generic</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(?=\&lt;(?:[A-Z_]|\*|in|out))</string>
<key>end</key>
<string>(?&lt;=\&gt;)(?!\&gt;)</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>&lt;</string>
<key>name</key>
<string>punctuation.bracket.angle.begin.kotlin</string>
</dict>
<dict>
<key>match</key>
<string>&gt;</string>
<key>name</key>
<string>punctuation.bracket.angle.end.kotlin</string>
</dict>
<dict>
<key>match</key>
<string>\*</string>
<key>name</key>
<string>entity.name.type.generic.wildcard.kotlin</string>
</dict>
<dict>
<key>include</key>
<string>#generic-parameter-list</string>
</dict>
<dict>
<key>match</key>
<string>,</string>
<key>name</key>
<string>punctuation.seperator.kotlin</string>
</dict>
</array>
</dict>
</array>
<key>repository</key>
<dict>
<key>generic-parameter-list</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#annotations</string>
</dict>
<dict>
<key>match</key>
<string>\b(in|out)\b</string>
<key>name</key>
<string>storage.modifier.generic.variance.kotlin</string>
</dict>
<dict>
<key>include</key>
<string>#built-in-types</string>
</dict>
<dict>
<key>include</key>
<string>#class-ident</string>
</dict>
<dict>
<key>include</key>
<string>#generic</string>
</dict>
<dict>
<key>include</key>
<string>#operators</string>
</dict>
</array>
</dict>
</dict>
</dict>
<key>class-ident</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\b[A-Z]\w+\b</string>
<string>\b[A-Z_]\w*\b</string>
<key>name</key>
<string>entity.name.type.class.kotlin</string>
<key>comment</key>
Expand Down Expand Up @@ -1446,6 +1532,10 @@
<key>include</key>
<string>#class-ident</string>
</dict>
<dict>
<key>include</key>
<string>#generic</string>
</dict>
<dict>
<key>match</key>
<string>(?&lt;![/=\-+!*%&lt;&gt;&amp;|\^~.])(-&gt;)(?![/=\-+!*%&lt;&gt;&amp;|\^~.])</string>
Expand Down
Loading

0 comments on commit e968288

Please sign in to comment.