Patch 8.2.0567
Problem:    Vim9: cannot put comments halfway expressions.
Solution:   Support # comments in many places.
Files:      runtime/doc/vim9.txt, src/vim9compile.c, src/userfunc.c,
            src/ex_docmd.c, src/testdir/test_vim9_func.vim,
            src/testdir/test_vim9_script.vim


*** ../vim-8.2.0566/runtime/doc/vim9.txt        2020-04-12 21:52:56.875998374 
+0200
--- runtime/doc/vim9.txt        2020-04-13 13:21:39.905265512 +0200
***************
*** 58,63 ****
--- 58,72 ----
  
  THIS IS STILL UNDER DEVELOPMENT - ANYTHING CAN BREAK - ANYTHING CAN CHANGE
  
+ Comments starting with # ~
+ 
+ In Vim script comments normally start with double quote.  That can also be the
+ start of a string, thus in many places it cannot be used.  In Vim9 script a
+ comment can also start with #.  Normally this is a command to list text with
+ numbers, but you can also use `:number` for that. >
+       let count = 0  # number of occurences of Ni!
+ 
+ 
  Vim9 functions ~
  
  `:def` has no extra arguments like `:function` does: "range", "abort", "dict"
***************
*** 241,246 ****
--- 250,258 ----
        let var =234    " Error!
  There must be white space before and after the "=": >
        let var = 234   " OK
+ White space must also be put before the # that starts a comment: >
+       let var = 234# Error!
+       let var = 234 # OK
  
  White space is required around most operators.
  
*** ../vim-8.2.0566/src/vim9compile.c   2020-04-12 22:53:50.767656185 +0200
--- src/vim9compile.c   2020-04-13 14:09:46.942764391 +0200
***************
*** 2070,2082 ****
  }
  
  /*
   * If "*arg" is at the end of the line, advance to the next line.
   * Return FAIL if beyond the last line, "*arg" is unmodified then.
   */
      static int
! may_get_next_line(char_u **arg, cctx_T *cctx)
  {
!     if (**arg == NUL)
      {
        char_u *next = next_line_from_context(cctx);
  
--- 2070,2092 ----
  }
  
  /*
+  * 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.
   */
      static int
! may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx)
  {
!     if (**arg == NUL || (VIM_ISWHITE(*whitep) && comment_start(*arg)))
      {
        char_u *next = next_line_from_context(cctx);
  
***************
*** 2321,2335 ****
      static int
  compile_arguments(char_u **arg, cctx_T *cctx, int *argcount)
  {
!     char_u *p = *arg;
  
      for (;;)
      {
!       if (*p == NUL)
        {
            p = next_line_from_context(cctx);
            if (p == NULL)
!               break;
            p = skipwhite(p);
        }
        if (*p == ')')
--- 2331,2347 ----
      static int
  compile_arguments(char_u **arg, cctx_T *cctx, int *argcount)
  {
!     char_u  *p = *arg;
!     char_u  *whitep = *arg;
  
      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 == ')')
***************
*** 2353,2361 ****
            if (*p != NUL && !VIM_ISWHITE(*p))
                semsg(_(e_white_after), ",");
        }
        p = skipwhite(p);
      }
! 
      emsg(_(e_missing_close));
      return FAIL;
  }
--- 2365,2374 ----
            if (*p != NUL && !VIM_ISWHITE(*p))
                semsg(_(e_white_after), ",");
        }
+       whitep = p;
        p = skipwhite(p);
      }
! failret:
      emsg(_(e_missing_close));
      return FAIL;
  }
