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