diff options
author | Merlin Volkmer <49447733+Meerschwein@users.noreply.github.com> | 2023-01-04 19:49:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-04 19:49:31 +0100 |
commit | b2320c423ba37e02a9867839c13d5eab4d5b4d33 (patch) | |
tree | 425dedb81aaefa2d0d9b64679828f4444392250e /plugins/language_nix.lua | |
parent | 350cbc7e50e30f00b479062e5295fbdd45cc843f (diff) | |
download | lite-xl-plugins-b2320c423ba37e02a9867839c13d5eab4d5b4d33.tar.gz lite-xl-plugins-b2320c423ba37e02a9867839c13d5eab4d5b4d33.zip |
add language_nix (#189)
* add language_nix
* formatting and a tweak to paths
* add string escaping
* add manifest entry
* fix search paths
* remove unnecessary string escaping
* remove entry in README
* simplify comments
Diffstat (limited to 'plugins/language_nix.lua')
-rw-r--r-- | plugins/language_nix.lua | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/plugins/language_nix.lua b/plugins/language_nix.lua new file mode 100644 index 0000000..149c2fa --- /dev/null +++ b/plugins/language_nix.lua @@ -0,0 +1,87 @@ +-- mod-version:3 +-- https://nixos.wiki/wiki/Overview_of_the_Nix_Language +local syntax = require "core.syntax" + +local function merge_tables(a, b) + for _, v in pairs(b) do + table.insert(a, v) + end +end + +local default_symbols = { + ["import"] = "keyword2", + ["with"] = "keyword2", + ["builtins"] = "keyword2", + ["inherit"] = "keyword2", + ["assert"] = "keyword2", + ["let"] = "keyword2", + ["in"] = "keyword2", + ["rec"] = "keyword2", + ["if"] = "keyword", + ["else"] = "keyword", + ["then"] = "keyword", + ["true"] = "literal", + ["false"] = "literal", + ["null"] = "literal", +} + +local default_patterns = {} + +local string_interpolation = { + { pattern = {"%${", "}"}, type = "keyword2", syntax = { + patterns = default_patterns, + symbols = default_symbols, + }}, + { pattern = "[%S][%w]*", type = "string" }, +} + +merge_tables(default_patterns, { + { pattern = "#.*", type = "comment" }, + { pattern = {"/%*", "%*/"}, type = "comment" }, + { pattern = "-?%.?%d+", type = "number" }, + + -- interpolation + { pattern = {"%${", "}"}, type = "keyword2", syntax = { + patterns = default_patterns, + symbols = default_symbols, + }}, + { pattern = {'"', '"', '\\'}, type = "string", syntax = { + patterns = string_interpolation, + symbols = {}, + }}, + { pattern = {"''", "''"}, type = "string", syntax = { + patterns = string_interpolation, + symbols = {}, + }}, + + -- operators + { pattern = "[%+%-%?!>%*]", type = "operator" }, + { pattern = "/ ", type = "operator" }, + { pattern = "< ", type = "operator" }, + { pattern = "//", type = "operator" }, + { pattern = "&&", type = "operator" }, + { pattern = "%->", type = "operator" }, + { pattern = "||", type = "operator" }, + { pattern = "==", type = "operator" }, + { pattern = "!=", type = "operator" }, + { pattern = ">=", type = "operator" }, + { pattern = "<=", type = "operator" }, + + -- paths (function because its not used otherwise) + { pattern = "%.?%.?/[^%s%[%]%(%){};,:]+", type = "function" }, + { pattern = "~/[^%s%[%]%(%){};,:]+", type = "function" }, + { pattern = {"<", ">"}, type = "function" }, + + -- every other symbol + { pattern = "[%a%-%_][%w%-%_]*", type = "symbol" }, + { pattern = ";%.,:", type = "normal" }, +}) + +syntax.add { + name = "Nix", + files = {"%.nix$"}, + comment = "#", + block_comment = {"/*", "*/"}, + patterns = default_patterns, + symbols = default_symbols, +} |