mirror of
https://github.com/neovim/neovim.git
synced 2025-12-06 14:42:35 +00:00
vim-patch:8.2.4934: string interpolation fails when not evaluating
Problem: String interpolation fails when not evaluating.
Solution: Skip the expression when not evaluating. (closes vim/vim#10398)
70c41241c2
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -84,9 +84,7 @@ syn case ignore
|
|||||||
|
|
||||||
let s:digits = "0123456789ABCDEF"
|
let s:digits = "0123456789ABCDEF"
|
||||||
for s:radix in range(2, 16)
|
for s:radix in range(2, 16)
|
||||||
" Nvim does not support interpolated strings yet.
|
exe $'syn match modula3Integer "\<{s:radix}_[{s:digits[:s:radix - 1]}]\+L\=\>"'
|
||||||
" exe $'syn match modula3Integer "\<{s:radix}_[{s:digits[:s:radix - 1]}]\+L\=\>"'
|
|
||||||
exe 'syn match modula3Integer "\<' .. s:radix .. '_[' .. s:digits[:s:radix - 1] .. ']\+L\=\>"'
|
|
||||||
endfor
|
endfor
|
||||||
unlet s:digits s:radix
|
unlet s:digits s:radix
|
||||||
|
|
||||||
|
|||||||
@@ -4140,7 +4140,7 @@ int eval_interp_string(char **arg, typval_T *rettv, bool evaluate)
|
|||||||
(*arg)++;
|
(*arg)++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
char *p = eval_one_expr_in_str(*arg, &ga);
|
char *p = eval_one_expr_in_str(*arg, &ga, evaluate);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -55,8 +55,9 @@ static const char *e_lock_unlock = N_("E940: Cannot lock or unlock variable %s")
|
|||||||
|
|
||||||
/// Evaluate one Vim expression {expr} in string "p" and append the
|
/// Evaluate one Vim expression {expr} in string "p" and append the
|
||||||
/// resulting string to "gap". "p" points to the opening "{".
|
/// resulting string to "gap". "p" points to the opening "{".
|
||||||
|
/// When "evaluate" is false only skip over the expression.
|
||||||
/// Return a pointer to the character after "}", NULL for an error.
|
/// Return a pointer to the character after "}", NULL for an error.
|
||||||
char *eval_one_expr_in_str(char *p, garray_T *gap)
|
char *eval_one_expr_in_str(char *p, garray_T *gap, bool evaluate)
|
||||||
{
|
{
|
||||||
char *block_start = skipwhite(p + 1); // skip the opening {
|
char *block_start = skipwhite(p + 1); // skip the opening {
|
||||||
char *block_end = block_start;
|
char *block_end = block_start;
|
||||||
@@ -73,14 +74,16 @@ char *eval_one_expr_in_str(char *p, garray_T *gap)
|
|||||||
semsg(_(e_missing_close_curly_str), p);
|
semsg(_(e_missing_close_curly_str), p);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*block_end = NUL;
|
if (evaluate) {
|
||||||
char *expr_val = eval_to_string(block_start, true);
|
*block_end = NUL;
|
||||||
*block_end = '}';
|
char *expr_val = eval_to_string(block_start, true);
|
||||||
if (expr_val == NULL) {
|
*block_end = '}';
|
||||||
return NULL;
|
if (expr_val == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ga_concat(gap, expr_val);
|
||||||
|
xfree(expr_val);
|
||||||
}
|
}
|
||||||
ga_concat(gap, expr_val);
|
|
||||||
xfree(expr_val);
|
|
||||||
|
|
||||||
return block_end + 1;
|
return block_end + 1;
|
||||||
}
|
}
|
||||||
@@ -129,7 +132,7 @@ char *eval_all_expr_in_str(char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate the expression and append the result.
|
// Evaluate the expression and append the result.
|
||||||
p = eval_one_expr_in_str(p, &ga);
|
p = eval_one_expr_in_str(p, &ga, true);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -35,9 +35,7 @@ func Test_getscriptinfo()
|
|||||||
source Xscript
|
source Xscript
|
||||||
let l = getscriptinfo()
|
let l = getscriptinfo()
|
||||||
call assert_match('Xscript$', l[-1].name)
|
call assert_match('Xscript$', l[-1].name)
|
||||||
" Nvim does not support interpolated strings yet.
|
call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_")
|
||||||
" call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_")
|
|
||||||
call assert_equal(g:loaded_script_id, '<SNR>' . l[-1].sid . '_')
|
|
||||||
call delete('Xscript')
|
call delete('Xscript')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user