lkundrak / rpms / vim

Forked from rpms/vim 4 years ago
Clone
c6c14b6
To: vim_dev@googlegroups.com
c6c14b6
Subject: Patch 7.4.036
c6c14b6
Fcc: outbox
c6c14b6
From: Bram Moolenaar <Bram@moolenaar.net>
c6c14b6
Mime-Version: 1.0
c6c14b6
Content-Type: text/plain; charset=UTF-8
c6c14b6
Content-Transfer-Encoding: 8bit
c6c14b6
------------
c6c14b6
c6c14b6
Patch 7.4.036
c6c14b6
Problem:    NFA engine does not capture group correctly when using \@>. (ZyX)
c6c14b6
Solution:   Copy submatches before doing the recursive match.
c6c14b6
Files:	    src/regexp_nfa.c, src/testdir/test64.in, src/testdir/test64.ok
c6c14b6
c6c14b6
c6c14b6
*** ../vim-7.4.035/src/regexp_nfa.c	2013-09-22 13:57:19.000000000 +0200
c6c14b6
--- src/regexp_nfa.c	2013-09-25 16:35:54.000000000 +0200
c6c14b6
***************
c6c14b6
*** 36,42 ****
c6c14b6
  {
c6c14b6
      NFA_SPLIT = -1024,
c6c14b6
      NFA_MATCH,
c6c14b6
!     NFA_SKIP_CHAR,		    /* matches a 0-length char */
c6c14b6
  
c6c14b6
      NFA_START_COLL,		    /* [abc] start */
c6c14b6
      NFA_END_COLL,		    /* [abc] end */
c6c14b6
--- 36,42 ----
c6c14b6
  {
c6c14b6
      NFA_SPLIT = -1024,
c6c14b6
      NFA_MATCH,
c6c14b6
!     NFA_EMPTY,			    /* matches 0-length */
c6c14b6
  
c6c14b6
      NFA_START_COLL,		    /* [abc] start */
c6c14b6
      NFA_END_COLL,		    /* [abc] end */
c6c14b6
***************
c6c14b6
*** 2005,2012 ****
c6c14b6
  	    {
c6c14b6
  		/* Ignore result of previous call to nfa_regatom() */
c6c14b6
  		post_ptr = post_start + my_post_start;
c6c14b6
! 		/* NFA_SKIP_CHAR has 0-length and works everywhere */
c6c14b6
! 		EMIT(NFA_SKIP_CHAR);
c6c14b6
  		return OK;
c6c14b6
  	    }
c6c14b6
  
c6c14b6
--- 2005,2012 ----
c6c14b6
  	    {
c6c14b6
  		/* Ignore result of previous call to nfa_regatom() */
c6c14b6
  		post_ptr = post_start + my_post_start;
c6c14b6
! 		/* NFA_EMPTY is 0-length and works everywhere */
c6c14b6
! 		EMIT(NFA_EMPTY);
c6c14b6
  		return OK;
c6c14b6
  	    }
c6c14b6
  
c6c14b6
***************
c6c14b6
*** 2170,2185 ****
c6c14b6
  	old_post_pos = (int)(post_ptr - post_start);
c6c14b6
  	if (nfa_regconcat() == FAIL)
c6c14b6
  	    return FAIL;
c6c14b6
! 	/* if concat is empty, skip a input char. But do emit a node */
c6c14b6
  	if (old_post_pos == (int)(post_ptr - post_start))
c6c14b6
! 	    EMIT(NFA_SKIP_CHAR);
c6c14b6
  	EMIT(NFA_CONCAT);
c6c14b6
  	ch = peekchr();
c6c14b6
      }
c6c14b6
  
c6c14b6
!     /* Even if a branch is empty, emit one node for it */
c6c14b6
      if (old_post_pos == (int)(post_ptr - post_start))
c6c14b6
! 	EMIT(NFA_SKIP_CHAR);
c6c14b6
  
c6c14b6
      return OK;
c6c14b6
  }
