aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorjgmdev <jgmdev@gmail.com>2022-03-01 22:05:46 -0400
committerjgmdev <jgmdev@gmail.com>2022-03-01 22:06:50 -0400
commit05a871c163bbdb2281e6390c3230ff0fa53ecef9 (patch)
tree8316203d9f3052e1d52160b22a0f0430ce58967d /plugins
parent0b71e55c2f2b7599175b7a549f57cda301e165d4 (diff)
downloadlite-xl-plugins-05a871c163bbdb2281e6390c3230ff0fa53ecef9.tar.gz
lite-xl-plugins-05a871c163bbdb2281e6390c3230ff0fa53ecef9.zip
language_sh: imported some patterns from language_pkgbuild to support coloring function, variable declarations and more
Diffstat (limited to 'plugins')
-rw-r--r--plugins/language_sh.lua46
1 files changed, 33 insertions, 13 deletions
diff --git a/plugins/language_sh.lua b/plugins/language_sh.lua
index ce92f19..fdfe867 100644
--- a/plugins/language_sh.lua
+++ b/plugins/language_sh.lua
@@ -9,17 +9,38 @@ syntax.add {
patterns = {
-- $# is a bash special variable and the '#' shouldn't be interpreted
-- as a comment.
- { pattern = "$[%a_@*#][%w_]*", type = "keyword2" },
- { pattern = "${.-}", type = "keyword2" },
- { pattern = "#.*\n", type = "comment" },
- { pattern = [[\.]], type = "normal" },
- { pattern = { '"', '"', '\\' }, type = "string" },
- { pattern = { "'", "'", '\\' }, type = "string" },
- { pattern = { '`', '`', '\\' }, type = "string" },
- { pattern = "%f[%w_][%d%.]+%f[^%w_]", type = "number" },
- { pattern = "[!<>|&%[%]=*]", type = "operator" },
- { pattern = "%f[%S]%-[%w%-_]+", type = "function" },
- { pattern = "[%a_][%w_]*", type = "symbol" },
+ { pattern = "$[%a_@*#][%w_]*", type = "keyword2" },
+ -- Comments
+ { pattern = "#.*\n", type = "comment" },
+ -- Strings
+ { pattern = { '"', '"', '\\' }, type = "string" },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = { '`', '`', '\\' }, type = "string" },
+ -- Ignore numbers that start with dots or slashes
+ { pattern = "%f[%w_%.%/]%d[%d%.]*%f[^%w_%.]", type = "number" },
+ -- Operators
+ { pattern = "[!<>|&%[%]:=*]", type = "operator" },
+ -- Match parameters
+ { pattern = "%f[%S][%+%-][%w%-_:]+", type = "function" },
+ { pattern = "%f[%S][%+%-][%w%-_]+%f[=]", type = "function" },
+ -- Prevent parameters with assignments from been matched as variables
+ {
+ pattern = "%s%-%a[%w_%-]*%s+()%d[%d%.]+",
+ type = { "function", "number" }
+ },
+ {
+ pattern = "%s%-%a[%w_%-]*%s+()%a[%a%-_:=]+",
+ type = { "function", "symbol" }
+ },
+ -- Match variable assignments
+ { pattern = "[_%a][%w_]+%f[%+=]", type = "keyword2" },
+ -- Match variable expansions
+ { pattern = "${.-}", type = "keyword2" },
+ { pattern = "$[%d$%a_@*][%w_]*", type = "keyword2" },
+ -- Functions
+ { pattern = "[%a_%-][%w_%-]*[%s]*%f[(]", type = "function" },
+ -- Everything else
+ { pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["case"] = "keyword",
@@ -71,8 +92,7 @@ syntax.add {
["unalias"] = "keyword",
["unset"] = "keyword",
["true"] = "literal",
- ["false"] = "literal",
- [":"] = "literal"
+ ["false"] = "literal"
}
}