Karsten Hopp 7918ec
To: vim_dev@googlegroups.com
Karsten Hopp 7918ec
Subject: Patch 7.3.1117
Karsten Hopp 7918ec
Fcc: outbox
Karsten Hopp 7918ec
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 7918ec
Mime-Version: 1.0
Karsten Hopp 7918ec
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 7918ec
Content-Transfer-Encoding: 8bit
Karsten Hopp 7918ec
------------
Karsten Hopp 7918ec
Karsten Hopp 7918ec
Patch 7.3.1117
Karsten Hopp 7918ec
Problem:    New regexp engine: \%[abc] not supported.
Karsten Hopp 7918ec
Solution:   Implement \%[abc].  Add tests.
Karsten Hopp 7918ec
Files:	    src/regexp_nfa.c, src/testdir/test64.in, src/testdir/test64.ok
Karsten Hopp 7918ec
Karsten Hopp 7918ec
Karsten Hopp 7918ec
*** ../vim-7.3.1116/src/regexp_nfa.c	2013-06-05 11:01:59.000000000 +0200
Karsten Hopp 7918ec
--- src/regexp_nfa.c	2013-06-05 11:03:19.000000000 +0200
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 61,66 ****
Karsten Hopp 7918ec
--- 61,67 ----
Karsten Hopp 7918ec
      NFA_COMPOSING,		    /* Next nodes in NFA are part of the
Karsten Hopp 7918ec
  				       composing multibyte char */
Karsten Hopp 7918ec
      NFA_END_COMPOSING,		    /* End of a composing char in the NFA */
Karsten Hopp 7918ec
+     NFA_OPT_CHARS,		    /* \%[abc] */
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
      /* The following are used only in the postfix form, not in the NFA */
Karsten Hopp 7918ec
      NFA_PREV_ATOM_NO_WIDTH,	    /* Used for \@= */
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 972,979 ****
Karsten Hopp 7918ec
  #endif
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  		case '[':
Karsten Hopp 7918ec
! 		    /* TODO: \%[abc] not supported yet */
Karsten Hopp 7918ec
! 		    return FAIL;
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  		default:
Karsten Hopp 7918ec
  		    {
Karsten Hopp 7918ec
--- 973,993 ----
Karsten Hopp 7918ec
  #endif
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  		case '[':
Karsten Hopp 7918ec
! 		    {
Karsten Hopp 7918ec
! 			int	    n;
Karsten Hopp 7918ec
! 
Karsten Hopp 7918ec
! 			/* \%[abc] */
Karsten Hopp 7918ec
! 			for (n = 0; (c = getchr()) != ']'; ++n)
Karsten Hopp 7918ec
! 			{
Karsten Hopp 7918ec
! 			    if (c == NUL)
Karsten Hopp 7918ec
! 				EMSG2_RET_FAIL(_(e_missing_sb),
Karsten Hopp 7918ec
! 						      reg_magic == MAGIC_ALL);
Karsten Hopp 7918ec
! 			    EMIT(c);
Karsten Hopp 7918ec
! 			}
Karsten Hopp 7918ec
! 			EMIT(NFA_OPT_CHARS);
Karsten Hopp 7918ec
! 			EMIT(n);
Karsten Hopp 7918ec
! 			break;
Karsten Hopp 7918ec
! 		    }
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  		default:
Karsten Hopp 7918ec
  		    {
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 989,995 ****
Karsten Hopp 7918ec
  			}
Karsten Hopp 7918ec
  			if (c == 'l' || c == 'c' || c == 'v')
Karsten Hopp 7918ec
  			{
Karsten Hopp 7918ec
- 			    EMIT(n);
Karsten Hopp 7918ec
  			    if (c == 'l')
Karsten Hopp 7918ec
  				/* \%{n}l  \%{n}<l  \%{n}>l  */
Karsten Hopp 7918ec
  				EMIT(cmp == '<' ? NFA_LNUM_LT :
Karsten Hopp 7918ec
--- 1003,1008 ----
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 1002,1015 ****
Karsten Hopp 7918ec
  				/* \%{n}v  \%{n}<v  \%{n}>v  */
Karsten Hopp 7918ec
  				EMIT(cmp == '<' ? NFA_VCOL_LT :
Karsten Hopp 7918ec
  				     cmp == '>' ? NFA_VCOL_GT : NFA_VCOL);
Karsten Hopp 7918ec
  			    break;
Karsten Hopp 7918ec
  			}
Karsten Hopp 7918ec
  			else if (c == '\'' && n == 0)
Karsten Hopp 7918ec
  			{
Karsten Hopp 7918ec
  			    /* \%'m  \%<'m  \%>'m  */
Karsten Hopp 7918ec
- 			    EMIT(getchr());
Karsten Hopp 7918ec
  			    EMIT(cmp == '<' ? NFA_MARK_LT :
Karsten Hopp 7918ec
  				 cmp == '>' ? NFA_MARK_GT : NFA_MARK);
Karsten Hopp 7918ec
  			    break;
Karsten Hopp 7918ec
  			}
Karsten Hopp 7918ec
  		    }
Karsten Hopp 7918ec
--- 1015,1029 ----
Karsten Hopp 7918ec
  				/* \%{n}v  \%{n}<v  \%{n}>v  */
Karsten Hopp 7918ec
  				EMIT(cmp == '<' ? NFA_VCOL_LT :
Karsten Hopp 7918ec
  				     cmp == '>' ? NFA_VCOL_GT : NFA_VCOL);
Karsten Hopp 7918ec
+ 			    EMIT(n);
Karsten Hopp 7918ec
  			    break;
Karsten Hopp 7918ec
  			}
