To: vim_dev@googlegroups.com Subject: Patch 8.2.0585 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0585 Problem: Vim9: # comment not recognized after :vim9script. Solution: Check script type. Make comment after ":echo" work. And in several other places. Files: src/ex_docmd.c, src/proto/ex_docmd.pro, src/eval.c, src/vim9compile.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.0584/src/ex_docmd.c 2020-04-13 15:06:49.917355649 +0200 --- src/ex_docmd.c 2020-04-16 21:43:19.309013512 +0200 *************** *** 1835,1841 **** * If we find a '|' or '\n' we set ea.nextcmd. */ if (*ea.cmd == NUL || *ea.cmd == '"' ! || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) { /* * strange vi behaviour: --- 1835,1844 ---- * If we find a '|' or '\n' we set ea.nextcmd. */ if (*ea.cmd == NUL || *ea.cmd == '"' ! #ifdef FEAT_EVAL ! || (*ea.cmd == '#' && !starts_with_colon && in_vim9script()) ! #endif ! || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) { /* * strange vi behaviour: *************** *** 4761,4772 **** do_cmdline_cmd(eap->do_ecmd_cmd); } int ends_excmd(int c) { #ifdef FEAT_EVAL if (c == '#') ! // TODO: should check for preceding white space return in_vim9script(); #endif return (c == NUL || c == '|' || c == '"' || c == '\n'); --- 4764,4794 ---- do_cmdline_cmd(eap->do_ecmd_cmd); } + /* + * Check if "c" ends an Ex command. + * In Vim9 script does not check for white space before #. + */ int ends_excmd(int c) { #ifdef FEAT_EVAL if (c == '#') ! return in_vim9script(); ! #endif ! return (c == NUL || c == '|' || c == '"' || c == '\n'); ! } ! ! /* ! * Like ends_excmd() but checks that a # in Vim9 script either has "cmd" equal ! * to "cmd_start" or has a white space character before it. ! */ ! int ! ends_excmd2(char_u *cmd_start, char_u *cmd) ! { ! int c = *cmd; ! ! #ifdef FEAT_EVAL ! if (c == '#' && (cmd == cmd_start || VIM_ISWHITE(cmd[-1]))) return in_vim9script(); #endif return (c == NUL || c == '|' || c == '"' || c == '\n'); *** ../vim-8.2.0584/src/proto/ex_docmd.pro 2020-01-26 15:52:33.023833239 +0100 --- src/proto/ex_docmd.pro 2020-04-16 21:40:43.157458406 +0200 *************** *** 19,24 **** --- 19,25 ---- char_u *skip_cmd_arg(char_u *p, int rembs); int get_bad_opt(char_u *p, exarg_T *eap); int ends_excmd(int c); + int ends_excmd2(char_u *before, char_u *cmd); char_u *find_nextcmd(char_u *p); char_u *check_nextcmd(char_u *p); char_u *get_command_name(expand_T *xp, int idx); *** ../vim-8.2.0584/src/eval.c 2020-04-12 19:37:13.506297291 +0200 --- src/eval.c 2020-04-16 21:45:43.768613889 +0200 *************** *** 6061,6067 **** if (eap->skip) ++emsg_skip; ! while (*arg != NUL && *arg != '|' && *arg != '\n' && !got_int) { // If eval1() causes an error message the text from the command may // still need to be cleared. E.g., "echo 22,44". --- 6061,6067 ---- if (eap->skip) ++emsg_skip; ! while ((!ends_excmd2(eap->cmd, arg) || *arg == '"') && !got_int) { // If eval1() causes an error message the text from the command may // still need to be cleared. E.g., "echo 22,44". *** ../vim-8.2.0584/src/vim9compile.c 2020-04-16 13:00:25.583729080 +0200 --- src/vim9compile.c 2020-04-16 22:05:16.285561523 +0200 *************** *** 108,113 **** --- 108,114 ---- struct cctx_S { ufunc_T *ctx_ufunc; // current function int ctx_lnum; // line number in current function + char_u *ctx_line_start; // start of current line or NULL garray_T ctx_instr; // generated instructions garray_T ctx_locals; // currently visible local variables *************** *** 2055,2068 **** static char_u * next_line_from_context(cctx_T *cctx) { ! char_u *line = NULL; do { ++cctx->ctx_lnum; if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len) break; line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]; SOURCING_LNUM = cctx->ctx_ufunc->uf_script_ctx.sc_lnum + cctx->ctx_lnum + 1; } while (line == NULL || *skipwhite(line) == NUL); --- 2056,2073 ---- static char_u * next_line_from_context(cctx_T *cctx) { ! char_u *line; do { ++cctx->ctx_lnum; if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len) + { + line = NULL; break; + } line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]; + cctx->ctx_line_start = line; SOURCING_LNUM = cctx->ctx_ufunc->uf_script_ctx.sc_lnum + cctx->ctx_lnum + 1; } while (line == NULL || *skipwhite(line) == NUL); *************** *** 5448,5454 **** } p = skipwhite(arg); ! if (ends_excmd(*p)) { scope->se_u.se_try.ts_caught_all = TRUE; scope->se_u.se_try.ts_catch_label = 0; --- 5453,5459 ---- } p = skipwhite(arg); ! if (ends_excmd2(arg, p)) { scope->se_u.se_try.ts_caught_all = TRUE; scope->se_u.se_try.ts_catch_label = 0; *************** *** 5782,5788 **** if (line != NULL && *line == '|') // the line continues after a '|' ++line; ! else if (line != NULL && *line != NUL) { semsg(_("E488: Trailing characters: %s"), line); goto erret; --- 5787,5795 ---- if (line != NULL && *line == '|') // the line continues after a '|' ++line; ! else if (line != NULL && *line != NUL ! && !(*line == '#' && (line == cctx.ctx_line_start ! || VIM_ISWHITE(line[-1])))) { semsg(_("E488: Trailing characters: %s"), line); goto erret; *** ../vim-8.2.0584/src/testdir/test_vim9_script.vim 2020-04-16 13:00:25.583729080 +0200 --- src/testdir/test_vim9_script.vim 2020-04-16 22:09:38.552896046 +0200 *************** *** 10,20 **** call delete('Xdef') endfunc ! func CheckScriptFailure(lines, error) ! call writefile(a:lines, 'Xdef') ! call assert_fails('so Xdef', a:error, a:lines) ! call delete('Xdef') ! endfunc def Test_syntax() let var = 234 --- 10,26 ---- call delete('Xdef') endfunc ! def CheckScriptFailure(lines: list, error: string) ! writefile(lines, 'Xdef') ! assert_fails('so Xdef', error, lines) ! delete('Xdef') ! enddef ! ! def CheckScriptSuccess(lines: list) ! writefile(lines, 'Xdef') ! so Xdef ! delete('Xdef') ! enddef def Test_syntax() let var = 234 *************** *** 269,283 **** def Test_try_catch() let l = [] ! try add(l, '1') throw 'wrong' add(l, '2') ! catch add(l, v:exception) ! finally add(l, '3') ! endtry assert_equal(['1', 'wrong', '3'], l) enddef --- 275,289 ---- def Test_try_catch() let l = [] ! try # comment add(l, '1') throw 'wrong' add(l, '2') ! catch # comment add(l, v:exception) ! finally # comment add(l, '3') ! endtry # comment assert_equal(['1', 'wrong', '3'], l) enddef *************** *** 1003,1008 **** --- 1009,1066 ---- ) enddef + def Test_vim9_comment() + CheckScriptSuccess([ + 'vim9script', + '# something', + ]) + CheckScriptFailure([ + 'vim9script', + ':# something', + ], 'E488:') + CheckScriptFailure([ + '# something', + ], 'E488:') + CheckScriptFailure([ + ':# something', + ], 'E488:') + + CheckScriptSuccess([ + 'vim9script', + 'echo "yes" # something', + ]) + CheckScriptFailure([ + 'vim9script', + 'echo "yes"# something', + ], 'E121:') + CheckScriptFailure([ + 'vim9script', + 'echo# something', + ], 'E121:') + CheckScriptFailure([ + 'echo "yes" # something', + ], 'E121:') + + CheckDefFailure([ + 'try# comment', + 'echo "yes"', + 'catch', + 'endtry', + ], 'E488:') + CheckDefFailure([ + 'try', + 'echo "yes"', + 'catch# comment', + 'endtry', + ], 'E488:') + CheckDefFailure([ + 'try', + 'echo "yes"', + 'catch', + 'endtry# comment', + ], 'E488:') + enddef + " Keep this last, it messes up highlighting. def Test_substitute_cmd() new *** ../vim-8.2.0584/src/version.c 2020-04-16 21:04:38.597969228 +0200 --- src/version.c 2020-04-16 21:16:35.676888873 +0200 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 585, /**/ -- A village. Sound of chanting of Latin canon, punctuated by short, sharp cracks. It comes nearer. We see it is a line of MONKS ala SEVENTH SEAL flagellation scene, chanting and banging themselves on the foreheads with wooden boards. "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 ///