1
0
forked from aniani/vim

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)
This commit is contained in:
LemonBoy
2022-05-06 13:14:50 +01:00
committed by Bram Moolenaar
parent e7d6dbc572
commit 2eaef106e4
16 changed files with 364 additions and 137 deletions

View File

@@ -1374,6 +1374,33 @@ compile_get_env(char_u **arg, cctx_T *cctx)
return ret;
}
/*
* Compile "$"string"" or "$'string'".
*/
static int
compile_interp_string(char_u **arg, cctx_T *cctx)
{
typval_T tv;
int ret;
int evaluate = cctx->ctx_skip != SKIP_YES;
// *arg is on the '$' character.
(*arg)++;
if (**arg == '"')
ret = eval_string(arg, &tv, evaluate);
else
ret = eval_lit_string(arg, &tv, evaluate);
if (ret == FAIL || !evaluate)
return ret;
ret = compile_all_expr_in_str(tv.vval.v_string, TRUE, cctx);
clear_tv(&tv);
return ret;
}
/*
* Compile "@r".
*/
@@ -2226,10 +2253,14 @@ compile_expr8(
/*
* Environment variable: $VAR.
* Interpolated string: $"string" or $'string'.
*/
case '$': if (generate_ppconst(cctx, ppconst) == FAIL)
return FAIL;
ret = compile_get_env(arg, cctx);
if ((*arg)[1] == '"' || (*arg)[1] == '\'')
ret = compile_interp_string(arg, cctx);
else
ret = compile_get_env(arg, cctx);
break;
/*