Karsten Hopp ee3896
To: vim_dev@googlegroups.com
Karsten Hopp ee3896
Subject: Patch 7.3.1085
Karsten Hopp ee3896
Fcc: outbox
Karsten Hopp ee3896
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp ee3896
Mime-Version: 1.0
Karsten Hopp ee3896
Content-Type: text/plain; charset=UTF-8
Karsten Hopp ee3896
Content-Transfer-Encoding: 8bit
Karsten Hopp ee3896
------------
Karsten Hopp ee3896
Karsten Hopp ee3896
Patch 7.3.1085
Karsten Hopp ee3896
Problem:    New regexp engine: Non-greedy multi doesn't work.
Karsten Hopp ee3896
Solution:   Implement \{-}.
Karsten Hopp ee3896
Files:	    src/regexp_nfa.c, src/testdir/test64.in, src/testdir/test64.ok
Karsten Hopp ee3896
Karsten Hopp ee3896
Karsten Hopp ee3896
*** ../vim-7.3.1084/src/regexp_nfa.c	2013-05-31 23:17:56.000000000 +0200
Karsten Hopp ee3896
--- src/regexp_nfa.c	2013-06-01 12:22:17.000000000 +0200
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 38,46 ****
Karsten Hopp ee3896
  
Karsten Hopp ee3896
      NFA_CONCAT,
Karsten Hopp ee3896
      NFA_OR,
Karsten Hopp ee3896
!     NFA_STAR,
Karsten Hopp ee3896
!     NFA_QUEST,
Karsten Hopp ee3896
!     NFA_QUEST_NONGREEDY,	    /* Non-greedy version of \? */
Karsten Hopp ee3896
      NFA_NOT,			    /* used for [^ab] negated char ranges */
Karsten Hopp ee3896
  
Karsten Hopp ee3896
      NFA_BOL,			    /* ^    Begin line */
Karsten Hopp ee3896
--- 38,47 ----
Karsten Hopp ee3896
  
Karsten Hopp ee3896
      NFA_CONCAT,
Karsten Hopp ee3896
      NFA_OR,
Karsten Hopp ee3896
!     NFA_STAR,			    /* greedy * */
Karsten Hopp ee3896
!     NFA_STAR_NONGREEDY,		    /* non-greedy * */
Karsten Hopp ee3896
!     NFA_QUEST,			    /* greedy \? */
Karsten Hopp ee3896
!     NFA_QUEST_NONGREEDY,	    /* non-greedy \? */
Karsten Hopp ee3896
      NFA_NOT,			    /* used for [^ab] negated char ranges */
Karsten Hopp ee3896
  
Karsten Hopp ee3896
      NFA_BOL,			    /* ^    Begin line */
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 1430,1445 ****
Karsten Hopp ee3896
  	    }
Karsten Hopp ee3896
  	    /*  <atom>{0,inf}, <atom>{0,} and <atom>{}  are equivalent to
Karsten Hopp ee3896
  	     *  <atom>*  */
Karsten Hopp ee3896
! 	    if (minval == 0 && maxval == MAX_LIMIT && greedy)
Karsten Hopp ee3896
  	    {
Karsten Hopp ee3896
! 		EMIT(NFA_STAR);
Karsten Hopp ee3896
  		break;
Karsten Hopp ee3896
  	    }
Karsten Hopp ee3896
  
Karsten Hopp ee3896
- 	    /* TODO: \{-} doesn't work yet */
Karsten Hopp ee3896
- 	    if (maxval == MAX_LIMIT && !greedy)
Karsten Hopp ee3896
- 		return FAIL;
Karsten Hopp ee3896
- 
Karsten Hopp ee3896
  	    /* Special case: x{0} or x{-0} */
Karsten Hopp ee3896
  	    if (maxval == 0)
Karsten Hopp ee3896
  	    {
Karsten Hopp ee3896
--- 1431,1447 ----
Karsten Hopp ee3896
  	    }
Karsten Hopp ee3896
  	    /*  <atom>{0,inf}, <atom>{0,} and <atom>{}  are equivalent to
Karsten Hopp ee3896
  	     *  <atom>*  */
