To: vim_dev@googlegroups.com Subject: Patch 8.2.1218 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1218 Problem: Vim9: cannot use 'text'->func(). Solution: Recognize string at start of command. Files: src/vim9compile.c, src/ex_docmd.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.1217/src/vim9compile.c 2020-07-13 18:55:44.937073001 +0200 --- src/vim9compile.c 2020-07-15 12:48:22.134903895 +0200 *************** *** 7048,7060 **** /* * COMMAND after range */ cmd = ea.cmd; ! ea.cmd = skip_range(ea.cmd, NULL); ! if (ea.cmd > cmd && !starts_with_colon) { ! emsg(_(e_colon_required)); ! goto erret; } p = find_ex_command(&ea, NULL, starts_with_colon ? NULL : (void *(*)(char_u *, size_t, cctx_T *))lookup_local, --- 7048,7064 ---- /* * COMMAND after range + * 'text'->func() should not be confused with 'a mark */ cmd = ea.cmd; ! if (*cmd != '\'') { ! ea.cmd = skip_range(ea.cmd, NULL); ! if (ea.cmd > cmd && !starts_with_colon) ! { ! emsg(_(e_colon_required)); ! goto erret; ! } } p = find_ex_command(&ea, NULL, starts_with_colon ? NULL : (void *(*)(char_u *, size_t, cctx_T *))lookup_local, *** ../vim-8.2.1217/src/ex_docmd.c 2020-07-12 17:07:01.024810908 +0200 --- src/ex_docmd.c 2020-07-15 13:50:48.938344906 +0200 *************** *** 1700,1705 **** --- 1700,1707 ---- char_u *cmd; #ifdef FEAT_EVAL int starts_with_colon; + int starts_with_quote; + int vim9script = in_vim9script(); #endif CLEAR_FIELD(ea); *************** *** 1760,1771 **** * We need the command to know what kind of range it uses. */ cmd = ea.cmd; ! ea.cmd = skip_range(ea.cmd, NULL); if (*ea.cmd == '*' && vim_strchr(p_cpo, CPO_STAR) == NULL) ea.cmd = skipwhite(ea.cmd + 1); #ifdef FEAT_EVAL ! if (in_vim9script() && !starts_with_colon) { if (ea.cmd > cmd) { --- 1762,1777 ---- * We need the command to know what kind of range it uses. */ cmd = ea.cmd; ! #ifdef FEAT_EVAL ! starts_with_quote = vim9script && *ea.cmd == '\''; ! if (!starts_with_quote) ! #endif ! ea.cmd = skip_range(ea.cmd, NULL); if (*ea.cmd == '*' && vim_strchr(p_cpo, CPO_STAR) == NULL) ea.cmd = skipwhite(ea.cmd + 1); #ifdef FEAT_EVAL ! if (vim9script && !starts_with_colon) { if (ea.cmd > cmd) { *************** *** 1859,1866 **** } ea.cmd = cmd; ! if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL) ! goto doend; /* * 5. Parse the command. --- 1865,1875 ---- } ea.cmd = cmd; ! #ifdef FEAT_EVAL ! if (!starts_with_quote) ! #endif ! if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL) ! goto doend; /* * 5. Parse the command. *************** *** 1880,1886 **** if (*ea.cmd == NUL || *ea.cmd == '"' #ifdef FEAT_EVAL || (*ea.cmd == '#' && ea.cmd[1] != '{' ! && !starts_with_colon && in_vim9script()) #endif || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) { --- 1889,1895 ---- if (*ea.cmd == NUL || *ea.cmd == '"' #ifdef FEAT_EVAL || (*ea.cmd == '#' && ea.cmd[1] != '{' ! && !starts_with_colon && vim9script) #endif || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) { *************** *** 3223,3248 **** * "lvar = value", "lvar(arg)", "[1, 2 3]->Func()" */ p = eap->cmd; ! if (lookup != NULL && (*p == '(' || *p == '{' ! || ((p = to_name_const_end(eap->cmd)) > eap->cmd && *p != NUL) ! || *p == '[')) { int oplen; int heredoc; ! // "funcname(" is always a function call. ! // "varname[]" is an expression. ! // "g:varname" is an expression. ! // "varname->expr" is an expression. ! // "varname.expr" is an expression. ! // "(..." is an expression. ! // "{..." is an dict expression. ! if (*p == '(' ! || *p == '{' ! || (*p == '[' && p > eap->cmd) ! || p[1] == ':' ! || (*p == '-' && p[1] == '>') ! || (*p == '.' && ASCII_ISALPHA(p[1]))) { eap->cmdidx = CMD_eval; return eap->cmd; --- 3232,3265 ---- * "lvar = value", "lvar(arg)", "[1, 2 3]->Func()" */ p = eap->cmd; ! if (lookup != NULL && (vim_strchr((char_u *)"{('[", *p) != NULL ! || ((p = to_name_const_end(eap->cmd)) > eap->cmd ! && *p != NUL))) { int oplen; int heredoc; ! if ( ! // "(..." is an expression. ! // "funcname(" is always a function call. ! *p == '(' ! || (p == eap->cmd ! ? ( ! // "{..." is an dict expression. ! *eap->cmd == '{' ! // "'string'->func()" is an expression. ! || *eap->cmd == '\'' ! // "g:varname" is an expression. ! || eap->cmd[1] == ':' ! ) ! : ( ! // "varname[]" is an expression. ! *p == '[' ! // "varname->func()" is an expression. ! || (*p == '-' && p[1] == '>') ! // "varname.expr" is an expression. ! || (*p == '.' && ASCII_ISALPHA(p[1])) ! ))) { eap->cmdidx = CMD_eval; return eap->cmd; *** ../vim-8.2.1217/src/testdir/test_vim9_func.vim 2020-07-13 20:41:04.472449703 +0200 --- src/testdir/test_vim9_func.vim 2020-07-15 13:28:44.993254127 +0200 *************** *** 355,360 **** --- 355,369 ---- ("some")->MyFunc() assert_equal('some', var) + 'asdfasdf'->MyFunc() + assert_equal('asdfasdf', var) + + def UseString() + 'xyork'->MyFunc() + enddef + UseString() + assert_equal('xyork', var) + MyFunc( 'continued' ) *** ../vim-8.2.1217/src/version.c 2020-07-15 11:19:06.902200748 +0200 --- src/version.c 2020-07-15 13:29:33.061173096 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1218, /**/ -- How To Keep A Healthy Level Of Insanity: 17. When the money comes out the ATM, scream "I won!, I won! 3rd time this week!!!!!" /// 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 ///