8b9a1c
To: vim_dev@googlegroups.com
8b9a1c
Subject: Patch 7.4.037
8b9a1c
Fcc: outbox
8b9a1c
From: Bram Moolenaar <Bram@moolenaar.net>
8b9a1c
Mime-Version: 1.0
8b9a1c
Content-Type: text/plain; charset=UTF-8
8b9a1c
Content-Transfer-Encoding: 8bit
8b9a1c
------------
8b9a1c
8b9a1c
Patch 7.4.037
8b9a1c
Problem:    Using "\ze" in a sub-pattern does not result in the end of the
8b9a1c
	    match to be set. (Axel Bender)
8b9a1c
Solution:   Copy the end of match position when a recursive match was
8b9a1c
	    successful.
8b9a1c
Files:	    src/regexp_nfa.c, src/testdir/test64.in, src/testdir/test64.ok
8b9a1c
8b9a1c
8b9a1c
*** ../vim-7.4.036/src/regexp_nfa.c	2013-09-25 16:41:50.000000000 +0200
8b9a1c
--- src/regexp_nfa.c	2013-09-25 18:09:59.000000000 +0200
8b9a1c
***************
8b9a1c
*** 3822,3827 ****
8b9a1c
--- 3822,3828 ----
8b9a1c
  static void clear_sub __ARGS((regsub_T *sub));
8b9a1c
  static void copy_sub __ARGS((regsub_T *to, regsub_T *from));
8b9a1c
  static void copy_sub_off __ARGS((regsub_T *to, regsub_T *from));
8b9a1c
+ static void copy_ze_off __ARGS((regsub_T *to, regsub_T *from));
8b9a1c
  static int sub_equal __ARGS((regsub_T *sub1, regsub_T *sub2));
8b9a1c
  static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen));
8b9a1c
  static int has_state_with_pos __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim));
8b9a1c
***************
8b9a1c
*** 3909,3914 ****
8b9a1c
--- 3910,3938 ----
8b9a1c
  }
8b9a1c
  
8b9a1c
  /*
8b9a1c
+  * Like copy_sub() but only do the end of the main match if \ze is present.
8b9a1c
+  */
8b9a1c
+     static void
8b9a1c
+ copy_ze_off(to, from)
8b9a1c
+     regsub_T	*to;
8b9a1c
+     regsub_T	*from;
8b9a1c
+ {
8b9a1c
+     if (nfa_has_zend)
8b9a1c
+     {
8b9a1c
+ 	if (REG_MULTI)
8b9a1c
+ 	{
8b9a1c
+ 	    if (from->list.multi[0].end.lnum >= 0)
8b9a1c
+ 		to->list.multi[0].end = from->list.multi[0].end;
8b9a1c
+ 	}
8b9a1c
+ 	else
8b9a1c
+ 	{
8b9a1c
+ 	    if (from->list.line[0].end != NULL)
8b9a1c
+ 		to->list.line[0].end = from->list.line[0].end;
8b9a1c
+ 	}
8b9a1c
+     }
8b9a1c
+ }
8b9a1c
+ 
8b9a1c
+ /*
8b9a1c
   * Return TRUE if "sub1" and "sub2" have the same start positions.
8b9a1c
   */
8b9a1c
      static int
8b9a1c
***************
8b9a1c
*** 5308,5313 ****
8b9a1c
--- 5332,5338 ----
8b9a1c
   * When "nfa_endp" is not NULL it is a required end-of-match position.
8b9a1c
   *
8b9a1c
   * Return TRUE if there is a match, FALSE otherwise.
8b9a1c
+  * When there is a match "submatch" contains the positions.
8b9a1c
   * Note: Caller must ensure that: start != NULL.
8b9a1c
   */
8b9a1c
      static int
8b9a1c
***************
8b9a1c
*** 5633,5638 ****
8b9a1c
--- 5658,5666 ----
8b9a1c
  			    if (nfa_has_zsubexpr)
8b9a1c
  				copy_sub_off(&t->subs.synt, &m->synt);
8b9a1c
  #endif
8b9a1c
+ 			    /* If the pattern has \ze and it matched in the
8b9a1c
+ 			     * sub pattern, use it. */
8b9a1c
+ 			    copy_ze_off(&t->subs.norm, &m->norm);
8b9a1c
  
8b9a1c
  			    /* t->state->out1 is the corresponding
8b9a1c
  			     * END_INVISIBLE node; Add its out to the current
8b9a1c
*** ../vim-7.4.036/src/testdir/test64.in	2013-09-25 16:41:50.000000000 +0200
8b9a1c
--- src/testdir/test64.in	2013-09-25 18:09:16.000000000 +0200
8b9a1c
***************
8b9a1c
*** 425,430 ****
8b9a1c
--- 425,431 ----
8b9a1c
  :"
8b9a1c
  :" complicated look-behind match
8b9a1c
  :call add(tl, [2, '\(r\@<=\|\w\@
8b9a1c
+ :call add(tl, [2, '^[a-z]\+\ze \&\(asdf\)\@
8b9a1c
  :"
8b9a1c
  :""""" \@>
8b9a1c
  :call add(tl, [2, '\(a*\)\@>a', 'aaaa'])
8b9a1c
*** ../vim-7.4.036/src/testdir/test64.ok	2013-09-25 16:41:50.000000000 +0200
8b9a1c
--- src/testdir/test64.ok	2013-09-25 18:10:05.000000000 +0200
8b9a1c
***************
8b9a1c
*** 983,988 ****
8b9a1c
--- 983,991 ----
8b9a1c
  OK 0 - \(r\@<=\|\w\@
8b9a1c
  OK 1 - \(r\@<=\|\w\@
8b9a1c
  OK 2 - \(r\@<=\|\w\@
8b9a1c
+ OK 0 - ^[a-z]\+\ze \&\(asdf\)\@
8b9a1c
+ OK 1 - ^[a-z]\+\ze \&\(asdf\)\@
8b9a1c
+ OK 2 - ^[a-z]\+\ze \&\(asdf\)\@
8b9a1c
  OK 0 - \(a*\)\@>a
8b9a1c
  OK 1 - \(a*\)\@>a
8b9a1c
  OK 2 - \(a*\)\@>a
8b9a1c
*** ../vim-7.4.036/src/version.c	2013-09-25 16:41:50.000000000 +0200
8b9a1c
--- src/version.c	2013-09-25 18:14:36.000000000 +0200
8b9a1c
***************
8b9a1c
*** 740,741 ****
8b9a1c
--- 740,743 ----
8b9a1c
  {   /* Add new patch number below this line */
8b9a1c
+ /**/
8b9a1c
+     37,
8b9a1c
  /**/
8b9a1c
8b9a1c
-- 
8b9a1c
MAN:     You don't frighten us, English pig-dog!  Go and boil your bottoms,
8b9a1c
         son of a silly person.  I blow my nose on you, so-called Arthur-king,
8b9a1c
         you and your silly English K...kaniggets.
8b9a1c
   He puts hands to his ears and blows a raspberry.
8b9a1c
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
8b9a1c
8b9a1c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
8b9a1c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
8b9a1c
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
8b9a1c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///