Karsten Hopp ee3896
! 	    if (minval == 0 && maxval == MAX_LIMIT)
Karsten Hopp ee3896
  	    {
Karsten Hopp ee3896
! 		if (greedy)
Karsten Hopp ee3896
! 		    /* \{}, \{0,} */
Karsten Hopp ee3896
! 		    EMIT(NFA_STAR);
Karsten Hopp ee3896
! 		else
Karsten Hopp ee3896
! 		    /* \{-}, \{-0,} */
Karsten Hopp ee3896
! 		    EMIT(NFA_STAR_NONGREEDY);
Karsten Hopp ee3896
  		break;
Karsten Hopp ee3896
  	    }
Karsten Hopp ee3896
  
Karsten Hopp ee3896
  	    /* Special case: x{0} or x{-0} */
Karsten Hopp ee3896
  	    if (maxval == 0)
Karsten Hopp ee3896
  	    {
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 1470,1476 ****
Karsten Hopp ee3896
  		if (i + 1 > minval)
Karsten Hopp ee3896
  		{
Karsten Hopp ee3896
  		    if (maxval == MAX_LIMIT)
Karsten Hopp ee3896
! 			EMIT(NFA_STAR);
Karsten Hopp ee3896
  		    else
Karsten Hopp ee3896
  			EMIT(quest);
Karsten Hopp ee3896
  		}
Karsten Hopp ee3896
--- 1472,1483 ----
Karsten Hopp ee3896
  		if (i + 1 > minval)
Karsten Hopp ee3896
  		{
Karsten Hopp ee3896
  		    if (maxval == MAX_LIMIT)
Karsten Hopp ee3896
! 		    {
Karsten Hopp ee3896
! 			if (greedy)
Karsten Hopp ee3896
! 			    EMIT(NFA_STAR);
Karsten Hopp ee3896
! 			else
Karsten Hopp ee3896
! 			    EMIT(NFA_STAR_NONGREEDY);
Karsten Hopp ee3896
! 		    }
Karsten Hopp ee3896
  		    else
Karsten Hopp ee3896
  			EMIT(quest);
Karsten Hopp ee3896
  		}
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 1776,1786 ****
Karsten Hopp ee3896
  	case NFA_EOF:		STRCPY(code, "NFA_EOF "); break;
Karsten Hopp ee3896
  	case NFA_BOF:		STRCPY(code, "NFA_BOF "); break;
Karsten Hopp ee3896
  	case NFA_STAR:		STRCPY(code, "NFA_STAR "); break;
Karsten Hopp ee3896
  	case NFA_NOT:		STRCPY(code, "NFA_NOT "); break;
Karsten Hopp ee3896
  	case NFA_SKIP_CHAR:	STRCPY(code, "NFA_SKIP_CHAR"); break;
Karsten Hopp ee3896
  	case NFA_OR:		STRCPY(code, "NFA_OR"); break;
Karsten Hopp ee3896
- 	case NFA_QUEST:		STRCPY(code, "NFA_QUEST"); break;
Karsten Hopp ee3896
- 	case NFA_QUEST_NONGREEDY: STRCPY(code, "NFA_QUEST_NON_GREEDY"); break;
Karsten Hopp ee3896
  	case NFA_END_NEG_RANGE:	STRCPY(code, "NFA_END_NEG_RANGE"); break;
Karsten Hopp ee3896
  	case NFA_CLASS_ALNUM:	STRCPY(code, "NFA_CLASS_ALNUM"); break;
Karsten Hopp ee3896
  	case NFA_CLASS_ALPHA:	STRCPY(code, "NFA_CLASS_ALPHA"); break;
Karsten Hopp ee3896
--- 1783,1794 ----
Karsten Hopp ee3896
  	case NFA_EOF:		STRCPY(code, "NFA_EOF "); break;
Karsten Hopp ee3896
  	case NFA_BOF:		STRCPY(code, "NFA_BOF "); break;
Karsten Hopp ee3896
  	case NFA_STAR:		STRCPY(code, "NFA_STAR "); break;
Karsten Hopp ee3896
+ 	case NFA_STAR_NONGREEDY: STRCPY(code, "NFA_STAR_NONGREEDY "); break;
Karsten Hopp ee3896
+ 	case NFA_QUEST:		STRCPY(code, "NFA_QUEST"); break;
Karsten Hopp ee3896
+ 	case NFA_QUEST_NONGREEDY: STRCPY(code, "NFA_QUEST_NON_GREEDY"); break;
Karsten Hopp ee3896
  	case NFA_NOT:		STRCPY(code, "NFA_NOT "); break;
Karsten Hopp ee3896
  	case NFA_SKIP_CHAR:	STRCPY(code, "NFA_SKIP_CHAR"); break;
Karsten Hopp ee3896
  	case NFA_OR:		STRCPY(code, "NFA_OR"); break;
Karsten Hopp ee3896
  	case NFA_END_NEG_RANGE:	STRCPY(code, "NFA_END_NEG_RANGE"); break;
Karsten Hopp ee3896
  	case NFA_CLASS_ALNUM:	STRCPY(code, "NFA_CLASS_ALNUM"); break;
Karsten Hopp ee3896
  	case NFA_CLASS_ALPHA:	STRCPY(code, "NFA_CLASS_ALPHA"); break;
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 2297,2303 ****
Karsten Hopp ee3896
  	    break;
Karsten Hopp ee3896
  
Karsten Hopp ee3896
  	case NFA_STAR:
Karsten Hopp ee3896
! 	    /* Zero or more */
Karsten Hopp ee3896
  	    if (nfa_calc_size == TRUE)
Karsten Hopp ee3896
  	    {
Karsten Hopp ee3896
  		nstate++;
Karsten Hopp ee3896
--- 2305,2311 ----
Karsten Hopp ee3896
  	    break;
Karsten Hopp ee3896
  
Karsten Hopp ee3896
  	case NFA_STAR:
Karsten Hopp ee3896
! 	    /* Zero or more, prefer more */
Karsten Hopp ee3896
  	    if (nfa_calc_size == TRUE)
Karsten Hopp ee3896
  	    {
Karsten Hopp ee3896
  		nstate++;
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 2311,2316 ****
Karsten Hopp ee3896
--- 2319,2339 ----
Karsten Hopp ee3896
  	    PUSH(frag(s, list1(&s->out1)));
Karsten Hopp ee3896
  	    break;
Karsten Hopp ee3896
  
Karsten Hopp ee3896
+ 	case NFA_STAR_NONGREEDY:
Karsten Hopp ee3896
+ 	    /* Zero or more, prefer zero */
Karsten Hopp ee3896
+ 	    if (nfa_calc_size == TRUE)
Karsten Hopp ee3896
+ 	    {
Karsten Hopp ee3896
+ 		nstate++;
Karsten Hopp ee3896
+ 		break;
Karsten Hopp ee3896
+ 	    }
Karsten Hopp ee3896
+ 	    e = POP();
Karsten Hopp ee3896
+ 	    s = new_state(NFA_SPLIT, NULL, e.start);
Karsten Hopp ee3896
+ 	    if (s == NULL)
Karsten Hopp ee3896
+ 		goto theend;
Karsten Hopp ee3896
+ 	    patch(e.out, s);
Karsten Hopp ee3896
+ 	    PUSH(frag(s, list1(&s->out)));
Karsten Hopp ee3896
+ 	    break;
Karsten Hopp ee3896
+ 
Karsten Hopp ee3896
  	case NFA_QUEST:
Karsten Hopp ee3896
  	    /* one or zero atoms=> greedy match */
Karsten Hopp ee3896
  	    if (nfa_calc_size == TRUE)
Karsten Hopp ee3896
*** ../vim-7.3.1084/src/testdir/test64.in	2013-05-31 23:17:56.000000000 +0200
Karsten Hopp ee3896
--- src/testdir/test64.in	2013-06-01 12:29:19.000000000 +0200
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 23,30 ****
Karsten Hopp ee3896
  :call add(tl, [2, 'ab', 'aab', 'ab'])
Karsten Hopp ee3896
  :call add(tl, [2, 'b', 'abcdef', 'b'])
Karsten Hopp ee3896
  :call add(tl, [2, 'bc*', 'abccccdef', 'bcccc'])
Karsten Hopp ee3896
! :call add(tl, [0, 'bc\{-}', 'abccccdef', 'b'])
Karsten Hopp ee3896
! :call add(tl, [0, 'bc\{-}\(d\)', 'abccccdef', 'bccccd', 'd'])
Karsten Hopp ee3896
  :call add(tl, [2, 'bc*', 'abbdef', 'b'])
Karsten Hopp ee3896
  :call add(tl, [2, 'c*', 'ccc', 'ccc'])
Karsten Hopp ee3896
  :call add(tl, [2, 'bc*', 'abdef', 'b'])
Karsten Hopp ee3896
--- 23,30 ----
Karsten Hopp ee3896
  :call add(tl, [2, 'ab', 'aab', 'ab'])
Karsten Hopp ee3896
  :call add(tl, [2, 'b', 'abcdef', 'b'])
Karsten Hopp ee3896
  :call add(tl, [2, 'bc*', 'abccccdef', 'bcccc'])
Karsten Hopp ee3896
! :call add(tl, [2, 'bc\{-}', 'abccccdef', 'b'])
Karsten Hopp ee3896
! :call add(tl, [2, 'bc\{-}\(d\)', 'abccccdef', 'bccccd', 'd'])
Karsten Hopp ee3896
  :call add(tl, [2, 'bc*', 'abbdef', 'b'])
Karsten Hopp ee3896
  :call add(tl, [2, 'c*', 'ccc', 'ccc'])
Karsten Hopp ee3896
  :call add(tl, [2, 'bc*', 'abdef', 'b'])
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 201,216 ****
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-0}', 'asoiuj', ''])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-2}', 'aaaa', 'aa'])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-2}', 'abcdefghijklmnopqrestuvwxyz1234567890'])
Karsten Hopp ee3896
! :call add(tl, [0, 'a\{-0,}', 'oij sdigfusnf', ''])
Karsten Hopp ee3896
! :call add(tl, [0, 'a\{-0,}', 'aaaaa aa', ''])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-2,}', 'sdfiougjdsafg'])
Karsten Hopp ee3896
! :call add(tl, [0, 'a\{-2,}', 'aaaaasfoij ', 'aa'])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-,0}', 'oidfguih iuhi hiu aaaa', ''])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-,5}', 'abcd', ''])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-,5}', 'aaaaaaaaaa', ''])
Karsten Hopp ee3896
  :" anti-greedy version of 'a*'
