Mercurial > vim
comparison src/eval.c @ 16219:bd49e1656c72 v8.1.1114
patch 8.1.1114: confusing overloaded operator "." for string concatenation
commit https://github.com/vim/vim/commit/0f248b006c2574abc00c9aa7886d8f33620eb822
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 4 15:36:05 2019 +0200
patch 8.1.1114: confusing overloaded operator "." for string concatenation
Problem: Confusing overloaded operator "." for string concatenation.
Solution: Add ".." for string concatenation. Also "let a ..= b".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 Apr 2019 15:45:04 +0200 |
parents | 097a56d293c7 |
children | abb67309c1ca |
comparison
equal
deleted
inserted
replaced
16218:0874f5cbaaa6 | 16219:bd49e1656c72 |
---|---|
1232 * ":let var -= expr" assignment command. | 1232 * ":let var -= expr" assignment command. |
1233 * ":let var *= expr" assignment command. | 1233 * ":let var *= expr" assignment command. |
1234 * ":let var /= expr" assignment command. | 1234 * ":let var /= expr" assignment command. |
1235 * ":let var %= expr" assignment command. | 1235 * ":let var %= expr" assignment command. |
1236 * ":let var .= expr" assignment command. | 1236 * ":let var .= expr" assignment command. |
1237 * ":let var ..= expr" assignment command. | |
1237 * ":let [var1, var2] = expr" unpack list. | 1238 * ":let [var1, var2] = expr" unpack list. |
1238 */ | 1239 */ |
1239 void | 1240 void |
1240 ex_let(exarg_T *eap) | 1241 ex_let(exarg_T *eap) |
1241 { | 1242 { |
1253 if (argend == NULL) | 1254 if (argend == NULL) |
1254 return; | 1255 return; |
1255 if (argend > arg && argend[-1] == '.') // for var.='str' | 1256 if (argend > arg && argend[-1] == '.') // for var.='str' |
1256 --argend; | 1257 --argend; |
1257 expr = skipwhite(argend); | 1258 expr = skipwhite(argend); |
1258 if (*expr != '=' && !(vim_strchr((char_u *)"+-*/%.", *expr) != NULL | 1259 if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%.", *expr) != NULL |
1259 && expr[1] == '=')) | 1260 && expr[1] == '=') || STRNCMP(expr, "..=", 3) == 0)) |
1260 { | 1261 { |
1261 /* | 1262 /* |
1262 * ":let" without "=": list variables | 1263 * ":let" without "=": list variables |
1263 */ | 1264 */ |
1264 if (*arg == '[') | 1265 if (*arg == '[') |
1284 op[0] = '='; | 1285 op[0] = '='; |
1285 op[1] = NUL; | 1286 op[1] = NUL; |
1286 if (*expr != '=') | 1287 if (*expr != '=') |
1287 { | 1288 { |
1288 if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL) | 1289 if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL) |
1290 { | |
1289 op[0] = *expr; // +=, -=, *=, /=, %= or .= | 1291 op[0] = *expr; // +=, -=, *=, /=, %= or .= |
1292 if (expr[0] == '.' && expr[1] == '.') // ..= | |
1293 ++expr; | |
1294 } | |
1290 expr = skipwhite(expr + 2); | 1295 expr = skipwhite(expr + 2); |
1291 } | 1296 } |
1292 else | 1297 else |
1293 expr = skipwhite(expr + 1); | 1298 expr = skipwhite(expr + 1); |
1294 | 1299 |
3811 /* | 3816 /* |
3812 * Handle fourth level expression: | 3817 * Handle fourth level expression: |
3813 * + number addition | 3818 * + number addition |
3814 * - number subtraction | 3819 * - number subtraction |
3815 * . string concatenation | 3820 * . string concatenation |
3821 * .. string concatenation | |
3816 * | 3822 * |
3817 * "arg" must point to the first non-white of the expression. | 3823 * "arg" must point to the first non-white of the expression. |
3818 * "arg" is advanced to the next non-white after the recognized expression. | 3824 * "arg" is advanced to the next non-white after the recognized expression. |
3819 * | 3825 * |
3820 * Return OK or FAIL. | 3826 * Return OK or FAIL. |
3870 } | 3876 } |
3871 | 3877 |
3872 /* | 3878 /* |
3873 * Get the second variable. | 3879 * Get the second variable. |
3874 */ | 3880 */ |
3881 if (op == '.' && *(*arg + 1) == '.') // .. string concatenation | |
3882 ++*arg; | |
3875 *arg = skipwhite(*arg + 1); | 3883 *arg = skipwhite(*arg + 1); |
3876 if (eval6(arg, &var2, evaluate, op == '.') == FAIL) | 3884 if (eval6(arg, &var2, evaluate, op == '.') == FAIL) |
3877 { | 3885 { |
3878 clear_tv(rettv); | 3886 clear_tv(rettv); |
3879 return FAIL; | 3887 return FAIL; |