comparison src/ex_eval.c @ 21459:a422bd80b434 v8.2.1280

patch 8.2.1280: Ex command error cannot contain an argument Commit: https://github.com/vim/vim/commit/8930caaa1a283092aca81fdbc3fcf15c7eadb197 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 23 16:37:03 2020 +0200 patch 8.2.1280: Ex command error cannot contain an argument Problem: Ex command error cannot contain an argument. Solution: Add ex_errmsg() and translate earlier. Use e_trailing_arg where possible.
author Bram Moolenaar <Bram@vim.org>
date Thu, 23 Jul 2020 16:45:03 +0200
parents b0baa80cb53f
children 4dfd00f481fb
comparison
equal deleted inserted replaced
21458:5b12080761da 21459:a422bd80b434
915 int skip; 915 int skip;
916 int result; 916 int result;
917 cstack_T *cstack = eap->cstack; 917 cstack_T *cstack = eap->cstack;
918 918
919 if (cstack->cs_idx == CSTACK_LEN - 1) 919 if (cstack->cs_idx == CSTACK_LEN - 1)
920 eap->errmsg = N_("E579: :if nesting too deep"); 920 eap->errmsg = _("E579: :if nesting too deep");
921 else 921 else
922 { 922 {
923 ++cstack->cs_idx; 923 ++cstack->cs_idx;
924 cstack->cs_flags[cstack->cs_idx] = 0; 924 cstack->cs_flags[cstack->cs_idx] = 0;
925 925
951 { 951 {
952 did_endif = TRUE; 952 did_endif = TRUE;
953 if (eap->cstack->cs_idx < 0 953 if (eap->cstack->cs_idx < 0
954 || (eap->cstack->cs_flags[eap->cstack->cs_idx] 954 || (eap->cstack->cs_flags[eap->cstack->cs_idx]
955 & (CSF_WHILE | CSF_FOR | CSF_TRY))) 955 & (CSF_WHILE | CSF_FOR | CSF_TRY)))
956 eap->errmsg = N_(e_endif_without_if); 956 eap->errmsg = _(e_endif_without_if);
957 else 957 else
958 { 958 {
959 /* 959 /*
960 * When debugging or a breakpoint was encountered, display the debug 960 * When debugging or a breakpoint was encountered, display the debug
961 * prompt (if not already done). This shows the user that an ":endif" 961 * prompt (if not already done). This shows the user that an ":endif"
995 || (cstack->cs_flags[cstack->cs_idx] 995 || (cstack->cs_flags[cstack->cs_idx]
996 & (CSF_WHILE | CSF_FOR | CSF_TRY))) 996 & (CSF_WHILE | CSF_FOR | CSF_TRY)))
997 { 997 {
998 if (eap->cmdidx == CMD_else) 998 if (eap->cmdidx == CMD_else)
999 { 999 {
1000 eap->errmsg = N_(e_else_without_if); 1000 eap->errmsg = _(e_else_without_if);
1001 return; 1001 return;
1002 } 1002 }
1003 eap->errmsg = N_(e_elseif_without_if); 1003 eap->errmsg = _(e_elseif_without_if);
1004 skip = TRUE; 1004 skip = TRUE;
1005 } 1005 }
1006 else if (cstack->cs_flags[cstack->cs_idx] & CSF_ELSE) 1006 else if (cstack->cs_flags[cstack->cs_idx] & CSF_ELSE)
1007 { 1007 {
1008 if (eap->cmdidx == CMD_else) 1008 if (eap->cmdidx == CMD_else)
1009 { 1009 {
1010 eap->errmsg = N_("E583: multiple :else"); 1010 eap->errmsg = _("E583: multiple :else");
1011 return; 1011 return;
1012 } 1012 }
1013 eap->errmsg = N_("E584: :elseif after :else"); 1013 eap->errmsg = _("E584: :elseif after :else");
1014 skip = TRUE; 1014 skip = TRUE;
1015 } 1015 }
1016 1016
1017 // if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it 1017 // if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it
1018 if (skip || cstack->cs_flags[cstack->cs_idx] & CSF_TRUE) 1018 if (skip || cstack->cs_flags[cstack->cs_idx] & CSF_TRUE)
1074 int skip; 1074 int skip;
1075 int result; 1075 int result;
1076 cstack_T *cstack = eap->cstack; 1076 cstack_T *cstack = eap->cstack;
1077 1077
1078 if (cstack->cs_idx == CSTACK_LEN - 1) 1078 if (cstack->cs_idx == CSTACK_LEN - 1)
1079 eap->errmsg = N_("E585: :while/:for nesting too deep"); 1079 eap->errmsg = _("E585: :while/:for nesting too deep");
1080 else 1080 else
1081 { 1081 {
1082 /* 1082 /*
1083 * The loop flag is set when we have jumped back from the matching 1083 * The loop flag is set when we have jumped back from the matching
1084 * ":endwhile" or ":endfor". When not set, need to initialise this 1084 * ":endwhile" or ":endfor". When not set, need to initialise this
1184 { 1184 {
1185 int idx; 1185 int idx;
1186 cstack_T *cstack = eap->cstack; 1186 cstack_T *cstack = eap->cstack;
1187 1187
1188 if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) 1188 if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0)
1189 eap->errmsg = N_(e_continue); 1189 eap->errmsg = _(e_continue);
1190 else 1190 else
1191 { 1191 {
1192 // Try to find the matching ":while". This might stop at a try 1192 // Try to find the matching ":while". This might stop at a try
1193 // conditional not in its finally clause (which is then to be executed 1193 // conditional not in its finally clause (which is then to be executed
1194 // next). Therefor, inactivate all conditionals except the ":while" 1194 // next). Therefor, inactivate all conditionals except the ":while"
1222 { 1222 {
1223 int idx; 1223 int idx;
1224 cstack_T *cstack = eap->cstack; 1224 cstack_T *cstack = eap->cstack;
1225 1225
1226 if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) 1226 if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0)
1227 eap->errmsg = N_(e_break); 1227 eap->errmsg = _(e_break);
1228 else 1228 else
1229 { 1229 {
1230 // Inactivate conditionals until the matching ":while" or a try 1230 // Inactivate conditionals until the matching ":while" or a try
1231 // conditional not in its finally clause (which is then to be 1231 // conditional not in its finally clause (which is then to be
1232 // executed next) is found. In the latter case, make the ":break" 1232 // executed next) is found. In the latter case, make the ":break"
1262 err = e_for; 1262 err = e_for;
1263 csf = CSF_FOR; 1263 csf = CSF_FOR;
1264 } 1264 }
1265 1265
1266 if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) 1266 if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0)
1267 eap->errmsg = err; 1267 eap->errmsg = _(err);
1268 else 1268 else
1269 { 1269 {
1270 fl = cstack->cs_flags[cstack->cs_idx]; 1270 fl = cstack->cs_flags[cstack->cs_idx];
1271 if (!(fl & csf)) 1271 if (!(fl & csf))
1272 { 1272 {
1278 eap->errmsg = _("E733: Using :endwhile with :for"); 1278 eap->errmsg = _("E733: Using :endwhile with :for");
1279 } 1279 }
1280 if (!(fl & (CSF_WHILE | CSF_FOR))) 1280 if (!(fl & (CSF_WHILE | CSF_FOR)))
1281 { 1281 {
1282 if (!(fl & CSF_TRY)) 1282 if (!(fl & CSF_TRY))
1283 eap->errmsg = e_endif; 1283 eap->errmsg = _(e_endif);
1284 else if (fl & CSF_FINALLY) 1284 else if (fl & CSF_FINALLY)
1285 eap->errmsg = e_endtry; 1285 eap->errmsg = _(e_endtry);
1286 // Try to find the matching ":while" and report what's missing. 1286 // Try to find the matching ":while" and report what's missing.
1287 for (idx = cstack->cs_idx; idx > 0; --idx) 1287 for (idx = cstack->cs_idx; idx > 0; --idx)
1288 { 1288 {
1289 fl = cstack->cs_flags[idx]; 1289 fl = cstack->cs_flags[idx];
1290 if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) 1290 if ((fl & CSF_TRY) && !(fl & CSF_FINALLY))
1291 { 1291 {
1292 // Give up at a try conditional not in its finally clause. 1292 // Give up at a try conditional not in its finally clause.
1293 // Ignore the ":endwhile"/":endfor". 1293 // Ignore the ":endwhile"/":endfor".
1294 eap->errmsg = err; 1294 eap->errmsg = _(err);
1295 return; 1295 return;
1296 } 1296 }
1297 if (fl & csf) 1297 if (fl & csf)
1298 break; 1298 break;
1299 } 1299 }
1445 { 1445 {
1446 int skip; 1446 int skip;
1447 cstack_T *cstack = eap->cstack; 1447 cstack_T *cstack = eap->cstack;
1448 1448
1449 if (cstack->cs_idx == CSTACK_LEN - 1) 1449 if (cstack->cs_idx == CSTACK_LEN - 1)
1450 eap->errmsg = N_("E601: :try nesting too deep"); 1450 eap->errmsg = _("E601: :try nesting too deep");
1451 else 1451 else
1452 { 1452 {
1453 ++cstack->cs_idx; 1453 ++cstack->cs_idx;
1454 ++cstack->cs_trylevel; 1454 ++cstack->cs_trylevel;
1455 cstack->cs_flags[cstack->cs_idx] = CSF_TRY; 1455 cstack->cs_flags[cstack->cs_idx] = CSF_TRY;
1524 cstack_T *cstack = eap->cstack; 1524 cstack_T *cstack = eap->cstack;
1525 char_u *pat; 1525 char_u *pat;
1526 1526
1527 if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) 1527 if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0)
1528 { 1528 {
1529 eap->errmsg = e_catch; 1529 eap->errmsg = _(e_catch);
1530 give_up = TRUE; 1530 give_up = TRUE;
1531 } 1531 }
1532 else 1532 else
1533 { 1533 {
1534 if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) 1534 if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
1543 break; 1543 break;
1544 if (cstack->cs_flags[idx] & CSF_FINALLY) 1544 if (cstack->cs_flags[idx] & CSF_FINALLY)
1545 { 1545 {
1546 // Give up for a ":catch" after ":finally" and ignore it. 1546 // Give up for a ":catch" after ":finally" and ignore it.
1547 // Just parse. 1547 // Just parse.
1548 eap->errmsg = N_("E604: :catch after :finally"); 1548 eap->errmsg = _("E604: :catch after :finally");
1549 give_up = TRUE; 1549 give_up = TRUE;
1550 } 1550 }
1551 else 1551 else
1552 rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, 1552 rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
1553 &cstack->cs_looplevel); 1553 &cstack->cs_looplevel);
1683 int skip = FALSE; 1683 int skip = FALSE;
1684 int pending = CSTP_NONE; 1684 int pending = CSTP_NONE;
1685 cstack_T *cstack = eap->cstack; 1685 cstack_T *cstack = eap->cstack;
1686 1686
1687 if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) 1687 if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0)
1688 eap->errmsg = e_finally; 1688 eap->errmsg = _(e_finally);
1689 else 1689 else
1690 { 1690 {
1691 if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) 1691 if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
1692 { 1692 {
1693 eap->errmsg = get_end_emsg(cstack); 1693 eap->errmsg = get_end_emsg(cstack);
1703 idx = cstack->cs_idx; 1703 idx = cstack->cs_idx;
1704 1704
1705 if (cstack->cs_flags[idx] & CSF_FINALLY) 1705 if (cstack->cs_flags[idx] & CSF_FINALLY)
1706 { 1706 {
1707 // Give up for a multiple ":finally" and ignore it. 1707 // Give up for a multiple ":finally" and ignore it.
1708 eap->errmsg = e_finally_dup; 1708 eap->errmsg = _(e_finally_dup);
1709 return; 1709 return;
1710 } 1710 }
1711 rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, 1711 rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
1712 &cstack->cs_looplevel); 1712 &cstack->cs_looplevel);
1713 1713
1812 int pending = CSTP_NONE; 1812 int pending = CSTP_NONE;
1813 void *rettv = NULL; 1813 void *rettv = NULL;
1814 cstack_T *cstack = eap->cstack; 1814 cstack_T *cstack = eap->cstack;
1815 1815
1816 if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) 1816 if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0)
1817 eap->errmsg = e_no_endtry; 1817 eap->errmsg = _(e_no_endtry);
1818 else 1818 else
1819 { 1819 {
1820 /* 1820 /*
1821 * Don't do something after an error, interrupt or throw in the try 1821 * Don't do something after an error, interrupt or throw in the try
1822 * block, catch clause, or finally clause preceding this ":endtry" or 1822 * block, catch clause, or finally clause preceding this ":endtry" or
2274 */ 2274 */
2275 static char * 2275 static char *
2276 get_end_emsg(cstack_T *cstack) 2276 get_end_emsg(cstack_T *cstack)
2277 { 2277 {
2278 if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) 2278 if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE)
2279 return e_endwhile; 2279 return _(e_endwhile);
2280 if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) 2280 if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR)
2281 return e_endfor; 2281 return _(e_endfor);
2282 return e_endif; 2282 return _(e_endif);
2283 } 2283 }
2284 2284
2285 2285
2286 /* 2286 /*
2287 * Rewind conditionals until index "idx" is reached. "cond_type" and 2287 * Rewind conditionals until index "idx" is reached. "cond_type" and