c6c14b6
--- 2170,2185 ----
c6c14b6
  	old_post_pos = (int)(post_ptr - post_start);
c6c14b6
  	if (nfa_regconcat() == FAIL)
c6c14b6
  	    return FAIL;
c6c14b6
! 	/* if concat is empty do emit a node */
c6c14b6
  	if (old_post_pos == (int)(post_ptr - post_start))
c6c14b6
! 	    EMIT(NFA_EMPTY);
c6c14b6
  	EMIT(NFA_CONCAT);
c6c14b6
  	ch = peekchr();
c6c14b6
      }
c6c14b6
  
c6c14b6
!     /* if a branch is empty, emit one node for it */
c6c14b6
      if (old_post_pos == (int)(post_ptr - post_start))
c6c14b6
! 	EMIT(NFA_EMPTY);
c6c14b6
  
c6c14b6
      return OK;
c6c14b6
  }
c6c14b6
***************
c6c14b6
*** 2423,2429 ****
c6c14b6
  	case NFA_STAR_NONGREEDY: STRCPY(code, "NFA_STAR_NONGREEDY "); break;
c6c14b6
  	case NFA_QUEST:		STRCPY(code, "NFA_QUEST"); break;
c6c14b6
  	case NFA_QUEST_NONGREEDY: STRCPY(code, "NFA_QUEST_NON_GREEDY"); break;
c6c14b6
! 	case NFA_SKIP_CHAR:	STRCPY(code, "NFA_SKIP_CHAR"); break;
c6c14b6
  	case NFA_OR:		STRCPY(code, "NFA_OR"); break;
c6c14b6
  
c6c14b6
  	case NFA_START_COLL:	STRCPY(code, "NFA_START_COLL"); break;
c6c14b6
--- 2423,2429 ----
c6c14b6
  	case NFA_STAR_NONGREEDY: STRCPY(code, "NFA_STAR_NONGREEDY "); break;
c6c14b6
  	case NFA_QUEST:		STRCPY(code, "NFA_QUEST"); break;
c6c14b6
  	case NFA_QUEST_NONGREEDY: STRCPY(code, "NFA_QUEST_NON_GREEDY"); break;
c6c14b6
! 	case NFA_EMPTY:		STRCPY(code, "NFA_EMPTY"); break;
c6c14b6
  	case NFA_OR:		STRCPY(code, "NFA_OR"); break;
c6c14b6
  
c6c14b6
  	case NFA_START_COLL:	STRCPY(code, "NFA_START_COLL"); break;
c6c14b6
***************
c6c14b6
*** 3067,3073 ****
c6c14b6
  	    case NFA_ZSTART:
c6c14b6
  	    case NFA_ZEND:
c6c14b6
  	    case NFA_OPT_CHARS:
c6c14b6
! 	    case NFA_SKIP_CHAR:
c6c14b6
  	    case NFA_START_PATTERN:
c6c14b6
  	    case NFA_END_PATTERN:
c6c14b6
  	    case NFA_COMPOSING:
c6c14b6
--- 3067,3073 ----
c6c14b6
  	    case NFA_ZSTART:
c6c14b6
  	    case NFA_ZEND:
c6c14b6
  	    case NFA_OPT_CHARS:
c6c14b6
! 	    case NFA_EMPTY:
c6c14b6
  	    case NFA_START_PATTERN:
c6c14b6
  	    case NFA_END_PATTERN:
c6c14b6
  	    case NFA_COMPOSING:
c6c14b6
***************
c6c14b6
*** 3265,3279 ****
c6c14b6
  	    PUSH(frag(e1.start, e2.out));
c6c14b6
  	    break;
c6c14b6
  
c6c14b6
! 	case NFA_SKIP_CHAR:
c6c14b6
! 	    /* Symbol of 0-length, Used in a repetition
c6c14b6
! 	     * with max/min count of 0 */
c6c14b6
  	    if (nfa_calc_size == TRUE)
