Mercurial > vim
diff src/vim9compile.c @ 20013:bf377a9ffccb v8.2.0562
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Commit: https://github.com/vim/vim/commit/9c7e6dd653b62f54324f3c00d69cb348d8611a9f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 12 20:55:20 2020 +0200
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Problem: Vim9: cannot split an expression into multiple lines.
Solution: Continue in next line after an operator.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Apr 2020 21:00:06 +0200 |
parents | 628011800942 |
children | c001ee73519a |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -2070,6 +2070,24 @@ next_line_from_context(cctx_T *cctx) } /* + * If "*arg" is at the end of the line, advance to the next line. + * Return FAIL if beyond the last line, "*arg" is unmodified then. + */ + static int +may_get_next_line(char_u **arg, cctx_T *cctx) +{ + if (**arg == NUL) + { + char_u *next = next_line_from_context(cctx); + + if (next == NULL) + return FAIL; + *arg = skipwhite(next); + } + return OK; +} + +/* * Generate an instruction to load script-local variable "name", without the * leading "s:". * Also finds imported variables. @@ -3394,14 +3412,17 @@ compile_expr6(char_u **arg, cctx_T *cctx op = skipwhite(*arg); if (*op != '*' && *op != '/' && *op != '%') break; - if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(op[1])) + if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[1])) { char_u buf[3]; vim_strncpy(buf, op, 1); semsg(_(e_white_both), buf); + return FAIL; } *arg = skipwhite(op + 1); + if (may_get_next_line(arg, cctx) == FAIL) + return FAIL; // get the second variable if (compile_expr7(arg, cctx) == FAIL) @@ -3438,15 +3459,18 @@ compile_expr5(char_u **arg, cctx_T *cctx break; oplen = (*op == '.' ? 2 : 1); - if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(op[oplen])) + if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[oplen])) { char_u buf[3]; vim_strncpy(buf, op, oplen); semsg(_(e_white_both), buf); + return FAIL; } *arg = skipwhite(op + oplen); + if (may_get_next_line(arg, cctx) == FAIL) + return FAIL; // get the second variable if (compile_expr6(arg, cctx) == FAIL) @@ -3572,16 +3596,20 @@ compile_expr4(char_u **arg, cctx_T *cctx ++len; // nothing appended: match case - if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(p[len])) + if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[len])) { char_u buf[7]; vim_strncpy(buf, p, len); semsg(_(e_white_both), buf); + return FAIL; } // get the second variable *arg = skipwhite(p + len); + if (may_get_next_line(arg, cctx) == FAIL) + return FAIL; + if (compile_expr5(arg, cctx) == FAIL) return FAIL; @@ -3611,8 +3639,11 @@ compile_and_or(char_u **arg, cctx_T *cct ga_init2(&end_ga, sizeof(int), 10); while (p[0] == opchar && p[1] == opchar) { - if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(p[2])) + if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[2])) + { semsg(_(e_white_both), op); + return FAIL; + } if (ga_grow(&end_ga, 1) == FAIL) { @@ -3626,6 +3657,9 @@ compile_and_or(char_u **arg, cctx_T *cct // eval the next expression *arg = skipwhite(p + 2); + if (may_get_next_line(arg, cctx) == FAIL) + return FAIL; + if ((opchar == '|' ? compile_expr3(arg, cctx) : compile_expr4(arg, cctx)) == FAIL) { @@ -3726,13 +3760,19 @@ compile_expr1(char_u **arg, cctx_T *cct type_T *type1; type_T *type2; - if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(p[1])) + if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1])) + { semsg(_(e_white_both), "?"); + return FAIL; + } generate_JUMP(cctx, JUMP_IF_FALSE, 0); // evaluate the second expression; any type is accepted *arg = skipwhite(p + 1); + if (may_get_next_line(arg, cctx) == FAIL) + return FAIL; + if (compile_expr1(arg, cctx) == FAIL) return FAIL; @@ -3754,11 +3794,17 @@ compile_expr1(char_u **arg, cctx_T *cct emsg(_(e_missing_colon)); return FAIL; } - if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(p[1])) + if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1])) + { semsg(_(e_white_both), ":"); + return FAIL; + } // evaluate the third expression *arg = skipwhite(p + 1); + if (may_get_next_line(arg, cctx) == FAIL) + return FAIL; + if (compile_expr1(arg, cctx) == FAIL) return FAIL;