Mercurial > vim
comparison src/vim9expr.c @ 28718:723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Commit: https://github.com/vim/vim/commit/2eaef106e4a7fc9dc74a7e672b5f550ec1f9786e
Author: LemonBoy <thatlemon@gmail.com>
Date: Fri May 6 13:14:50 2022 +0100
patch 8.2.4883: string interpolation only works in heredoc
Problem: String interpolation only works in heredoc.
Solution: Support interpolated strings. Use syntax for heredoc consistent
with strings, similar to C#. (closes #10327)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 06 May 2022 14:15:03 +0200 |
parents | bfd8e25fa207 |
children | 3626ca6a20ea |
comparison
equal
deleted
inserted
replaced
28717:3953457538c9 | 28718:723c7d940cba |
---|---|
1373 vim_free(name); | 1373 vim_free(name); |
1374 return ret; | 1374 return ret; |
1375 } | 1375 } |
1376 | 1376 |
1377 /* | 1377 /* |
1378 * Compile "$"string"" or "$'string'". | |
1379 */ | |
1380 static int | |
1381 compile_interp_string(char_u **arg, cctx_T *cctx) | |
1382 { | |
1383 typval_T tv; | |
1384 int ret; | |
1385 int evaluate = cctx->ctx_skip != SKIP_YES; | |
1386 | |
1387 // *arg is on the '$' character. | |
1388 (*arg)++; | |
1389 | |
1390 if (**arg == '"') | |
1391 ret = eval_string(arg, &tv, evaluate); | |
1392 else | |
1393 ret = eval_lit_string(arg, &tv, evaluate); | |
1394 | |
1395 if (ret == FAIL || !evaluate) | |
1396 return ret; | |
1397 | |
1398 ret = compile_all_expr_in_str(tv.vval.v_string, TRUE, cctx); | |
1399 clear_tv(&tv); | |
1400 | |
1401 return ret; | |
1402 } | |
1403 | |
1404 /* | |
1378 * Compile "@r". | 1405 * Compile "@r". |
1379 */ | 1406 */ |
1380 static int | 1407 static int |
1381 compile_get_register(char_u **arg, cctx_T *cctx) | 1408 compile_get_register(char_u **arg, cctx_T *cctx) |
1382 { | 1409 { |
2224 ret = compile_get_option(arg, cctx); | 2251 ret = compile_get_option(arg, cctx); |
2225 break; | 2252 break; |
2226 | 2253 |
2227 /* | 2254 /* |
2228 * Environment variable: $VAR. | 2255 * Environment variable: $VAR. |
2256 * Interpolated string: $"string" or $'string'. | |
2229 */ | 2257 */ |
2230 case '$': if (generate_ppconst(cctx, ppconst) == FAIL) | 2258 case '$': if (generate_ppconst(cctx, ppconst) == FAIL) |
2231 return FAIL; | 2259 return FAIL; |
2232 ret = compile_get_env(arg, cctx); | 2260 if ((*arg)[1] == '"' || (*arg)[1] == '\'') |
2261 ret = compile_interp_string(arg, cctx); | |
2262 else | |
2263 ret = compile_get_env(arg, cctx); | |
2233 break; | 2264 break; |
2234 | 2265 |
2235 /* | 2266 /* |
2236 * Register contents: @r. | 2267 * Register contents: @r. |
2237 */ | 2268 */ |