c6c14b6
  	    {
c6c14b6
  		nstate++;
c6c14b6
  		break;
c6c14b6
  	    }
c6c14b6
! 	    s = alloc_state(NFA_SKIP_CHAR, NULL, NULL);
c6c14b6
  	    if (s == NULL)
c6c14b6
  		goto theend;
c6c14b6
  	    PUSH(frag(s, list1(&s->out)));
c6c14b6
--- 3265,3278 ----
c6c14b6
  	    PUSH(frag(e1.start, e2.out));
c6c14b6
  	    break;
c6c14b6
  
c6c14b6
! 	case NFA_EMPTY:
c6c14b6
! 	    /* 0-length, used in a repetition with max/min count of 0 */
c6c14b6
  	    if (nfa_calc_size == TRUE)
c6c14b6
  	    {
c6c14b6
  		nstate++;
c6c14b6
  		break;
c6c14b6
  	    }
c6c14b6
! 	    s = alloc_state(NFA_EMPTY, NULL, NULL);
c6c14b6
  	    if (s == NULL)
c6c14b6
  		goto theend;
c6c14b6
  	    PUSH(frag(s, list1(&s->out)));
c6c14b6
***************
c6c14b6
*** 4209,4215 ****
c6c14b6
  	case NFA_MOPEN:
c6c14b6
  	case NFA_ZEND:
c6c14b6
  	case NFA_SPLIT:
c6c14b6
! 	case NFA_SKIP_CHAR:
c6c14b6
  	    /* These nodes are not added themselves but their "out" and/or
c6c14b6
  	     * "out1" may be added below.  */
c6c14b6
  	    break;
c6c14b6
--- 4208,4214 ----
c6c14b6
  	case NFA_MOPEN:
c6c14b6
  	case NFA_ZEND:
c6c14b6
  	case NFA_SPLIT:
c6c14b6
! 	case NFA_EMPTY:
c6c14b6
  	    /* These nodes are not added themselves but their "out" and/or
c6c14b6
  	     * "out1" may be added below.  */
c6c14b6
  	    break;
c6c14b6
***************
c6c14b6
*** 4337,4343 ****
c6c14b6
  	    subs = addstate(l, state->out1, subs, pim, off);
c6c14b6
  	    break;
c6c14b6
  
c6c14b6
! 	case NFA_SKIP_CHAR:
c6c14b6
  	case NFA_NOPEN:
c6c14b6
  	case NFA_NCLOSE:
c6c14b6
  	    subs = addstate(l, state->out, subs, pim, off);
c6c14b6
--- 4336,4342 ----
c6c14b6
  	    subs = addstate(l, state->out1, subs, pim, off);
c6c14b6
  	    break;
c6c14b6
  
c6c14b6
! 	case NFA_EMPTY:
c6c14b6
  	case NFA_NOPEN:
c6c14b6
  	case NFA_NCLOSE:
c6c14b6
  	    subs = addstate(l, state->out, subs, pim, off);
