Patch 8.2.1029
Problem:    Vim9: cannot chain function calls with -> at line start.
Solution:   Peek ahead for a following line starting with "->". (closes #6306)
Files:      src/vim9compile.c, src/testdir/test_vim9_expr.vim


*** ../vim-8.2.1028/src/vim9compile.c   2020-06-21 15:52:55.810451610 +0200
--- src/vim9compile.c   2020-06-21 16:56:09.932131056 +0200
***************
*** 2381,2391 ****
  }
  
  /*
   * 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;
  
--- 2381,2422 ----
  }
  
  /*
+  * Return TRUE if "p" points at a "#" but not at "#{".
+  */
+     static int
+ comment_start(char_u *p)
+ {
+     return p[0] == '#' && p[1] != '{';
+ }
+ 
+ /*
+  * Return a pointer to the next line that isn't empty or only contains a
+  * comment. Skips over white space.
+  * Returns NULL if there is none.
+  */
+     static char_u *
+ peek_next_line(cctx_T *cctx)
+ {
+     int lnum = cctx->ctx_lnum;
+ 
+     while (++lnum < cctx->ctx_ufunc->uf_lines.ga_len)
+     {
+       char_u *line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[lnum];
+       char_u *p = skipwhite(line);
+ 
+       if (*p != NUL && !comment_start(p))
+           return p;
+     }
+     return NULL;
+ }
+ 
+ /*
   * Get the next line of the function from "cctx".
+  * Skips over empty lines.  Skips over comment lines if "skip_comment" is 
TRUE.
   * Returns NULL when at the end.
   */
      static char_u *
