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,28 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "CodepadLangKotlin"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
s.platforms = { :ios => "17.0" }
|
|
13
|
+
s.source = { :git => "https://github.com/SectionTN/react-native-codepad.git", :tag => "v#{s.version}" }
|
|
14
|
+
|
|
15
|
+
s.source_files = ["ios/*.{h,swift}", "grammar/src/parser.c", "grammar/src/scanner.c"]
|
|
16
|
+
s.public_header_files = "ios/*.h"
|
|
17
|
+
s.preserve_paths = "grammar/**/*"
|
|
18
|
+
s.compiler_flags = "-w"
|
|
19
|
+
s.pod_target_xcconfig = {
|
|
20
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/grammar/src\"",
|
|
21
|
+
"GCC_OPTIMIZATION_LEVEL" => "1",
|
|
22
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
23
|
+
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
24
|
+
"DEFINES_MODULE" => "YES",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
s.dependency "Codepad"
|
|
28
|
+
end
|
package/README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# react-native-codepad-lang-kotlin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generated package. Do not edit by hand; run `yarn gen:languages` in the react-native-codepad repository.
|
|
4
|
+
|
|
5
|
+
Grammar: fwcd/tree-sitter-kotlin at 1852ea17b7f60fb3f9d84e0b1555d56b46b39fb1. Queries: nvim-treesitter at e289100ff98969e118c702199d88b764ce9e7fdf.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add react-native-codepad react-native-codepad-lang-kotlin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then pass `language="kotlin"` to `CodeEditor`. Theme token keys this package produces:
|
|
14
|
+
|
|
15
|
+
### kotlin
|
|
16
|
+
|
|
17
|
+
- `attribute`
|
|
18
|
+
- `boolean`
|
|
19
|
+
- `character`
|
|
20
|
+
- `character.special`
|
|
21
|
+
- `comment`
|
|
22
|
+
- `comment.documentation`
|
|
23
|
+
- `constant`
|
|
24
|
+
- `constructor`
|
|
25
|
+
- `function`
|
|
26
|
+
- `function.builtin`
|
|
27
|
+
- `function.call`
|
|
28
|
+
- `keyword`
|
|
29
|
+
- `keyword.conditional`
|
|
30
|
+
- `keyword.coroutine`
|
|
31
|
+
- `keyword.directive`
|
|
32
|
+
- `keyword.exception`
|
|
33
|
+
- `keyword.function`
|
|
34
|
+
- `keyword.import`
|
|
35
|
+
- `keyword.modifier`
|
|
36
|
+
- `keyword.repeat`
|
|
37
|
+
- `keyword.return`
|
|
38
|
+
- `keyword.type`
|
|
39
|
+
- `label`
|
|
40
|
+
- `module`
|
|
41
|
+
- `none`
|
|
42
|
+
- `number`
|
|
43
|
+
- `number.float`
|
|
44
|
+
- `operator`
|
|
45
|
+
- `punctuation.bracket`
|
|
46
|
+
- `punctuation.delimiter`
|
|
47
|
+
- `punctuation.special`
|
|
48
|
+
- `spell`
|
|
49
|
+
- `string`
|
|
50
|
+
- `string.escape`
|
|
51
|
+
- `string.regexp`
|
|
52
|
+
- `type`
|
|
53
|
+
- `type.builtin`
|
|
54
|
+
- `type.definition`
|
|
55
|
+
- `variable`
|
|
56
|
+
- `variable.builtin`
|
|
57
|
+
- `variable.member`
|
|
58
|
+
- `variable.parameter`
|
|
59
|
+
|
|
60
|
+
See the [languages guide](https://sectiontn.github.io/react-native-codepad/guides/languages/) for aliases, injections and themes.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
project(codepad_lang_kotlin C)
|
|
3
|
+
set(GRAMMAR ${CMAKE_SOURCE_DIR}/../grammar)
|
|
4
|
+
|
|
5
|
+
add_library(codepad_lang_kotlin SHARED
|
|
6
|
+
src/main/cpp/lang.c
|
|
7
|
+
${GRAMMAR}/src/parser.c
|
|
8
|
+
${GRAMMAR}/src/scanner.c
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
target_include_directories(codepad_lang_kotlin PRIVATE ${GRAMMAR}/src)
|
|
12
|
+
|
|
13
|
+
# Parser tables are data. -O1 keeps large grammars from taking minutes to compile.
|
|
14
|
+
set_source_files_properties(${GRAMMAR}/src/parser.c PROPERTIES COMPILE_OPTIONS "-O1")
|
|
15
|
+
target_compile_options(codepad_lang_kotlin PRIVATE -std=c11 -O2 -fvisibility=hidden -w)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
dependencies {
|
|
7
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
8
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
apply plugin: "com.android.library"
|
|
13
|
+
if (project.extensions.findByName("kotlin") == null) {
|
|
14
|
+
apply plugin: "kotlin-android"
|
|
15
|
+
}
|
|
16
|
+
apply plugin: "com.facebook.react"
|
|
17
|
+
|
|
18
|
+
def safeExtGet(prop, fallback) {
|
|
19
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def reactNativeArchitectures() {
|
|
23
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
24
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
android {
|
|
28
|
+
namespace "me.sectiontn.codepad.lang.kotlin"
|
|
29
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 36)
|
|
30
|
+
|
|
31
|
+
defaultConfig {
|
|
32
|
+
minSdkVersion safeExtGet("minSdkVersion", 24)
|
|
33
|
+
consumerProguardFiles "consumer-rules.pro"
|
|
34
|
+
externalNativeBuild {
|
|
35
|
+
cmake {
|
|
36
|
+
arguments "-DANDROID_STL=none", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
37
|
+
abiFilters(*reactNativeArchitectures())
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (rootProject.ext.has("ndkVersion")) {
|
|
43
|
+
ndkVersion rootProject.ext.ndkVersion
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
externalNativeBuild {
|
|
47
|
+
cmake {
|
|
48
|
+
path "CMakeLists.txt"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
compileOptions {
|
|
53
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
54
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
dependencies {
|
|
59
|
+
implementation "com.facebook.react:react-android"
|
|
60
|
+
implementation project(":react-native-codepad")
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-keep class me.sectiontn.codepad.lang.kotlin.KotlinLanguage { *; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.1
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#include <jni.h>
|
|
2
|
+
#include <stdint.h>
|
|
3
|
+
|
|
4
|
+
const void *tree_sitter_kotlin(void);
|
|
5
|
+
|
|
6
|
+
JNIEXPORT jlong JNICALL Java_me_sectiontn_codepad_lang_kotlin_KotlinLanguage_nativeLanguage(JNIEnv *env, jobject thiz) {
|
|
7
|
+
(void) env;
|
|
8
|
+
(void) thiz;
|
|
9
|
+
return (jlong) (intptr_t) tree_sitter_kotlin();
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package me.sectiontn.codepad.lang.kotlin
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
|
+
|
|
8
|
+
// Empty package so React Native autolinking includes this Gradle module.
|
|
9
|
+
class CodepadLangKotlinPackage : BaseReactPackage() {
|
|
10
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
|
|
11
|
+
|
|
12
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { HashMap() }
|
|
13
|
+
}
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
package me.sectiontn.codepad.lang.kotlin
|
|
2
|
+
|
|
3
|
+
import me.sectiontn.codepad.syntax.LanguageProvider
|
|
4
|
+
|
|
5
|
+
class KotlinLanguage : LanguageProvider {
|
|
6
|
+
override val id: String = "kotlin"
|
|
7
|
+
override val languagePointer: Long get() = nativeLanguage()
|
|
8
|
+
override val highlights: String = HIGHLIGHTS
|
|
9
|
+
override val injections: String = INJECTIONS
|
|
10
|
+
|
|
11
|
+
private external fun nativeLanguage(): Long
|
|
12
|
+
|
|
13
|
+
companion object {
|
|
14
|
+
init {
|
|
15
|
+
System.loadLibrary("codepad_lang_kotlin")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private val HIGHLIGHTS: String = """; Identifiers
|
|
19
|
+
(simple_identifier) @variable
|
|
20
|
+
|
|
21
|
+
; `it` keyword inside lambdas
|
|
22
|
+
; FIXME: This will highlight the keyword outside of lambdas since tree-sitter
|
|
23
|
+
; does not allow us to check for arbitrary nestation
|
|
24
|
+
((simple_identifier) @variable.builtin
|
|
25
|
+
(#eq? @variable.builtin "it"))
|
|
26
|
+
|
|
27
|
+
; `field` keyword inside property getter/setter
|
|
28
|
+
; FIXME: This will highlight the keyword outside of getters and setters
|
|
29
|
+
; since tree-sitter does not allow us to check for arbitrary nestation
|
|
30
|
+
((simple_identifier) @variable.builtin
|
|
31
|
+
(#eq? @variable.builtin "field"))
|
|
32
|
+
|
|
33
|
+
[
|
|
34
|
+
"this"
|
|
35
|
+
"super"
|
|
36
|
+
"this@"
|
|
37
|
+
"super@"
|
|
38
|
+
] @variable.builtin
|
|
39
|
+
|
|
40
|
+
; NOTE: for consistency with "super@"
|
|
41
|
+
(super_expression
|
|
42
|
+
"@" @variable.builtin)
|
|
43
|
+
|
|
44
|
+
(class_parameter
|
|
45
|
+
(simple_identifier) @variable.member)
|
|
46
|
+
|
|
47
|
+
; NOTE: temporary fix for treesitter bug that causes delay in file opening
|
|
48
|
+
;(class_body
|
|
49
|
+
; (property_declaration
|
|
50
|
+
; (variable_declaration
|
|
51
|
+
; (simple_identifier) @variable.member)))
|
|
52
|
+
; id_1.id_2.id_3: `id_2` and `id_3` are assumed as object properties
|
|
53
|
+
(_
|
|
54
|
+
(navigation_suffix
|
|
55
|
+
(simple_identifier) @variable.member))
|
|
56
|
+
|
|
57
|
+
; SCREAMING CASE identifiers are assumed to be constants
|
|
58
|
+
((simple_identifier) @constant
|
|
59
|
+
(#match? @constant "^[A-Z][A-Z0-9_]*${'$'}"))
|
|
60
|
+
|
|
61
|
+
(_
|
|
62
|
+
(navigation_suffix
|
|
63
|
+
(simple_identifier) @constant
|
|
64
|
+
(#match? @constant "^[A-Z][A-Z0-9_]*${'$'}")))
|
|
65
|
+
|
|
66
|
+
(enum_entry
|
|
67
|
+
(simple_identifier) @constant)
|
|
68
|
+
|
|
69
|
+
(type_identifier) @type
|
|
70
|
+
|
|
71
|
+
; '?' operator, replacement for Java @Nullable
|
|
72
|
+
(nullable_type) @punctuation.special
|
|
73
|
+
|
|
74
|
+
(type_alias
|
|
75
|
+
(type_identifier) @type.definition)
|
|
76
|
+
|
|
77
|
+
((type_identifier) @type.builtin
|
|
78
|
+
(#any-of? @type.builtin
|
|
79
|
+
"Byte" "Short" "Int" "Long" "UByte" "UShort" "UInt" "ULong" "Float" "Double" "Boolean" "Char"
|
|
80
|
+
"String" "Array" "ByteArray" "ShortArray" "IntArray" "LongArray" "UByteArray" "UShortArray"
|
|
81
|
+
"UIntArray" "ULongArray" "FloatArray" "DoubleArray" "BooleanArray" "CharArray" "Map" "Set"
|
|
82
|
+
"List" "EmptyMap" "EmptySet" "EmptyList" "MutableMap" "MutableSet" "MutableList"))
|
|
83
|
+
|
|
84
|
+
(package_header
|
|
85
|
+
"package" @keyword
|
|
86
|
+
.
|
|
87
|
+
(identifier
|
|
88
|
+
(simple_identifier) @module))
|
|
89
|
+
|
|
90
|
+
(import_header
|
|
91
|
+
"import" @keyword.import)
|
|
92
|
+
|
|
93
|
+
(wildcard_import) @character.special
|
|
94
|
+
|
|
95
|
+
; The last `simple_identifier` in a `import_header` will always either be a function
|
|
96
|
+
; or a type. Classes can appear anywhere in the import path, unlike functions
|
|
97
|
+
(import_header
|
|
98
|
+
(identifier
|
|
99
|
+
(simple_identifier) @type @_import)
|
|
100
|
+
(import_alias
|
|
101
|
+
(type_identifier) @type.definition)?
|
|
102
|
+
(#match? @_import "^[A-Z]"))
|
|
103
|
+
|
|
104
|
+
(import_header
|
|
105
|
+
(identifier
|
|
106
|
+
(simple_identifier) @function @_import .)
|
|
107
|
+
(import_alias
|
|
108
|
+
(type_identifier) @function)?
|
|
109
|
+
(#match? @_import "^[a-z]"))
|
|
110
|
+
|
|
111
|
+
(label) @label
|
|
112
|
+
|
|
113
|
+
; Function definitions
|
|
114
|
+
(function_declaration
|
|
115
|
+
(simple_identifier) @function)
|
|
116
|
+
|
|
117
|
+
(getter
|
|
118
|
+
"get" @function.builtin)
|
|
119
|
+
|
|
120
|
+
(setter
|
|
121
|
+
"set" @function.builtin)
|
|
122
|
+
|
|
123
|
+
(primary_constructor) @constructor
|
|
124
|
+
|
|
125
|
+
(secondary_constructor
|
|
126
|
+
"constructor" @constructor)
|
|
127
|
+
|
|
128
|
+
(constructor_invocation
|
|
129
|
+
(user_type
|
|
130
|
+
(type_identifier) @constructor))
|
|
131
|
+
|
|
132
|
+
(anonymous_initializer
|
|
133
|
+
"init" @constructor)
|
|
134
|
+
|
|
135
|
+
(parameter
|
|
136
|
+
(simple_identifier) @variable.parameter)
|
|
137
|
+
|
|
138
|
+
(parameter_with_optional_type
|
|
139
|
+
(simple_identifier) @variable.parameter)
|
|
140
|
+
|
|
141
|
+
; lambda parameters
|
|
142
|
+
(lambda_literal
|
|
143
|
+
(lambda_parameters
|
|
144
|
+
(variable_declaration
|
|
145
|
+
(simple_identifier) @variable.parameter)))
|
|
146
|
+
|
|
147
|
+
; Function calls
|
|
148
|
+
; function()
|
|
149
|
+
(call_expression
|
|
150
|
+
.
|
|
151
|
+
(simple_identifier) @function.call)
|
|
152
|
+
|
|
153
|
+
; ::function
|
|
154
|
+
(callable_reference
|
|
155
|
+
.
|
|
156
|
+
(simple_identifier) @function.call)
|
|
157
|
+
|
|
158
|
+
; object.function() or object.property.function()
|
|
159
|
+
(call_expression
|
|
160
|
+
(navigation_expression
|
|
161
|
+
(navigation_suffix
|
|
162
|
+
(simple_identifier) @function.call) .))
|
|
163
|
+
|
|
164
|
+
(call_expression
|
|
165
|
+
.
|
|
166
|
+
(simple_identifier) @function.builtin
|
|
167
|
+
(#any-of? @function.builtin
|
|
168
|
+
"arrayOf" "arrayOfNulls" "byteArrayOf" "shortArrayOf" "intArrayOf" "longArrayOf" "ubyteArrayOf"
|
|
169
|
+
"ushortArrayOf" "uintArrayOf" "ulongArrayOf" "floatArrayOf" "doubleArrayOf" "booleanArrayOf"
|
|
170
|
+
"charArrayOf" "emptyArray" "mapOf" "setOf" "listOf" "emptyMap" "emptySet" "emptyList"
|
|
171
|
+
"mutableMapOf" "mutableSetOf" "mutableListOf" "print" "println" "error" "TODO" "run"
|
|
172
|
+
"runCatching" "repeat" "lazy" "lazyOf" "enumValues" "enumValueOf" "assert" "check"
|
|
173
|
+
"checkNotNull" "require" "requireNotNull" "with" "synchronized"))
|
|
174
|
+
|
|
175
|
+
; Literals
|
|
176
|
+
[
|
|
177
|
+
(line_comment)
|
|
178
|
+
(multiline_comment)
|
|
179
|
+
] @comment @spell
|
|
180
|
+
|
|
181
|
+
((multiline_comment) @comment.documentation
|
|
182
|
+
(#match? @comment.documentation "^/[*][*][^*].*[*]/${'$'}"))
|
|
183
|
+
|
|
184
|
+
(shebang_line) @keyword.directive
|
|
185
|
+
|
|
186
|
+
(real_literal) @number.float
|
|
187
|
+
|
|
188
|
+
[
|
|
189
|
+
(integer_literal)
|
|
190
|
+
(long_literal)
|
|
191
|
+
(hex_literal)
|
|
192
|
+
(bin_literal)
|
|
193
|
+
(unsigned_literal)
|
|
194
|
+
] @number
|
|
195
|
+
|
|
196
|
+
[
|
|
197
|
+
(null_literal)
|
|
198
|
+
; should be highlighted the same as booleans
|
|
199
|
+
(boolean_literal)
|
|
200
|
+
] @boolean
|
|
201
|
+
|
|
202
|
+
(character_literal) @character
|
|
203
|
+
|
|
204
|
+
(string_literal) @string
|
|
205
|
+
|
|
206
|
+
; NOTE: Escapes not allowed in multi-line strings
|
|
207
|
+
(character_literal
|
|
208
|
+
(character_escape_seq) @string.escape)
|
|
209
|
+
|
|
210
|
+
; There are 3 ways to define a regex
|
|
211
|
+
; - "[abc]?".toRegex()
|
|
212
|
+
(call_expression
|
|
213
|
+
(navigation_expression
|
|
214
|
+
(string_literal) @string.regexp
|
|
215
|
+
(navigation_suffix
|
|
216
|
+
((simple_identifier) @_function
|
|
217
|
+
(#eq? @_function "toRegex")))))
|
|
218
|
+
|
|
219
|
+
; - Regex("[abc]?")
|
|
220
|
+
(call_expression
|
|
221
|
+
((simple_identifier) @_function
|
|
222
|
+
(#eq? @_function "Regex"))
|
|
223
|
+
(call_suffix
|
|
224
|
+
(value_arguments
|
|
225
|
+
(value_argument
|
|
226
|
+
(string_literal) @string.regexp))))
|
|
227
|
+
|
|
228
|
+
; - Regex.fromLiteral("[abc]?")
|
|
229
|
+
(call_expression
|
|
230
|
+
(navigation_expression
|
|
231
|
+
((simple_identifier) @_class
|
|
232
|
+
(#eq? @_class "Regex"))
|
|
233
|
+
(navigation_suffix
|
|
234
|
+
((simple_identifier) @_function
|
|
235
|
+
(#eq? @_function "fromLiteral"))))
|
|
236
|
+
(call_suffix
|
|
237
|
+
(value_arguments
|
|
238
|
+
(value_argument
|
|
239
|
+
(string_literal) @string.regexp))))
|
|
240
|
+
|
|
241
|
+
; Keywords
|
|
242
|
+
(type_alias
|
|
243
|
+
"typealias" @keyword)
|
|
244
|
+
|
|
245
|
+
(companion_object
|
|
246
|
+
"companion" @keyword)
|
|
247
|
+
|
|
248
|
+
[
|
|
249
|
+
(class_modifier)
|
|
250
|
+
(member_modifier)
|
|
251
|
+
(function_modifier)
|
|
252
|
+
(property_modifier)
|
|
253
|
+
(platform_modifier)
|
|
254
|
+
(variance_modifier)
|
|
255
|
+
(parameter_modifier)
|
|
256
|
+
(visibility_modifier)
|
|
257
|
+
(reification_modifier)
|
|
258
|
+
(inheritance_modifier)
|
|
259
|
+
] @keyword.modifier
|
|
260
|
+
|
|
261
|
+
[
|
|
262
|
+
"val"
|
|
263
|
+
"var"
|
|
264
|
+
; "typeof" ; NOTE: It is reserved for future use
|
|
265
|
+
] @keyword
|
|
266
|
+
|
|
267
|
+
[
|
|
268
|
+
"enum"
|
|
269
|
+
"class"
|
|
270
|
+
"object"
|
|
271
|
+
"interface"
|
|
272
|
+
] @keyword.type
|
|
273
|
+
|
|
274
|
+
[
|
|
275
|
+
"return"
|
|
276
|
+
"return@"
|
|
277
|
+
] @keyword.return
|
|
278
|
+
|
|
279
|
+
"suspend" @keyword.coroutine
|
|
280
|
+
|
|
281
|
+
"fun" @keyword.function
|
|
282
|
+
|
|
283
|
+
[
|
|
284
|
+
"if"
|
|
285
|
+
"else"
|
|
286
|
+
"when"
|
|
287
|
+
] @keyword.conditional
|
|
288
|
+
|
|
289
|
+
[
|
|
290
|
+
"for"
|
|
291
|
+
"do"
|
|
292
|
+
"while"
|
|
293
|
+
"continue"
|
|
294
|
+
"continue@"
|
|
295
|
+
"break"
|
|
296
|
+
"break@"
|
|
297
|
+
] @keyword.repeat
|
|
298
|
+
|
|
299
|
+
[
|
|
300
|
+
"try"
|
|
301
|
+
"catch"
|
|
302
|
+
"throw"
|
|
303
|
+
"finally"
|
|
304
|
+
] @keyword.exception
|
|
305
|
+
|
|
306
|
+
(annotation
|
|
307
|
+
"@" @attribute
|
|
308
|
+
(use_site_target)? @attribute)
|
|
309
|
+
|
|
310
|
+
(annotation
|
|
311
|
+
(user_type
|
|
312
|
+
(type_identifier) @attribute))
|
|
313
|
+
|
|
314
|
+
(annotation
|
|
315
|
+
(constructor_invocation
|
|
316
|
+
(user_type
|
|
317
|
+
(type_identifier) @attribute)))
|
|
318
|
+
|
|
319
|
+
(file_annotation
|
|
320
|
+
"@" @attribute
|
|
321
|
+
"file" @attribute
|
|
322
|
+
":" @attribute)
|
|
323
|
+
|
|
324
|
+
(file_annotation
|
|
325
|
+
(user_type
|
|
326
|
+
(type_identifier) @attribute))
|
|
327
|
+
|
|
328
|
+
(file_annotation
|
|
329
|
+
(constructor_invocation
|
|
330
|
+
(user_type
|
|
331
|
+
(type_identifier) @attribute)))
|
|
332
|
+
|
|
333
|
+
; Operators & Punctuation
|
|
334
|
+
[
|
|
335
|
+
"!"
|
|
336
|
+
"!="
|
|
337
|
+
"!=="
|
|
338
|
+
"="
|
|
339
|
+
"=="
|
|
340
|
+
"==="
|
|
341
|
+
">"
|
|
342
|
+
">="
|
|
343
|
+
"<"
|
|
344
|
+
"<="
|
|
345
|
+
"||"
|
|
346
|
+
"&&"
|
|
347
|
+
"+"
|
|
348
|
+
"++"
|
|
349
|
+
"+="
|
|
350
|
+
"-"
|
|
351
|
+
"--"
|
|
352
|
+
"-="
|
|
353
|
+
"*"
|
|
354
|
+
"*="
|
|
355
|
+
"/"
|
|
356
|
+
"/="
|
|
357
|
+
"%"
|
|
358
|
+
"%="
|
|
359
|
+
"?."
|
|
360
|
+
"?:"
|
|
361
|
+
"!!"
|
|
362
|
+
"is"
|
|
363
|
+
"in"
|
|
364
|
+
"as"
|
|
365
|
+
"as?"
|
|
366
|
+
".."
|
|
367
|
+
"..<"
|
|
368
|
+
"->"
|
|
369
|
+
] @operator
|
|
370
|
+
|
|
371
|
+
[
|
|
372
|
+
"("
|
|
373
|
+
")"
|
|
374
|
+
"["
|
|
375
|
+
"]"
|
|
376
|
+
"{"
|
|
377
|
+
"}"
|
|
378
|
+
] @punctuation.bracket
|
|
379
|
+
|
|
380
|
+
[
|
|
381
|
+
"."
|
|
382
|
+
","
|
|
383
|
+
";"
|
|
384
|
+
":"
|
|
385
|
+
"::"
|
|
386
|
+
] @punctuation.delimiter
|
|
387
|
+
|
|
388
|
+
(super_expression
|
|
389
|
+
[
|
|
390
|
+
"<"
|
|
391
|
+
">"
|
|
392
|
+
] @punctuation.delimiter)
|
|
393
|
+
|
|
394
|
+
(type_arguments
|
|
395
|
+
[
|
|
396
|
+
"<"
|
|
397
|
+
">"
|
|
398
|
+
] @punctuation.delimiter)
|
|
399
|
+
|
|
400
|
+
(type_parameters
|
|
401
|
+
[
|
|
402
|
+
"<"
|
|
403
|
+
">"
|
|
404
|
+
] @punctuation.delimiter)
|
|
405
|
+
|
|
406
|
+
; NOTE: `interpolated_identifier`s can be highlighted in any way
|
|
407
|
+
(string_literal
|
|
408
|
+
(interpolation_expression_start) @punctuation.special
|
|
409
|
+
(interpolated_expression) @none
|
|
410
|
+
(interpolation_expression_end) @punctuation.special)
|
|
411
|
+
"""
|
|
412
|
+
private val INJECTIONS: String = """([
|
|
413
|
+
(line_comment)
|
|
414
|
+
(multiline_comment)
|
|
415
|
+
] @injection.content
|
|
416
|
+
(#set! injection.language "comment"))
|
|
417
|
+
|
|
418
|
+
; There are 3 ways to define a regex
|
|
419
|
+
; - "[abc]?".toRegex()
|
|
420
|
+
(call_expression
|
|
421
|
+
(navigation_expression
|
|
422
|
+
((string_literal
|
|
423
|
+
(string_content) @injection.content)
|
|
424
|
+
(#set! injection.language "regex"))
|
|
425
|
+
(navigation_suffix
|
|
426
|
+
((simple_identifier) @_function
|
|
427
|
+
(#eq? @_function "toRegex")))))
|
|
428
|
+
|
|
429
|
+
; - Regex("[abc]?")
|
|
430
|
+
(call_expression
|
|
431
|
+
((simple_identifier) @_function
|
|
432
|
+
(#eq? @_function "Regex"))
|
|
433
|
+
(call_suffix
|
|
434
|
+
(value_arguments
|
|
435
|
+
(value_argument
|
|
436
|
+
(string_literal
|
|
437
|
+
(string_content) @injection.content)
|
|
438
|
+
(#set! injection.language "regex")))))
|
|
439
|
+
|
|
440
|
+
; - Regex.fromLiteral("[abc]?")
|
|
441
|
+
(call_expression
|
|
442
|
+
(navigation_expression
|
|
443
|
+
((simple_identifier) @_class
|
|
444
|
+
(#eq? @_class "Regex"))
|
|
445
|
+
(navigation_suffix
|
|
446
|
+
((simple_identifier) @_function
|
|
447
|
+
(#eq? @_function "fromLiteral"))))
|
|
448
|
+
(call_suffix
|
|
449
|
+
(value_arguments
|
|
450
|
+
(value_argument
|
|
451
|
+
(string_literal
|
|
452
|
+
(string_content) @injection.content)
|
|
453
|
+
(#set! injection.language "regex")))))
|
|
454
|
+
|
|
455
|
+
; "pi = %.2f".format(3.14159)
|
|
456
|
+
((call_expression
|
|
457
|
+
(navigation_expression
|
|
458
|
+
(string_literal
|
|
459
|
+
(string_content) @injection.content)
|
|
460
|
+
(navigation_suffix
|
|
461
|
+
(simple_identifier) @_method)))
|
|
462
|
+
(#eq? @_method "format")
|
|
463
|
+
(#set! injection.language "printf"))
|
|
464
|
+
"""
|
|
465
|
+
}
|
|
466
|
+
}
|
package/grammar/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 fwcd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|