diff options
author | PerilousBooklet <raffaele.orabona@protonmail.com> | 2024-04-20 19:42:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-20 19:42:17 +0200 |
commit | 7e246005baa6ea4232de5c0665fe1f32744a5d4c (patch) | |
tree | f5a9d96aecaa8e9ac8f3688d18e842a0975a518b /plugins | |
parent | 92c0069ae603fa9cc8dc3493570aab55d1f753ee (diff) | |
download | lite-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>
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/language_kotlin.lua | 123 |
1 files changed, 123 insertions, 0 deletions
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", + }, +} |