Karsten Hopp ee3896
! :call add(tl, [0, 'a\{-}', 'bbbcddiuhfcd', ''])
Karsten Hopp ee3896
! :call add(tl, [0, 'a\{-}', 'aaaaioudfh coisf jda', ''])
Karsten Hopp ee3896
  :"
Karsten Hopp ee3896
  :" Test groups of characters and submatches
Karsten Hopp ee3896
  :call add(tl, [2, '\(abc\)*', 'abcabcabc', 'abcabcabc', 'abc'])
Karsten Hopp ee3896
--- 201,216 ----
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-0}', 'asoiuj', ''])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-2}', 'aaaa', 'aa'])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-2}', 'abcdefghijklmnopqrestuvwxyz1234567890'])
Karsten Hopp ee3896
! :call add(tl, [2, 'a\{-0,}', 'oij sdigfusnf', ''])
Karsten Hopp ee3896
! :call add(tl, [2, 'a\{-0,}', 'aaaaa aa', ''])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-2,}', 'sdfiougjdsafg'])
Karsten Hopp ee3896
! :call add(tl, [2, 'a\{-2,}', 'aaaaasfoij ', 'aa'])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-,0}', 'oidfguih iuhi hiu aaaa', ''])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-,5}', 'abcd', ''])
Karsten Hopp ee3896
  :call add(tl, [2, 'a\{-,5}', 'aaaaaaaaaa', ''])
