mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -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}.
|
* Return OK or FAIL. Returns NOTDONE for {expr}.
|
||||||
*/
|
*/
|
||||||
int
|
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;
|
int evaluate = evalarg == NULL ? FALSE
|
||||||
evalarg_T evalarg;
|
: evalarg->eval_flags & EVAL_EVALUATE;
|
||||||
dict_T *d = NULL;
|
dict_T *d = NULL;
|
||||||
typval_T tvkey;
|
typval_T tvkey;
|
||||||
typval_T tv;
|
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 *start = skipwhite(*arg + 1);
|
||||||
char_u buf[NUMBUFLEN];
|
char_u buf[NUMBUFLEN];
|
||||||
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
|
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
|
||||||
|
int had_comma;
|
||||||
CLEAR_FIELD(evalarg);
|
int getnext;
|
||||||
evalarg.eval_flags = flags;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First check if it's not a curly-braces thing: {expr}.
|
* 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;
|
tv.v_type = VAR_UNKNOWN;
|
||||||
|
|
||||||
*arg = skipwhite(*arg + 1);
|
*arg = skipwhite(*arg + 1);
|
||||||
|
eval_next_non_blank(*arg, evalarg, &getnext);
|
||||||
|
if (getnext)
|
||||||
|
*arg = eval_next_line(evalarg);
|
||||||
while (**arg != '}' && **arg != NUL)
|
while (**arg != '}' && **arg != NUL)
|
||||||
{
|
{
|
||||||
if ((literal
|
if ((literal
|
||||||
? get_literal_key(arg, &tvkey)
|
? get_literal_key(arg, &tvkey)
|
||||||
: eval1(arg, &tvkey, &evalarg)) == FAIL) // recursive!
|
: eval1(arg, &tvkey, evalarg)) == FAIL) // recursive!
|
||||||
goto failret;
|
goto failret;
|
||||||
|
|
||||||
if (**arg != ':')
|
if (**arg != ':')
|
||||||
@@ -857,9 +859,17 @@ eval_dict(char_u **arg, typval_T *rettv, int flags, int literal)
|
|||||||
goto failret;
|
goto failret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (vim9script && (*arg)[1] != NUL && !VIM_ISWHITE((*arg)[1]))
|
||||||
|
{
|
||||||
|
semsg(_(e_white_after), ":");
|
||||||
|
goto failret;
|
||||||
|
}
|
||||||
|
|
||||||
*arg = skipwhite(*arg + 1);
|
*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)
|
if (evaluate)
|
||||||
clear_tv(&tvkey);
|
clear_tv(&tvkey);
|
||||||
@@ -887,15 +897,30 @@ eval_dict(char_u **arg, typval_T *rettv, int flags, int literal)
|
|||||||
}
|
}
|
||||||
clear_tv(&tvkey);
|
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 == '}')
|
if (**arg == '}')
|
||||||
break;
|
break;
|
||||||
if (**arg != ',')
|
if (!had_comma)
|
||||||
{
|
{
|
||||||
if (evaluate)
|
if (evaluate)
|
||||||
semsg(_(e_missing_dict_comma), *arg);
|
semsg(_(e_missing_dict_comma), *arg);
|
||||||
goto failret;
|
goto failret;
|
||||||
}
|
}
|
||||||
*arg = skipwhite(*arg + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (**arg != '}')
|
if (**arg != '}')
|
||||||
|
@@ -2787,7 +2787,7 @@ eval7(
|
|||||||
case '#': if ((*arg)[1] == '{')
|
case '#': if ((*arg)[1] == '{')
|
||||||
{
|
{
|
||||||
++*arg;
|
++*arg;
|
||||||
ret = eval_dict(arg, rettv, flags, TRUE);
|
ret = eval_dict(arg, rettv, evalarg, TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret = NOTDONE;
|
ret = NOTDONE;
|
||||||
@@ -2799,7 +2799,7 @@ eval7(
|
|||||||
*/
|
*/
|
||||||
case '{': ret = get_lambda_tv(arg, rettv, evaluate);
|
case '{': ret = get_lambda_tv(arg, rettv, evaluate);
|
||||||
if (ret == NOTDONE)
|
if (ret == NOTDONE)
|
||||||
ret = eval_dict(arg, rettv, flags, FALSE);
|
ret = eval_dict(arg, rettv, evalarg, FALSE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -32,7 +32,7 @@ varnumber_T dict_get_number(dict_T *d, char_u *key);
|
|||||||
varnumber_T dict_get_number_def(dict_T *d, char_u *key, int def);
|
varnumber_T dict_get_number_def(dict_T *d, char_u *key, int def);
|
||||||
varnumber_T dict_get_number_check(dict_T *d, char_u *key);
|
varnumber_T dict_get_number_check(dict_T *d, char_u *key);
|
||||||
char_u *dict2string(typval_T *tv, int copyID, int restore_copyID);
|
char_u *dict2string(typval_T *tv, int copyID, int restore_copyID);
|
||||||
int eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal);
|
int eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal);
|
||||||
void dict_extend(dict_T *d1, dict_T *d2, char_u *action);
|
void dict_extend(dict_T *d1, dict_T *d2, char_u *action);
|
||||||
dictitem_T *dict_lookup(hashitem_T *hi);
|
dictitem_T *dict_lookup(hashitem_T *hi);
|
||||||
int dict_equal(dict_T *d1, dict_T *d2, int ic, int recursive);
|
int dict_equal(dict_T *d1, dict_T *d2, int ic, int recursive);
|
||||||
|
@@ -1002,6 +1002,12 @@ def Test_expr7_list_vim9script()
|
|||||||
assert_equal([11, 22], l)
|
assert_equal([11, 22], l)
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
let l = [11,22]
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1069:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr7_lambda()
|
def Test_expr7_lambda()
|
||||||
@@ -1034,6 +1040,40 @@ def Test_expr7_dict()
|
|||||||
call CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:')
|
call CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_expr7_dict_vim9script()
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
let d = {
|
||||||
|
'one':
|
||||||
|
1,
|
||||||
|
'two': 2,
|
||||||
|
}
|
||||||
|
assert_equal({'one': 1, 'two': 2}, d)
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
let d = #{one: 1,
|
||||||
|
two: 2,
|
||||||
|
}
|
||||||
|
assert_equal({'one': 1, 'two': 2}, d)
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
let d = #{one:1, two: 2}
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1069:')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
let d = #{one: 1,two: 2}
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1069:')
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_expr_member()
|
def Test_expr_member()
|
||||||
assert_equal(1, g:dict_one.one)
|
assert_equal(1, g:dict_one.one)
|
||||||
let d: dict<number> = g:dict_one
|
let d: dict<number> = g:dict_one
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1068,
|
||||||
/**/
|
/**/
|
||||||
1067,
|
1067,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -2996,7 +2996,7 @@ to_name_const_end(char_u *arg)
|
|||||||
{
|
{
|
||||||
// Can be "#{a: 1}->Func()".
|
// Can be "#{a: 1}->Func()".
|
||||||
++p;
|
++p;
|
||||||
if (eval_dict(&p, &rettv, 0, TRUE) == FAIL)
|
if (eval_dict(&p, &rettv, NULL, TRUE) == FAIL)
|
||||||
p = arg;
|
p = arg;
|
||||||
}
|
}
|
||||||
else if (p == arg && *arg == '{')
|
else if (p == arg && *arg == '{')
|
||||||
@@ -3006,7 +3006,7 @@ to_name_const_end(char_u *arg)
|
|||||||
// Can be "{x -> ret}()".
|
// Can be "{x -> ret}()".
|
||||||
// Can be "{'a': 1}->Func()".
|
// Can be "{'a': 1}->Func()".
|
||||||
if (ret == NOTDONE)
|
if (ret == NOTDONE)
|
||||||
ret = eval_dict(&p, &rettv, 0, FALSE);
|
ret = eval_dict(&p, &rettv, NULL, FALSE);
|
||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
p = arg;
|
p = arg;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user