diff options
-rw-r--r-- | manifest.json | 13 | ||||
-rw-r--r-- | plugins/language_kotlin.lua | 123 |
2 files changed, 135 insertions, 1 deletions
diff --git a/manifest.json b/manifest.json index b4bb072..fc2a09c 100644 --- a/manifest.json +++ b/manifest.json @@ -113,6 +113,7 @@ "language_json": {}, "language_jsx": {}, "language_julia": {}, + "language_kotlin": {}, "language_lilypond": {}, "language_liquid": {}, "language_lobster": {}, @@ -164,7 +165,7 @@ "id": "meta_languages", "mod_version": "3", "type": "meta", - "version": "0.1.14" + "version": "0.1.15" }, { "description": "Align multiple carets and selections *([clip](https://user-images.githubusercontent.com/2798487/165631951-532f8d24-d596-4dd0-9d21-ff53c71ed32f.mp4))*", @@ -1161,6 +1162,16 @@ "version": "0.1" }, { + "description": "Syntax for the [Kotlin](https://kotlinlang.org/docs/home.html) programming language", + "id": "language_kotlin", + "mod_version": "3", + "path": "plugins/language_kotlin.lua", + "tags": [ + "language" + ], + "version": "0.1" + }, + { "checksum": "08a9f8635b09a98cec9dfca8bb65f24fd7b6585c7e8308773e7ddff9a3e5a60f", "description": "Syntax for [Kaitai](http://kaitai.io/) struct files", "id": "language_ksy", diff --git a/plugins/language_kotlin.lua b/plugins/language_kotlin.lua new file mode 100644 index 0000000..288ba34 --- /dev/null +++ b/plugins/language_kotlin.lua @@ -0,0 +1,123 @@ +-- mod-version:3 +local syntax = require "core.syntax" + +syntax.add { + name = "Kotlin", + files = { "%.kt$" }, + comment = "//", + block_comment = { "/*", "*/" }, + patterns = { + { pattern = "//.*", type = "comment" }, -- Comment, single-line + { pattern = { "/%*", "%*/" }, type = "comment" }, -- Comment, multi-line + { pattern = { '"', '"', '\\' }, type = "string" }, -- String, quotation marks + { pattern = { "'", "'", '\\' }, type = "string" }, -- String, apices + { pattern = "'\\x%x?%x?%x?%x'", type = "string" }, -- Character hexadecimal escape sequence + { pattern = "'\\u%x%x%x%x'", type = "string" }, -- Character unicode escape sequence + { pattern = "'\\?.'", type = "string" }, -- Character literal + { pattern = "-?0x%x+", type = "number" }, -- ? + { pattern = "-?%d+[%deE]*f?", type = "number" }, -- ? + { pattern = "-?%.?%d+f?", type = "number" }, -- ? + { regex = [[\-\>(?=\s)]], type = "operator" }, -- Lambda + { regex = [[\.{2}\<?\s?(?=[\\-]?[a-z0-9])]], type = "operator" }, -- Range operators + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- Operators + { regex = [[\?(?=\.)]], type = "operator" }, -- ?. operator + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- Function/Method/Class + { regex = [[let(?=\s\{)]], type = "function" }, -- ? operator + { regex = [[\?\:(?=\s?)]], type = "operator" }, -- elvis operator + { regex = [[this(?=\.?\@?)]], type = "keyword" }, -- this keyword + { regex = "\\@\\w+", type = "keyword2" }, -- Annotations + { regex = [[[a-zA-Z]+\@(?=\s?[a-zA-Z])]], type = "keyword2" }, -- Annotations (this pattern is lower priority than the `this keyword` pattern) + { regex = "[A-Z][A-Z_]+", type = "keyword2" }, -- Constants, FULL UPPERCASE + { pattern = "import()%s+()[%w_.]+", type = { "keyword", "normal", "normal" } }, + { pattern = "[%a_][%w_]*", type = "symbol" }, -- ? + }, + symbols = { + -- Hard keywords + ["as"] = "keyword", + ["break"] = "keyword", + ["class"] = "keyword", + ["continue"] = "keyword", + ["do"] = "keyword", + ["else"] = "keyword", + ["for"] = "keyword", + ["fun"] = "keyword", + ["if"] = "keyword", + ["in"] = "keyword", + ["!in"] = "keyword", + ["interface"] = "keyword", + ["is"] = "keyword", + ["!is"] = "keyword", + ["object"] = "keyword", + ["package"] = "keyword", + ["return"] = "keyword", + ["super"] = "keyword", + ["this"] = "keyword", + ["throw"] = "keyword", + ["try"] = "keyword", + ["typealias"] = "keyword", + ["typeof"] = "keyword", + ["val"] = "keyword", + ["var"] = "keyword", + ["when"] = "keyword", + ["while"] = "keyword", + + -- Soft keywords + ["by"] = "keyword", + ["catch"] = "keyword", + ["constructor"] = "keyword", + ["delegate"] = "keyword", + ["dynamic"] = "keyword", + ["field"] = "keyword", + ["file"] = "keyword", + ["finally"] = "keyword", + ["get"] = "keyword", + ["import"] = "keyword", + ["init"] = "keyword", + ["param"] = "keyword", + ["property"] = "keyword", + ["receiver"] = "keyword", + ["set"] = "keyword", + ["setparam"] = "keyword", + ["value"] = "keyword", + ["where"] = "keyword", + + -- Modifier keywords + ["abstract"] = "keyword", + ["actual"] = "keyword", + ["annotation"] = "keyword", + ["companion"] = "keyword", + ["const"] = "keyword", + ["crossinline"] = "keyword", + ["data"] = "keyword", + ["enum"] = "keyword", + ["expect"] = "keyword", + ["external"] = "keyword", + ["final"] = "keyword", + ["inline"] = "keyword", + ["inner"] = "keyword", + ["infix"] = "keyword", + ["internal"] = "keyword", + ["lateinit"] = "keyword", + ["noinline"] = "keyword", + ["open"] = "keyword", + ["operator"] = "keyword", + ["out"] = "keyword", + ["override"] = "keyword", + ["private"] = "keyword", + ["protected"] = "keyword", + ["public"] = "keyword", + ["reified"] = "keyword", + ["sealed"] = "keyword", + ["suspend"] = "keyword", + ["tailrec"] = "keyword", + ["vararg"] = "keyword", + + -- Special identifiers + ["it"] = "keyword", + + -- Boolean + ["true"] = "literal", + ["false"] = "literal", + ["null"] = "literal", + }, +} |