Karsten Hopp ee3896
  :" anti-greedy version of 'a*'
Karsten Hopp ee3896
! :call add(tl, [2, 'a\{-}', 'bbbcddiuhfcd', ''])
Karsten Hopp ee3896
! :call add(tl, [2, 'a\{-}', 'aaaaioudfh coisf jda', ''])
Karsten Hopp ee3896
  :"
Karsten Hopp ee3896
  :" Test groups of characters and submatches
Karsten Hopp ee3896
  :call add(tl, [2, '\(abc\)*', 'abcabcabc', 'abcabcabc', 'abc'])
Karsten Hopp ee3896
*** ../vim-7.3.1084/src/testdir/test64.ok	2013-05-31 23:17:56.000000000 +0200
Karsten Hopp ee3896
--- src/testdir/test64.ok	2013-06-01 12:29:38.000000000 +0200
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 10,17 ****
Karsten Hopp ee3896
--- 10,19 ----
Karsten Hopp ee3896
  OK 2 - bc*
Karsten Hopp ee3896
  OK 0 - bc\{-}
Karsten Hopp ee3896
  OK 1 - bc\{-}
Karsten Hopp ee3896
+ OK 2 - bc\{-}
Karsten Hopp ee3896
  OK 0 - bc\{-}\(d\)