Karsten Hopp 7918ec
  			else if (c == '\'' && n == 0)
Karsten Hopp 7918ec
  			{
Karsten Hopp 7918ec
  			    /* \%'m  \%<'m  \%>'m  */
Karsten Hopp 7918ec
  			    EMIT(cmp == '<' ? NFA_MARK_LT :
Karsten Hopp 7918ec
  				 cmp == '>' ? NFA_MARK_GT : NFA_MARK);
Karsten Hopp 7918ec
+ 			    EMIT(getchr());
Karsten Hopp 7918ec
  			    break;
Karsten Hopp 7918ec
  			}
Karsten Hopp 7918ec
  		    }
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 1885,1890 ****
Karsten Hopp 7918ec
--- 1899,1905 ----
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  	case NFA_COMPOSING:	    STRCPY(code, "NFA_COMPOSING"); break;
Karsten Hopp 7918ec
  	case NFA_END_COMPOSING:	    STRCPY(code, "NFA_END_COMPOSING"); break;
Karsten Hopp 7918ec
+ 	case NFA_OPT_CHARS:	    STRCPY(code, "NFA_OPT_CHARS"); break;
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  	case NFA_MOPEN:
Karsten Hopp 7918ec
  	case NFA_MOPEN1:
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 2558,2567 ****
Karsten Hopp 7918ec
--- 2573,2621 ----
Karsten Hopp 7918ec
  	    PUSH(frag(s, list1(&s->out)));
Karsten Hopp 7918ec
  	    break;
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
+ 	case NFA_OPT_CHARS:
Karsten Hopp 7918ec
+ 	  {
Karsten Hopp 7918ec
+ 	    int    n;
Karsten Hopp 7918ec
+ 
Karsten Hopp 7918ec
+ 	    /* \%[abc] */
Karsten Hopp 7918ec
+ 	    n = *++p; /* get number of characters */
Karsten Hopp 7918ec
+ 	    if (nfa_calc_size == TRUE)
Karsten Hopp 7918ec
+ 	    {
Karsten Hopp 7918ec
+ 		nstate += n;
Karsten Hopp 7918ec
+ 		break;
Karsten Hopp 7918ec
+ 	    }
Karsten Hopp 7918ec
+ 	    e1.out = NULL; /* stores list with out1's */
Karsten Hopp 7918ec
+ 	    s1 = NULL; /* previous NFA_SPLIT to connect to */
Karsten Hopp 7918ec
+ 	    while (n-- > 0)
Karsten Hopp 7918ec
+ 	    {
Karsten Hopp 7918ec
+ 		e = POP(); /* get character */
Karsten Hopp 7918ec
+ 		s = alloc_state(NFA_SPLIT, e.start, NULL);
Karsten Hopp 7918ec
+ 		if (s == NULL)
Karsten Hopp 7918ec
+ 		    goto theend;
Karsten Hopp 7918ec
+ 		if (e1.out == NULL)
Karsten Hopp 7918ec
+ 		    e1 = e;
Karsten Hopp 7918ec
+ 		patch(e.out, s1);
Karsten Hopp 7918ec
+ 		append(e1.out, list1(&s->out1));
Karsten Hopp 7918ec
+ 		s1 = s;
Karsten Hopp 7918ec
+ 	    }
Karsten Hopp 7918ec
+ 	    PUSH(frag(s, e1.out));
Karsten Hopp 7918ec
+ 	    break;
Karsten Hopp 7918ec
+ 	  }
Karsten Hopp 7918ec
+ 
Karsten Hopp 7918ec
  	case NFA_PREV_ATOM_NO_WIDTH:
