diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-14 21:08:00 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-04-15 17:59:32 +0800 |
commit | bacb5021d4eff33c67eb659fb01125b2abcacd79 (patch) | |
tree | 553983c2a337c8183899bd3f33abb84033bce5fc /src/nvim/eval.c | |
parent | 2cf8f01e7d0469b592bacecd5f224b4fe3149a62 (diff) | |
download | rneovim-bacb5021d4eff33c67eb659fb01125b2abcacd79.tar.gz rneovim-bacb5021d4eff33c67eb659fb01125b2abcacd79.tar.bz2 rneovim-bacb5021d4eff33c67eb659fb01125b2abcacd79.zip |
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 vim/vim#10327)
https://github.com/vim/vim/commit/2eaef106e4a7fc9dc74a7e672b5f550ec1f9786e
Cherry-pick Test_Debugger_breakadd_expr() from Vim.
Co-authored-by: LemonBoy <thatlemon@gmail.com>
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b240c36977..f8a9326703 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3100,8 +3100,13 @@ static int eval7(char **arg, typval_T *rettv, evalarg_T *const evalarg, bool wan ret = eval_option((const char **)arg, rettv, evaluate); break; // Environment variable: $VAR. + // Interpolated string: $"string" or $'string'. case '$': - ret = eval_env_var(arg, rettv, evaluate); + if ((*arg)[1] == '"' || (*arg)[1] == '\'') { + ret = eval_interp_string(arg, rettv, evaluate); + } else { + ret = eval_env_var(arg, rettv, evaluate); + } break; // Register contents: @r. @@ -4053,6 +4058,32 @@ static int eval_lit_string(char **arg, typval_T *rettv, int evaluate) return OK; } +int eval_interp_string(char **arg, typval_T *rettv, int evaluate) +{ + // *arg is on the '$' character. + (*arg)++; + + rettv->v_type = VAR_STRING; + + typval_T tv; + int ret; + if (**arg == '"') { + ret = eval_string(arg, &tv, evaluate); + } else { + ret = eval_lit_string(arg, &tv, evaluate); + } + + if (ret == FAIL || !evaluate) { + return ret; + } + + rettv->vval.v_string = eval_all_expr_in_str(tv.vval.v_string); + + tv_clear(&tv); + + return rettv->vval.v_string != NULL ? OK : FAIL; +} + /// @return the function name of the partial. char *partial_name(partial_T *pt) FUNC_ATTR_PURE |