To: vim_dev@googlegroups.com Subject: Patch 8.2.4948 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4948 Problem: Cannot use Perl heredoc in nested :def function. (Virginia Senioria) Solution: Only concatenate heredoc lines when not in a nested function. (closes #10415) Files: src/userfunc.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.4947/src/userfunc.c 2022-05-09 20:09:19.294641425 +0100 --- src/userfunc.c 2022-05-13 13:49:20.462560859 +0100 *************** *** 1051,1103 **** skip_until = vim_strnsave(p, skiptowhite(p) - p); getline_options = GETLINE_NONE; is_heredoc = TRUE; ! if (eap->cmdidx == CMD_def) heredoc_concat_len = newlines->ga_len + 1; } ! // 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] =='<'); ! if (!found) ! // skip over the argument after "cmd" ! arg = skipwhite(skiptowhite(arg)); ! if (found || (arg[0] == '=' && arg[1] == '<' && arg[2] =='<' ! && (checkforcmd(&p, "let", 2) ! || checkforcmd(&p, "var", 3) ! || checkforcmd(&p, "final", 5) ! || checkforcmd(&p, "const", 5)))) ! { ! p = skipwhite(arg + 3); ! while (TRUE) { ! if (STRNCMP(p, "trim", 4) == 0) { ! // Ignore leading white space. ! p = skipwhite(p + 4); ! 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; } - skip_until = vim_strnsave(p, skiptowhite(p) - p); - getline_options = GETLINE_NONE; - is_heredoc = TRUE; } } } --- 1051,1107 ---- skip_until = vim_strnsave(p, skiptowhite(p) - p); getline_options = GETLINE_NONE; is_heredoc = TRUE; ! if (eap->cmdidx == CMD_def && nesting == 0) heredoc_concat_len = newlines->ga_len + 1; } ! if (!is_heredoc) { ! // 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] =='<'); ! if (!found) ! // skip over the argument after "cmd" ! arg = skipwhite(skiptowhite(arg)); ! if (found || (arg[0] == '=' && arg[1] == '<' ! && arg[2] =='<' ! && (checkforcmd(&p, "let", 2) ! || checkforcmd(&p, "var", 3) ! || checkforcmd(&p, "final", 5) ! || checkforcmd(&p, "const", 5)))) { ! p = skipwhite(arg + 3); ! while (TRUE) { ! if (STRNCMP(p, "trim", 4) == 0) ! { ! // Ignore leading white space. ! p = skipwhite(p + 4); ! 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; } ! skip_until = vim_strnsave(p, skiptowhite(p) - p); ! getline_options = GETLINE_NONE; ! is_heredoc = TRUE; } } } } *** ../vim-8.2.4947/src/testdir/test_vim9_func.vim 2022-05-07 21:14:01.642973330 +0100 --- src/testdir/test_vim9_func.vim 2022-05-13 13:48:43.446331611 +0100 *************** *** 4155,4159 **** --- 4155,4177 ---- enddef 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-8.2.4947/src/version.c 2022-05-13 12:41:39.469488941 +0100 --- src/version.c 2022-05-13 13:45:49.945278257 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4948, /**/ -- hundred-and-one symptoms of being an internet addict: 188. You purchase a laptop so you can surf while sitting on the can. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///