comparison 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
comparison
equal deleted inserted replaced
19472:fa1ea6285f80 19473:b09afbebffee
4737 /* 4737 /*
4738 * Loop over all the lines of the function and generate instructions. 4738 * Loop over all the lines of the function and generate instructions.
4739 */ 4739 */
4740 for (;;) 4740 for (;;)
4741 { 4741 {
4742 int is_ex_command;
4743
4742 if (line != NULL && *line == '|') 4744 if (line != NULL && *line == '|')
4743 // the line continues after a '|' 4745 // the line continues after a '|'
4744 ++line; 4746 ++line;
4745 else if (line != NULL && *line != NUL) 4747 else if (line != NULL && *line != NUL)
4746 { 4748 {
4791 if (*ea.cmd == '{') 4793 if (*ea.cmd == '{')
4792 { 4794 {
4793 line = compile_block(ea.cmd, &cctx); 4795 line = compile_block(ea.cmd, &cctx);
4794 continue; 4796 continue;
4795 } 4797 }
4798 is_ex_command = *ea.cmd == ':';
4796 4799
4797 /* 4800 /*
4798 * COMMAND MODIFIERS 4801 * COMMAND MODIFIERS
4799 */ 4802 */
4800 if (parse_command_modifiers(&ea, &errormsg, FALSE) == FAIL) 4803 if (parse_command_modifiers(&ea, &errormsg, FALSE) == FAIL)
4808 4811
4809 // Skip ":call" to get to the function name. 4812 // Skip ":call" to get to the function name.
4810 if (checkforcmd(&ea.cmd, "call", 3)) 4813 if (checkforcmd(&ea.cmd, "call", 3))
4811 ea.cmd = skipwhite(ea.cmd); 4814 ea.cmd = skipwhite(ea.cmd);
4812 4815
4813 // Assuming the command starts with a variable or function name, find 4816 if (!is_ex_command)
4814 // what follows. Also "&opt = val", "$ENV = val" and "@r = val". 4817 {
4815 p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@') 4818 // Assuming the command starts with a variable or function name,
4819 // find what follows. Also "&opt = val", "$ENV = val" and "@r =
4820 // val".
4821 p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
4816 ? ea.cmd + 1 : ea.cmd; 4822 ? ea.cmd + 1 : ea.cmd;
4817 p = to_name_end(p); 4823 p = to_name_end(p);
4818 if (p > ea.cmd && *p != NUL) 4824 if (p > ea.cmd && *p != NUL)
4819 {
4820 int oplen;
4821 int heredoc;
4822
4823 // "funcname(" is always a function call.
4824 // "varname[]" is an expression.
4825 // "varname->expr" is an expression.
4826 if (*p == '('
4827 || *p == '['
4828 || ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
4829 || (*p == '-' && p[1] == '>'))
4830 { 4825 {
4831 // TODO 4826 int oplen;
4832 } 4827 int heredoc;
4833 4828
4834 oplen = assignment_len(skipwhite(p), &heredoc); 4829 // "funcname(" is always a function call.
4835 if (oplen > 0) 4830 // "varname[]" is an expression.
4836 { 4831 // "varname->expr" is an expression.
4837 // Recognize an assignment if we recognize the variable name: 4832 if (*p == '('
4838 // "g:var = expr" 4833 || *p == '['
4839 // "var = expr" where "var" is a local var name.
4840 // "&opt = expr"
4841 // "$ENV = expr"
4842 // "@r = expr"
4843 if (*ea.cmd == '&'
4844 || *ea.cmd == '$'
4845 || *ea.cmd == '@'
4846 || ((p - ea.cmd) > 2 && ea.cmd[1] == ':') 4834 || ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
4847 || lookup_local(ea.cmd, p - ea.cmd, &cctx) >= 0 4835 || (*p == '-' && p[1] == '>'))
4848 || lookup_script(ea.cmd, p - ea.cmd) == OK
4849 || find_imported(ea.cmd, p - ea.cmd, &cctx) != NULL)
4850 { 4836 {
4851 line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx); 4837 // TODO
4852 if (line == NULL) 4838 }
4853 goto erret; 4839
4854 continue; 4840 oplen = assignment_len(skipwhite(p), &heredoc);
4841 if (oplen > 0)
4842 {
4843 // Recognize an assignment if we recognize the variable
4844 // name:
4845 // "g:var = expr"
4846 // "var = expr" where "var" is a local var name.
4847 // "&opt = expr"
4848 // "$ENV = expr"
4849 // "@r = expr"
4850 if (*ea.cmd == '&'
4851 || *ea.cmd == '$'
4852 || *ea.cmd == '@'
4853 || ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
4854 || lookup_local(ea.cmd, p - ea.cmd, &cctx) >= 0
4855 || lookup_script(ea.cmd, p - ea.cmd) == OK
4856 || find_imported(ea.cmd, p - ea.cmd, &cctx) != NULL)
4857 {
4858 line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx);
4859 if (line == NULL)
4860 goto erret;
4861 continue;
4862 }
4855 } 4863 }
4856 } 4864 }
4857 } 4865 }
4858 4866
4859 /* 4867 /*
4860 * COMMAND after range 4868 * COMMAND after range
4861 */ 4869 */
4862 ea.cmd = skip_range(ea.cmd, NULL); 4870 ea.cmd = skip_range(ea.cmd, NULL);
4863 p = find_ex_command(&ea, NULL, lookup_local, &cctx); 4871 p = find_ex_command(&ea, NULL, is_ex_command ? NULL : lookup_local,
4872 &cctx);
4864 4873
4865 if (p == ea.cmd && ea.cmdidx != CMD_SIZE) 4874 if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
4866 { 4875 {
4867 if (cctx.ctx_skip == TRUE) 4876 if (cctx.ctx_skip == TRUE)
4868 { 4877 {