To: vim_dev@googlegroups.com Subject: Patch 8.2.1045 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1045 Problem: Vim9: line break before operator does not work. Solution: Peek the next line for an operator. Files: src/vim9compile.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.1044/src/vim9compile.c 2020-06-22 23:02:14.769942569 +0200 --- src/vim9compile.c 2020-06-23 22:23:27.045930096 +0200 *************** *** 2414,2419 **** --- 2414,2440 ---- } /* + * Called when checking for a following operator at "arg". When the rest of + * the line is empty or only a comment, peek the next line. If there is a next + * line return a pointer to it and set "nextp". + * Otherwise skip over white space. + */ + static char_u * + may_peek_next_line(cctx_T *cctx, char_u *arg, char_u **nextp) + { + char_u *p = skipwhite(arg); + + *nextp = NULL; + if (*p == NUL || (VIM_ISWHITE(*arg) && comment_start(p))) + { + *nextp = peek_next_line(cctx); + if (*nextp != NULL) + return *nextp; + } + return p; + } + + /* * Get the next line of the function from "cctx". * Skips over empty lines. Skips over comment lines if "skip_comment" is TRUE. * Returns NULL when at the end. *************** *** 3947,3952 **** --- 3968,3974 ---- compile_expr6(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) { char_u *op; + char_u *next; int ppconst_used = ppconst->pp_used; // get the first expression *************** *** 3958,3966 **** */ for (;;) { ! op = skipwhite(*arg); if (*op != '*' && *op != '/' && *op != '%') break; if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[1])) { --- 3980,3993 ---- */ for (;;) { ! op = may_peek_next_line(cctx, *arg, &next); if (*op != '*' && *op != '/' && *op != '%') break; + if (next != NULL) + { + *arg = next_line_from_context(cctx, TRUE); + op = skipwhite(*arg); + } if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[1])) { *************** *** 4018,4023 **** --- 4045,4051 ---- compile_expr5(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) { char_u *op; + char_u *next; int oplen; int ppconst_used = ppconst->pp_used; *************** *** 4030,4039 **** */ for (;;) { ! op = skipwhite(*arg); ! if (*op != '+' && *op != '-' && !(*op == '.' && (*(*arg + 1) == '.'))) break; oplen = (*op == '.' ? 2 : 1); if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[oplen])) { --- 4058,4072 ---- */ for (;;) { ! op = may_peek_next_line(cctx, *arg, &next); ! if (*op != '+' && *op != '-' && !(*op == '.' && *(op + 1) == '.')) break; oplen = (*op == '.' ? 2 : 1); + if (next != NULL) + { + *arg = next_line_from_context(cctx, TRUE); + op = skipwhite(*arg); + } if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[oplen])) { *************** *** 4127,4132 **** --- 4160,4166 ---- { exptype_T type = EXPR_UNKNOWN; char_u *p; + char_u *next; int len = 2; int type_is = FALSE; int ppconst_used = ppconst->pp_used; *************** *** 4135,4141 **** if (compile_expr5(arg, cctx, ppconst) == FAIL) return FAIL; ! p = skipwhite(*arg); type = get_compare_type(p, &len, &type_is); /* --- 4169,4175 ---- if (compile_expr5(arg, cctx, ppconst) == FAIL) return FAIL; ! p = may_peek_next_line(cctx, *arg, &next); type = get_compare_type(p, &len, &type_is); /* *************** *** 4145,4150 **** --- 4179,4189 ---- { int ic = FALSE; // Default: do not ignore case + if (next != NULL) + { + *arg = next_line_from_context(cctx, TRUE); + p = skipwhite(*arg); + } if (type_is && (p[len] == '?' || p[len] == '#')) { semsg(_(e_invexpr2), *arg); *************** *** 4221,4227 **** ppconst_T *ppconst, int ppconst_used UNUSED) { ! char_u *p = skipwhite(*arg); int opchar = *op; if (p[0] == opchar && p[1] == opchar) --- 4260,4267 ---- ppconst_T *ppconst, int ppconst_used UNUSED) { ! char_u *next; ! char_u *p = may_peek_next_line(cctx, *arg, &next); int opchar = *op; if (p[0] == opchar && p[1] == opchar) *************** *** 4235,4240 **** --- 4275,4286 ---- ga_init2(&end_ga, sizeof(int), 10); while (p[0] == opchar && p[1] == opchar) { + if (next != NULL) + { + *arg = next_line_from_context(cctx, TRUE); + p = skipwhite(*arg); + } + if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[2])) { semsg(_(e_white_both), op); *************** *** 4265,4271 **** ga_clear(&end_ga); return FAIL; } ! p = skipwhite(*arg); } generate_ppconst(cctx, ppconst); --- 4311,4318 ---- ga_clear(&end_ga); return FAIL; } ! ! p = may_peek_next_line(cctx, *arg, &next); } generate_ppconst(cctx, ppconst); *************** *** 4349,4360 **** { char_u *p; int ppconst_used = ppconst->pp_used; // Evaluate the first expression. if (compile_expr2(arg, cctx, ppconst) == FAIL) return FAIL; ! p = skipwhite(*arg); if (*p == '?') { garray_T *instr = &cctx->ctx_instr; --- 4396,4408 ---- { char_u *p; int ppconst_used = ppconst->pp_used; + char_u *next; // Evaluate the first expression. if (compile_expr2(arg, cctx, ppconst) == FAIL) return FAIL; ! p = may_peek_next_line(cctx, *arg, &next); if (*p == '?') { garray_T *instr = &cctx->ctx_instr; *************** *** 4368,4373 **** --- 4416,4427 ---- int const_value = FALSE; int save_skip = cctx->ctx_skip; + if (next != NULL) + { + *arg = next_line_from_context(cctx, TRUE); + p = skipwhite(*arg); + } + if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1])) { semsg(_(e_white_both), "?"); *************** *** 4415,4426 **** } // Check for the ":". ! p = skipwhite(*arg); if (*p != ':') { emsg(_(e_missing_colon)); return FAIL; } if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1])) { semsg(_(e_white_both), ":"); --- 4469,4486 ---- } // Check for the ":". ! p = may_peek_next_line(cctx, *arg, &next); if (*p != ':') { emsg(_(e_missing_colon)); return FAIL; } + if (next != NULL) + { + *arg = next_line_from_context(cctx, TRUE); + p = skipwhite(*arg); + } + if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1])) { semsg(_(e_white_both), ":"); *** ../vim-8.2.1044/src/testdir/test_vim9_expr.vim 2020-06-22 23:02:14.773942551 +0200 --- src/testdir/test_vim9_expr.vim 2020-06-23 22:24:10.473774553 +0200 *************** *** 13,18 **** --- 13,21 ---- assert_equal('one', 0.1 ? 'one' : 'two') endif assert_equal('one', 'x' ? 'one' : 'two') + assert_equal('one', 'x' + ? 'one' + : 'two') assert_equal('one', 0z1234 ? 'one' : 'two') assert_equal('one', [0] ? 'one' : 'two') assert_equal('one', #{x: 0} ? 'one' : 'two') *************** *** 70,75 **** --- 73,80 ---- 0 || 7) assert_equal(0, 0 || 0) + assert_equal(0, 0 + || 0) assert_equal('', 0 || '') g:vals = [] *************** *** 81,87 **** assert_equal([0, 5], g:vals) g:vals = [] ! assert_equal(4, Record(0) || Record(4) || Record(0)) assert_equal([0, 4], g:vals) g:vals = [] --- 86,94 ---- assert_equal([0, 5], g:vals) g:vals = [] ! assert_equal(4, Record(0) ! || Record(4) ! || Record(0)) assert_equal([0, 4], g:vals) g:vals = [] *************** *** 104,110 **** assert_equal(0, 0 && 0 && 7) ! assert_equal(7, 2 && 3 && 7) assert_equal(0, 0 && 0) assert_equal(0, 0 && '') assert_equal('', 8 && '') --- 111,119 ---- assert_equal(0, 0 && 0 && 7) ! assert_equal(7, 2 ! && 3 ! && 7) assert_equal(0, 0 && 0) assert_equal(0, 0 && '') assert_equal('', 8 && '') *************** *** 158,164 **** assert_equal(true, true == true) assert_equal(false, true == false) ! assert_equal(true, true == trueVar) assert_equal(false, true == falseVar) assert_equal(true, true == g:atrue) assert_equal(false, g:atrue == false) --- 167,174 ---- assert_equal(true, true == true) assert_equal(false, true == false) ! assert_equal(true, true ! == trueVar) assert_equal(false, true == falseVar) assert_equal(true, true == g:atrue) assert_equal(false, g:atrue == false) *************** *** 250,256 **** assert_equal(false, true != true) assert_equal(true, true != false) ! assert_equal(false, true != trueVar) assert_equal(true, true != falseVar) assert_equal(false, true != g:atrue) assert_equal(true, g:atrue != false) --- 260,267 ---- assert_equal(false, true != true) assert_equal(true, true != false) ! assert_equal(false, true ! != trueVar) assert_equal(true, true != falseVar) assert_equal(false, true != g:atrue) assert_equal(true, g:atrue != false) *************** *** 334,340 **** assert_true(nr2 > 1) assert_false(nr2 > 2) ! assert_false(nr2 > 3) if has('float') let ff = 2.0 assert_true(ff > 0.0) --- 345,352 ---- assert_true(nr2 > 1) assert_false(nr2 > 2) ! assert_false(nr2 ! > 3) if has('float') let ff = 2.0 assert_true(ff > 0.0) *************** *** 367,373 **** assert_false(2 < 0) assert_false(2 < 2) ! assert_true(2 < 3) let nr2 = 2 assert_false(nr2 < 0) assert_false(nr2 < 2) --- 379,386 ---- assert_false(2 < 0) assert_false(2 < 2) ! assert_true(2 ! < 3) let nr2 = 2 assert_false(nr2 < 0) assert_false(nr2 < 2) *************** *** 385,391 **** assert_false(2 <= 0) assert_false(2 <= 1) ! assert_true(2 <= 2) assert_true(2 <= 3) let nr2 = 2 assert_false(nr2 <= 0) --- 398,405 ---- assert_false(2 <= 0) assert_false(2 <= 1) ! assert_true(2 ! <= 2) assert_true(2 <= 3) let nr2 = 2 assert_false(nr2 <= 0) *************** *** 404,409 **** --- 418,425 ---- " test =~ comperator def Test_expr4_match() assert_equal(false, '2' =~ '0') + assert_equal(false, '' + =~ '0') assert_equal(true, '2' =~ '[0-9]') enddef *************** *** 411,416 **** --- 427,434 ---- " test !~ comperator def Test_expr4_nomatch() assert_equal(true, '2' !~ '0') + assert_equal(true, '' + !~ '0') assert_equal(false, '2' !~ '[0-9]') enddef *************** *** 424,430 **** other) let myblob = 0z1234 ! assert_false(myblob is 0z1234) let otherblob = myblob assert_true(myblob is otherblob) enddef --- 442,449 ---- other) let myblob = 0z1234 ! assert_false(myblob ! is 0z1234) let otherblob = myblob assert_true(myblob is otherblob) enddef *************** *** 439,445 **** other) let myblob = 0z1234 ! assert_true(myblob isnot 0z1234) let otherblob = myblob assert_false(myblob isnot otherblob) enddef --- 458,465 ---- other) let myblob = 0z1234 ! assert_true(myblob ! isnot 0z1234) let otherblob = myblob assert_false(myblob isnot otherblob) enddef *************** *** 522,547 **** assert_equal(66, 60 + 6) assert_equal(70, 60 + g:anint) ! assert_equal(9, g:alsoint + 5) assert_equal(14, g:alsoint + g:anint) assert_equal([1, 2, 3, 4], [1] + g:alist) assert_equal(54, 60 - 6) assert_equal(50, 60 - g:anint) ! assert_equal(-1, g:alsoint - 5) assert_equal(-6, g:alsoint - g:anint) assert_equal('hello', 'hel' .. 'lo') assert_equal('hello 123', 'hello ' .. 123) ! assert_equal('hello 123', 'hello ' .. 123) assert_equal('123 hello', 123 .. ' hello') assert_equal('123456', 123 .. 456) assert_equal([1, 2, 3, 4], [1, 2] + [3, 4]) assert_equal(0z11223344, 0z1122 + 0z3344) ! assert_equal(0z112201ab, 0z1122 + g:ablob) assert_equal(0z01ab3344, g:ablob + 0z3344) assert_equal(0z01ab01ab, g:ablob + g:ablob) enddef --- 542,571 ---- assert_equal(66, 60 + 6) assert_equal(70, 60 + g:anint) ! assert_equal(9, g:alsoint ! + 5) assert_equal(14, g:alsoint + g:anint) assert_equal([1, 2, 3, 4], [1] + g:alist) assert_equal(54, 60 - 6) assert_equal(50, 60 - g:anint) ! assert_equal(-1, g:alsoint ! - 5) assert_equal(-6, g:alsoint - g:anint) assert_equal('hello', 'hel' .. 'lo') assert_equal('hello 123', 'hello ' .. 123) ! assert_equal('hello 123', 'hello ' ! .. 123) assert_equal('123 hello', 123 .. ' hello') assert_equal('123456', 123 .. 456) assert_equal([1, 2, 3, 4], [1, 2] + [3, 4]) assert_equal(0z11223344, 0z1122 + 0z3344) ! assert_equal(0z112201ab, 0z1122 ! + g:ablob) assert_equal(0z01ab3344, g:ablob + 0z3344) assert_equal(0z01ab01ab, g:ablob + g:ablob) enddef *************** *** 554,566 **** assert_equal(66.0, 60.0 + 6) assert_equal(66.0, 60 + 6.0) ! assert_equal(5.1, g:afloat + 5) assert_equal(8.1, 8 + g:afloat) assert_equal(10.1, g:anint + g:afloat) assert_equal(10.1, g:afloat + g:anint) assert_equal(54.0, 60.0 - 6.0) ! assert_equal(54.0, 60.0 - 6) assert_equal(54.0, 60 - 6.0) assert_equal(-4.9, g:afloat - 5) assert_equal(7.9, 8 - g:afloat) --- 578,592 ---- assert_equal(66.0, 60.0 + 6) assert_equal(66.0, 60 + 6.0) ! assert_equal(5.1, g:afloat ! + 5) assert_equal(8.1, 8 + g:afloat) assert_equal(10.1, g:anint + g:afloat) assert_equal(10.1, g:afloat + g:anint) assert_equal(54.0, 60.0 - 6.0) ! assert_equal(54.0, 60.0 ! - 6) assert_equal(54.0, 60 - 6.0) assert_equal(-4.9, g:afloat - 5) assert_equal(7.9, 8 - g:afloat) *************** *** 599,618 **** assert_equal(36, 6 * 6) assert_equal(24, 6 * g:alsoint) ! assert_equal(24, g:alsoint * 6) assert_equal(40, g:anint * g:alsoint) assert_equal(10, 60 / 6) assert_equal(6, 60 / g:anint) assert_equal(1, g:anint / 6) ! assert_equal(2, g:anint / g:alsoint) assert_equal(5, 11 % 6) assert_equal(4, g:anint % 6) assert_equal(3, 13 % g:anint) ! assert_equal(2, g:anint % g:alsoint) assert_equal(4, 6 * 4 / 6) --- 625,647 ---- assert_equal(36, 6 * 6) assert_equal(24, 6 * g:alsoint) ! assert_equal(24, g:alsoint ! * 6) assert_equal(40, g:anint * g:alsoint) assert_equal(10, 60 / 6) assert_equal(6, 60 / g:anint) assert_equal(1, g:anint / 6) ! assert_equal(2, g:anint ! / g:alsoint) assert_equal(5, 11 % 6) assert_equal(4, g:anint % 6) assert_equal(3, 13 % g:anint) ! assert_equal(2, g:anint ! % g:alsoint) assert_equal(4, 6 * 4 / 6) *************** *** 623,630 **** if has('float') let xf = [2.0] let yf = [3.0] ! assert_equal(5.0, xf[0] + yf[0]) ! assert_equal(6.0, xf[0] * yf[0]) endif call CheckDefFailure(["let x = 6 * xxx"], 'E1001') --- 652,661 ---- if has('float') let xf = [2.0] let yf = [3.0] ! assert_equal(5.0, xf[0] ! + yf[0]) ! assert_equal(6.0, xf[0] ! * yf[0]) endif call CheckDefFailure(["let x = 6 * xxx"], 'E1001') *** ../vim-8.2.1044/src/version.c 2020-06-23 21:01:19.398080502 +0200 --- src/version.c 2020-06-23 22:25:14.357550378 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1045, /**/ -- BRIDGEKEEPER: What is your favorite colour? GAWAIN: Blue ... No yelloooooww! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///