Mercurial > vim
diff src/vim9compile.c @ 24533:9c404d78d767 v8.2.2806
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Commit: https://github.com/vim/vim/commit/bdc0f1c6986e5d64f647e0924a4de795b47c549a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 24 19:08:24 2021 +0200
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Problem: Vim9: using "++nr" as a command might not work.
Solution: Do not recognize "++" and "--" in a following line as addition or
subtraction.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 24 Apr 2021 19:15:04 +0200 |
parents | 3bfec39ce31c |
children | 3a290891a015 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -4688,6 +4688,10 @@ compile_expr5(char_u **arg, cctx_T *cctx op = may_peek_next_line(cctx, *arg, &next); if (*op != '+' && *op != '-' && !(*op == '.' && *(op + 1) == '.')) break; + if (op[0] == op[1] && *op != '.' && next) + // Finding "++" or "--" on the next line is a separate command. + // But ".." is concatenation. + break; oplen = (*op == '.' ? 2 : 1); if (next != NULL) { @@ -6395,6 +6399,7 @@ compile_assign_unlet( * "const name = expr" * "name = expr" * "arg" points to "name". + * "++arg" and "--arg" * Return NULL for an error. * Return "arg" if it does not look like a variable list. */ @@ -6413,6 +6418,7 @@ compile_assignment(char_u *arg, exarg_T char_u *op; int oplen = 0; int heredoc = FALSE; + int incdec = FALSE; type_T *rhs_type = &t_any; char_u *sp; int is_decl = is_decl_command(cmdidx); @@ -6447,6 +6453,12 @@ compile_assignment(char_u *arg, exarg_T error_white_both(op, oplen); return NULL; } + if (eap->cmdidx == CMD_increment || eap->cmdidx == CMD_decrement) + { + op = (char_u *)(eap->cmdidx == CMD_increment ? "+=" : "-="); + oplen = 2; + incdec = TRUE; + } if (heredoc) { @@ -6571,23 +6583,31 @@ compile_assignment(char_u *arg, exarg_T goto theend; } - // Compile the expression. Temporarily hide the new local - // variable here, it is not available to this expression. - if (lhs.lhs_new_local) - --cctx->ctx_locals.ga_len; + // Compile the expression. instr_count = instr->ga_len; - wp = op + oplen; - if (may_get_next_line_error(wp, &p, cctx) == FAIL) + if (incdec) + { + r = generate_PUSHNR(cctx, 1); + } + else { + // Temporarily hide the new local variable here, it is + // not available to this expression. + if (lhs.lhs_new_local) + --cctx->ctx_locals.ga_len; + wp = op + oplen; + if (may_get_next_line_error(wp, &p, cctx) == FAIL) + { + if (lhs.lhs_new_local) + ++cctx->ctx_locals.ga_len; + goto theend; + } + r = compile_expr0_ext(&p, cctx, &is_const); if (lhs.lhs_new_local) ++cctx->ctx_locals.ga_len; - goto theend; + if (r == FAIL) + goto theend; } - r = compile_expr0_ext(&p, cctx, &is_const); - if (lhs.lhs_new_local) - ++cctx->ctx_locals.ga_len; - if (r == FAIL) - goto theend; } else if (semicolon && var_idx == var_count - 1) { @@ -9018,9 +9038,11 @@ compile_def_function( /* * COMMAND after range * 'text'->func() should not be confused with 'a mark + * "++nr" and "--nr" are eval commands */ cmd = ea.cmd; - if (*cmd != '\'' || starts_with_colon) + if (starts_with_colon || !(*cmd == '\'' + || (cmd[0] == cmd[1] && (*cmd == '+' || *cmd == '-')))) { ea.cmd = skip_range(ea.cmd, TRUE, NULL); if (ea.cmd > cmd) @@ -9125,6 +9147,8 @@ compile_def_function( case CMD_var: case CMD_final: case CMD_const: + case CMD_increment: + case CMD_decrement: line = compile_assignment(p, &ea, ea.cmdidx, &cctx); if (line == p) line = NULL;