Karsten Hopp 7918ec
  	case NFA_PREV_ATOM_NO_WIDTH_NEG:
Karsten Hopp 7918ec
  	case NFA_PREV_ATOM_JUST_BEFORE:
Karsten Hopp 7918ec
  	case NFA_PREV_ATOM_JUST_BEFORE_NEG:
Karsten Hopp 7918ec
+ 	  {
Karsten Hopp 7918ec
+ 	    int neg = (*p == NFA_PREV_ATOM_NO_WIDTH_NEG
Karsten Hopp 7918ec
+ 				      || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG);
Karsten Hopp 7918ec
+ 	    int before = (*p == NFA_PREV_ATOM_JUST_BEFORE
Karsten Hopp 7918ec
+ 				      || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG);
Karsten Hopp 7918ec
+ 	    int n;
Karsten Hopp 7918ec
+ 
Karsten Hopp 7918ec
+ 	    if (before)
Karsten Hopp 7918ec
+ 		n = *++p; /* get the count */
Karsten Hopp 7918ec
+ 
Karsten Hopp 7918ec
  	    /* The \@= operator: match the preceding atom with zero width.
Karsten Hopp 7918ec
  	     * The \@! operator: no match for the preceding atom.
Karsten Hopp 7918ec
  	     * The \@<= operator: match for the preceding atom.
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 2583,2603 ****
Karsten Hopp 7918ec
  	    s = alloc_state(NFA_START_INVISIBLE, e.start, s1);
Karsten Hopp 7918ec
  	    if (s == NULL)
Karsten Hopp 7918ec
  		goto theend;
Karsten Hopp 7918ec
! 	    if (*p == NFA_PREV_ATOM_NO_WIDTH_NEG
Karsten Hopp 7918ec
! 				       || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG)
Karsten Hopp 7918ec
  	    {
Karsten Hopp 7918ec
  		s->negated = TRUE;
Karsten Hopp 7918ec
  		s1->negated = TRUE;
Karsten Hopp 7918ec
  	    }
Karsten Hopp 7918ec
! 	    if (*p == NFA_PREV_ATOM_JUST_BEFORE
Karsten Hopp 7918ec
! 				       || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG)
Karsten Hopp 7918ec
  	    {
Karsten Hopp 7918ec
! 		s->val = *++p; /* get the count */
Karsten Hopp 7918ec
  		++s->c; /* NFA_START_INVISIBLE -> NFA_START_INVISIBLE_BEFORE */
Karsten Hopp 7918ec
  	    }
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  	    PUSH(frag(s, list1(&s1->out)));
Karsten Hopp 7918ec
  	    break;
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  #ifdef FEAT_MBYTE
Karsten Hopp 7918ec
  	case NFA_COMPOSING:	/* char with composing char */
Karsten Hopp 7918ec
--- 2637,2656 ----
Karsten Hopp 7918ec
  	    s = alloc_state(NFA_START_INVISIBLE, e.start, s1);
Karsten Hopp 7918ec
  	    if (s == NULL)
Karsten Hopp 7918ec
  		goto theend;
Karsten Hopp 7918ec
! 	    if (neg)
Karsten Hopp 7918ec
  	    {
Karsten Hopp 7918ec
  		s->negated = TRUE;
Karsten Hopp 7918ec
  		s1->negated = TRUE;
Karsten Hopp 7918ec
  	    }
Karsten Hopp 7918ec
! 	    if (before)
Karsten Hopp 7918ec
  	    {
Karsten Hopp 7918ec
! 		s->val = n; /* store the count */
Karsten Hopp 7918ec
  		++s->c; /* NFA_START_INVISIBLE -> NFA_START_INVISIBLE_BEFORE */
Karsten Hopp 7918ec
  	    }
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  	    PUSH(frag(s, list1(&s1->out)));
Karsten Hopp 7918ec
  	    break;
