# HG changeset patch # User Bram Moolenaar # Date 1664712009 -7200 # Node ID 9d7914012b82458f96040d654ce090e2b3cda8ef # Parent 827c77642cb1f2ba3dc113d313883d4d122f04ce patch 9.0.0637: syntax of commands in Vim9 script depends on +eval feature Commit: https://github.com/vim/vim/commit/eda29c971c0592d85c5856da7708f3edfdc54cfa Author: Bram Moolenaar Date: Sun Oct 2 12:59:00 2022 +0100 patch 9.0.0637: syntax of commands in Vim9 script depends on +eval feature Problem: Syntax of commands in Vim9 script depends on +eval feature. Solution: Use same syntax with and without the +eval feature. diff --git a/src/errors.h b/src/errors.h --- a/src/errors.h +++ b/src/errors.h @@ -2713,8 +2713,10 @@ EXTERN char e_item_not_found_in_script_s INIT(= N_("E1048: Item not found in script: %s")); EXTERN char e_item_not_exported_in_script_str[] INIT(= N_("E1049: Item not exported in script: %s")); +#endif EXTERN char e_colon_required_before_range_str[] INIT(= N_("E1050: Colon required before a range: %s")); +#ifdef FEAT_EVAL EXTERN char e_wrong_argument_type_for_plus[] INIT(= N_("E1051: Wrong argument type for +")); EXTERN char e_cannot_declare_an_option[] diff --git a/src/ex_docmd.c b/src/ex_docmd.c --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -1684,10 +1684,8 @@ current_tab_nr(tabpage_T *tab) static int comment_start(char_u *p, int starts_with_colon UNUSED) { -#ifdef FEAT_EVAL if (in_vim9script()) return p[0] == '#' && !starts_with_colon; -#endif return *p == '"'; } @@ -1736,9 +1734,9 @@ do_one_cmd( int ni; // set when Not Implemented char_u *cmd; int starts_with_colon = FALSE; -#ifdef FEAT_EVAL int may_have_range; int vim9script; +#ifdef FEAT_EVAL int did_set_expr_line = FALSE; #endif int sourcing = flags & DOCMD_VERBOSE; @@ -1787,9 +1785,6 @@ do_one_cmd( if (parse_command_modifiers(&ea, &errormsg, &cmdmod, FALSE) == FAIL) goto doend; apply_cmdmod(&cmdmod); -#ifdef FEAT_EVAL - vim9script = in_vim9script(); -#endif after_modifier = ea.cmd; #ifdef FEAT_EVAL @@ -1805,9 +1800,10 @@ do_one_cmd( * We need the command to know what kind of range it uses. */ cmd = ea.cmd; -#ifdef FEAT_EVAL + // In Vim9 script a colon is required before the range. This may also be // after command modifiers. + vim9script = in_vim9script(); if (vim9script && (flags & DOCMD_RANGEOK) == 0) { may_have_range = FALSE; @@ -1822,16 +1818,18 @@ do_one_cmd( else may_have_range = TRUE; if (may_have_range) -#endif ea.cmd = skip_range(ea.cmd, TRUE, NULL); -#ifdef FEAT_EVAL if (vim9script && !may_have_range) { if (ea.cmd == cmd + 1 && *cmd == '$') // should be "$VAR = val" --ea.cmd; +#ifdef FEAT_EVAL p = find_ex_command(&ea, NULL, lookup_scriptitem, NULL); +#else + p = find_ex_command(&ea, NULL, NULL, NULL); +#endif if (ea.cmdidx == CMD_SIZE) { char_u *ar = skip_range(ea.cmd, TRUE, NULL); @@ -1846,7 +1844,6 @@ do_one_cmd( } } else -#endif p = find_ex_command(&ea, NULL, NULL, NULL); #ifdef FEAT_EVAL @@ -1930,13 +1927,10 @@ do_one_cmd( } ea.cmd = cmd; -#ifdef FEAT_EVAL if (!may_have_range) ea.line1 = ea.line2 = default_address(&ea); - else -#endif - if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL) - goto doend; + else if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL) + goto doend; /* * 5. Parse the command. @@ -5275,24 +5269,20 @@ separate_nextcmd(exarg_T *eap, int keep_ } #endif - // Check for '"': start of comment or '|': next command + // Check for '"'/'#': start of comment or '|': next command // :@" and :*" do not start a comment! // :redir @" doesn't either. else if ((*p == '"' -#ifdef FEAT_EVAL && !in_vim9script() -#endif && !(eap->argt & EX_NOTRLCOM) && ((eap->cmdidx != CMD_at && eap->cmdidx != CMD_star) || p != eap->arg) && (eap->cmdidx != CMD_redir || p != eap->arg + 1 || p[-1] != '@')) -#ifdef FEAT_EVAL || (*p == '#' && in_vim9script() && !(eap->argt & EX_NOTRLCOM) && p > eap->cmd && VIM_ISWHITE(p[-1])) -#endif || *p == '|' || *p == '\n') { /* @@ -5636,10 +5626,8 @@ ends_excmd(int c) { int comment_char = '"'; -#ifdef FEAT_EVAL if (in_vim9script()) comment_char = '#'; -#endif return (c == NUL || c == '|' || c == comment_char || c == '\n'); } @@ -5654,12 +5642,10 @@ ends_excmd2(char_u *cmd_start UNUSED, ch if (c == NUL || c == '|' || c == '\n') return TRUE; -#ifdef FEAT_EVAL if (in_vim9script()) // # starts a comment, #{ might be a mistake, #{{ can start a fold return c == '#' && (cmd[1] != '{' || cmd[2] == '{') && (cmd == cmd_start || VIM_ISWHITE(cmd[-1])); -#endif return c == '"'; } diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -12,6 +12,7 @@ CLEANUP_FILES = test.log messages startt # Tests for tiny and small builds. SCRIPTS_TINY = \ + test10 \ test20 \ test21 \ test22 \ @@ -22,6 +23,7 @@ SCRIPTS_TINY = \ test27 SCRIPTS_TINY_OUT = \ + test10.out \ test20.out \ test21.out \ test22.out \ diff --git a/src/testdir/test10.in b/src/testdir/test10.in new file mode 100644 --- /dev/null +++ b/src/testdir/test10.in @@ -0,0 +1,21 @@ +Test that vim9script also works without the +eval feature. + +STARTTEST +:/^START/+1,/^END/-1:w! Xvim9 +:so Xvim9 +ENDTEST + +START +vim9script + +if 1 + echo 'this is skipped without +eval' +endif + +# colon required for a range +:$-1,$w! test.out +qa! +END + +first line +last line diff --git a/src/testdir/test10.ok b/src/testdir/test10.ok new file mode 100644 --- /dev/null +++ b/src/testdir/test10.ok @@ -0,0 +1,2 @@ +first line +last line diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -700,6 +700,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 637, +/**/ 636, /**/ 635,