Patch 8.2.0555
Problem:    Vim9: line continuation is not always needed.
Solution:   Recognize continuation lines automatically in list and dict.
Files:      runtime/doc/vim9.txt, src/vim9compile.c,
            src/testdir/test_vim9_expr.vim, src/testdir/test_vim9_script.vim


*** ../vim-8.2.0554/runtime/doc/vim9.txt        2020-04-11 20:50:25.372120470 
+0200
--- runtime/doc/vim9.txt        2020-04-12 15:40:46.231272691 +0200
***************
*** 175,180 ****
--- 175,191 ----
  number of arguments and any return type.  The function can be defined later.
  
  
+ Automatic line continuation ~
+ 
+ In many cases it is obvious that an expression continues on the next line.  In
+ those cases there is no need to prefix the line with a backslash.  For
+ example, when a list spans multiple lines: >
+       let mylist = [
+               'one',
+               'two',
+               ]
+ 
+ 
  No curly braces expansion ~
  
  |curly-braces-names| cannot be used.
*** ../vim-8.2.0554/src/vim9compile.c   2020-04-12 14:39:49.134760416 +0200
--- src/vim9compile.c   2020-04-12 16:37:06.588186468 +0200
***************
*** 2535,2540 ****
--- 2535,2561 ----
  }
  
  /*
+  * Get the next line of the function from "cctx".
+  * Returns NULL when at the end.
+  */
+     static char_u *
+ next_line_from_context(cctx_T *cctx)
+ {
+     char_u    *line = NULL;
+ 
+     do
+     {
+       ++cctx->ctx_lnum;
+       if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len)
+           break;
+       line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
+       SOURCING_LNUM = cctx->ctx_ufunc->uf_script_ctx.sc_lnum
+                                                         + cctx->ctx_lnum + 1;
+     } while (line == NULL);
+     return line;
+ }
+ 
+ /*
   * parse a list: [expr, expr]
   * "*arg" points to the '['.
   */
***************
*** 2544,2555 ****
      char_u    *p = skipwhite(*arg + 1);
      int               count = 0;
  
!     while (*p != ']')
      {
        if (*p == NUL)
        {
!           semsg(_(e_list_end), *arg);
!           return FAIL;
        }
        if (compile_expr1(&p, cctx) == FAIL)
            break;
--- 2565,2589 ----
      char_u    *p = skipwhite(*arg + 1);
      int               count = 0;
  
!     for (;;)
      {
        if (*p == NUL)
        {
!           p = next_line_from_context(cctx);
!           if (p == NULL)
!           {
!               semsg(_(e_list_end), *arg);
!               return FAIL;
!           }
!           p = skipwhite(p);
!       }
!       if (*p == ']')
!       {
!           ++p;
!           // Allow for following comment, after at least one space.
!           if (VIM_ISWHITE(*p) && *skipwhite(p) == '"')
!               p += STRLEN(p);
!           break;
        }
        if (compile_expr1(&p, cctx) == FAIL)
            break;
***************
*** 2558,2564 ****
            ++p;
        p = skipwhite(p);
      }
!     *arg = p + 1;
  
      generate_NEWLIST(cctx, count);
      return OK;
--- 2592,2598 ----
            ++p;
        p = skipwhite(p);
      }
!     *arg = p;
  
      generate_NEWLIST(cctx, count);
      return OK;
***************
*** 2657,2666 ****
      if (d == NULL)
        return FAIL;
      *arg = skipwhite(*arg + 1);
