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 --- plugins/language_nim.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'plugins/language_nim.lua') 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