3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.290
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.290
3ef2ca
Problem:    A non-greedy match followed by a branch is too greedy. (Ingo
3ef2ca
	    Karkat)
3ef2ca
Solution:   Add NFA_MATCH when it is already in the state list if the position
3ef2ca
	    differs.
3ef2ca
Files:	    src/testdir/test64.in, src/testdir/test64.ok, src/regexp_nfa.c
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.289/src/testdir/test64.in	2014-05-13 15:56:45.017670668 +0200
3ef2ca
--- src/testdir/test64.in	2014-05-13 16:15:57.213680754 +0200
3ef2ca
***************
3ef2ca
*** 238,244 ****
3ef2ca
  :call add(tl, [2, '\vx(.{-,8})yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz','ayxa','xayzxayz'])
3ef2ca
  :call add(tl, [2, '\vx(.*)yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz', 'ayxayzxayzxa',''])
3ef2ca
  :call add(tl, [2, '\v(a{1,2}){-2,3}','aaaaaaa','aaaa','aa'])
3ef2ca
! :call add(tl, [2, '\v(a{-1,3})+','aa','aa','a'])
3ef2ca
  :"
3ef2ca
  :" Test Character classes
3ef2ca
  :call add(tl, [2, '\d\+e\d\d','test 10e23 fd','10e23'])
3ef2ca
--- 238,248 ----
3ef2ca
  :call add(tl, [2, '\vx(.{-,8})yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz','ayxa','xayzxayz'])
3ef2ca
  :call add(tl, [2, '\vx(.*)yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz', 'ayxayzxayzxa',''])
3ef2ca
  :call add(tl, [2, '\v(a{1,2}){-2,3}','aaaaaaa','aaaa','aa'])
3ef2ca
! :call add(tl, [2, '\v(a{-1,3})+', 'aa', 'aa', 'a'])
3ef2ca
! :call add(tl, [2, '^\s\{-}\zs\( x\|x$\)', ' x', ' x', ' x'])
3ef2ca
! :call add(tl, [2, '^\s\{-}\zs\(x\| x$\)', ' x', ' x', ' x'])
3ef2ca
! :call add(tl, [2, '^\s\{-}\ze\(x\| x$\)', ' x', '', ' x'])
3ef2ca
! :call add(tl, [2, '^\(\s\{-}\)\(x\| x$\)', ' x', ' x', '', ' x'])
3ef2ca
  :"
3ef2ca
  :" Test Character classes
3ef2ca
  :call add(tl, [2, '\d\+e\d\d','test 10e23 fd','10e23'])
3ef2ca
***************
3ef2ca
*** 462,476 ****
3ef2ca
  :    try
3ef2ca
  :      let l = matchlist(text, pat)
3ef2ca
  :    catch
3ef2ca
! :      $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", caused an exception: \"' . v:exception . '\"'
3ef2ca
  :    endtry
3ef2ca
  :" check the match itself
3ef2ca
  :    if len(l) == 0 && len(t) > matchidx
3ef2ca
! :      $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"'
3ef2ca
  :    elseif len(l) > 0 && len(t) == matchidx
3ef2ca
! :      $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match'
3ef2ca
  :    elseif len(t) > matchidx && l[0] != t[matchidx]
3ef2ca
! :      $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"'
3ef2ca
  :    else
3ef2ca
  :      $put ='OK ' . engine . ' - ' . pat
3ef2ca
  :    endif
3ef2ca
--- 466,480 ----
3ef2ca
  :    try
3ef2ca
  :      let l = matchlist(text, pat)
3ef2ca
  :    catch
3ef2ca
! :      $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", caused an exception: \"' . v:exception . '\"'
3ef2ca
  :    endtry
3ef2ca
  :" check the match itself
3ef2ca
  :    if len(l) == 0 && len(t) > matchidx
3ef2ca
! :      $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"'
3ef2ca
  :    elseif len(l) > 0 && len(t) == matchidx
3ef2ca
! :      $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match'
3ef2ca
  :    elseif len(t) > matchidx && l[0] != t[matchidx]
3ef2ca
! :      $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"'
3ef2ca
  :    else
3ef2ca
  :      $put ='OK ' . engine . ' - ' . pat
3ef2ca
  :    endif
3ef2ca
***************
3ef2ca
*** 483,489 ****
3ef2ca
  :          let e = t[matchidx + i]
