Skip to content

Commit e968288

Browse files
authored
Match generics even in deep nested contexts. Match inherited contexts correctly (#41)
Fixes #19 and #40.
1 parent e2b7595 commit e968288

11 files changed

+291
-24
lines changed

dist/Kotlin.JSON-tmLanguage

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"name": "entity.name.class.kotlin"
5858
}
5959
},
60-
"end": "(?=\\(|\\{|:|$)",
60+
"end": "(?=\\(|\\{|$)",
6161
"patterns": [
6262
{
6363
"include": "#comments"
@@ -125,6 +125,9 @@
125125
"repository": {
126126
"class-parameter-list": {
127127
"patterns": [
128+
{
129+
"include": "#generic"
130+
},
128131
{
129132
"include": "#annotations"
130133
},
@@ -249,6 +252,9 @@
249252
},
250253
"end": "(?=\\()",
251254
"patterns": [
255+
{
256+
"include": "#generic"
257+
},
252258
{
253259
"match": "(`[^`]*`)",
254260
"comment": "Backtick quoted function names",
@@ -374,10 +380,64 @@
374380
}
375381
}
376382
},
383+
"generic": {
384+
"patterns": [
385+
{
386+
"begin": "(?=\\<(?:[A-Z_]|\\*|in|out))",
387+
"end": "(?<=\\>)(?!\\>)",
388+
"patterns": [
389+
{
390+
"match": "<",
391+
"name": "punctuation.bracket.angle.begin.kotlin"
392+
},
393+
{
394+
"match": ">",
395+
"name": "punctuation.bracket.angle.end.kotlin"
396+
},
397+
{
398+
"match": "\\*",
399+
"name": "entity.name.type.generic.wildcard.kotlin"
400+
},
401+
{
402+
"include": "#generic-parameter-list"
403+
},
404+
{
405+
"match": ",",
406+
"name": "punctuation.seperator.kotlin"
407+
}
408+
]
409+
}
410+
],
411+
"repository": {
412+
"generic-parameter-list": {
413+
"patterns": [
414+
{
415+
"include": "#annotations"
416+
},
417+
{
418+
"match": "\\b(in|out)\\b",
419+
"name": "storage.modifier.generic.variance.kotlin"
420+
},
421+
{
422+
"include": "#built-in-types"
423+
},
424+
{
425+
"include": "#class-ident"
426+
},
427+
{
428+
"include": "#generic"
429+
},
430+
{
431+
"include": "#operators"
432+
}
433+
]
434+
}
435+
}
436+
},
377437
"class-ident": {
378438
"patterns": [
379439
{
380-
"match": "\\b[A-Z]\\w+\\b",
440+
"match": "\\b[A-Z_]\\w*\\b",
381441
"name": "entity.name.type.class.kotlin",
382442
"comment": "Classes generally start with an Uppercase Char"
383443
}
@@ -957,6 +1017,9 @@
9571017
{
9581018
"include": "#class-ident"
9591019
},
1020+
{
1021+
"include": "#generic"
1022+
},
9601023
{
9611024
"match": "(?<![/=\\-+!*%<>&|\\^~.])(->)(?![/=\\-+!*%<>&|\\^~.])",
9621025
"captures": {

dist/Kotlin.YAML-tmLanguage

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ repository:
2727
name: meta.class.kotlin
2828
patterns:
2929
- {include: '#keyword'}
30-
- {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'}]}
30+
- {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'}]}
3131
- {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'}]}
3232
- {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'}]}
3333
repository:
3434
class-parameter-list:
3535
patterns:
36+
- {include: '#generic'}
3637
- {include: '#annotations'}
3738
- {include: '#keywords'}
3839
- {match: '(\w+)\s*(:)', captures: {'1': {name: variable.parameter.function.kotlin}, '2': {name: keyword.operator.declaration.kotlin}}}
@@ -77,7 +78,7 @@ repository:
7778
name: meta.function.kotlin
7879
patterns:
7980
- {include: '#keywords'}
80-
- {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'}]}
81+
- {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'}]}
8182
- {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'}]}
8283
- {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'}]}
8384
- {include: '#return-type'}
@@ -93,10 +94,30 @@ repository:
9394
return-type:
9495
patterns:
9596
- {name: meta.return.type.kotlin, begin: '(?<=\))\s*(:)(?=\s*\S)', end: '(?<![:|&])(?=$|^|[{};,]|//)', patterns: [{include: '#types'}]}
97+
generic:
98+
patterns:
99+
-
100+
begin: '(?=\<(?:[A-Z_]|\*|in|out))'
101+
end: '(?<=\>)(?!\>)'
102+
patterns:
103+
- {match: '<', name: punctuation.bracket.angle.begin.kotlin}
104+
- {match: '>', name: punctuation.bracket.angle.end.kotlin}
105+
- {match: '\*', name: entity.name.type.generic.wildcard.kotlin}
106+
- {include: '#generic-parameter-list'}
107+
- {match: ',', name: punctuation.seperator.kotlin}
108+
repository:
109+
generic-parameter-list:
110+
patterns:
111+
- {include: '#annotations'}
112+
- {match: \b(in|out)\b, name: storage.modifier.generic.variance.kotlin}
113+
- {include: '#built-in-types'}
114+
- {include: '#class-ident'}
115+
- {include: '#generic'}
116+
- {include: '#operators'}
96117
class-ident:
97118
patterns:
98119
-
99-
match: '\b[A-Z]\w+\b'
120+
match: '\b[A-Z_]\w*\b'
100121
name: entity.name.type.class.kotlin
101122
comment: 'Classes generally start with an Uppercase Char'
102123
imports:
@@ -336,6 +357,8 @@ repository:
336357
include: '#built-in-types'
337358
-
338359
include: '#class-ident'
360+
-
361+
include: '#generic'
339362
-
340363
match: '(?<![/=\-+!*%<>&|\^~.])(->)(?![/=\-+!*%<>&|\^~.])'
341364
captures:

dist/Kotlin.tmLanguage

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
</dict>
9696
</dict>
9797
<key>end</key>
98-
<string>(?=\(|\{|:|$)</string>
98+
<string>(?=\(|\{|$)</string>
9999
<key>patterns</key>
100100
<array>
101101
<dict>
@@ -197,6 +197,10 @@
197197
<dict>
198198
<key>patterns</key>
199199
<array>
200+
<dict>
201+
<key>include</key>
202+
<string>#generic</string>
203+
</dict>
200204
<dict>
201205
<key>include</key>
202206
<string>#annotations</string>
@@ -384,6 +388,10 @@
384388
<string>(?=\()</string>
385389
<key>patterns</key>
386390
<array>
391+
<dict>
392+
<key>include</key>
393+
<string>#generic</string>
394+
</dict>
387395
<dict>
388396
<key>match</key>
389397
<string>(`[^`]*`)</string>
@@ -570,13 +578,91 @@
570578
</dict>
571579
</dict>
572580
</dict>
581+
<key>generic</key>
582+
<dict>
583+
<key>patterns</key>
584+
<array>
585+
<dict>
586+
<key>begin</key>
587+
<string>(?=\&lt;(?:[A-Z_]|\*|in|out))</string>
588+
<key>end</key>
589+
<string>(?&lt;=\&gt;)(?!\&gt;)</string>
590+
<key>patterns</key>
591+
<array>
592+
<dict>
593+
<key>match</key>
594+
<string>&lt;</string>
595+
<key>name</key>
596+
<string>punctuation.bracket.angle.begin.kotlin</string>
597+
</dict>
598+
<dict>
599+
<key>match</key>
600+
<string>&gt;</string>
601+
<key>name</key>
602+
<string>punctuation.bracket.angle.end.kotlin</string>
603+
</dict>
604+
<dict>
605+
<key>match</key>
606+
<string>\*</string>
607+
<key>name</key>
608+
<string>entity.name.type.generic.wildcard.kotlin</string>
609+
</dict>
610+
<dict>
611+
<key>include</key>
612+
<string>#generic-parameter-list</string>
613+
</dict>
614+
<dict>
615+
<key>match</key>
616+
<string>,</string>
617+
<key>name</key>
618+
<string>punctuation.seperator.kotlin</string>
619+
</dict>
620+
</array>
621+
</dict>
622+
</array>
623+
<key>repository</key>
624+
<dict>
625+
<key>generic-parameter-list</key>
626+
<dict>
627+
<key>patterns</key>
628+
<array>
629+
<dict>
630+
<key>include</key>
631+
<string>#annotations</string>
632+
</dict>
633+
<dict>
634+
<key>match</key>
635+
<string>\b(in|out)\b</string>
636+
<key>name</key>
637+
<string>storage.modifier.generic.variance.kotlin</string>
638+
</dict>
639+
<dict>
640+
<key>include</key>
641+
<string>#built-in-types</string>
642+
</dict>
643+
<dict>
644+
<key>include</key>
645+
<string>#class-ident</string>
646+
</dict>
647+
<dict>
648+
<key>include</key>
649+
<string>#generic</string>
650+
</dict>
651+
<dict>
652+
<key>include</key>
653+
<string>#operators</string>
654+
</dict>
655+
</array>
656+
</dict>
657+
</dict>
658+
</dict>
573659
<key>class-ident</key>
574660
<dict>
575661
<key>patterns</key>
576662
<array>
577663
<dict>
578664
<key>match</key>
579-
<string>\b[A-Z]\w+\b</string>
665+
<string>\b[A-Z_]\w*\b</string>
580666
<key>name</key>
581667
<string>entity.name.type.class.kotlin</string>
582668
<key>comment</key>
@@ -1446,6 +1532,10 @@
14461532
<key>include</key>
14471533
<string>#class-ident</string>
14481534
</dict>
1535+
<dict>
1536+
<key>include</key>
1537+
<string>#generic</string>
1538+
</dict>
14491539
<dict>
14501540
<key>match</key>
14511541
<string>(?&lt;![/=\-+!*%&lt;&gt;&amp;|\^~.])(-&gt;)(?![/=\-+!*%&lt;&gt;&amp;|\^~.])</string>

0 commit comments

Comments
 (0)