Patch 8.2.1065

3 views
Skip to first unread message

Bram Moolenaar

unread,
Jun 26, 2020, 4:47:05 PM6/26/20
to vim...@googlegroups.com

Patch 8.2.1065
Problem: Vim9: no line break allowed inside a list.
Solution: Handle line break inside a list in Vim9 script.
Files: src/eval.c, src/proto/eval.pro, src/list.c, src/proto/list.pro,
src/vim9compile.c, src/testdir/test_vim9_expr.vim,
src/testdir/test_arglist.vim


*** ../vim-8.2.1064/src/eval.c 2020-06-26 22:00:33.923923669 +0200
--- src/eval.c 2020-06-26 22:16:06.897654858 +0200
***************
*** 1771,1777 ****
* Otherwise just return "arg" unmodified and set "getnext" to FALSE.
* "arg" must point somewhere inside a line, not at the start.
*/
! static char_u *
eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
{
*getnext = FALSE;
--- 1771,1777 ----
* Otherwise just return "arg" unmodified and set "getnext" to FALSE.
* "arg" must point somewhere inside a line, not at the start.
*/
! char_u *
eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
{
*getnext = FALSE;
***************
*** 1796,1802 ****
/*
* To be called when eval_next_non_blank() sets "getnext" to TRUE.
*/
! static char_u *
eval_next_line(evalarg_T *evalarg)
{
vim_free(evalarg->eval_tofree);
--- 1796,1802 ----
/*
* To be called when eval_next_non_blank() sets "getnext" to TRUE.
*/
! char_u *
eval_next_line(evalarg_T *evalarg)
{
vim_free(evalarg->eval_tofree);
***************
*** 2773,2779 ****
/*
* List: [expr, expr]
*/
! case '[': ret = get_list_tv(arg, rettv, flags, TRUE);
break;

/*
--- 2773,2779 ----
/*
* List: [expr, expr]
*/
! case '[': ret = get_list_tv(arg, rettv, evalarg, TRUE);
break;

/*
*** ../vim-8.2.1064/src/proto/eval.pro 2020-06-24 20:33:59.561106332 +0200
--- src/proto/eval.pro 2020-06-26 22:16:24.417611402 +0200
***************
*** 26,31 ****
--- 26,33 ----
void free_for_info(void *fi_void);
void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx);
int pattern_match(char_u *pat, char_u *text, int ic);
+ char_u *eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext);
+ char_u *eval_next_line(evalarg_T *evalarg);
int eval0(char_u *arg, typval_T *rettv, exarg_T *eap, evalarg_T *evalarg);
int eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
void eval_addblob(typval_T *tv1, typval_T *tv2);
*** ../vim-8.2.1064/src/list.c 2020-06-24 22:07:41.816626147 +0200
--- src/list.c 2020-06-26 22:39:20.506051071 +0200
***************
*** 1156,1174 ****

/*
* Allocate a variable for a List and fill it from "*arg".
* Return OK or FAIL.
*/
int
! get_list_tv(char_u **arg, typval_T *rettv, int flags, int do_error)
{
! int evaluate = flags & EVAL_EVALUATE;
list_T *l = NULL;
typval_T tv;
listitem_T *item;
! evalarg_T evalarg;
!
! CLEAR_FIELD(evalarg);
! evalarg.eval_flags = flags;

if (evaluate)
{
--- 1156,1174 ----

/*
* Allocate a variable for a List and fill it from "*arg".
+ * "*arg" points to the "[".
* Return OK or FAIL.
*/
int
! get_list_tv(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int do_error)
{
! int evaluate = evalarg == NULL ? FALSE
! : evalarg->eval_flags & EVAL_EVALUATE;
! int getnext;
list_T *l = NULL;
typval_T tv;
listitem_T *item;
! int had_comma;

if (evaluate)
{
***************
*** 1178,1186 ****
}

*arg = skipwhite(*arg + 1);
while (**arg != ']' && **arg != NUL)
{
! if (eval1(arg, &tv, &evalarg) == FAIL) // recursive!
goto failret;
if (evaluate)
{
--- 1178,1189 ----
}

*arg = skipwhite(*arg + 1);
+ eval_next_non_blank(*arg, evalarg, &getnext);
+ if (getnext)
+ *arg = eval_next_line(evalarg);
while (**arg != ']' && **arg != NUL)
{
! if (eval1(arg, &tv, evalarg) == FAIL) // recursive!
goto failret;
if (evaluate)
{
***************
*** 1195,1209 ****
clear_tv(&tv);
}

if (**arg == ']')
break;
! if (**arg != ',')
{
if (do_error)
semsg(_("E696: Missing comma in List: %s"), *arg);
goto failret;
}
- *arg = skipwhite(*arg + 1);
}

if (**arg != ']')
--- 1198,1221 ----
clear_tv(&tv);
}

+ // the comma must comma after the value
+ had_comma = **arg == ',';
+ if (had_comma)
+ *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 (!had_comma)
{
if (do_error)
semsg(_("E696: Missing comma in List: %s"), *arg);
goto failret;
}
}

if (**arg != ']')
*** ../vim-8.2.1064/src/proto/list.pro 2020-06-16 11:34:38.314223444 +0200
--- src/proto/list.pro 2020-06-26 22:09:21.970622280 +0200
***************
*** 39,45 ****
char_u *list2string(typval_T *tv, int copyID, int restore_copyID);
int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int restore_copyID, int copyID);
void f_join(typval_T *argvars, typval_T *rettv);
! int get_list_tv(char_u **arg, typval_T *rettv, int flags, int do_error);
int write_list(FILE *fd, list_T *list, int binary);
void init_static_list(staticList10_T *sl);
void f_list2str(typval_T *argvars, typval_T *rettv);
--- 39,45 ----
char_u *list2string(typval_T *tv, int copyID, int restore_copyID);
int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int restore_copyID, int copyID);
void f_join(typval_T *argvars, typval_T *rettv);
! int get_list_tv(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int do_error);
int write_list(FILE *fd, list_T *list, int binary);
void init_static_list(staticList10_T *sl);
void f_list2str(typval_T *argvars, typval_T *rettv);
*** ../vim-8.2.1064/src/vim9compile.c 2020-06-23 22:26:01.893386768 +0200
--- src/vim9compile.c 2020-06-26 22:09:19.406628117 +0200
***************
*** 2989,2995 ****
{

// Can be "[1, 2, 3]->Func()".
! if (get_list_tv(&p, &rettv, 0, FALSE) == FAIL)
p = arg;
}
else if (p == arg && *arg == '#' && arg[1] == '{')
--- 2989,2995 ----
{

// Can be "[1, 2, 3]->Func()".
! if (get_list_tv(&p, &rettv, NULL, FALSE) == FAIL)
p = arg;
}
else if (p == arg && *arg == '#' && arg[1] == '{')
*** ../vim-8.2.1064/src/testdir/test_vim9_expr.vim 2020-06-26 22:00:33.923923669 +0200
--- src/testdir/test_vim9_expr.vim 2020-06-26 22:23:13.364575713 +0200
***************
*** 974,980 ****
" list
assert_equal(g:list_empty, [])
assert_equal(g:list_empty, [ ])
! assert_equal(g:list_mixed, [1, 'b', false])
assert_equal('b', g:list_mixed[1])

call CheckDefExecFailure(["let x = g:anint[3]"], 'E714:')
--- 974,980 ----
" list
assert_equal(g:list_empty, [])
assert_equal(g:list_empty, [ ])
! assert_equal(g:list_mixed, [1, 'b', false,])
assert_equal('b', g:list_mixed[1])

call CheckDefExecFailure(["let x = g:anint[3]"], 'E714:')
***************
*** 984,989 ****
--- 984,1009 ----
call CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:')
enddef

+ def Test_expr7_list_vim9script()
+ let lines =<< trim END
+ vim9script
+ let l = [
+ 11,
+ 22,
+ ]
+ assert_equal([11, 22], l)
+ END
+ CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ let l = [11,
+ 22]
+ assert_equal([11, 22], l)
+ END
+ CheckScriptSuccess(lines)
+ enddef
+
def Test_expr7_lambda()
" lambda
let La = { -> 'result'}
*** ../vim-8.2.1064/src/testdir/test_arglist.vim 2020-05-31 21:27:58.331221914 +0200
--- src/testdir/test_arglist.vim 2020-06-26 22:35:29.954657383 +0200
***************
*** 175,196 ****

let save_columns = &columns
let &columns = 79
! exe 'args ' .. join(range(1, 81))
! call assert_equal(join([
! \ '',
! \ '[1] 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 ',
! \ '2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 ',
! \ '3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 ',
! \ '4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 ',
! \ '5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ',
! \ ], "\n"),
! \ execute('args'))

! " No trailing newline with one item per row.
! let long_arg = repeat('X', 81)
! exe 'args ' .. long_arg
! call assert_equal("\n[".long_arg.']', execute('args'))
! let &columns = save_columns

" Setting argument list should fail when the current buffer has unsaved
" changes
--- 175,199 ----

let save_columns = &columns
let &columns = 79
! try
! exe 'args ' .. join(range(1, 81))
! call assert_equal(join([
! \ '',
! \ '[1] 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 ',
! \ '2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 ',
! \ '3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 ',
! \ '4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 ',
! \ '5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ',
! \ ], "\n"),
! \ execute('args'))

! " No trailing newline with one item per row.
! let long_arg = repeat('X', 81)
! exe 'args ' .. long_arg
! call assert_equal("\n[".long_arg.']', execute('args'))
! finally
! let &columns = save_columns
! endtry

" Setting argument list should fail when the current buffer has unsaved
" changes
*** ../vim-8.2.1064/src/version.c 2020-06-26 22:00:33.923923669 +0200
--- src/version.c 2020-06-26 22:45:27.889467685 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1065,
/**/

--
<Beeth> Girls are like internet domain names,
the ones I like are already taken.
<honx> Well, you can stil get one from a strange country :-P

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages