mirror of
https://github.com/vim/vim.git
synced 2025-10-28 09:27:14 -04:00
patch 8.2.1068: Vim9: no line break allowed inside a dict
Problem: Vim9: no line break allowed inside a dict. Solution: Handle line break inside a dict in Vim9 script.
This commit is contained in:
45
src/dict.c
45
src/dict.c
@@ -792,10 +792,10 @@ get_literal_key(char_u **arg, typval_T *tv)
|
||||
* Return OK or FAIL. Returns NOTDONE for {expr}.
|
||||
*/
|
||||
int
|
||||
eval_dict(char_u **arg, typval_T *rettv, int flags, int literal)
|
||||
eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
|
||||
{
|
||||
int evaluate = flags & EVAL_EVALUATE;
|
||||
evalarg_T evalarg;
|
||||
int evaluate = evalarg == NULL ? FALSE
|
||||
: evalarg->eval_flags & EVAL_EVALUATE;
|
||||
dict_T *d = NULL;
|
||||
typval_T tvkey;
|
||||
typval_T tv;
|
||||
@@ -804,9 +804,8 @@ eval_dict(char_u **arg, typval_T *rettv, int flags, int literal)
|
||||
char_u *start = skipwhite(*arg + 1);
|
||||
char_u buf[NUMBUFLEN];
|
||||
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
|
||||
|
||||
CLEAR_FIELD(evalarg);
|
||||
evalarg.eval_flags = flags;
|
||||
int had_comma;
|
||||
int getnext;
|
||||
|
||||
/*
|
||||
* First check if it's not a curly-braces thing: {expr}.
|
||||
@@ -833,11 +832,14 @@ eval_dict(char_u **arg, typval_T *rettv, int flags, int literal)
|
||||
tv.v_type = VAR_UNKNOWN;
|
||||
|
||||
*arg = skipwhite(*arg + 1);
|
||||
eval_next_non_blank(*arg, evalarg, &getnext);
|
||||
if (getnext)
|
||||
*arg = eval_next_line(evalarg);
|
||||
while (**arg != '}' && **arg != NUL)
|
||||
{
|
||||
if ((literal
|
||||
? get_literal_key(arg, &tvkey)
|
||||
: eval1(arg, &tvkey, &evalarg)) == FAIL) // recursive!
|
||||
: eval1(arg, &tvkey, evalarg)) == FAIL) // recursive!
|
||||
goto failret;
|
||||
|
||||
if (**arg != ':')
|
||||
@@ -857,9 +859,17 @@ eval_dict(char_u **arg, typval_T *rettv, int flags, int literal)
|
||||
goto failret;
|
||||
}
|
||||
}
|
||||
if (vim9script && (*arg)[1] != NUL && !VIM_ISWHITE((*arg)[1]))
|
||||
{
|
||||
semsg(_(e_white_after), ":");
|
||||
goto failret;
|
||||
}
|
||||
|
||||
*arg = skipwhite(*arg + 1);
|
||||
if (eval1(arg, &tv, &evalarg) == FAIL) // recursive!
|
||||
eval_next_non_blank(*arg, evalarg, &getnext);
|
||||
if (getnext)
|
||||
*arg = eval_next_line(evalarg);
|
||||
if (eval1(arg, &tv, evalarg) == FAIL) // recursive!
|
||||
{
|
||||
if (evaluate)
|
||||
clear_tv(&tvkey);
|
||||
@@ -887,15 +897,30 @@ eval_dict(char_u **arg, typval_T *rettv, int flags, int literal)
|
||||
}
|
||||
clear_tv(&tvkey);
|
||||
|
||||
// the comma must come after the value
|
||||
had_comma = **arg == ',';
|
||||
if (had_comma)
|
||||
{
|
||||
if (vim9script && (*arg)[1] != NUL && !VIM_ISWHITE((*arg)[1]))
|
||||
{
|
||||
semsg(_(e_white_after), ",");
|
||||
goto failret;
|
||||
}
|
||||
*arg = skipwhite(*arg + 1);
|
||||
}
|
||||
|
||||
// the "}" can be on the next line
|
||||
eval_next_non_blank(*arg, evalarg, &getnext);
|
||||
if (getnext)
|
||||
*arg = eval_next_line(evalarg);
|
||||
if (**arg == '}')
|
||||
break;
|
||||
if (**arg != ',')
|
||||
if (!had_comma)
|
||||
{
|
||||
if (evaluate)
|
||||
semsg(_(e_missing_dict_comma), *arg);
|
||||
goto failret;
|
||||
}
|
||||
*arg = skipwhite(*arg + 1);
|
||||
}
|
||||
|
||||
if (**arg != '}')
|
||||
|
||||
Reference in New Issue
Block a user