Skip to content

Commit

Permalink
Heredocs with "-" can have spaces before closing
Browse files Browse the repository at this point in the history
If a here-doc start delimiter begins with "-", then spaces are allowed
to come before the closing delimiter.

This patch fixes what would otherwise be parsed incorrectly:

	<<-EOF
	....
		EOF
  • Loading branch information
silasdb committed Nov 28, 2020
1 parent 01eef9f commit f4f0f5b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lua/lexers/bash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f4f0f5b

Please sign in to comment.