!     while (**arg != '}' && **arg != NUL)
      {
        char_u *key = NULL;
  
        if (literal)
        {
            char_u *p = to_name_end(*arg, !literal);
--- 2691,2711 ----
      if (d == NULL)
        return FAIL;
      *arg = skipwhite(*arg + 1);
!     for (;;)
      {
        char_u *key = NULL;
  
+       if (**arg == NUL || (literal && **arg == '"'))
+       {
+           *arg = next_line_from_context(cctx);
+           if (*arg == NULL)
+               goto failret;
+           *arg = skipwhite(*arg);
+       }
+ 
+       if (**arg == '}')
+           break;
+ 
        if (literal)
        {
            char_u *p = to_name_end(*arg, !literal);
***************
*** 2714,2723 ****
--- 2759,2783 ----
        }
  
        *arg = skipwhite(*arg + 1);
+       if (**arg == NUL)
+       {
+           *arg = next_line_from_context(cctx);
+           if (*arg == NULL)
+               goto failret;
+           *arg = skipwhite(*arg);
+       }
+ 
        if (compile_expr1(arg, cctx) == FAIL)
            return FAIL;
        ++count;
  
+       if (**arg == NUL || *skipwhite(*arg) == '"')
+       {
+           *arg = next_line_from_context(cctx);
+           if (*arg == NULL)
+               goto failret;
+           *arg = skipwhite(*arg);
+       }
        if (**arg == '}')
            break;
        if (**arg != ',')
***************
*** 2735,2744 ****
--- 2795,2810 ----
      }
      *arg = *arg + 1;
  
+     // Allow for following comment, after at least one space.
+     if (VIM_ISWHITE(**arg) && *skipwhite(*arg) == '"')
+       *arg += STRLEN(*arg);
+ 
      dict_unref(d);
      return generate_NEWDICT(cctx, count);
  
  failret:
+     if (*arg == NULL)
+       semsg(_(e_missing_dict_end), _("[end of lines]"));
      dict_unref(d);
      return FAIL;
  }
***************
*** 5645,5660 ****
        }
        else
        {
!           do
!           {
!               ++cctx.ctx_lnum;
!               if (cctx.ctx_lnum == ufunc->uf_lines.ga_len)
!                   break;
!               line = ((char_u **)ufunc->uf_lines.ga_data)[cctx.ctx_lnum];
!           } while (line == NULL);
!           if (cctx.ctx_lnum == ufunc->uf_lines.ga_len)
                break;
-           SOURCING_LNUM = ufunc->uf_script_ctx.sc_lnum + cctx.ctx_lnum + 1;
        }
        emsg_before = called_emsg;
  
--- 5711,5719 ----
        }
        else
        {
!           line = next_line_from_context(&cctx);
!           if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len)
                break;
        }
        emsg_before = called_emsg;
  
*** ../vim-8.2.0554/src/testdir/test_vim9_expr.vim      2020-04-09 
19:34:40.051480485 +0200
--- src/testdir/test_vim9_expr.vim      2020-04-12 15:54:19.833753628 +0200
***************
*** 767,773 ****
  
    call CheckDefFailure("let x = #{8: 8}", 'E1014:')
    call CheckDefFailure("let x = #{xxx}", 'E720:')
!   call CheckDefFailure("let x = #{xxx: 1", 'E722:')
    call CheckDefFailure("let x = #{xxx: 1,", 'E723:')
    call CheckDefFailure("let x = {'a': xxx}", 'E1001:')
    call CheckDefFailure("let x = {xxx: 8}", 'E1001:')
--- 767,773 ----
  
    call CheckDefFailure("let x = #{8: 8}", 'E1014:')
    call CheckDefFailure("let x = #{xxx}", 'E720:')
!   call CheckDefFailure("let x = #{xxx: 1", 'E723:')
    call CheckDefFailure("let x = #{xxx: 1,", 'E723:')
    call CheckDefFailure("let x = {'a': xxx}", 'E1001:')
    call CheckDefFailure("let x = {xxx: 8}", 'E1001:')
*** ../vim-8.2.0554/src/testdir/test_vim9_script.vim    2020-04-09 
20:10:50.389873647 +0200
--- src/testdir/test_vim9_script.vim    2020-04-12 16:35:24.364421907 +0200
***************
*** 966,971 ****
--- 966,995 ----
    assert_true(caught, 'should have caught an exception')
  enddef
  
+ def Test_automatic_line_continuation()
+   let mylist = [
+       'one',
+       'two',
+       'three',
+       ] " comment
+   assert_equal(['one', 'two', 'three'], mylist)
+ 
+   let mydict = {
+       'one': 1,
+       'two': 2,
+       'three':
+           3,
+       } " comment
+   assert_equal({'one': 1, 'two': 2, 'three': 3}, mydict)
+   mydict = #{
+       one: 1,  " comment
+       two:
+            2,
+       three: 3  " comment
+       }
+   assert_equal(#{one: 1, two: 2, three: 3}, mydict)
+ enddef
+ 
  " Keep this last, it messes up highlighting.
  def Test_substitute_cmd()
    new
*** ../vim-8.2.0554/src/version.c       2020-04-12 15:10:36.618312729 +0200
--- src/version.c       2020-04-12 15:39:11.763484958 +0200
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     555,
  /**/

-- 
The most powerful force in the universe is gossip.

 /// Bram Moolenaar -- [email protected] -- 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    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202004121439.03CEdgot001876%40masaka.moolenaar.net.

Raspunde prin e-mail lui