comparison src/ex_docmd.c @ 21130:4a1e8086759b v8.2.1116

patch 8.2.1116: Vim9: parsing command checks for list twice Commit: https://github.com/vim/vim/commit/d2ef6b320bf2e2f3fcc0bb858b16898e6f74b4d9 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 2 21:11:34 2020 +0200 patch 8.2.1116: Vim9: parsing command checks for list twice Problem: Vim9: parsing command checks for list twice. Solution: Adjust how a command is parsed.
author Bram Moolenaar <Bram@vim.org>
date Thu, 02 Jul 2020 21:15:05 +0200
parents 839ace6773aa
children 96ae8622cfb6
comparison
equal deleted inserted replaced
21129:9a40ce00f714 21130:4a1e8086759b
3217 /* 3217 /*
3218 * Recognize a Vim9 script function/method call and assignment: 3218 * Recognize a Vim9 script function/method call and assignment:
3219 * "lvar = value", "lvar(arg)", "[1, 2 3]->Func()" 3219 * "lvar = value", "lvar(arg)", "[1, 2 3]->Func()"
3220 */ 3220 */
3221 p = eap->cmd; 3221 p = eap->cmd;
3222 if (lookup != NULL && (*p == '(' || *p == '[' || *p == '{' 3222 if (lookup != NULL && (*p == '(' || *p == '{'
3223 || ((p = to_name_const_end(eap->cmd)) > eap->cmd && *p != NUL))) 3223 || ((p = to_name_const_end(eap->cmd)) > eap->cmd && *p != NUL)
3224 || *p == '['))
3224 { 3225 {
3225 int oplen; 3226 int oplen;
3226 int heredoc; 3227 int heredoc;
3227 3228
3228 // "funcname(" is always a function call. 3229 // "funcname(" is always a function call.
3231 // "varname->expr" is an expression. 3232 // "varname->expr" is an expression.
3232 // "(..." is an expression. 3233 // "(..." is an expression.
3233 // "{..." is an dict expression. 3234 // "{..." is an dict expression.
3234 if (*p == '(' 3235 if (*p == '('
3235 || *p == '{' 3236 || *p == '{'
3237 || (*p == '[' && p > eap->cmd)
3236 || p[1] == ':' 3238 || p[1] == ':'
3237 || (*p == '-' && p[1] == '>')) 3239 || (*p == '-' && p[1] == '>'))
3240 {
3241 eap->cmdidx = CMD_eval;
3242 return eap->cmd;
3243 }
3244
3245 // "[...]->Method()" is a list expression, but "[a, b] = Func()" is
3246 // an assignment.
3247 // If there is no line break inside the "[...]" then "p" is advanced to
3248 // after the "]" by to_name_const_end(): check if a "=" follows.
3249 // If "[...]" has a line break "p" still points at the "[" and it can't
3250 // be an assignment.
3251 if (*eap->cmd == '[' && (p == eap->cmd || *skipwhite(p) != '='))
3238 { 3252 {
3239 eap->cmdidx = CMD_eval; 3253 eap->cmdidx = CMD_eval;
3240 return eap->cmd; 3254 return eap->cmd;
3241 } 3255 }
3242 3256
3250 || lookup(eap->cmd, p - eap->cmd, cctx) != NULL) 3264 || lookup(eap->cmd, p - eap->cmd, cctx) != NULL)
3251 { 3265 {
3252 eap->cmdidx = CMD_let; 3266 eap->cmdidx = CMD_let;
3253 return eap->cmd; 3267 return eap->cmd;
3254 } 3268 }
3255 }
3256
3257 // "[...]->Method()" is a list expression. But "[a, b] = Func()" is
3258 // an assignment.
3259 if (*p == '[' && (eval_list(&p, NULL, NULL, FALSE) == FAIL
3260 || *skipwhite(p) != '='))
3261 {
3262 eap->cmdidx = CMD_eval;
3263 return eap->cmd;
3264 } 3269 }
3265 } 3270 }
3266 #endif 3271 #endif
3267 3272
3268 /* 3273 /*