Mercurial > vim
comparison src/eval.c @ 16223:abb67309c1ca v8.1.1116
patch 8.1.1116: cannot enforce a Vim script style
commit https://github.com/vim/vim/commit/558ca4ae55096f8763ab8515a304cda9c57f18a7
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 4 18:15:38 2019 +0200
patch 8.1.1116: cannot enforce a Vim script style
Problem: Cannot enforce a Vim script style.
Solution: Add the :scriptversion command. (closes https://github.com/vim/vim/issues/3857)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 Apr 2019 18:30:05 +0200 |
parents | bd49e1656c72 |
children | 0761a4c111a7 |
comparison
equal
deleted
inserted
replaced
16222:5a55ab44b5a1 | 16223:abb67309c1ca |
---|---|
1247 int var_count = 0; | 1247 int var_count = 0; |
1248 int semicolon = 0; | 1248 int semicolon = 0; |
1249 char_u op[2]; | 1249 char_u op[2]; |
1250 char_u *argend; | 1250 char_u *argend; |
1251 int first = TRUE; | 1251 int first = TRUE; |
1252 int concat; | |
1252 | 1253 |
1253 argend = skip_var_list(arg, &var_count, &semicolon); | 1254 argend = skip_var_list(arg, &var_count, &semicolon); |
1254 if (argend == NULL) | 1255 if (argend == NULL) |
1255 return; | 1256 return; |
1256 if (argend > arg && argend[-1] == '.') // for var.='str' | 1257 if (argend > arg && argend[-1] == '.') // for var.='str' |
1257 --argend; | 1258 --argend; |
1258 expr = skipwhite(argend); | 1259 expr = skipwhite(argend); |
1259 if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%.", *expr) != NULL | 1260 concat = expr[0] == '.' |
1260 && expr[1] == '=') || STRNCMP(expr, "..=", 3) == 0)) | 1261 && ((expr[1] == '=' && current_sctx.sc_version < 2) |
1262 || (expr[1] == '.' && expr[2] == '=')); | |
1263 if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%", *expr) != NULL | |
1264 && expr[1] == '=') || concat)) | |
1261 { | 1265 { |
1262 /* | 1266 /* |
1263 * ":let" without "=": list variables | 1267 * ":let" without "=": list variables |
1264 */ | 1268 */ |
1265 if (*arg == '[') | 1269 if (*arg == '[') |
1266 emsg(_(e_invarg)); | 1270 emsg(_(e_invarg)); |
1271 else if (expr[0] == '.') | |
1272 emsg(_("E985: .= is not supported with script version 2")); | |
1267 else if (!ends_excmd(*arg)) | 1273 else if (!ends_excmd(*arg)) |
1268 /* ":let var1 var2" */ | 1274 /* ":let var1 var2" */ |
1269 arg = list_arg_vars(eap, arg, &first); | 1275 arg = list_arg_vars(eap, arg, &first); |
1270 else if (!eap->skip) | 1276 else if (!eap->skip) |
1271 { | 1277 { |
3815 | 3821 |
3816 /* | 3822 /* |
3817 * Handle fourth level expression: | 3823 * Handle fourth level expression: |
3818 * + number addition | 3824 * + number addition |
3819 * - number subtraction | 3825 * - number subtraction |
3820 * . string concatenation | 3826 * . string concatenation (if script version is 1) |
3821 * .. string concatenation | 3827 * .. string concatenation |
3822 * | 3828 * |
3823 * "arg" must point to the first non-white of the expression. | 3829 * "arg" must point to the first non-white of the expression. |
3824 * "arg" is advanced to the next non-white after the recognized expression. | 3830 * "arg" is advanced to the next non-white after the recognized expression. |
3825 * | 3831 * |
3836 float_T f1 = 0, f2 = 0; | 3842 float_T f1 = 0, f2 = 0; |
3837 #endif | 3843 #endif |
3838 char_u *s1, *s2; | 3844 char_u *s1, *s2; |
3839 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; | 3845 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; |
3840 char_u *p; | 3846 char_u *p; |
3847 int concat; | |
3841 | 3848 |
3842 /* | 3849 /* |
3843 * Get the first variable. | 3850 * Get the first variable. |
3844 */ | 3851 */ |
3845 if (eval6(arg, rettv, evaluate, FALSE) == FAIL) | 3852 if (eval6(arg, rettv, evaluate, FALSE) == FAIL) |
3848 /* | 3855 /* |
3849 * Repeat computing, until no '+', '-' or '.' is following. | 3856 * Repeat computing, until no '+', '-' or '.' is following. |
3850 */ | 3857 */ |
3851 for (;;) | 3858 for (;;) |
3852 { | 3859 { |
3860 // "." is only string concatenation when scriptversion is 1 | |
3853 op = **arg; | 3861 op = **arg; |
3854 if (op != '+' && op != '-' && op != '.') | 3862 concat = op == '.' |
3863 && (*(*arg + 1) == '.' || current_sctx.sc_version < 2); | |
3864 if (op != '+' && op != '-' && !concat) | |
3855 break; | 3865 break; |
3856 | 3866 |
3857 if ((op != '+' || (rettv->v_type != VAR_LIST | 3867 if ((op != '+' || (rettv->v_type != VAR_LIST |
3858 && rettv->v_type != VAR_BLOB)) | 3868 && rettv->v_type != VAR_BLOB)) |
3859 #ifdef FEAT_FLOAT | 3869 #ifdef FEAT_FLOAT |
4222 start_leader = *arg; | 4232 start_leader = *arg; |
4223 while (**arg == '!' || **arg == '-' || **arg == '+') | 4233 while (**arg == '!' || **arg == '-' || **arg == '+') |
4224 *arg = skipwhite(*arg + 1); | 4234 *arg = skipwhite(*arg + 1); |
4225 end_leader = *arg; | 4235 end_leader = *arg; |
4226 | 4236 |
4237 if (**arg == '.' && (!isdigit(*(*arg + 1)) | |
4238 #ifdef FEAT_FLOAT | |
4239 || current_sctx.sc_version < 2 | |
4240 #endif | |
4241 )) | |
4242 { | |
4243 semsg(_(e_invexpr2), *arg); | |
4244 ++*arg; | |
4245 return FAIL; | |
4246 } | |
4247 | |
4227 switch (**arg) | 4248 switch (**arg) |
4228 { | 4249 { |
4229 /* | 4250 /* |
4230 * Number constant. | 4251 * Number constant. |
4231 */ | 4252 */ |
4237 case '5': | 4258 case '5': |
4238 case '6': | 4259 case '6': |
4239 case '7': | 4260 case '7': |
4240 case '8': | 4261 case '8': |
4241 case '9': | 4262 case '9': |
4263 case '.': | |
4242 { | 4264 { |
4243 #ifdef FEAT_FLOAT | 4265 #ifdef FEAT_FLOAT |
4244 char_u *p = skipdigits(*arg + 1); | 4266 char_u *p; |
4245 int get_float = FALSE; | 4267 int get_float = FALSE; |
4246 | 4268 |
4247 /* We accept a float when the format matches | 4269 /* We accept a float when the format matches |
4248 * "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very | 4270 * "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very |
4249 * strict to avoid backwards compatibility problems. | 4271 * strict to avoid backwards compatibility problems. |
4272 * With script version 2 and later the leading digit can be | |
4273 * omitted. | |
4250 * Don't look for a float after the "." operator, so that | 4274 * Don't look for a float after the "." operator, so that |
4251 * ":let vers = 1.2.3" doesn't fail. */ | 4275 * ":let vers = 1.2.3" doesn't fail. */ |
4276 if (**arg == '.') | |
4277 p = *arg; | |
4278 else | |
4279 p = skipdigits(*arg + 1); | |
4252 if (!want_string && p[0] == '.' && vim_isdigit(p[1])) | 4280 if (!want_string && p[0] == '.' && vim_isdigit(p[1])) |
4253 { | 4281 { |
4254 get_float = TRUE; | 4282 get_float = TRUE; |
4255 p = skipdigits(p + 2); | 4283 p = skipdigits(p + 2); |
4256 if (*p == 'e' || *p == 'E') | 4284 if (*p == 'e' || *p == 'E') |