comparison src/userfunc.c @ 28850:338212bba072 v8.2.4948

patch 8.2.4948: cannot use Perl heredoc in nested :def function Commit: https://github.com/vim/vim/commit/d881d1598467d88808bafd2fa86982ebbca7dcc1 Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 13 13:50:36 2022 +0100 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)
author Bram Moolenaar <Bram@vim.org>
date Fri, 13 May 2022 15:00:03 +0200
parents d0241e74bfdb
children a712ea475390
comparison
equal deleted inserted replaced
28849:be5bc2060ee8 28850:338212bba072
1049 skip_until = vim_strsave((char_u *)"."); 1049 skip_until = vim_strsave((char_u *)".");
1050 else 1050 else
1051 skip_until = vim_strnsave(p, skiptowhite(p) - p); 1051 skip_until = vim_strnsave(p, skiptowhite(p) - p);
1052 getline_options = GETLINE_NONE; 1052 getline_options = GETLINE_NONE;
1053 is_heredoc = TRUE; 1053 is_heredoc = TRUE;
1054 if (eap->cmdidx == CMD_def) 1054 if (eap->cmdidx == CMD_def && nesting == 0)
1055 heredoc_concat_len = newlines->ga_len + 1; 1055 heredoc_concat_len = newlines->ga_len + 1;
1056 } 1056 }
1057 1057
1058 // Check for ":cmd v =<< [trim] EOF" 1058 if (!is_heredoc)
1059 // and ":cmd [a, b] =<< [trim] EOF" 1059 {
1060 // and "lines =<< [trim] EOF" for Vim9 1060 // Check for ":cmd v =<< [trim] EOF"
1061 // Where "cmd" can be "let", "var", "final" or "const". 1061 // and ":cmd [a, b] =<< [trim] EOF"
1062 arg = skipwhite(skiptowhite(p)); 1062 // and "lines =<< [trim] EOF" for Vim9
1063 if (*arg == '[') 1063 // Where "cmd" can be "let", "var", "final" or "const".
1064 arg = vim_strchr(arg, ']'); 1064 arg = skipwhite(skiptowhite(p));
1065 if (arg != NULL) 1065 if (*arg == '[')
1066 { 1066 arg = vim_strchr(arg, ']');
1067 int found = (eap->cmdidx == CMD_def && arg[0] == '=' 1067 if (arg != NULL)
1068 {
1069 int found = (eap->cmdidx == CMD_def && arg[0] == '='
1068 && arg[1] == '<' && arg[2] =='<'); 1070 && arg[1] == '<' && arg[2] =='<');
1069 1071
1070 if (!found) 1072 if (!found)
1071 // skip over the argument after "cmd" 1073 // skip over the argument after "cmd"
1072 arg = skipwhite(skiptowhite(arg)); 1074 arg = skipwhite(skiptowhite(arg));
1073 if (found || (arg[0] == '=' && arg[1] == '<' && arg[2] =='<' 1075 if (found || (arg[0] == '=' && arg[1] == '<'
1074 && (checkforcmd(&p, "let", 2) 1076 && arg[2] =='<'
1075 || checkforcmd(&p, "var", 3) 1077 && (checkforcmd(&p, "let", 2)
1076 || checkforcmd(&p, "final", 5) 1078 || checkforcmd(&p, "var", 3)
1077 || checkforcmd(&p, "const", 5)))) 1079 || checkforcmd(&p, "final", 5)
1078 { 1080 || checkforcmd(&p, "const", 5))))
1079 p = skipwhite(arg + 3);
1080 while (TRUE)
1081 { 1081 {
1082 if (STRNCMP(p, "trim", 4) == 0) 1082 p = skipwhite(arg + 3);
1083 while (TRUE)
1083 { 1084 {
1084 // Ignore leading white space. 1085 if (STRNCMP(p, "trim", 4) == 0)
1085 p = skipwhite(p + 4); 1086 {
1086 heredoc_trimmed = vim_strnsave(theline, 1087 // Ignore leading white space.
1087 skipwhite(theline) - theline); 1088 p = skipwhite(p + 4);
1088 continue; 1089 heredoc_trimmed = vim_strnsave(theline,
1090 skipwhite(theline) - theline);
1091 continue;
1092 }
1093 if (STRNCMP(p, "eval", 4) == 0)
1094 {
1095 // Ignore leading white space.
1096 p = skipwhite(p + 4);
1097 continue;
1098 }
1099 break;
1089 } 1100 }
1090 if (STRNCMP(p, "eval", 4) == 0) 1101 skip_until = vim_strnsave(p, skiptowhite(p) - p);
1091 { 1102 getline_options = GETLINE_NONE;
1092 // Ignore leading white space. 1103 is_heredoc = TRUE;
1093 p = skipwhite(p + 4);
1094 continue;
1095 }
1096 break;
1097 } 1104 }
1098 skip_until = vim_strnsave(p, skiptowhite(p) - p);
1099 getline_options = GETLINE_NONE;
1100 is_heredoc = TRUE;
1101 } 1105 }
1102 } 1106 }
1103 } 1107 }
1104 1108
1105 // Add the line to the function. 1109 // Add the line to the function.