***************
*** 2589,2599 ****
  compile_list(char_u **arg, cctx_T *cctx)
  {
      char_u    *p = skipwhite(*arg + 1);
      int               count = 0;
  
      for (;;)
      {
!       if (*p == NUL)
        {
            p = next_line_from_context(cctx);
            if (p == NULL)
--- 2602,2613 ----
  compile_list(char_u **arg, cctx_T *cctx)
  {
      char_u    *p = skipwhite(*arg + 1);
+     char_u    *whitep = *arg + 1;
      int               count = 0;
  
      for (;;)
      {
!       while (*p == NUL || (VIM_ISWHITE(*whitep) && comment_start(p)))
        {
            p = next_line_from_context(cctx);
            if (p == NULL)
***************
*** 2601,2606 ****
--- 2615,2621 ----
                semsg(_(e_list_end), *arg);
                return FAIL;
            }
+           whitep = (char_u *)" ";
            p = skipwhite(p);
        }
        if (*p == ']')
***************
*** 2616,2621 ****
--- 2631,2637 ----
        ++count;
        if (*p == ',')
            ++p;
+       whitep = p;
        p = skipwhite(p);
      }
      *arg = p;
***************
*** 2713,2718 ****
--- 2729,2736 ----
      int               count = 0;
      dict_T    *d = dict_alloc();
      dictitem_T        *item;
+     char_u    *whitep = *arg;
+     char_u    *p;
  
      if (d == NULL)
        return FAIL;
***************
*** 2721,2731 ****
      {
        char_u *key = NULL;
  
!       if (**arg == NUL || (literal && **arg == '"'))
        {
            *arg = next_line_from_context(cctx);
            if (*arg == NULL)
                goto failret;
            *arg = skipwhite(*arg);
        }
  
--- 2739,2751 ----
      {
        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);
        }
  
***************
*** 2734,2750 ****
  
        if (literal)
        {
!           char_u *p = to_name_end(*arg, !literal);
  
!           if (p == *arg)
            {
                semsg(_("E1014: Invalid key: %s"), *arg);
                return FAIL;
            }
!           key = vim_strnsave(*arg, p - *arg);
            if (generate_PUSHS(cctx, key) == FAIL)
                return FAIL;
!           *arg = p;
        }
        else
        {
--- 2754,2770 ----
  
        if (literal)
        {
!           char_u *end = to_name_end(*arg, !literal);
  
!           if (end == *arg)
            {
                semsg(_("E1014: Invalid key: %s"), *arg);
                return FAIL;
            }
!           key = vim_strnsave(*arg, end - *arg);
            if (generate_PUSHS(cctx, key) == FAIL)
                return FAIL;
!           *arg = end;
        }
        else
        {
***************
*** 2784,2795 ****
            return FAIL;
        }
  
        *arg = skipwhite(*arg + 1);
!       if (**arg == NUL)
        {
            *arg = next_line_from_context(cctx);
            if (*arg == NULL)
                goto failret;
            *arg = skipwhite(*arg);
        }
  
--- 2804,2817 ----
            return FAIL;
        }
  
+       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);
        }
  
***************
*** 2797,2808 ****
            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;
--- 2819,2834 ----
            return FAIL;
        ++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;
***************
*** 2811,2823 ****
            semsg(_(e_missing_dict_comma), *arg);
            goto failret;
        }
        *arg = skipwhite(*arg + 1);
      }
  
      *arg = *arg + 1;
  
      // Allow for following comment, after at least one space.
!     if (VIM_ISWHITE(**arg) && *skipwhite(*arg) == '"')
        *arg += STRLEN(*arg);
  
      dict_unref(d);
--- 2837,2851 ----
            semsg(_(e_missing_dict_comma), *arg);
            goto failret;
        }
+       whitep = *arg + 1;
        *arg = skipwhite(*arg + 1);
      }
  
      *arg = *arg + 1;
  
      // Allow for following comment, after at least one space.
!     p = skipwhite(*arg);
!     if (VIM_ISWHITE(**arg) && (*p == '"' || comment_start(p)))
        *arg += STRLEN(*arg);
  
      dict_unref(d);
***************
*** 3422,3428 ****
            return FAIL;
        }
        *arg = skipwhite(op + 1);
!       if (may_get_next_line(arg, cctx) == FAIL)
            return FAIL;
  
        // get the second variable
--- 3450,3456 ----
            return FAIL;
        }
        *arg = skipwhite(op + 1);
!       if (may_get_next_line(op + 1, arg, cctx) == FAIL)
            return FAIL;
  
        // get the second variable
***************
*** 3470,3476 ****
        }
  
        *arg = skipwhite(op + oplen);
!       if (may_get_next_line(arg, cctx) == FAIL)
            return FAIL;
  
        // get the second variable
--- 3498,3504 ----
        }
  
        *arg = skipwhite(op + oplen);
!       if (may_get_next_line(op + oplen, arg, cctx) == FAIL)
            return FAIL;
  
        // get the second variable
***************
*** 3608,3614 ****
  
        // get the second variable
        *arg = skipwhite(p + len);
!       if (may_get_next_line(arg, cctx) == FAIL)
            return FAIL;
  
        if (compile_expr5(arg, cctx) == FAIL)
--- 3636,3642 ----
  
        // get the second variable
        *arg = skipwhite(p + len);
!       if (may_get_next_line(p + len, arg, cctx) == FAIL)
            return FAIL;
  
        if (compile_expr5(arg, cctx) == FAIL)
***************
*** 3658,3664 ****
  
            // eval the next expression
            *arg = skipwhite(p + 2);
