react-native-codepad-lang-kotlin 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,393 @@
1
+ ; Identifiers
2
+ (simple_identifier) @variable
3
+
4
+ ; `it` keyword inside lambdas
5
+ ; FIXME: This will highlight the keyword outside of lambdas since tree-sitter
6
+ ; does not allow us to check for arbitrary nestation
7
+ ((simple_identifier) @variable.builtin
8
+ (#eq? @variable.builtin "it"))
9
+
10
+ ; `field` keyword inside property getter/setter
11
+ ; FIXME: This will highlight the keyword outside of getters and setters
12
+ ; since tree-sitter does not allow us to check for arbitrary nestation
13
+ ((simple_identifier) @variable.builtin
14
+ (#eq? @variable.builtin "field"))
15
+
16
+ [
17
+ "this"
18
+ "super"
19
+ "this@"
20
+ "super@"
21
+ ] @variable.builtin
22
+
23
+ ; NOTE: for consistency with "super@"
24
+ (super_expression
25
+ "@" @variable.builtin)
26
+
27
+ (class_parameter
28
+ (simple_identifier) @variable.member)
29
+
30
+ ; NOTE: temporary fix for treesitter bug that causes delay in file opening
31
+ ;(class_body
32
+ ; (property_declaration
33
+ ; (variable_declaration
34
+ ; (simple_identifier) @variable.member)))
35
+ ; id_1.id_2.id_3: `id_2` and `id_3` are assumed as object properties
36
+ (_
37
+ (navigation_suffix
38
+ (simple_identifier) @variable.member))
39
+
40
+ ; SCREAMING CASE identifiers are assumed to be constants
41
+ ((simple_identifier) @constant
42
+ (#match? @constant "^[A-Z][A-Z0-9_]*$"))
43
+
44
+ (_
45
+ (navigation_suffix
46
+ (simple_identifier) @constant
47
+ (#match? @constant "^[A-Z][A-Z0-9_]*$")))
48
+
49
+ (enum_entry
50
+ (simple_identifier) @constant)
51
+
52
+ (type_identifier) @type
53
+
54
+ ; '?' operator, replacement for Java @Nullable
55
+ (nullable_type) @punctuation.special
56
+
57
+ (type_alias
58
+ (type_identifier) @type.definition)
59
+
60
+ ((type_identifier) @type.builtin
61
+ (#any-of? @type.builtin
62
+ "Byte" "Short" "Int" "Long" "UByte" "UShort" "UInt" "ULong" "Float" "Double" "Boolean" "Char"
63
+ "String" "Array" "ByteArray" "ShortArray" "IntArray" "LongArray" "UByteArray" "UShortArray"
64
+ "UIntArray" "ULongArray" "FloatArray" "DoubleArray" "BooleanArray" "CharArray" "Map" "Set"
65
+ "List" "EmptyMap" "EmptySet" "EmptyList" "MutableMap" "MutableSet" "MutableList"))
66
+
67
+ (package_header
68
+ "package" @keyword
69
+ .
70
+ (identifier
71
+ (simple_identifier) @module))
72
+
73
+ (import_header
74
+ "import" @keyword.import)
75
+
76
+ (wildcard_import) @character.special
77
+
78
+ ; The last `simple_identifier` in a `import_header` will always either be a function
79
+ ; or a type. Classes can appear anywhere in the import path, unlike functions
80
+ (import_header
81
+ (identifier
82
+ (simple_identifier) @type @_import)
83
+ (import_alias
84
+ (type_identifier) @type.definition)?
85
+ (#match? @_import "^[A-Z]"))
86
+
87
+ (import_header
88
+ (identifier
89
+ (simple_identifier) @function @_import .)
90
+ (import_alias
91
+ (type_identifier) @function)?
92
+ (#match? @_import "^[a-z]"))
93
+
94
+ (label) @label
95
+
96
+ ; Function definitions
97
+ (function_declaration
98
+ (simple_identifier) @function)
99
+
100
+ (getter
101
+ "get" @function.builtin)
102
+
103
+ (setter
104
+ "set" @function.builtin)
105
+
106
+ (primary_constructor) @constructor
107
+
108
+ (secondary_constructor
109
+ "constructor" @constructor)
110
+
111
+ (constructor_invocation
112
+ (user_type
113
+ (type_identifier) @constructor))
114
+
115
+ (anonymous_initializer
116
+ "init" @constructor)
117
+
118
+ (parameter
119
+ (simple_identifier) @variable.parameter)
120
+
121
+ (parameter_with_optional_type
122
+ (simple_identifier) @variable.parameter)
123
+
124
+ ; lambda parameters
125
+ (lambda_literal
126
+ (lambda_parameters
127
+ (variable_declaration
128
+ (simple_identifier) @variable.parameter)))
129
+
130
+ ; Function calls
131
+ ; function()
132
+ (call_expression
133
+ .
134
+ (simple_identifier) @function.call)
135
+
136
+ ; ::function
137
+ (callable_reference
138
+ .
139
+ (simple_identifier) @function.call)
140
+
141
+ ; object.function() or object.property.function()
142
+ (call_expression
143
+ (navigation_expression
144
+ (navigation_suffix
145
+ (simple_identifier) @function.call) .))
146
+
147
+ (call_expression
148
+ .
149
+ (simple_identifier) @function.builtin
150
+ (#any-of? @function.builtin
151
+ "arrayOf" "arrayOfNulls" "byteArrayOf" "shortArrayOf" "intArrayOf" "longArrayOf" "ubyteArrayOf"
152
+ "ushortArrayOf" "uintArrayOf" "ulongArrayOf" "floatArrayOf" "doubleArrayOf" "booleanArrayOf"
153
+ "charArrayOf" "emptyArray" "mapOf" "setOf" "listOf" "emptyMap" "emptySet" "emptyList"
154
+ "mutableMapOf" "mutableSetOf" "mutableListOf" "print" "println" "error" "TODO" "run"
155
+ "runCatching" "repeat" "lazy" "lazyOf" "enumValues" "enumValueOf" "assert" "check"
156
+ "checkNotNull" "require" "requireNotNull" "with" "synchronized"))
157
+
158
+ ; Literals
159
+ [
160
+ (line_comment)
161
+ (multiline_comment)
162
+ ] @comment @spell
163
+
164
+ ((multiline_comment) @comment.documentation
165
+ (#match? @comment.documentation "^/[*][*][^*].*[*]/$"))
166
+
167
+ (shebang_line) @keyword.directive
168
+
169
+ (real_literal) @number.float
170
+
171
+ [
172
+ (integer_literal)
173
+ (long_literal)
174
+ (hex_literal)
175
+ (bin_literal)
176
+ (unsigned_literal)
177
+ ] @number
178
+
179
+ [
180
+ (null_literal)
181
+ ; should be highlighted the same as booleans
182
+ (boolean_literal)
183
+ ] @boolean
184
+
185
+ (character_literal) @character
186
+
187
+ (string_literal) @string
188
+
189
+ ; NOTE: Escapes not allowed in multi-line strings
190
+ (character_literal
191
+ (character_escape_seq) @string.escape)
192
+
193
+ ; There are 3 ways to define a regex
194
+ ; - "[abc]?".toRegex()
195
+ (call_expression
196
+ (navigation_expression
197
+ (string_literal) @string.regexp
198
+ (navigation_suffix
199
+ ((simple_identifier) @_function
200
+ (#eq? @_function "toRegex")))))
201
+
202
+ ; - Regex("[abc]?")
203
+ (call_expression
204
+ ((simple_identifier) @_function
205
+ (#eq? @_function "Regex"))
206
+ (call_suffix
207
+ (value_arguments
208
+ (value_argument
209
+ (string_literal) @string.regexp))))
210
+
211
+ ; - Regex.fromLiteral("[abc]?")
212
+ (call_expression
213
+ (navigation_expression
214
+ ((simple_identifier) @_class
215
+ (#eq? @_class "Regex"))
216
+ (navigation_suffix
217
+ ((simple_identifier) @_function
218
+ (#eq? @_function "fromLiteral"))))
219
+ (call_suffix
220
+ (value_arguments
221
+ (value_argument
222
+ (string_literal) @string.regexp))))
223
+
224
+ ; Keywords
225
+ (type_alias
226
+ "typealias" @keyword)
227
+
228
+ (companion_object
229
+ "companion" @keyword)
230
+
231
+ [
232
+ (class_modifier)
233
+ (member_modifier)
234
+ (function_modifier)
235
+ (property_modifier)
236
+ (platform_modifier)
237
+ (variance_modifier)
238
+ (parameter_modifier)
239
+ (visibility_modifier)
240
+ (reification_modifier)
241
+ (inheritance_modifier)
242
+ ] @keyword.modifier
243
+
244
+ [
245
+ "val"
246
+ "var"
247
+ ; "typeof" ; NOTE: It is reserved for future use
248
+ ] @keyword
249
+
250
+ [
251
+ "enum"
252
+ "class"
253
+ "object"
254
+ "interface"
255
+ ] @keyword.type
256
+
257
+ [
258
+ "return"
259
+ "return@"
260
+ ] @keyword.return
261
+
262
+ "suspend" @keyword.coroutine
263
+
264
+ "fun" @keyword.function
265
+
266
+ [
267
+ "if"
268
+ "else"
269
+ "when"
270
+ ] @keyword.conditional
271
+
272
+ [
273
+ "for"
274
+ "do"
275
+ "while"
276
+ "continue"
277
+ "continue@"
278
+ "break"
279
+ "break@"
280
+ ] @keyword.repeat
281
+
282
+ [
283
+ "try"
284
+ "catch"
285
+ "throw"
286
+ "finally"
287
+ ] @keyword.exception
288
+
289
+ (annotation
290
+ "@" @attribute
291
+ (use_site_target)? @attribute)
292
+
293
+ (annotation
294
+ (user_type
295
+ (type_identifier) @attribute))
296
+
297
+ (annotation
298
+ (constructor_invocation
299
+ (user_type
300
+ (type_identifier) @attribute)))
301
+
302
+ (file_annotation
303
+ "@" @attribute
304
+ "file" @attribute
305
+ ":" @attribute)
306
+
307
+ (file_annotation
308
+ (user_type
309
+ (type_identifier) @attribute))
310
+
311
+ (file_annotation
312
+ (constructor_invocation
313
+ (user_type
314
+ (type_identifier) @attribute)))
315
+
316
+ ; Operators & Punctuation
317
+ [
318
+ "!"
319
+ "!="
320
+ "!=="
321
+ "="
322
+ "=="
323
+ "==="
324
+ ">"
325
+ ">="
326
+ "<"
327
+ "<="
328
+ "||"
329
+ "&&"
330
+ "+"
331
+ "++"
332
+ "+="
333
+ "-"
334
+ "--"
335
+ "-="
336
+ "*"
337
+ "*="
338
+ "/"
339
+ "/="
340
+ "%"
341
+ "%="
342
+ "?."
343
+ "?:"
344
+ "!!"
345
+ "is"
346
+ "in"
347
+ "as"
348
+ "as?"
349
+ ".."
350
+ "..<"
351
+ "->"
352
+ ] @operator
353
+
354
+ [
355
+ "("
356
+ ")"
357
+ "["
358
+ "]"
359
+ "{"
360
+ "}"
361
+ ] @punctuation.bracket
362
+
363
+ [
364
+ "."
365
+ ","
366
+ ";"
367
+ ":"
368
+ "::"
369
+ ] @punctuation.delimiter
370
+
371
+ (super_expression
372
+ [
373
+ "<"
374
+ ">"
375
+ ] @punctuation.delimiter)
376
+
377
+ (type_arguments
378
+ [
379
+ "<"
380
+ ">"
381
+ ] @punctuation.delimiter)
382
+
383
+ (type_parameters
384
+ [
385
+ "<"
386
+ ">"
387
+ ] @punctuation.delimiter)
388
+
389
+ ; NOTE: `interpolated_identifier`s can be highlighted in any way
390
+ (string_literal
391
+ (interpolation_expression_start) @punctuation.special
392
+ (interpolated_expression) @none
393
+ (interpolation_expression_end) @punctuation.special)
@@ -0,0 +1,52 @@
1
+ ([
2
+ (line_comment)
3
+ (multiline_comment)
4
+ ] @injection.content
5
+ (#set! injection.language "comment"))
6
+
7
+ ; There are 3 ways to define a regex
8
+ ; - "[abc]?".toRegex()
9
+ (call_expression
10
+ (navigation_expression
11
+ ((string_literal
12
+ (string_content) @injection.content)
13
+ (#set! injection.language "regex"))
14
+ (navigation_suffix
15
+ ((simple_identifier) @_function
16
+ (#eq? @_function "toRegex")))))
17
+
18
+ ; - Regex("[abc]?")
19
+ (call_expression
20
+ ((simple_identifier) @_function
21
+ (#eq? @_function "Regex"))
22
+ (call_suffix
23
+ (value_arguments
24
+ (value_argument
25
+ (string_literal
26
+ (string_content) @injection.content)
27
+ (#set! injection.language "regex")))))
28
+
29
+ ; - Regex.fromLiteral("[abc]?")
30
+ (call_expression
31
+ (navigation_expression
32
+ ((simple_identifier) @_class
33
+ (#eq? @_class "Regex"))
34
+ (navigation_suffix
35
+ ((simple_identifier) @_function
36
+ (#eq? @_function "fromLiteral"))))
37
+ (call_suffix
38
+ (value_arguments
39
+ (value_argument
40
+ (string_literal
41
+ (string_content) @injection.content)
42
+ (#set! injection.language "regex")))))
43
+
44
+ ; "pi = %.2f".format(3.14159)
45
+ ((call_expression
46
+ (navigation_expression
47
+ (string_literal
48
+ (string_content) @injection.content)
49
+ (navigation_suffix
50
+ (simple_identifier) @_method)))
51
+ (#eq? @_method "format")
52
+ (#set! injection.language "printf"))
@@ -0,0 +1,78 @@
1
+ ; Imports
2
+ (package_header
3
+ .
4
+ (identifier) @local.definition.namespace)
5
+
6
+ (import_header
7
+ (identifier
8
+ (simple_identifier) @local.definition.import .)
9
+ (import_alias
10
+ (type_identifier) @local.definition.import)?)
11
+
12
+ ; Functions
13
+ (function_declaration
14
+ .
15
+ (simple_identifier) @local.definition.function
16
+ (#set! definition.function.scope "parent"))
17
+
18
+ (class_body
19
+ (function_declaration
20
+ .
21
+ (simple_identifier) @local.definition.method)
22
+ (#set! definition.method.scope "parent"))
23
+
24
+ ; Variables
25
+ (function_declaration
26
+ (function_value_parameters
27
+ (parameter
28
+ (simple_identifier) @local.definition.parameter)))
29
+
30
+ (lambda_literal
31
+ (lambda_parameters
32
+ (variable_declaration
33
+ (simple_identifier) @local.definition.parameter)))
34
+
35
+ ; NOTE: temporary fix for treesitter bug that causes delay in file opening
36
+ ;(class_body
37
+ ; (property_declaration
38
+ ; (variable_declaration
39
+ ; (simple_identifier) @local.definition.field)))
40
+ (class_declaration
41
+ (primary_constructor
42
+ (class_parameter
43
+ (simple_identifier) @local.definition.field)))
44
+
45
+ (enum_class_body
46
+ (enum_entry
47
+ (simple_identifier) @local.definition.field))
48
+
49
+ (variable_declaration
50
+ (simple_identifier) @local.definition.var)
51
+
52
+ ; Types
53
+ (class_declaration
54
+ (type_identifier) @local.definition.type
55
+ (#set! definition.type.scope "parent"))
56
+
57
+ (type_alias
58
+ (type_identifier) @local.definition.type
59
+ (#set! definition.type.scope "parent"))
60
+
61
+ ; Scopes
62
+ [
63
+ (if_expression)
64
+ (when_expression)
65
+ (when_entry)
66
+ (for_statement)
67
+ (while_statement)
68
+ (do_while_statement)
69
+ (lambda_literal)
70
+ (function_declaration)
71
+ (primary_constructor)
72
+ (secondary_constructor)
73
+ (anonymous_initializer)
74
+ (class_declaration)
75
+ (enum_class_body)
76
+ (enum_entry)
77
+ (interpolated_expression)
78
+ ] @local.scope
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export const kotlin = 'kotlin' as const;