vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 8d150bdf772ce549d7175cad96cfb2f0c4c190f6 parent 5a9352d04471a1b6f030c0997fedf112b76b395b Author: Silas <silas_git@nocafe.net> Date: Tue, 8 Dec 2020 17:37:43 -0300 lexers: fix bug in bash lexer for last here-doc 38e1df0 allowed "<<-EOF" heredocs to be parsed correctly, but it introduced a bug that made the lexer fail when the beginning of a here-doc was the last string in a file (optionally followed only by blanks). In order to fix this, move everything regarding "delimiter" within the block that is executed only if "delimiter" is not nil. Diffstat:
| M | lua/lexers/bash.lua | | | 16 | ++++++++-------- |
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/lua/lexers/bash.lua b/lua/lexers/bash.lua @@ -20,15 +20,15 @@ local ex_str = l.delimited_range('`') local heredoc = '<<' * P(function(input, 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 + -- 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 local _, e = input:find(close_pattern, e) return e and e + 1 or #input + 1 end