From 4e867a309271f69a0f5a7bba13832a86552405da Mon Sep 17 00:00:00 2001 From: carrexxii <154758622+carrexxii@users.noreply.github.com> Date: Thu, 4 Jul 2024 17:33:26 +0200 Subject: Add Nim string interpolation syntax highlighting (#448) * Add Nim string interpolation syntax highlighting * Use frontier matches * Bump version number for language_nim --- manifest.json | 2 +- 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 -- cgit v1.2.3