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.
- package/CodepadLangKotlin.podspec +28 -0
- package/README.md +59 -2
- package/android/CMakeLists.txt +15 -0
- package/android/build.gradle +61 -0
- package/android/consumer-rules.pro +1 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/assets/codepad-languages/kotlin +1 -0
- package/android/src/main/cpp/lang.c +10 -0
- package/android/src/main/java/me/sectiontn/codepad/lang/kotlin/CodepadLangKotlinPackage.kt +13 -0
- package/android/src/main/java/me/sectiontn/codepad/lang/kotlin/KotlinLanguage.kt +466 -0
- package/grammar/LICENSE +9 -0
- package/grammar/src/parser.c +4 -0
- package/grammar/src/scanner.c +979 -0
- package/grammar/src/tree_sitter/alloc.h +54 -0
- package/grammar/src/tree_sitter/array.h +291 -0
- package/grammar/src/tree_sitter/parser.h +266 -0
- package/ios/CPLangKotlin.h +11 -0
- package/ios/CPLangKotlin.swift +459 -0
- package/package.json +40 -4
- package/queries/kotlin/highlights.scm +393 -0
- package/queries/kotlin/injections.scm +52 -0
- package/queries/kotlin/locals.scm +78 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Codepad
|
|
3
|
+
|
|
4
|
+
@objc(CPLangKotlin)
|
|
5
|
+
public final class CPLangKotlin: NSObject, CPLanguageProvider {
|
|
6
|
+
public let id: String = "kotlin"
|
|
7
|
+
public var languagePointer: UnsafeRawPointer { UnsafeRawPointer(tree_sitter_kotlin()) }
|
|
8
|
+
public let highlights: String = #"""
|
|
9
|
+
; Identifiers
|
|
10
|
+
(simple_identifier) @variable
|
|
11
|
+
|
|
12
|
+
; `it` keyword inside lambdas
|
|
13
|
+
; FIXME: This will highlight the keyword outside of lambdas since tree-sitter
|
|
14
|
+
; does not allow us to check for arbitrary nestation
|
|
15
|
+
((simple_identifier) @variable.builtin
|
|
16
|
+
(#eq? @variable.builtin "it"))
|
|
17
|
+
|
|
18
|
+
; `field` keyword inside property getter/setter
|
|
19
|
+
; FIXME: This will highlight the keyword outside of getters and setters
|
|
20
|
+
; since tree-sitter does not allow us to check for arbitrary nestation
|
|
21
|
+
((simple_identifier) @variable.builtin
|
|
22
|
+
(#eq? @variable.builtin "field"))
|
|
23
|
+
|
|
24
|
+
[
|
|
25
|
+
"this"
|
|
26
|
+
"super"
|
|
27
|
+
"this@"
|
|
28
|
+
"super@"
|
|
29
|
+
] @variable.builtin
|
|
30
|
+
|
|
31
|
+
; NOTE: for consistency with "super@"
|
|
32
|
+
(super_expression
|
|
33
|
+
"@" @variable.builtin)
|
|
34
|
+
|
|
35
|
+
(class_parameter
|
|
36
|
+
(simple_identifier) @variable.member)
|
|
37
|
+
|
|
38
|
+
; NOTE: temporary fix for treesitter bug that causes delay in file opening
|
|
39
|
+
;(class_body
|
|
40
|
+
; (property_declaration
|
|
41
|
+
; (variable_declaration
|
|
42
|
+
; (simple_identifier) @variable.member)))
|
|
43
|
+
; id_1.id_2.id_3: `id_2` and `id_3` are assumed as object properties
|
|
44
|
+
(_
|
|
45
|
+
(navigation_suffix
|
|
46
|
+
(simple_identifier) @variable.member))
|
|
47
|
+
|
|
48
|
+
; SCREAMING CASE identifiers are assumed to be constants
|
|
49
|
+
((simple_identifier) @constant
|
|
50
|
+
(#match? @constant "^[A-Z][A-Z0-9_]*$"))
|
|
51
|
+
|
|
52
|
+
(_
|
|
53
|
+
(navigation_suffix
|
|
54
|
+
(simple_identifier) @constant
|
|
55
|
+
(#match? @constant "^[A-Z][A-Z0-9_]*$")))
|
|
56
|
+
|
|
57
|
+
(enum_entry
|
|
58
|
+
(simple_identifier) @constant)
|
|
59
|
+
|
|
60
|
+
(type_identifier) @type
|
|
61
|
+
|
|
62
|
+
; '?' operator, replacement for Java @Nullable
|
|
63
|
+
(nullable_type) @punctuation.special
|
|
64
|
+
|
|
65
|
+
(type_alias
|
|
66
|
+
(type_identifier) @type.definition)
|
|
67
|
+
|
|
68
|
+
((type_identifier) @type.builtin
|
|
69
|
+
(#any-of? @type.builtin
|
|
70
|
+
"Byte" "Short" "Int" "Long" "UByte" "UShort" "UInt" "ULong" "Float" "Double" "Boolean" "Char"
|
|
71
|
+
"String" "Array" "ByteArray" "ShortArray" "IntArray" "LongArray" "UByteArray" "UShortArray"
|
|
72
|
+
"UIntArray" "ULongArray" "FloatArray" "DoubleArray" "BooleanArray" "CharArray" "Map" "Set"
|
|
73
|
+
"List" "EmptyMap" "EmptySet" "EmptyList" "MutableMap" "MutableSet" "MutableList"))
|
|
74
|
+
|
|
75
|
+
(package_header
|
|
76
|
+
"package" @keyword
|
|
77
|
+
.
|
|
78
|
+
(identifier
|
|
79
|
+
(simple_identifier) @module))
|
|
80
|
+
|
|
81
|
+
(import_header
|
|
82
|
+
"import" @keyword.import)
|
|
83
|
+
|
|
84
|
+
(wildcard_import) @character.special
|
|
85
|
+
|
|
86
|
+
; The last `simple_identifier` in a `import_header` will always either be a function
|
|
87
|
+
; or a type. Classes can appear anywhere in the import path, unlike functions
|
|
88
|
+
(import_header
|
|
89
|
+
(identifier
|
|
90
|
+
(simple_identifier) @type @_import)
|
|
91
|
+
(import_alias
|
|
92
|
+
(type_identifier) @type.definition)?
|
|
93
|
+
(#match? @_import "^[A-Z]"))
|
|
94
|
+
|
|
95
|
+
(import_header
|
|
96
|
+
(identifier
|
|
97
|
+
(simple_identifier) @function @_import .)
|
|
98
|
+
(import_alias
|
|
99
|
+
(type_identifier) @function)?
|
|
100
|
+
(#match? @_import "^[a-z]"))
|
|
101
|
+
|
|
102
|
+
(label) @label
|
|
103
|
+
|
|
104
|
+
; Function definitions
|
|
105
|
+
(function_declaration
|
|
106
|
+
(simple_identifier) @function)
|
|
107
|
+
|
|
108
|
+
(getter
|
|
109
|
+
"get" @function.builtin)
|
|
110
|
+
|
|
111
|
+
(setter
|
|
112
|
+
"set" @function.builtin)
|
|
113
|
+
|
|
114
|
+
(primary_constructor) @constructor
|
|
115
|
+
|
|
116
|
+
(secondary_constructor
|
|
117
|
+
"constructor" @constructor)
|
|
118
|
+
|
|
119
|
+
(constructor_invocation
|
|
120
|
+
(user_type
|
|
121
|
+
(type_identifier) @constructor))
|
|
122
|
+
|
|
123
|
+
(anonymous_initializer
|
|
124
|
+
"init" @constructor)
|
|
125
|
+
|
|
126
|
+
(parameter
|
|
127
|
+
(simple_identifier) @variable.parameter)
|
|
128
|
+
|
|
129
|
+
(parameter_with_optional_type
|
|
130
|
+
(simple_identifier) @variable.parameter)
|
|
131
|
+
|
|
132
|
+
; lambda parameters
|
|
133
|
+
(lambda_literal
|
|
134
|
+
(lambda_parameters
|
|
135
|
+
(variable_declaration
|
|
136
|
+
(simple_identifier) @variable.parameter)))
|
|
137
|
+
|
|
138
|
+
; Function calls
|
|
139
|
+
; function()
|
|
140
|
+
(call_expression
|
|
141
|
+
.
|
|
142
|
+
(simple_identifier) @function.call)
|
|
143
|
+
|
|
144
|
+
; ::function
|
|
145
|
+
(callable_reference
|
|
146
|
+
.
|
|
147
|
+
(simple_identifier) @function.call)
|
|
148
|
+
|
|
149
|
+
; object.function() or object.property.function()
|
|
150
|
+
(call_expression
|
|
151
|
+
(navigation_expression
|
|
152
|
+
(navigation_suffix
|
|
153
|
+
(simple_identifier) @function.call) .))
|
|
154
|
+
|
|
155
|
+
(call_expression
|
|
156
|
+
.
|
|
157
|
+
(simple_identifier) @function.builtin
|
|
158
|
+
(#any-of? @function.builtin
|
|
159
|
+
"arrayOf" "arrayOfNulls" "byteArrayOf" "shortArrayOf" "intArrayOf" "longArrayOf" "ubyteArrayOf"
|
|
160
|
+
"ushortArrayOf" "uintArrayOf" "ulongArrayOf" "floatArrayOf" "doubleArrayOf" "booleanArrayOf"
|
|
161
|
+
"charArrayOf" "emptyArray" "mapOf" "setOf" "listOf" "emptyMap" "emptySet" "emptyList"
|
|
162
|
+
"mutableMapOf" "mutableSetOf" "mutableListOf" "print" "println" "error" "TODO" "run"
|
|
163
|
+
"runCatching" "repeat" "lazy" "lazyOf" "enumValues" "enumValueOf" "assert" "check"
|
|
164
|
+
"checkNotNull" "require" "requireNotNull" "with" "synchronized"))
|
|
165
|
+
|
|
166
|
+
; Literals
|
|
167
|
+
[
|
|
168
|
+
(line_comment)
|
|
169
|
+
(multiline_comment)
|
|
170
|
+
] @comment @spell
|
|
171
|
+
|
|
172
|
+
((multiline_comment) @comment.documentation
|
|
173
|
+
(#match? @comment.documentation "^/[*][*][^*].*[*]/$"))
|
|
174
|
+
|
|
175
|
+
(shebang_line) @keyword.directive
|
|
176
|
+
|
|
177
|
+
(real_literal) @number.float
|
|
178
|
+
|
|
179
|
+
[
|
|
180
|
+
(integer_literal)
|
|
181
|
+
(long_literal)
|
|
182
|
+
(hex_literal)
|
|
183
|
+
(bin_literal)
|
|
184
|
+
(unsigned_literal)
|
|
185
|
+
] @number
|
|
186
|
+
|
|
187
|
+
[
|
|
188
|
+
(null_literal)
|
|
189
|
+
; should be highlighted the same as booleans
|
|
190
|
+
(boolean_literal)
|
|
191
|
+
] @boolean
|
|
192
|
+
|
|
193
|
+
(character_literal) @character
|
|
194
|
+
|
|
195
|
+
(string_literal) @string
|
|
196
|
+
|
|
197
|
+
; NOTE: Escapes not allowed in multi-line strings
|
|
198
|
+
(character_literal
|
|
199
|
+
(character_escape_seq) @string.escape)
|
|
200
|
+
|
|
201
|
+
; There are 3 ways to define a regex
|
|
202
|
+
; - "[abc]?".toRegex()
|
|
203
|
+
(call_expression
|
|
204
|
+
(navigation_expression
|
|
205
|
+
(string_literal) @string.regexp
|
|
206
|
+
(navigation_suffix
|
|
207
|
+
((simple_identifier) @_function
|
|
208
|
+
(#eq? @_function "toRegex")))))
|
|
209
|
+
|
|
210
|
+
; - Regex("[abc]?")
|
|
211
|
+
(call_expression
|
|
212
|
+
((simple_identifier) @_function
|
|
213
|
+
(#eq? @_function "Regex"))
|
|
214
|
+
(call_suffix
|
|
215
|
+
(value_arguments
|
|
216
|
+
(value_argument
|
|
217
|
+
(string_literal) @string.regexp))))
|
|
218
|
+
|
|
219
|
+
; - Regex.fromLiteral("[abc]?")
|
|
220
|
+
(call_expression
|
|
221
|
+
(navigation_expression
|
|
222
|
+
((simple_identifier) @_class
|
|
223
|
+
(#eq? @_class "Regex"))
|
|
224
|
+
(navigation_suffix
|
|
225
|
+
((simple_identifier) @_function
|
|
226
|
+
(#eq? @_function "fromLiteral"))))
|
|
227
|
+
(call_suffix
|
|
228
|
+
(value_arguments
|
|
229
|
+
(value_argument
|
|
230
|
+
(string_literal) @string.regexp))))
|
|
231
|
+
|
|
232
|
+
; Keywords
|
|
233
|
+
(type_alias
|
|
234
|
+
"typealias" @keyword)
|
|
235
|
+
|
|
236
|
+
(companion_object
|
|
237
|
+
"companion" @keyword)
|
|
238
|
+
|
|
239
|
+
[
|
|
240
|
+
(class_modifier)
|
|
241
|
+
(member_modifier)
|
|
242
|
+
(function_modifier)
|
|
243
|
+
(property_modifier)
|
|
244
|
+
(platform_modifier)
|
|
245
|
+
(variance_modifier)
|
|
246
|
+
(parameter_modifier)
|
|
247
|
+
(visibility_modifier)
|
|
248
|
+
(reification_modifier)
|
|
249
|
+
(inheritance_modifier)
|
|
250
|
+
] @keyword.modifier
|
|
251
|
+
|
|
252
|
+
[
|
|
253
|
+
"val"
|
|
254
|
+
"var"
|
|
255
|
+
; "typeof" ; NOTE: It is reserved for future use
|
|
256
|
+
] @keyword
|
|
257
|
+
|
|
258
|
+
[
|
|
259
|
+
"enum"
|
|
260
|
+
"class"
|
|
261
|
+
"object"
|
|
262
|
+
"interface"
|
|
263
|
+
] @keyword.type
|
|
264
|
+
|
|
265
|
+
[
|
|
266
|
+
"return"
|
|
267
|
+
"return@"
|
|
268
|
+
] @keyword.return
|
|
269
|
+
|
|
270
|
+
"suspend" @keyword.coroutine
|
|
271
|
+
|
|
272
|
+
"fun" @keyword.function
|
|
273
|
+
|
|
274
|
+
[
|
|
275
|
+
"if"
|
|
276
|
+
"else"
|
|
277
|
+
"when"
|
|
278
|
+
] @keyword.conditional
|
|
279
|
+
|
|
280
|
+
[
|
|
281
|
+
"for"
|
|
282
|
+
"do"
|
|
283
|
+
"while"
|
|
284
|
+
"continue"
|
|
285
|
+
"continue@"
|
|
286
|
+
"break"
|
|
287
|
+
"break@"
|
|
288
|
+
] @keyword.repeat
|
|
289
|
+
|
|
290
|
+
[
|
|
291
|
+
"try"
|
|
292
|
+
"catch"
|
|
293
|
+
"throw"
|
|
294
|
+
"finally"
|
|
295
|
+
] @keyword.exception
|
|
296
|
+
|
|
297
|
+
(annotation
|
|
298
|
+
"@" @attribute
|
|
299
|
+
(use_site_target)? @attribute)
|
|
300
|
+
|
|
301
|
+
(annotation
|
|
302
|
+
(user_type
|
|
303
|
+
(type_identifier) @attribute))
|
|
304
|
+
|
|
305
|
+
(annotation
|
|
306
|
+
(constructor_invocation
|
|
307
|
+
(user_type
|
|
308
|
+
(type_identifier) @attribute)))
|
|
309
|
+
|
|
310
|
+
(file_annotation
|
|
311
|
+
"@" @attribute
|
|
312
|
+
"file" @attribute
|
|
313
|
+
":" @attribute)
|
|
314
|
+
|
|
315
|
+
(file_annotation
|
|
316
|
+
(user_type
|
|
317
|
+
(type_identifier) @attribute))
|
|
318
|
+
|
|
319
|
+
(file_annotation
|
|
320
|
+
(constructor_invocation
|
|
321
|
+
(user_type
|
|
322
|
+
(type_identifier) @attribute)))
|
|
323
|
+
|
|
324
|
+
; Operators & Punctuation
|
|
325
|
+
[
|
|
326
|
+
"!"
|
|
327
|
+
"!="
|
|
328
|
+
"!=="
|
|
329
|
+
"="
|
|
330
|
+
"=="
|
|
331
|
+
"==="
|
|
332
|
+
">"
|
|
333
|
+
">="
|
|
334
|
+
"<"
|
|
335
|
+
"<="
|
|
336
|
+
"||"
|
|
337
|
+
"&&"
|
|
338
|
+
"+"
|
|
339
|
+
"++"
|
|
340
|
+
"+="
|
|
341
|
+
"-"
|
|
342
|
+
"--"
|
|
343
|
+
"-="
|
|
344
|
+
"*"
|
|
345
|
+
"*="
|
|
346
|
+
"/"
|
|
347
|
+
"/="
|
|
348
|
+
"%"
|
|
349
|
+
"%="
|
|
350
|
+
"?."
|
|
351
|
+
"?:"
|
|
352
|
+
"!!"
|
|
353
|
+
"is"
|
|
354
|
+
"in"
|
|
355
|
+
"as"
|
|
356
|
+
"as?"
|
|
357
|
+
".."
|
|
358
|
+
"..<"
|
|
359
|
+
"->"
|
|
360
|
+
] @operator
|
|
361
|
+
|
|
362
|
+
[
|
|
363
|
+
"("
|
|
364
|
+
")"
|
|
365
|
+
"["
|
|
366
|
+
"]"
|
|
367
|
+
"{"
|
|
368
|
+
"}"
|
|
369
|
+
] @punctuation.bracket
|
|
370
|
+
|
|
371
|
+
[
|
|
372
|
+
"."
|
|
373
|
+
","
|
|
374
|
+
";"
|
|
375
|
+
":"
|
|
376
|
+
"::"
|
|
377
|
+
] @punctuation.delimiter
|
|
378
|
+
|
|
379
|
+
(super_expression
|
|
380
|
+
[
|
|
381
|
+
"<"
|
|
382
|
+
">"
|
|
383
|
+
] @punctuation.delimiter)
|
|
384
|
+
|
|
385
|
+
(type_arguments
|
|
386
|
+
[
|
|
387
|
+
"<"
|
|
388
|
+
">"
|
|
389
|
+
] @punctuation.delimiter)
|
|
390
|
+
|
|
391
|
+
(type_parameters
|
|
392
|
+
[
|
|
393
|
+
"<"
|
|
394
|
+
">"
|
|
395
|
+
] @punctuation.delimiter)
|
|
396
|
+
|
|
397
|
+
; NOTE: `interpolated_identifier`s can be highlighted in any way
|
|
398
|
+
(string_literal
|
|
399
|
+
(interpolation_expression_start) @punctuation.special
|
|
400
|
+
(interpolated_expression) @none
|
|
401
|
+
(interpolation_expression_end) @punctuation.special)
|
|
402
|
+
|
|
403
|
+
"""#
|
|
404
|
+
public let injections: String = #"""
|
|
405
|
+
([
|
|
406
|
+
(line_comment)
|
|
407
|
+
(multiline_comment)
|
|
408
|
+
] @injection.content
|
|
409
|
+
(#set! injection.language "comment"))
|
|
410
|
+
|
|
411
|
+
; There are 3 ways to define a regex
|
|
412
|
+
; - "[abc]?".toRegex()
|
|
413
|
+
(call_expression
|
|
414
|
+
(navigation_expression
|
|
415
|
+
((string_literal
|
|
416
|
+
(string_content) @injection.content)
|
|
417
|
+
(#set! injection.language "regex"))
|
|
418
|
+
(navigation_suffix
|
|
419
|
+
((simple_identifier) @_function
|
|
420
|
+
(#eq? @_function "toRegex")))))
|
|
421
|
+
|
|
422
|
+
; - Regex("[abc]?")
|
|
423
|
+
(call_expression
|
|
424
|
+
((simple_identifier) @_function
|
|
425
|
+
(#eq? @_function "Regex"))
|
|
426
|
+
(call_suffix
|
|
427
|
+
(value_arguments
|
|
428
|
+
(value_argument
|
|
429
|
+
(string_literal
|
|
430
|
+
(string_content) @injection.content)
|
|
431
|
+
(#set! injection.language "regex")))))
|
|
432
|
+
|
|
433
|
+
; - Regex.fromLiteral("[abc]?")
|
|
434
|
+
(call_expression
|
|
435
|
+
(navigation_expression
|
|
436
|
+
((simple_identifier) @_class
|
|
437
|
+
(#eq? @_class "Regex"))
|
|
438
|
+
(navigation_suffix
|
|
439
|
+
((simple_identifier) @_function
|
|
440
|
+
(#eq? @_function "fromLiteral"))))
|
|
441
|
+
(call_suffix
|
|
442
|
+
(value_arguments
|
|
443
|
+
(value_argument
|
|
444
|
+
(string_literal
|
|
445
|
+
(string_content) @injection.content)
|
|
446
|
+
(#set! injection.language "regex")))))
|
|
447
|
+
|
|
448
|
+
; "pi = %.2f".format(3.14159)
|
|
449
|
+
((call_expression
|
|
450
|
+
(navigation_expression
|
|
451
|
+
(string_literal
|
|
452
|
+
(string_content) @injection.content)
|
|
453
|
+
(navigation_suffix
|
|
454
|
+
(simple_identifier) @_method)))
|
|
455
|
+
(#eq? @_method "format")
|
|
456
|
+
(#set! injection.language "printf"))
|
|
457
|
+
|
|
458
|
+
"""#
|
|
459
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-codepad-lang-kotlin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "tree-sitter Kotlin grammar and highlight queries for react-native-codepad",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"types": "./src/index.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"android",
|
|
10
|
+
"ios",
|
|
11
|
+
"grammar",
|
|
12
|
+
"queries",
|
|
13
|
+
"*.podspec",
|
|
14
|
+
"!android/build",
|
|
15
|
+
"!android/.cxx"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"react-native",
|
|
19
|
+
"codepad",
|
|
20
|
+
"tree-sitter",
|
|
21
|
+
"kotlin"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/SectionTN/react-native-codepad.git",
|
|
26
|
+
"directory": "languages/kotlin"
|
|
27
|
+
},
|
|
28
|
+
"author": "Rayen Sbai <rayensbai2@gmail.com> (https://github.com/SectionTN)",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"homepage": "https://github.com/SectionTN/react-native-codepad#readme",
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react-native-codepad": "0.1.1"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org/"
|
|
36
|
+
},
|
|
37
|
+
"codepad": {
|
|
38
|
+
"generated": true,
|
|
39
|
+
"grammar": "fwcd/tree-sitter-kotlin@1852ea17b7f60fb3f9d84e0b1555d56b46b39fb1",
|
|
40
|
+
"queries": "nvim-treesitter/nvim-treesitter@e289100ff98969e118c702199d88b764ce9e7fdf"
|
|
41
|
+
}
|
|
42
|
+
}
|