diff --git a/manifest.json b/manifest.json index 68a69ee1..2bcf7b53 100644 --- a/manifest.json +++ b/manifest.json @@ -1541,7 +1541,7 @@ "tags": [ "language" ], - "version": "0.2" + "version": "0.3" }, { "description": "Syntax for ssh & sshd config files", diff --git a/plugins/language_sh.lua b/plugins/language_sh.lua index f8cf5521..8f38ca8d 100644 --- a/plugins/language_sh.lua +++ b/plugins/language_sh.lua @@ -1,21 +1,41 @@ -- mod-version:3 local syntax = require "core.syntax" +local expansion_syntax = { + name = "Shell script parameter expansion", + symbols = {} +} +expansion_syntax.patterns = { + { pattern = { "%${", "}", "\\" }, type = "keyword2", syntax = expansion_syntax }, + { pattern = "[^%$}]+", type = "string" }, + { pattern = "[%$}]", type = "string" }, +} + +local string_syntax = { + name = "Shell script string", + patterns = { + { pattern = { "%${", "}", "\\" }, type = "keyword2", syntax = expansion_syntax }, + { pattern = '[^%$"]+', type = "string" }, + { pattern = '[%$"]', type = "string" }, + }, + symbols = {} +} + syntax.add { name = "Shell script", - files = { "%.sh$", "%.bash$", "^%.bashrc$", "^%.bash_profile$", "^%.profile$", "%.zsh$", "%.fish$" }, - headers = "^#!.*bin.*sh\n", + files = { "%.sh$", "%.bash$", "%.bashrc$", "%.bash_profile$", "%.profile$", "%.zprofile$", "%.zsh$", "%.zshrc$", "%.fish$" }, + headers = "^#!.*bin.*sh", comment = "#", patterns = { -- $# is a bash special variable and the '#' shouldn't be interpreted -- as a comment. { pattern = "$[%a_@*#][%w_]*", type = "keyword2" }, -- Comments - { pattern = "#.*\n", type = "comment" }, + { pattern = "#.*", type = "comment" }, -- Strings - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { "'", "'", '\\' }, type = "string" }, - { pattern = { '`', '`', '\\' }, type = "string" }, + { pattern = { '"', '"', '\\' }, type = "string", syntax = string_syntax }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = { '`', '`', '\\' }, type = "string", syntax = ".sh" }, -- Ignore numbers that start with dots or slashes { pattern = "%f[%w_%.%/]%d[%d%.]*%f[^%w_%.]", type = "number" }, -- Operators @@ -35,7 +55,7 @@ syntax.add { -- Match variable assignments { pattern = "[_%a][%w_]+%f[%+=]", type = "keyword2" }, -- Match variable expansions - { pattern = "${.-}", type = "keyword2" }, + { pattern = { "${", "}", '\\' }, type = "keyword2", syntax = expansion_syntax }, { pattern = "$[%d$%a_@*][%w_]*", type = "keyword2" }, -- Functions { pattern = "[%a_%-][%w_%-]*[%s]*%f[(]", type = "function" }, @@ -95,4 +115,3 @@ syntax.add { ["false"] = "literal" } } -