mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Problem: Cannot use Perl heredoc in nested :def function. (Virginia Senioria) Solution: Only concatenate heredoc lines when not in a nested function. (closes #10415)
This commit is contained in:
@@ -4155,5 +4155,23 @@ if has('lua')
|
|||||||
enddef
|
enddef
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if has('perl')
|
||||||
|
def Test_perl_heredoc_nested()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def F(): string
|
||||||
|
def G(): string
|
||||||
|
perl << EOF
|
||||||
|
EOF
|
||||||
|
return 'done'
|
||||||
|
enddef
|
||||||
|
return G()
|
||||||
|
enddef
|
||||||
|
assert_equal('done', F())
|
||||||
|
END
|
||||||
|
v9.CheckScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
||||||
|
@@ -1051,53 +1051,57 @@ get_function_body(
|
|||||||
skip_until = vim_strnsave(p, skiptowhite(p) - p);
|
skip_until = vim_strnsave(p, skiptowhite(p) - p);
|
||||||
getline_options = GETLINE_NONE;
|
getline_options = GETLINE_NONE;
|
||||||
is_heredoc = TRUE;
|
is_heredoc = TRUE;
|
||||||
if (eap->cmdidx == CMD_def)
|
if (eap->cmdidx == CMD_def && nesting == 0)
|
||||||
heredoc_concat_len = newlines->ga_len + 1;
|
heredoc_concat_len = newlines->ga_len + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for ":cmd v =<< [trim] EOF"
|
if (!is_heredoc)
|
||||||
// and ":cmd [a, b] =<< [trim] EOF"
|
|
||||||
// and "lines =<< [trim] EOF" for Vim9
|
|
||||||
// Where "cmd" can be "let", "var", "final" or "const".
|
|
||||||
arg = skipwhite(skiptowhite(p));
|
|
||||||
if (*arg == '[')
|
|
||||||
arg = vim_strchr(arg, ']');
|
|
||||||
if (arg != NULL)
|
|
||||||
{
|
{
|
||||||
int found = (eap->cmdidx == CMD_def && arg[0] == '='
|
// Check for ":cmd v =<< [trim] EOF"
|
||||||
|
// and ":cmd [a, b] =<< [trim] EOF"
|
||||||
|
// and "lines =<< [trim] EOF" for Vim9
|
||||||
|
// Where "cmd" can be "let", "var", "final" or "const".
|
||||||
|
arg = skipwhite(skiptowhite(p));
|
||||||
|
if (*arg == '[')
|
||||||
|
arg = vim_strchr(arg, ']');
|
||||||
|
if (arg != NULL)
|
||||||
|
{
|
||||||
|
int found = (eap->cmdidx == CMD_def && arg[0] == '='
|
||||||
&& arg[1] == '<' && arg[2] =='<');
|
&& arg[1] == '<' && arg[2] =='<');
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
// skip over the argument after "cmd"
|
// skip over the argument after "cmd"
|
||||||
arg = skipwhite(skiptowhite(arg));
|
arg = skipwhite(skiptowhite(arg));
|
||||||
if (found || (arg[0] == '=' && arg[1] == '<' && arg[2] =='<'
|
if (found || (arg[0] == '=' && arg[1] == '<'
|
||||||
&& (checkforcmd(&p, "let", 2)
|
&& arg[2] =='<'
|
||||||
|| checkforcmd(&p, "var", 3)
|
&& (checkforcmd(&p, "let", 2)
|
||||||
|| checkforcmd(&p, "final", 5)
|
|| checkforcmd(&p, "var", 3)
|
||||||
|| checkforcmd(&p, "const", 5))))
|
|| checkforcmd(&p, "final", 5)
|
||||||
{
|
|| checkforcmd(&p, "const", 5))))
|
||||||
p = skipwhite(arg + 3);
|
|
||||||
while (TRUE)
|
|
||||||
{
|
{
|
||||||
if (STRNCMP(p, "trim", 4) == 0)
|
p = skipwhite(arg + 3);
|
||||||
|
while (TRUE)
|
||||||
{
|
{
|
||||||
// Ignore leading white space.
|
if (STRNCMP(p, "trim", 4) == 0)
|
||||||
p = skipwhite(p + 4);
|
{
|
||||||
heredoc_trimmed = vim_strnsave(theline,
|
// Ignore leading white space.
|
||||||
skipwhite(theline) - theline);
|
p = skipwhite(p + 4);
|
||||||
continue;
|
heredoc_trimmed = vim_strnsave(theline,
|
||||||
|
skipwhite(theline) - theline);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (STRNCMP(p, "eval", 4) == 0)
|
||||||
|
{
|
||||||
|
// Ignore leading white space.
|
||||||
|
p = skipwhite(p + 4);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (STRNCMP(p, "eval", 4) == 0)
|
skip_until = vim_strnsave(p, skiptowhite(p) - p);
|
||||||
{
|
getline_options = GETLINE_NONE;
|
||||||
// Ignore leading white space.
|
is_heredoc = TRUE;
|
||||||
p = skipwhite(p + 4);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
skip_until = vim_strnsave(p, skiptowhite(p) - p);
|
|
||||||
getline_options = GETLINE_NONE;
|
|
||||||
is_heredoc = TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -746,6 +746,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4948,
|
||||||
/**/
|
/**/
|
||||||
4947,
|
4947,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user