Karsten Hopp 7918ec
+ 	  }
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  #ifdef FEAT_MBYTE
Karsten Hopp 7918ec
  	case NFA_COMPOSING:	/* char with composing char */
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 2750,2767 ****
Karsten Hopp 7918ec
  	case NFA_MARK:
Karsten Hopp 7918ec
  	case NFA_MARK_GT:
Karsten Hopp 7918ec
  	case NFA_MARK_LT:
Karsten Hopp 7918ec
  	    if (nfa_calc_size == TRUE)
Karsten Hopp 7918ec
  	    {
Karsten Hopp 7918ec
  		nstate += 1;
Karsten Hopp 7918ec
  		break;
Karsten Hopp 7918ec
  	    }
Karsten Hopp 7918ec
! 	    e1 = POP();
Karsten Hopp 7918ec
! 	    s = alloc_state(*p, NULL, NULL);
Karsten Hopp 7918ec
  	    if (s == NULL)
Karsten Hopp 7918ec
  		goto theend;
Karsten Hopp 7918ec
! 	    s->val = e1.start->c; /* lnum, col or mark name */
Karsten Hopp 7918ec
  	    PUSH(frag(s, list1(&s->out)));
Karsten Hopp 7918ec
  	    break;
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  	case NFA_ZSTART:
Karsten Hopp 7918ec
  	case NFA_ZEND:
Karsten Hopp 7918ec
--- 2803,2823 ----
Karsten Hopp 7918ec
  	case NFA_MARK:
Karsten Hopp 7918ec
  	case NFA_MARK_GT:
Karsten Hopp 7918ec
  	case NFA_MARK_LT:
Karsten Hopp 7918ec
+ 	  {
Karsten Hopp 7918ec
+ 	    int n = *++p; /* lnum, col or mark name */
Karsten Hopp 7918ec
+ 
Karsten Hopp 7918ec
  	    if (nfa_calc_size == TRUE)
Karsten Hopp 7918ec
  	    {
Karsten Hopp 7918ec
  		nstate += 1;
Karsten Hopp 7918ec
  		break;
Karsten Hopp 7918ec
  	    }
Karsten Hopp 7918ec
! 	    s = alloc_state(p[-1], NULL, NULL);
Karsten Hopp 7918ec
  	    if (s == NULL)
Karsten Hopp 7918ec
  		goto theend;
Karsten Hopp 7918ec
! 	    s->val = n;
Karsten Hopp 7918ec
  	    PUSH(frag(s, list1(&s->out)));
Karsten Hopp 7918ec
  	    break;
Karsten Hopp 7918ec
+ 	  }
Karsten Hopp 7918ec
  
Karsten Hopp 7918ec
  	case NFA_ZSTART:
Karsten Hopp 7918ec
  	case NFA_ZEND:
Karsten Hopp 7918ec
*** ../vim-7.3.1116/src/testdir/test64.in	2013-06-04 21:27:33.000000000 +0200
Karsten Hopp 7918ec
--- src/testdir/test64.in	2013-06-04 23:45:44.000000000 +0200
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 352,357 ****
Karsten Hopp 7918ec
--- 352,370 ----
Karsten Hopp 7918ec
  :call add(tl, [2, '\%u0020', 'yes no', ' '])
Karsten Hopp 7918ec
  :call add(tl, [2, '\%U00000020', 'yes no', ' '])
Karsten Hopp 7918ec
  :"
