diff options
author | carrexxii <154758622+carrexxii@users.noreply.github.com> | 2024-07-04 17:33:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-04 17:33:26 +0200 |
commit | 4e867a309271f69a0f5a7bba13832a86552405da (patch) | |
tree | 77834f5317c2a759245a4ba55bda317668e2d05b | |
parent | 086c31541366e2d4d3027764d572572348d812de (diff) | |
download | lite-xl-plugins-4e867a309271f69a0f5a7bba13832a86552405da.tar.gz lite-xl-plugins-4e867a309271f69a0f5a7bba13832a86552405da.zip |
Add Nim string interpolation syntax highlighting (#448)
* Add Nim string interpolation syntax highlighting
* Use frontier matches
* Bump version number for language_nim
-rw-r--r-- | manifest.json | 2 | ||||
-rw-r--r-- | plugins/language_nim.lua | 27 |
2 files changed, 26 insertions, 3 deletions
diff --git a/manifest.json b/manifest.json index 5b60f9f..da44c61 100644 --- a/manifest.json +++ b/manifest.json @@ -1311,7 +1311,7 @@ "tags": [ "language" ], - "version": "0.1" + "version": "0.2" }, { "description": "Syntax for the [Nix](https://nixos.wiki/wiki/Overview_of_the_Nix_Language) expression language", diff --git a/plugins/language_nim.lua b/plugins/language_nim.lua index d7726d1..425544e 100644 --- a/plugins/language_nim.lua +++ b/plugins/language_nim.lua @@ -88,14 +88,37 @@ for _, type in ipairs(standard_generic_types) do table.insert(patterns, { pattern = type.." +%f[%w]", type = "keyword2" }) end +local function string_pattern(start, stop, syntax) + return { + pattern = { start, stop, '\\' }, + type = "string", + syntax = syntax and { + patterns = syntax, + symbols = {}, + } or nil + } +end + +local interpolation_syntax = { + { pattern = { '{{', '}}' }, type = "string" }, + { pattern = { '{', '}', '\\' }, type = "keyword2", syntax = ".nim" }, + { pattern = "[%S][%w]*", type = "string" }, +} + local user_patterns = { -- comments { pattern = { "##?%[", "]##?" }, type = "comment" }, { pattern = "##?.-\n", type = "comment" }, -- strings and chars - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { '"""', '"""[^"]' }, type = "string" }, { pattern = { "'", "'", '\\' }, type = "literal" }, + string_pattern('"""', '"""%f[^"]'), + string_pattern('"' , '"' ), + string_pattern('\\"', '\\"' ), -- For highlighting strings inside iterpolated blocks + -- string interpolation + string_pattern('%&"""' , '"""%f[^"]', interpolation_syntax), + string_pattern('fmt"""', '"""%f[^"]', interpolation_syntax), + string_pattern('%&"' , '"' , interpolation_syntax), + string_pattern('fmt"' , '"' , interpolation_syntax), -- function calls { pattern = "[a-zA-Z][a-zA-Z0-9_]*%f[(]", type = "function" }, -- identifiers |