! next_line_from_context(cctx_T *cctx, int skip_comment)
  {
      char_u    *line;
  
***************
*** 2400,2419 ****
        line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
        cctx->ctx_line_start = line;
        SOURCING_LNUM = cctx->ctx_lnum + 1;
!     } while (line == NULL || *skipwhite(line) == NUL);
      return line;
  }
  
  /*
-  * Return TRUE if "p" points at a "#" but not at "#{".
-  */
-     static int
- comment_start(char_u *p)
- {
-     return p[0] == '#' && p[1] != '{';
- }
- 
- /*
   * If "*arg" is at the end of the line, advance to the next line.
   * Also when "whitep" points to white space and "*arg" is on a "#".
   * Return FAIL if beyond the last line, "*arg" is unmodified then.
--- 2431,2442 ----
        line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
        cctx->ctx_line_start = line;
        SOURCING_LNUM = cctx->ctx_lnum + 1;
!     } while (line == NULL || *skipwhite(line) == NUL
!                         || (skip_comment && comment_start(skipwhite(line))));
      return line;
  }
  
  /*
   * If "*arg" is at the end of the line, advance to the next line.
   * Also when "whitep" points to white space and "*arg" is on a "#".
   * Return FAIL if beyond the last line, "*arg" is unmodified then.
***************
*** 2423,2429 ****
  {
      if (**arg == NUL || (VIM_ISWHITE(*whitep) && comment_start(*arg)))
      {
!       char_u *next = next_line_from_context(cctx);
  
        if (next == NULL)
            return FAIL;
--- 2446,2452 ----
  {
      if (**arg == NUL || (VIM_ISWHITE(*whitep) && comment_start(*arg)))
      {
!       char_u *next = next_line_from_context(cctx, TRUE);
  
        if (next == NULL)
            return FAIL;
***************
*** 2752,2765 ****
  
      for (;;)
      {
!       while (*p == NUL || (VIM_ISWHITE(*whitep) && comment_start(p)))
!       {
!           p = next_line_from_context(cctx);
!           if (p == NULL)
!               goto failret;
!           whitep = (char_u *)" ";
!           p = skipwhite(p);
!       }
        if (*p == ')')
        {
            *arg = p + 1;
--- 2775,2782 ----
  
      for (;;)
      {
!       if (may_get_next_line(whitep, &p, cctx) == FAIL)
!           goto failret;
        if (*p == ')')
        {
            *arg = p + 1;
***************
*** 2986,3001 ****
  
      for (;;)
      {
!       while (*p == NUL || (VIM_ISWHITE(*whitep) && comment_start(p)))
        {
!           p = next_line_from_context(cctx);
!           if (p == NULL)
!           {
!               semsg(_(e_list_end), *arg);
!               return FAIL;
!           }
!           whitep = (char_u *)" ";
!           p = skipwhite(p);
        }
        if (*p == ']')
        {
--- 3003,3012 ----
  
      for (;;)
      {
!       if (may_get_next_line(whitep, &p, cctx) == FAIL)
        {
!           semsg(_(e_list_end), *arg);
!           return FAIL;
        }
        if (*p == ']')
        {
***************
*** 3112,3125 ****
      {
        char_u *key = NULL;
  
!       while (**arg == NUL || (literal && **arg == '"')
!                             || (VIM_ISWHITE(*whitep) && comment_start(*arg)))
        {
!           *arg = next_line_from_context(cctx);
!           if (*arg == NULL)
!               goto failret;
!           whitep = (char_u *)" ";
!           *arg = skipwhite(*arg);
        }
  
        if (**arg == '}')
--- 3123,3132 ----
      {
        char_u *key = NULL;
  
!       if (may_get_next_line(whitep, arg, cctx) == FAIL)
        {
!           *arg = NULL;
!           goto failret;
        }
  
        if (**arg == '}')
***************
*** 3179,3191 ****
  
        whitep = *arg + 1;
        *arg = skipwhite(*arg + 1);
!       while (**arg == NUL || (VIM_ISWHITE(*whitep) && comment_start(*arg)))
        {
!           *arg = next_line_from_context(cctx);
!           if (*arg == NULL)
!               goto failret;
!           whitep = (char_u *)" ";
!           *arg = skipwhite(*arg);
        }
  
        if (compile_expr0(arg, cctx) == FAIL)
--- 3186,3195 ----
  
        whitep = *arg + 1;
        *arg = skipwhite(*arg + 1);
!       if (may_get_next_line(whitep, arg, cctx) == FAIL)
        {
!           *arg = NULL;
!           goto failret;
        }
  
        if (compile_expr0(arg, cctx) == FAIL)
***************
*** 3193,3207 ****
        ++count;
  
        whitep = *arg;
!       p = skipwhite(*arg);
!       while (*p == NUL || (VIM_ISWHITE(*whitep) && comment_start(p)))
        {
!           *arg = next_line_from_context(cctx);
!           if (*arg == NULL)
!               goto failret;
!           whitep = (char_u *)" ";
!           *arg = skipwhite(*arg);
!           p = *arg;
        }
        if (**arg == '}')
            break;
--- 3197,3207 ----
        ++count;
  
        whitep = *arg;
!       *arg = skipwhite(*arg);
!       if (may_get_next_line(whitep, arg, cctx) == FAIL)
        {
!           *arg = NULL;
!           goto failret;
        }
        if (**arg == '}')
            break;
***************
*** 3506,3511 ****
--- 3506,3529 ----
  {
      for (;;)
      {
+       char_u *p = skipwhite(*arg);
+ 
+       if (*p == NUL || (VIM_ISWHITE(**arg) && comment_start(p)))
+       {
+           char_u *next = peek_next_line(cctx);
+ 
+           // If a following line starts with "->{" or "->X" advance to that
+           // line, so that a line break before "->" is allowed.
+           if (next != NULL && next[0] == '-' && next[1] == '>'
+                   && (next[2] == '{' || ASCII_ISALPHA(next[2])))
+           {
+               next = next_line_from_context(cctx, TRUE);
+               if (next == NULL)
+                   return FAIL;
+               *arg = skipwhite(next);
+           }
+       }
+ 
        if (**arg == '(')
        {
            garray_T    *stack = &cctx->ctx_type_stack;
***************
*** 3526,3533 ****
        }
        else if (**arg == '-' && (*arg)[1] == '>')
        {
-           char_u *p;
- 
            if (generate_ppconst(cctx, ppconst) == FAIL)
                return FAIL;
  
--- 3544,3549 ----
***************
*** 3570,3576 ****
        {
            garray_T    *stack = &cctx->ctx_type_stack;
            type_T      **typep;
-           char_u      *p;
  
            // list index: list[123]
            // dict member: dict[key]
--- 3586,3591 ----
***************
*** 3618,3625 ****
        }
        else if (**arg == '.' && (*arg)[1] != '.')
        {
-           char_u *p;
- 
            if (generate_ppconst(cctx, ppconst) == FAIL)
                return FAIL;
  
--- 3633,3638 ----
***************
*** 6696,6702 ****
        }
        else
        {
!           line = next_line_from_context(&cctx);
            if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len)
                // beyond the last line
                break;
--- 6709,6715 ----
        }
        else
        {
!           line = next_line_from_context(&cctx, FALSE);
            if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len)
                // beyond the last line
                break;
*** ../vim-8.2.1028/src/testdir/test_vim9_expr.vim      2020-06-21 
15:52:55.810451610 +0200
--- src/testdir/test_vim9_expr.vim      2020-06-21 16:33:33.772246811 +0200
***************
*** 1036,1041 ****
--- 1036,1059 ----
        map('string(v:key)')
    assert_equal(['0', '1', '2'], l)
  
+   l = range
+       ->map('string(v:key)')
+   assert_equal(['0', '1', '2'], l)
+ 
+   l = range # comment
+       ->map('string(v:key)')
+   assert_equal(['0', '1', '2'], l)
+ 
+   l = range
+ 
+       ->map('string(v:key)')
+   assert_equal(['0', '1', '2'], l)
+ 
+   l = range
+       # comment
+       ->map('string(v:key)')
+   assert_equal(['0', '1', '2'], l)
+ 
    assert_equal('1', l[
        1])
  
*** ../vim-8.2.1028/src/version.c       2020-06-21 15:52:55.810451610 +0200
--- src/version.c       2020-06-21 16:29:45.868861685 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1029,
  /**/

-- 
MONK: ... and the Lord spake, saying, "First shalt thou take out the Holy Pin,
      then shalt thou count to three, no more, no less.  Three shalt be the
      number thou shalt count, and the number of the counting shalt be three.
      Four shalt thou not count, neither count thou two, excepting that thou
      then proceed to three.  Five is right out.  Once the number three, being
      the third number, be reached, then lobbest thou thy Holy Hand Grenade of
      Antioch towards thou foe, who being naughty in my sight, shall snuff it.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// 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/202006211458.05LEweeR1171141%40masaka.moolenaar.net.

Raspunde prin e-mail lui