Karsten Hopp 7918ec
+ :""""" \%[abc]
Karsten Hopp 7918ec
+ :call add(tl, [2, 'foo\%[bar]', 'fobar'])
Karsten Hopp 7918ec
+ :call add(tl, [2, 'foo\%[bar]', 'foobar', 'foobar'])
Karsten Hopp 7918ec
+ :call add(tl, [2, 'foo\%[bar]', 'fooxx', 'foo'])
Karsten Hopp 7918ec
+ :call add(tl, [2, 'foo\%[bar]', 'foobxx', 'foob'])
Karsten Hopp 7918ec
+ :call add(tl, [2, 'foo\%[bar]', 'foobaxx', 'fooba'])
Karsten Hopp 7918ec
+ :call add(tl, [2, 'foo\%[bar]', 'foobarxx', 'foobar'])
Karsten Hopp 7918ec
+ :call add(tl, [2, 'foo\%[bar]x', 'foobxx', 'foobx'])
Karsten Hopp 7918ec
+ :call add(tl, [2, 'foo\%[bar]x', 'foobarxx', 'foobarx'])
Karsten Hopp 7918ec
+ :call add(tl, [2, '\%[bar]x', 'barxx', 'barx'])
Karsten Hopp 7918ec
+ :call add(tl, [2, '\%[bar]x', 'bxx', 'bx'])
Karsten Hopp 7918ec
+ :call add(tl, [2, '\%[bar]x', 'xxx', 'x'])
Karsten Hopp 7918ec
+ :"
Karsten Hopp 7918ec
  :"""" Alternatives, must use first longest match
Karsten Hopp 7918ec
  :call add(tl, [2, 'goo\|go', 'google', 'goo'])
Karsten Hopp 7918ec
  :call add(tl, [2, '\
Karsten Hopp 7918ec
*** ../vim-7.3.1116/src/testdir/test64.ok	2013-06-04 21:27:33.000000000 +0200
Karsten Hopp 7918ec
--- src/testdir/test64.ok	2013-06-04 23:50:43.000000000 +0200
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 797,802 ****
Karsten Hopp 7918ec
--- 797,835 ----
Karsten Hopp 7918ec
  OK 0 - \%U00000020
Karsten Hopp 7918ec
  OK 1 - \%U00000020
Karsten Hopp 7918ec
  OK 2 - \%U00000020
Karsten Hopp 7918ec
+ OK 0 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 1 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 2 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 0 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 1 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 2 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 0 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 1 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 2 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 0 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 1 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 2 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 0 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 1 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 2 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 0 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 1 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 2 - foo\%[bar]
Karsten Hopp 7918ec
+ OK 0 - foo\%[bar]x
Karsten Hopp 7918ec
+ OK 1 - foo\%[bar]x
Karsten Hopp 7918ec
+ OK 2 - foo\%[bar]x
Karsten Hopp 7918ec
+ OK 0 - foo\%[bar]x
Karsten Hopp 7918ec
+ OK 1 - foo\%[bar]x
Karsten Hopp 7918ec
+ OK 2 - foo\%[bar]x
Karsten Hopp 7918ec
+ OK 0 - \%[bar]x
Karsten Hopp 7918ec
+ OK 1 - \%[bar]x
Karsten Hopp 7918ec
+ OK 2 - \%[bar]x
Karsten Hopp 7918ec
+ OK 0 - \%[bar]x
Karsten Hopp 7918ec
+ OK 1 - \%[bar]x
Karsten Hopp 7918ec
+ OK 2 - \%[bar]x
Karsten Hopp 7918ec
+ OK 0 - \%[bar]x
Karsten Hopp 7918ec
+ OK 1 - \%[bar]x
Karsten Hopp 7918ec
+ OK 2 - \%[bar]x
Karsten Hopp 7918ec
  OK 0 - goo\|go
Karsten Hopp 7918ec
  OK 1 - goo\|go
Karsten Hopp 7918ec
  OK 2 - goo\|go
Karsten Hopp 7918ec
*** ../vim-7.3.1116/src/version.c	2013-06-05 11:01:59.000000000 +0200
Karsten Hopp 7918ec
--- src/version.c	2013-06-05 11:04:15.000000000 +0200
Karsten Hopp 7918ec
***************
Karsten Hopp 7918ec
*** 730,731 ****
Karsten Hopp 7918ec
--- 730,733 ----
Karsten Hopp 7918ec
  {   /* Add new patch number below this line */
Karsten Hopp 7918ec
+ /**/
Karsten Hopp 7918ec
+     1117,
Karsten Hopp 7918ec
  /**/
Karsten Hopp 7918ec
Karsten Hopp 7918ec
-- 
Karsten Hopp 7918ec
From "know your smileys":
Karsten Hopp 7918ec
 :-)	Funny
Karsten Hopp 7918ec
 |-)	Funny Oriental
Karsten Hopp 7918ec
 (-:	Funny Australian
Karsten Hopp 7918ec
Karsten Hopp 7918ec
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 7918ec
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 7918ec
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 7918ec
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///