Mercurial > vim
comparison src/ex_docmd.c @ 21335:af3663df42bf v8.2.1218
patch 8.2.1218: Vim9: cannot use 'text'->func()
Commit: https://github.com/vim/vim/commit/3d48e25dcb661eb09ccdaa73d4e2559201ff2eb1
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 15 14:15:52 2020 +0200
patch 8.2.1218: Vim9: cannot use 'text'->func()
Problem: Vim9: cannot use 'text'->func().
Solution: Recognize string at start of command.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 15 Jul 2020 14:30:04 +0200 |
parents | 8d1d11afd8c8 |
children | fb8c8fcb7b60 |
comparison
equal
deleted
inserted
replaced
21334:d7dc824cbbe5 | 21335:af3663df42bf |
---|---|
1698 int save_reg_executing = reg_executing; | 1698 int save_reg_executing = reg_executing; |
1699 int ni; // set when Not Implemented | 1699 int ni; // set when Not Implemented |
1700 char_u *cmd; | 1700 char_u *cmd; |
1701 #ifdef FEAT_EVAL | 1701 #ifdef FEAT_EVAL |
1702 int starts_with_colon; | 1702 int starts_with_colon; |
1703 int starts_with_quote; | |
1704 int vim9script = in_vim9script(); | |
1703 #endif | 1705 #endif |
1704 | 1706 |
1705 CLEAR_FIELD(ea); | 1707 CLEAR_FIELD(ea); |
1706 ea.line1 = 1; | 1708 ea.line1 = 1; |
1707 ea.line2 = 1; | 1709 ea.line2 = 1; |
1758 * 3. Skip over the range to find the command. Let "p" point to after it. | 1760 * 3. Skip over the range to find the command. Let "p" point to after it. |
1759 * | 1761 * |
1760 * We need the command to know what kind of range it uses. | 1762 * We need the command to know what kind of range it uses. |
1761 */ | 1763 */ |
1762 cmd = ea.cmd; | 1764 cmd = ea.cmd; |
1763 ea.cmd = skip_range(ea.cmd, NULL); | 1765 #ifdef FEAT_EVAL |
1766 starts_with_quote = vim9script && *ea.cmd == '\''; | |
1767 if (!starts_with_quote) | |
1768 #endif | |
1769 ea.cmd = skip_range(ea.cmd, NULL); | |
1764 if (*ea.cmd == '*' && vim_strchr(p_cpo, CPO_STAR) == NULL) | 1770 if (*ea.cmd == '*' && vim_strchr(p_cpo, CPO_STAR) == NULL) |
1765 ea.cmd = skipwhite(ea.cmd + 1); | 1771 ea.cmd = skipwhite(ea.cmd + 1); |
1766 | 1772 |
1767 #ifdef FEAT_EVAL | 1773 #ifdef FEAT_EVAL |
1768 if (in_vim9script() && !starts_with_colon) | 1774 if (vim9script && !starts_with_colon) |
1769 { | 1775 { |
1770 if (ea.cmd > cmd) | 1776 if (ea.cmd > cmd) |
1771 { | 1777 { |
1772 emsg(_(e_colon_required)); | 1778 emsg(_(e_colon_required)); |
1773 goto doend; | 1779 goto doend; |
1857 ea.addr_type = ADDR_OTHER; | 1863 ea.addr_type = ADDR_OTHER; |
1858 #endif | 1864 #endif |
1859 } | 1865 } |
1860 | 1866 |
1861 ea.cmd = cmd; | 1867 ea.cmd = cmd; |
1862 if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL) | 1868 #ifdef FEAT_EVAL |
1863 goto doend; | 1869 if (!starts_with_quote) |
1870 #endif | |
1871 if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL) | |
1872 goto doend; | |
1864 | 1873 |
1865 /* | 1874 /* |
1866 * 5. Parse the command. | 1875 * 5. Parse the command. |
1867 */ | 1876 */ |
1868 | 1877 |
1878 * If we find a '|' or '\n' we set ea.nextcmd. | 1887 * If we find a '|' or '\n' we set ea.nextcmd. |
1879 */ | 1888 */ |
1880 if (*ea.cmd == NUL || *ea.cmd == '"' | 1889 if (*ea.cmd == NUL || *ea.cmd == '"' |
1881 #ifdef FEAT_EVAL | 1890 #ifdef FEAT_EVAL |
1882 || (*ea.cmd == '#' && ea.cmd[1] != '{' | 1891 || (*ea.cmd == '#' && ea.cmd[1] != '{' |
1883 && !starts_with_colon && in_vim9script()) | 1892 && !starts_with_colon && vim9script) |
1884 #endif | 1893 #endif |
1885 || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) | 1894 || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) |
1886 { | 1895 { |
1887 /* | 1896 /* |
1888 * strange vi behaviour: | 1897 * strange vi behaviour: |
3221 /* | 3230 /* |
3222 * Recognize a Vim9 script function/method call and assignment: | 3231 * Recognize a Vim9 script function/method call and assignment: |
3223 * "lvar = value", "lvar(arg)", "[1, 2 3]->Func()" | 3232 * "lvar = value", "lvar(arg)", "[1, 2 3]->Func()" |
3224 */ | 3233 */ |
3225 p = eap->cmd; | 3234 p = eap->cmd; |
3226 if (lookup != NULL && (*p == '(' || *p == '{' | 3235 if (lookup != NULL && (vim_strchr((char_u *)"{('[", *p) != NULL |
3227 || ((p = to_name_const_end(eap->cmd)) > eap->cmd && *p != NUL) | 3236 || ((p = to_name_const_end(eap->cmd)) > eap->cmd |
3228 || *p == '[')) | 3237 && *p != NUL))) |
3229 { | 3238 { |
3230 int oplen; | 3239 int oplen; |
3231 int heredoc; | 3240 int heredoc; |
3232 | 3241 |
3233 // "funcname(" is always a function call. | 3242 if ( |
3234 // "varname[]" is an expression. | 3243 // "(..." is an expression. |
3235 // "g:varname" is an expression. | 3244 // "funcname(" is always a function call. |
3236 // "varname->expr" is an expression. | 3245 *p == '(' |
3237 // "varname.expr" is an expression. | 3246 || (p == eap->cmd |
3238 // "(..." is an expression. | 3247 ? ( |
3239 // "{..." is an dict expression. | 3248 // "{..." is an dict expression. |
3240 if (*p == '(' | 3249 *eap->cmd == '{' |
3241 || *p == '{' | 3250 // "'string'->func()" is an expression. |
3242 || (*p == '[' && p > eap->cmd) | 3251 || *eap->cmd == '\'' |
3243 || p[1] == ':' | 3252 // "g:varname" is an expression. |
3244 || (*p == '-' && p[1] == '>') | 3253 || eap->cmd[1] == ':' |
3245 || (*p == '.' && ASCII_ISALPHA(p[1]))) | 3254 ) |
3255 : ( | |
3256 // "varname[]" is an expression. | |
3257 *p == '[' | |
3258 // "varname->func()" is an expression. | |
3259 || (*p == '-' && p[1] == '>') | |
3260 // "varname.expr" is an expression. | |
3261 || (*p == '.' && ASCII_ISALPHA(p[1])) | |
3262 ))) | |
3246 { | 3263 { |
3247 eap->cmdidx = CMD_eval; | 3264 eap->cmdidx = CMD_eval; |
3248 return eap->cmd; | 3265 return eap->cmd; |
3249 } | 3266 } |
3250 | 3267 |