aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerilousBooklet <raffaele.orabona@protonmail.com>2024-04-20 19:42:17 +0200
committerGitHub <noreply@github.com>2024-04-20 19:42:17 +0200
commit7e246005baa6ea4232de5c0665fe1f32744a5d4c (patch)
treef5a9d96aecaa8e9ac8f3688d18e842a0975a518b
parent92c0069ae603fa9cc8dc3493570aab55d1f753ee (diff)
downloadlite-xl-plugins-7e246005baa6ea4232de5c0665fe1f32744a5d4c.tar.gz
lite-xl-plugins-7e246005baa6ea4232de5c0665fe1f32744a5d4c.zip
Add Kotlin syntax highlighting support. (#406)
* WIP: added basic syntax highlighting for Kotlin. * WIP: added a few more patterns. * Fixed overcomplicated single-line comment pattern. * Fixed source syntax docs address. * Realigned single-line comment pattern. * Added .. and ..< operators and new FIX. * WIP: working on range operator patterns. * Some more adjustments. * Removed comment. * Fixed double dots left-adiacent to number being colored as number and fixed lambda color. * Update plugins/language_kotlin.lua Co-authored-by: Guldoman <giulio.lettieri@gmail.com> * Updated to use raw strings in the annotations and this patterns. * Added block_comment. * Fixed types indentation. * Achieved perfection.. * Added patterns for $ after var and let function * Added elvis operator. * Added pattern. * Fixed elvis operator. * Achieved true perfection. * Added entry to meta-languages package. * Bumped meta_languages version. * Bumped meta_languages version and added second _. * Update plugins/language_kotlin.lua Co-authored-by: Guldoman <giulio.lettieri@gmail.com> * Updated the range operator pattern. * Update plugins/language_kotlin.lua Co-authored-by: Guldoman <giulio.lettieri@gmail.com> * Update plugins/language_kotlin.lua Co-authored-by: Guldoman <giulio.lettieri@gmail.com> * Update plugins/language_kotlin.lua Co-authored-by: Guldoman <giulio.lettieri@gmail.com> * Fixed last patterns and tidied up a bit. --------- Co-authored-by: Guldoman <giulio.lettieri@gmail.com>
-rw-r--r--manifest.json13
-rw-r--r--plugins/language_kotlin.lua123
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",
+ },
+}