Mercurial > vim
diff src/vim9compile.c @ 19473:b09afbebffee v8.2.0294
patch 8.2.0294: cannot use Ex command that is also a function name
Commit: https://github.com/vim/vim/commit/5b1c8fe3d588ab450d4646a0088db4efda88200a
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Feb 21 18:42:43 2020 +0100
patch 8.2.0294: cannot use Ex command that is also a function name
Problem: Cannot use Ex command that is also a function name.
Solution: Recognize an Ex command by a colon prefix.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 21 Feb 2020 18:45:06 +0100 |
parents | f41e46f02c8c |
children | c27837cbe922 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -4739,6 +4739,8 @@ compile_def_function(ufunc_T *ufunc, int */ for (;;) { + int is_ex_command; + if (line != NULL && *line == '|') // the line continues after a '|' ++line; @@ -4793,6 +4795,7 @@ compile_def_function(ufunc_T *ufunc, int line = compile_block(ea.cmd, &cctx); continue; } + is_ex_command = *ea.cmd == ':'; /* * COMMAND MODIFIERS @@ -4810,48 +4813,53 @@ compile_def_function(ufunc_T *ufunc, int if (checkforcmd(&ea.cmd, "call", 3)) ea.cmd = skipwhite(ea.cmd); - // Assuming the command starts with a variable or function name, find - // what follows. Also "&opt = val", "$ENV = val" and "@r = val". - p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@') - ? ea.cmd + 1 : ea.cmd; - p = to_name_end(p); - if (p > ea.cmd && *p != NUL) + if (!is_ex_command) { - int oplen; - int heredoc; - - // "funcname(" is always a function call. - // "varname[]" is an expression. - // "varname->expr" is an expression. - if (*p == '(' - || *p == '[' - || ((p - ea.cmd) > 2 && ea.cmd[1] == ':') - || (*p == '-' && p[1] == '>')) + // Assuming the command starts with a variable or function name, + // find what follows. Also "&opt = val", "$ENV = val" and "@r = + // val". + p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@') + ? ea.cmd + 1 : ea.cmd; + p = to_name_end(p); + if (p > ea.cmd && *p != NUL) { - // TODO - } - - oplen = assignment_len(skipwhite(p), &heredoc); - if (oplen > 0) - { - // Recognize an assignment if we recognize the variable name: - // "g:var = expr" - // "var = expr" where "var" is a local var name. - // "&opt = expr" - // "$ENV = expr" - // "@r = expr" - if (*ea.cmd == '&' - || *ea.cmd == '$' - || *ea.cmd == '@' + int oplen; + int heredoc; + + // "funcname(" is always a function call. + // "varname[]" is an expression. + // "varname->expr" is an expression. + if (*p == '(' + || *p == '[' || ((p - ea.cmd) > 2 && ea.cmd[1] == ':') - || lookup_local(ea.cmd, p - ea.cmd, &cctx) >= 0 - || lookup_script(ea.cmd, p - ea.cmd) == OK - || find_imported(ea.cmd, p - ea.cmd, &cctx) != NULL) + || (*p == '-' && p[1] == '>')) + { + // TODO + } + + oplen = assignment_len(skipwhite(p), &heredoc); + if (oplen > 0) { - line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx); - if (line == NULL) - goto erret; - continue; + // Recognize an assignment if we recognize the variable + // name: + // "g:var = expr" + // "var = expr" where "var" is a local var name. + // "&opt = expr" + // "$ENV = expr" + // "@r = expr" + if (*ea.cmd == '&' + || *ea.cmd == '$' + || *ea.cmd == '@' + || ((p - ea.cmd) > 2 && ea.cmd[1] == ':') + || lookup_local(ea.cmd, p - ea.cmd, &cctx) >= 0 + || lookup_script(ea.cmd, p - ea.cmd) == OK + || find_imported(ea.cmd, p - ea.cmd, &cctx) != NULL) + { + line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx); + if (line == NULL) + goto erret; + continue; + } } } } @@ -4860,7 +4868,8 @@ compile_def_function(ufunc_T *ufunc, int * COMMAND after range */ ea.cmd = skip_range(ea.cmd, NULL); - p = find_ex_command(&ea, NULL, lookup_local, &cctx); + p = find_ex_command(&ea, NULL, is_ex_command ? NULL : lookup_local, + &cctx); if (p == ea.cmd && ea.cmdidx != CMD_SIZE) {