vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 38e1df0953be8cc5e29c53ebbab3756d3863dbf1
parent f84df43acc61a8bd1af8265a2839874bd7ae8904
Author: Silas <silas_git@nocafe.net>
Date:   Fri, 27 Nov 2020 22:07:58 -0300

Heredocs with "-" can have spaces before closing

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

Diffstat:
Mlua/lexers/bash.lua | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git 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)