!           if (may_get_next_line(arg, cctx) == FAIL)
                return FAIL;
  
            if ((opchar == '|' ? compile_expr3(arg, cctx)
--- 3686,3692 ----
  
            // eval the next expression
            *arg = skipwhite(p + 2);
!           if (may_get_next_line(p + 2, arg, cctx) == FAIL)
                return FAIL;
  
            if ((opchar == '|' ? compile_expr3(arg, cctx)
***************
*** 3771,3777 ****
  
        // evaluate the second expression; any type is accepted
        *arg = skipwhite(p + 1);
!       if (may_get_next_line(arg, cctx) == FAIL)
            return FAIL;
  
        if (compile_expr1(arg, cctx) == FAIL)
--- 3799,3805 ----
  
        // evaluate the second expression; any type is accepted
        *arg = skipwhite(p + 1);
!       if (may_get_next_line(p + 1, arg, cctx) == FAIL)
            return FAIL;
  
        if (compile_expr1(arg, cctx) == FAIL)
***************
*** 3803,3809 ****
  
        // evaluate the third expression
        *arg = skipwhite(p + 1);
!       if (may_get_next_line(arg, cctx) == FAIL)
            return FAIL;
  
        if (compile_expr1(arg, cctx) == FAIL)
--- 3831,3837 ----
  
        // evaluate the third expression
        *arg = skipwhite(p + 1);
!       if (may_get_next_line(p + 1, arg, cctx) == FAIL)
            return FAIL;
  
        if (compile_expr1(arg, cctx) == FAIL)
*** ../vim-8.2.0566/src/userfunc.c      2020-04-12 21:52:56.875998374 +0200
--- src/userfunc.c      2020-04-13 14:23:15.161565646 +0200
***************
*** 154,159 ****
--- 154,160 ----
      int               c;
      int               any_default = FALSE;
      char_u    *expr;
+     char_u    *whitep = arg;
  
      if (newargs != NULL)
        ga_init2(newargs, (int)sizeof(char_u *), 3);
***************
*** 170,176 ****
       */
      while (*p != endchar)
      {
!       if (eap != NULL && *p == NUL && eap->getline != NULL)
        {
            char_u *theline;
  
--- 171,178 ----
       */
      while (*p != endchar)
      {
!       while (eap != NULL && eap->getline != NULL
!                        && (*p == NUL || (VIM_ISWHITE(*whitep) && *p == '#')))
        {
            char_u *theline;
  
***************
*** 180,185 ****
--- 182,188 ----
                break;
            vim_free(*line_to_free);
            *line_to_free = theline;
+           whitep = (char_u *)" ";
            p = skipwhite(theline);
        }
  
***************
*** 228,233 ****
--- 231,237 ----
                // find the end of the expression (doesn't evaluate it)
                any_default = TRUE;
                p = skipwhite(p) + 1;
+               whitep = p;
                p = skipwhite(p);
                expr = p;
                if (eval1(&p, &rettv, FALSE) != FAIL)
***************
*** 264,269 ****
--- 268,274 ----
            else
                mustend = TRUE;
        }
+       whitep = p;
        p = skipwhite(p);
      }
  
***************
*** 2595,2601 ****
      // Makes 'exe "func Test()\n...\nendfunc"' work.
      if (*p == '\n')
        line_arg = p + 1;
!     else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg)
        emsg(_(e_trailing));
  
      /*
--- 2600,2607 ----
      // Makes 'exe "func Test()\n...\nendfunc"' work.
      if (*p == '\n')
        line_arg = p + 1;
!     else if (*p != NUL && *p != '"' && !(eap->cmdidx == CMD_def && *p == '#')
!                                                   && !eap->skip && !did_emsg)
        emsg(_(e_trailing));
  
      /*
*** ../vim-8.2.0566/src/ex_docmd.c      2020-04-12 20:01:00.310654732 +0200
--- src/ex_docmd.c      2020-04-13 14:27:29.777050824 +0200
***************
*** 4764,4769 ****
--- 4764,4772 ----
      int
  ends_excmd(int c)
  {
+     if (c == '#')
+       // TODO: should check for preceding white space
+       return in_vim9script();
      return (c == NUL || c == '|' || c == '"' || c == '\n');
  }
  
*** ../vim-8.2.0566/src/testdir/test_vim9_func.vim      2020-04-12 
22:22:27.060446273 +0200
--- src/testdir/test_vim9_func.vim      2020-04-13 14:19:18.374007229 +0200
***************
*** 569,574 ****
--- 569,582 ----
    return arg1 .. arg2 .. join(rest, '-')
  enddef
  
+ def MultiLineComment(
+     arg1: string, # comment
+     arg2 = 1234, # comment
+     ...rest: list<string> # comment
+       ): string # comment
+   return arg1 .. arg2 .. join(rest, '-')
+ enddef
+ 
  def Test_multiline()
    assert_equal('text1234', MultiLine('text'))
    assert_equal('text777', MultiLine('text', 777))
*** ../vim-8.2.0566/src/testdir/test_vim9_script.vim    2020-04-12 
22:53:50.767656185 +0200
--- src/testdir/test_vim9_script.vim    2020-04-13 14:12:04.574641793 +0200
***************
*** 983,992 ****
        } " 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)
  
--- 983,999 ----
        } " comment
    assert_equal({'one': 1, 'two': 2, 'three': 3}, mydict)
    mydict = #{
!       one: 1,  # comment
!       two:     # comment
!            2,  # comment
!       three: 3 # comment
!       }
!   assert_equal(#{one: 1, two: 2, three: 3}, mydict)
!   mydict = #{
!       one: 1, 
!       two: 
!            2, 
!       three: 3 
        }
    assert_equal(#{one: 1, two: 2, three: 3}, mydict)
  
*** ../vim-8.2.0566/src/version.c       2020-04-12 23:09:20.789245505 +0200
--- src/version.c       2020-04-13 13:36:18.458463452 +0200
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     567,
  /**/

-- 
Computers make very fast, very accurate, mistakes.

 /// 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/202004131242.03DCg3E4012046%40masaka.moolenaar.net.

Raspunde prin e-mail lui