blob: f47358e48703b6b50a9174e7de9a0c6e909643fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
;;; Kotlin
(simple_identifier) @variable
; Reset some
(navigation_suffix (simple_identifier) @none)
(import_header (identifier (simple_identifier) @none))
(package_header (identifier (simple_identifier) @none))
;; Strings
(line_string_literal) @string
(multi_line_string_literal) @string
; Interpolated
(interpolated_identifier) @variable
(interpolated_expression) @none
;; Suffixes
(navigation_expression (navigation_suffix (simple_identifier) @property ))
; Reset some
(assignment (navigation_expression (navigation_suffix (simple_identifier) @none )))
(call_expression (navigation_expression (navigation_suffix (simple_identifier) @none )))
(navigation_expression (navigation_expression (navigation_suffix (simple_identifier) @none )))
;; Variables/fields
; attribute in data classes etc.
(class_parameter (simple_identifier) @field)
; variable in normal classes
(property_declaration (variable_declaration (simple_identifier) @variable))
; accessed field in blocks. `logger` in `logger.info("")`
(statements (call_expression (navigation_expression (simple_identifier) @variable)))
(indexing_expression (call_expression (navigation_expression (simple_identifier) @variable)))
; `classProp` in `classProp.lastIndex`
(statements (navigation_expression (simple_identifier) @variable))
; `variable` in `variable = car.doors`
(directly_assignable_expression (simple_identifier) @variable)
;; Constants
; Assume all-caps names are constants
((simple_identifier) @constant
(#match? @constant "^[A-Z][A-Z_0-9]+$"))
((interpolated_identifier) @constant
(#vim-match? @constant "^[A-Z][A-Z_0-9]+$"))
(lambda_parameters) @parameter
;; Builtin functions
((simple_identifier) @function.macro
(#vim-match? @function.macro "^(commonPrefixWith|commonSuffixWith|endsWith|findAnyOf|findLastAnyOf|hasSurrogatePairAt|ifBlank|ifEmpty|indexOf|indexOfAny|isEmpty|isNotBlank|isNotEmpty|isNullOrBlank|isNullOrEmpty|lastIndexOf|lastIndexOfAny|lineSequence|lines|orEmpty|padEnd|padStart|removePrefix|removeRange|removeSuffix|removeSurrounding|replace|replaceAfter|replaceAfterLast|replaceBefore|replaceBeforeLast|replaceFirst|replaceRange|split|splitToSequence|startsWith|subSequence|substring|substringAfter|substringAfterLast|substringBefore|substringBeforeLast|trim|trimEnd|trimStart|containsKey|containsValue|filter|filterKeys|filterNot|filterNotTo|filterTo|filterValues|getOrElse|getOrPut|getValue|ifEmpty|isNotEmpty|isNullOrEmpty|mapKeys|mapKeysTo|mapValues|mapValuesTo|orEmpty|putAll|remove|toMap|toMutableMap|toPair|also|apply|let|run|takeIf|takeUnless|prependIndent|replaceIndent|replaceIndentByMargin|trimIndent|trimMargin|all|any|asIterable|asSequence|associate|associateBy|associateByTo|associateTo|associateWith|associateWithTo|chunked|chunkedSequence|count|drop|dropLast|dropLastWhile|dropWhile|elementAtOrElse|elementAtOrNull|filter|filterIndexed|filterIndexedTo|filterNot|filterNotTo|filterTo|find|findLast|first|firstOrNull|flatMap|flatMapIndexed|flatMapIndexedTo|flatMapTo|fold|foldIndexed|foldRight|foldRightIndexed|forEach|forEachIndexed|getOrElse|getOrNull|groupBy|groupByTo|groupingBy|indexOfFirst|indexOfLast|last|lastOrNull|map|mapIndexed|mapIndexedNotNull|mapIndexedNotNullTo|mapIndexedTo|mapNotNull|mapNotNullTo|mapTo|max|maxBy|maxByOrNull|maxOf|maxOfOrNull|maxOfWith|maxOfWithOrNull|maxOrNull|maxWith|maxWithOrNull|min|minBy|minByOrNull|minOf|minOfOrNull|minOfWith|minOfWithOrNull|minOrNull|minWith|minWithOrNull|none|onEach|onEachIndexed|partition|random|randomOrNull|reduce|reduceIndexed|reduceIndexedOrNull|reduceOrNull|reduceRight|reduceRightIndexed|reduceRightIndexedOrNull|reduceRightOrNull|reversed|runningFold|runningFoldIndexed|runningReduce|runningReduceIndexed|scan|scanIndexed|scanReduce|scanReduceIndexed|single|singleOrNull|slice|sumBy|sumByDouble|sumOf|take|takeLast|takeLastWhile|takeWhile|toCollection|toHashSet|toList|toMutableList|toSet|windowed|windowedSequence|withIndex|zip|zipWithNext)$"))
(call_expression
(simple_identifier) @function)
((simple_identifier) @function.builtin
(#vim-match? @function.builtin "^(print|println|buildMap|emptyMap|hashMapOf|linkedMapOf|mapOf|mutableMapOf|buildSet|emptySet|hashSetOf|linkedSetOf|mutableSetOf|setOf|setOfNotNull|TODO|repeat|run|with)$"))
;; Numbers
(integer_literal) @number
;; Booleans
(boolean_literal) @boolean
;; Types
(type_identifier) @type
;; Annotations
(annotation (single_annotation) @attribute)
(single_annotation (user_type (type_identifier) @attribute))
(single_annotation (constructor_invocation (user_type (type_identifier) @attribute)))
;; it
(indexing_expression (simple_identifier) @variable.builtin
(#vim-match? @variable.builtin "^it$"))
;; Operators
[
"="
"-"
"->"
"+"
"++"
"--"
"*"
] @operator
;; Keyword operators
[
"in"
] @keyword.operator
((simple_identifier) @keyword.operator
(#vim-match? @keyword.operator "^to$"))
;; Keywords
[
"this"
"override"
"enum"
"as"
"class"
"object"
"data"
"val"
"init"
"private"
"var"
"break"
"by"
"fun"
"companion"
"constructor"
"throw"
] @keyword
[
"return"
] @keyword.return
(null_literal) @keyword
; const etc.
(property_modifier) @keyword
;; Conditionals
[
"if"
"is"
"else"
"when"
] @conditional
;; Loops
[
"for"
"while"
] @repeat
;; Includes
"import" @include
"package" @include
;; Punctuation
[
"::"
";"
"."
","
] @punctuation.delimiter
[
"$"
"${"
"}"
] @none
[
"["
"]"
"{"
"}"
"("
")"
] @punctuation.bracket
[
"$"
] @punctuation.special
;; Comments
(comment) @comment
; Functions
(function_declaration (simple_identifier) @function)
(ERROR) @error
; TODO parameter
|