aboutsummaryrefslogtreecommitdiff
path: root/plugins/language_sh.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/language_sh.lua')
-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"
}
}