aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/bash.lua
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2020-12-01 11:21:05 +0100
committerMarc André Tanner <mat@brain-dump.org>2020-12-01 11:21:05 +0100
commit52fbef0d664279692db074067b7441e79058ee3c (patch)
tree6329d15b160e28dabf753d9da3e6e3ff2030bf3a /lua/lexers/bash.lua
parenta970f6315af20d2c76aee23336149d2dc0da23e6 (diff)
parentf4f0f5b22a2e52bd0391ee7f6cd4b99c98028fe9 (diff)
downloadvis-52fbef0d664279692db074067b7441e79058ee3c.tar.gz
vis-52fbef0d664279692db074067b7441e79058ee3c.tar.xz
Merge branch 's-0-bash-heredoc' of https://github.com/silasdb/vis
Diffstat (limited to 'lua/lexers/bash.lua')
-rw-r--r--lua/lexers/bash.lua14
1 files changed, 11 insertions, 3 deletions
diff --git a/lua/lexers/bash.lua b/lua/lexers/bash.lua
index 207cb22..4dc4cf6 100644
--- a/lua/lexers/bash.lua
+++ b/lua/lexers/bash.lua
@@ -18,10 +18,18 @@ local sq_str = l.delimited_range("'", false, true)
local dq_str = l.delimited_range('"')
local ex_str = l.delimited_range('`')
local heredoc = '<<' * P(function(input, index)
- local s, e, _, delimiter =
- input:find('%-?(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', index)
+ local s, e, minus, _, delimiter =
+ input:find('(-?)(["\']?)([%a_][%w_]*)%2[\n\r\f;]+', index)
+ -- If the starting delimiter of a here-doc begins with "-", then
+ -- spaces are allowed to come before the closing delimiter.
+ local close_pattern
+ if minus == '-' then
+ close_pattern = '[\n\r\f%s]+'..delimiter..'\n'
+ else
+ close_pattern = '[\n\r\f]+'..delimiter..'\n'
+ end
if s == index and delimiter then
- local _, e = input:find('[\n\r\f]+'..delimiter..'\n', e)
+ local _, e = input:find(close_pattern, e)
return e and e + 1 or #input + 1
end
end)