3ef2ca
  :        endif
3ef2ca
  :        if l[i] != e
3ef2ca
! :          $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
3ef2ca
  :        endif
3ef2ca
  :      endfor
3ef2ca
  :      unlet i
3ef2ca
--- 487,493 ----
3ef2ca
  :          let e = t[matchidx + i]
3ef2ca
  :        endif
3ef2ca
  :        if l[i] != e
3ef2ca
! :          $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
3ef2ca
  :        endif
3ef2ca
  :      endfor
3ef2ca
  :      unlet i
3ef2ca
*** ../vim-7.4.289/src/testdir/test64.ok	2014-05-13 15:56:45.017670668 +0200
3ef2ca
--- src/testdir/test64.ok	2014-05-13 16:39:35.077693166 +0200
3ef2ca
***************
3ef2ca
*** 533,538 ****
3ef2ca
--- 533,550 ----
3ef2ca
  OK 0 - \v(a{-1,3})+
3ef2ca
  OK 1 - \v(a{-1,3})+
3ef2ca
  OK 2 - \v(a{-1,3})+
3ef2ca
+ OK 0 - ^\s\{-}\zs\( x\|x$\)
3ef2ca
+ OK 1 - ^\s\{-}\zs\( x\|x$\)
3ef2ca
+ OK 2 - ^\s\{-}\zs\( x\|x$\)
3ef2ca
+ OK 0 - ^\s\{-}\zs\(x\| x$\)
3ef2ca
+ OK 1 - ^\s\{-}\zs\(x\| x$\)
3ef2ca
+ OK 2 - ^\s\{-}\zs\(x\| x$\)
3ef2ca
+ OK 0 - ^\s\{-}\ze\(x\| x$\)
3ef2ca
+ OK 1 - ^\s\{-}\ze\(x\| x$\)
3ef2ca
+ OK 2 - ^\s\{-}\ze\(x\| x$\)
3ef2ca
+ OK 0 - ^\(\s\{-}\)\(x\| x$\)
3ef2ca
+ OK 1 - ^\(\s\{-}\)\(x\| x$\)
3ef2ca
+ OK 2 - ^\(\s\{-}\)\(x\| x$\)
3ef2ca
  OK 0 - \d\+e\d\d
3ef2ca
  OK 1 - \d\+e\d\d
3ef2ca
  OK 2 - \d\+e\d\d
3ef2ca
*** ../vim-7.4.289/src/regexp_nfa.c	2014-05-13 15:56:45.021670668 +0200
3ef2ca
--- src/regexp_nfa.c	2014-05-13 16:37:58.481692320 +0200
3ef2ca
***************
3ef2ca
*** 4324,4331 ****
3ef2ca
  	    {
3ef2ca
  		/* This state is already in the list, don't add it again,
3ef2ca
  		 * unless it is an MOPEN that is used for a backreference or
3ef2ca
! 		 * when there is a PIM. */
3ef2ca
! 		if (!nfa_has_backref && pim == NULL && !l->has_pim)
3ef2ca
  		{
3ef2ca
  skip_add:
3ef2ca
  #ifdef ENABLE_LOG
3ef2ca
--- 4324,4333 ----
3ef2ca
  	    {
3ef2ca
  		/* This state is already in the list, don't add it again,
3ef2ca
  		 * unless it is an MOPEN that is used for a backreference or
3ef2ca
! 		 * when there is a PIM. For NFA_MATCH check the position,
3ef2ca
! 		 * lower position is preferred. */
3ef2ca
! 		if (!nfa_has_backref && pim == NULL && !l->has_pim
3ef2ca
! 						     && state->c != NFA_MATCH)
3ef2ca
  		{
3ef2ca
  skip_add:
3ef2ca
  #ifdef ENABLE_LOG
3ef2ca
*** ../vim-7.4.289/src/version.c	2014-05-13 15:56:45.025670668 +0200
3ef2ca
--- src/version.c	2014-05-13 16:13:33.953679500 +0200
3ef2ca
***************
3ef2ca
*** 736,737 ****
3ef2ca
--- 736,739 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     290,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
Although the scythe isn't pre-eminent among the weapons of war, anyone who
3ef2ca
has been on the wrong end of, say, a peasants' revolt will know that in
3ef2ca
skilled hands it is fearsome.
3ef2ca
					-- (Terry Pratchett, Mort)
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///