c6c14b6
***************
c6c14b6
*** 5604,5612 ****
c6c14b6
  		    {
c6c14b6
  			int in_use = m->norm.in_use;
c6c14b6
  
c6c14b6
! 			/* Copy submatch info for the recursive call, so that
c6c14b6
! 			 * \1 can be matched. */
c6c14b6
  			copy_sub_off(&m->norm, &t->subs.norm);
c6c14b6
  
c6c14b6
  			/*
c6c14b6
  			 * First try matching the invisible match, then what
c6c14b6
--- 5603,5615 ----
c6c14b6
  		    {
c6c14b6
  			int in_use = m->norm.in_use;
c6c14b6
  
c6c14b6
! 			/* Copy submatch info for the recursive call, opposite
c6c14b6
! 			 * of what happens on success below. */
c6c14b6
  			copy_sub_off(&m->norm, &t->subs.norm);
c6c14b6
+ #ifdef FEAT_SYN_HL
c6c14b6
+ 			if (nfa_has_zsubexpr)
c6c14b6
+ 			    copy_sub_off(&m->synt, &t->subs.synt);
c6c14b6
+ #endif
c6c14b6
  
c6c14b6
  			/*
c6c14b6
  			 * First try matching the invisible match, then what
c6c14b6
***************
c6c14b6
*** 5713,5718 ****
c6c14b6
--- 5716,5728 ----
c6c14b6
  #endif
c6c14b6
  		    break;
c6c14b6
  		}
c6c14b6
+ 		/* Copy submatch info to the recursive call, opposite of what
c6c14b6
+ 		 * happens afterwards. */
c6c14b6
+ 		copy_sub_off(&m->norm, &t->subs.norm);
c6c14b6
+ #ifdef FEAT_SYN_HL
c6c14b6
+ 		if (nfa_has_zsubexpr)
c6c14b6
+ 		    copy_sub_off(&m->synt, &t->subs.synt);
c6c14b6
+ #endif
c6c14b6
  
c6c14b6
  		/* First try matching the pattern. */
c6c14b6
  		result = recursive_regmatch(t->state, NULL, prog,
c6c14b6
*** ../vim-7.4.035/src/testdir/test64.in	2013-09-22 13:57:19.000000000 +0200
c6c14b6
--- src/testdir/test64.in	2013-09-25 15:51:12.000000000 +0200
c6c14b6
***************
c6c14b6
*** 430,435 ****
c6c14b6
--- 430,436 ----
c6c14b6
  :call add(tl, [2, '\(a*\)\@>a', 'aaaa'])
c6c14b6
  :call add(tl, [2, '\(a*\)\@>b', 'aaab', 'aaab', 'aaa'])
c6c14b6
  :call add(tl, [2, '^\(.\{-}b\)\@>.', '  abcbd', '  abc', '  ab'])
c6c14b6
+ :call add(tl, [2, '\(.\{-}\)\(\)\@>$', 'abc', 'abc', 'abc', ''])
c6c14b6
  :" TODO: BT engine does not restore submatch after failure
c6c14b6
  :call add(tl, [1, '\(a*\)\@>a\|a\+', 'aaaa', 'aaaa'])
c6c14b6
  :"
c6c14b6
*** ../vim-7.4.035/src/testdir/test64.ok	2013-09-22 13:57:19.000000000 +0200
c6c14b6
--- src/testdir/test64.ok	2013-09-25 16:39:31.000000000 +0200
c6c14b6
***************
c6c14b6
*** 992,997 ****
c6c14b6
--- 992,1000 ----
c6c14b6
  OK 0 - ^\(.\{-}b\)\@>.
c6c14b6
  OK 1 - ^\(.\{-}b\)\@>.
c6c14b6
  OK 2 - ^\(.\{-}b\)\@>.
c6c14b6
+ OK 0 - \(.\{-}\)\(\)\@>$
c6c14b6
+ OK 1 - \(.\{-}\)\(\)\@>$
c6c14b6
+ OK 2 - \(.\{-}\)\(\)\@>$
c6c14b6
  OK 0 - \(a*\)\@>a\|a\+
c6c14b6
  OK 2 - \(a*\)\@>a\|a\+
c6c14b6
  OK 0 - \_[^8-9]\+
c6c14b6
*** ../vim-7.4.035/src/version.c	2013-09-22 15:43:34.000000000 +0200
c6c14b6
--- src/version.c	2013-09-25 16:40:01.000000000 +0200
c6c14b6
***************
c6c14b6
*** 740,741 ****
c6c14b6
--- 740,743 ----
c6c14b6
  {   /* Add new patch number below this line */
c6c14b6
+ /**/
c6c14b6
+     36,
c6c14b6
  /**/
c6c14b6
c6c14b6
-- 
c6c14b6
There is a fine line between courage and foolishness.
c6c14b6
Unfortunately, it's not a fence.
c6c14b6
c6c14b6
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
c6c14b6
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
c6c14b6
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
c6c14b6
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///