Karsten Hopp ee3896
  OK 1 - bc\{-}\(d\)
Karsten Hopp ee3896
+ OK 2 - bc\{-}\(d\)
Karsten Hopp ee3896
  OK 0 - bc*
Karsten Hopp ee3896
  OK 1 - bc*
Karsten Hopp ee3896
  OK 2 - bc*
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 437,449 ****
Karsten Hopp ee3896
--- 439,454 ----
Karsten Hopp ee3896
  OK 2 - a\{-2}
Karsten Hopp ee3896
  OK 0 - a\{-0,}
Karsten Hopp ee3896
  OK 1 - a\{-0,}
Karsten Hopp ee3896
+ OK 2 - a\{-0,}
Karsten Hopp ee3896
  OK 0 - a\{-0,}
Karsten Hopp ee3896
  OK 1 - a\{-0,}
Karsten Hopp ee3896
+ OK 2 - a\{-0,}
Karsten Hopp ee3896
  OK 0 - a\{-2,}
Karsten Hopp ee3896
  OK 1 - a\{-2,}
Karsten Hopp ee3896
  OK 2 - a\{-2,}
Karsten Hopp ee3896
  OK 0 - a\{-2,}
Karsten Hopp ee3896
  OK 1 - a\{-2,}
Karsten Hopp ee3896
+ OK 2 - a\{-2,}
Karsten Hopp ee3896
  OK 0 - a\{-,0}
Karsten Hopp ee3896
  OK 1 - a\{-,0}
Karsten Hopp ee3896
  OK 2 - a\{-,0}
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 455,462 ****
Karsten Hopp ee3896
--- 460,469 ----
Karsten Hopp ee3896
  OK 2 - a\{-,5}
Karsten Hopp ee3896
  OK 0 - a\{-}
Karsten Hopp ee3896
  OK 1 - a\{-}
Karsten Hopp ee3896
+ OK 2 - a\{-}
Karsten Hopp ee3896
  OK 0 - a\{-}
Karsten Hopp ee3896
  OK 1 - a\{-}
Karsten Hopp ee3896
+ OK 2 - a\{-}
Karsten Hopp ee3896
  OK 0 - \(abc\)*
Karsten Hopp ee3896
  OK 1 - \(abc\)*
Karsten Hopp ee3896
  OK 2 - \(abc\)*
Karsten Hopp ee3896
*** ../vim-7.3.1084/src/version.c	2013-05-31 23:17:56.000000000 +0200
Karsten Hopp ee3896
--- src/version.c	2013-06-01 12:39:01.000000000 +0200
Karsten Hopp ee3896
***************
Karsten Hopp ee3896
*** 730,731 ****
Karsten Hopp ee3896
--- 730,733 ----
Karsten Hopp ee3896
  {   /* Add new patch number below this line */
Karsten Hopp ee3896
+ /**/
Karsten Hopp ee3896
+     1085,
Karsten Hopp ee3896
  /**/
Karsten Hopp ee3896
Karsten Hopp ee3896
-- 
Karsten Hopp ee3896
hundred-and-one symptoms of being an internet addict:
Karsten Hopp ee3896
35. Your husband tells you he's had the beard for 2 months.
Karsten Hopp ee3896
Karsten Hopp ee3896
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp ee3896
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp ee3896
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp ee3896
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///