aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifest.json2
-rw-r--r--plugins/language_nim.lua27
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