Patch 7.4.2354
Problem:    The example that explains nested backreferences does not work
            properly with the new regexp engine. (Harm te Hennepe)
Solution:   Also save the end position when adding a state. (closes #990)
Files:      src/regexp_nfa.c, src/testdir/test_regexp_latin.vim


*** ../vim-7.4.2353/src/regexp_nfa.c    2016-08-29 22:48:12.165106045 +0200
--- src/regexp_nfa.c    2016-09-09 17:45:51.693549619 +0200
***************
*** 4354,4360 ****
  {
      int                       subidx;
      nfa_thread_T      *thread;
!     lpos_T            save_lpos;
      int                       save_in_use;
      char_u            *save_ptr;
      int                       i;
--- 4354,4360 ----
  {
      int                       subidx;
      nfa_thread_T      *thread;
!     struct multipos   save_multipos;
      int                       save_in_use;
      char_u            *save_ptr;
      int                       i;
***************
*** 4572,4579 ****
  
            /* avoid compiler warnings */
            save_ptr = NULL;
!           save_lpos.lnum = 0;
!           save_lpos.col = 0;
  
            /* Set the position (with "off" added) in the subexpression.  Save
             * and restore it when it was in use.  Otherwise fill any gap. */
--- 4572,4578 ----
  
            /* avoid compiler warnings */
            save_ptr = NULL;
!           vim_memset(&save_multipos, 0, sizeof(save_multipos));
  
            /* Set the position (with "off" added) in the subexpression.  Save
             * and restore it when it was in use.  Otherwise fill any gap. */
***************
*** 4581,4588 ****
            {
                if (subidx < sub->in_use)
                {
!                   save_lpos.lnum = sub->list.multi[subidx].start_lnum;
!                   save_lpos.col = sub->list.multi[subidx].start_col;
                    save_in_use = -1;
                }
                else
--- 4580,4586 ----
            {
                if (subidx < sub->in_use)
                {
!                   save_multipos = sub->list.multi[subidx];
                    save_in_use = -1;
                }
                else
***************
*** 4640,4649 ****
            if (save_in_use == -1)
            {
                if (REG_MULTI)
!                 {
!                   sub->list.multi[subidx].start_lnum = save_lpos.lnum;
!                   sub->list.multi[subidx].start_col = save_lpos.col;
!                 }
                else
                    sub->list.line[subidx].start = save_ptr;
            }
--- 4638,4644 ----
            if (save_in_use == -1)
            {
                if (REG_MULTI)
!                   sub->list.multi[subidx] = save_multipos;
                else
                    sub->list.line[subidx].start = save_ptr;
            }
***************
*** 4707,4714 ****
                sub->in_use = subidx + 1;
            if (REG_MULTI)
            {
!               save_lpos.lnum = sub->list.multi[subidx].end_lnum;
!               save_lpos.col = sub->list.multi[subidx].end_col;
                if (off == -1)
                {
                    sub->list.multi[subidx].end_lnum = reglnum + 1;
--- 4702,4708 ----
                sub->in_use = subidx + 1;
            if (REG_MULTI)
            {
!               save_multipos = sub->list.multi[subidx];
                if (off == -1)
                {
                    sub->list.multi[subidx].end_lnum = reglnum + 1;
***************
*** 4728,4735 ****
                save_ptr = sub->list.line[subidx].end;
                sub->list.line[subidx].end = reginput + off;
                /* avoid compiler warnings */
!               save_lpos.lnum = 0;
!               save_lpos.col = 0;
            }
  
            subs = addstate(l, state->out, subs, pim, off);
--- 4722,4728 ----
                save_ptr = sub->list.line[subidx].end;
                sub->list.line[subidx].end = reginput + off;
                /* avoid compiler warnings */
!               vim_memset(&save_multipos, 0, sizeof(save_multipos));
            }
  
            subs = addstate(l, state->out, subs, pim, off);
***************
*** 4742,4751 ****
                sub = &subs->norm;
  
            if (REG_MULTI)
!             {
!               sub->list.multi[subidx].end_lnum = save_lpos.lnum;
!               sub->list.multi[subidx].end_col = save_lpos.col;
!             }
            else
                sub->list.line[subidx].end = save_ptr;
            sub->in_use = save_in_use;
--- 4735,4741 ----
                sub = &subs->norm;
  
            if (REG_MULTI)
!               sub->list.multi[subidx] = save_multipos;
            else
                sub->list.line[subidx].end = save_ptr;
            sub->in_use = save_in_use;
*** ../vim-7.4.2353/src/testdir/test_regexp_latin.vim   2016-08-18 
23:04:44.662592810 +0200
--- src/testdir/test_regexp_latin.vim   2016-09-09 17:52:55.139578167 +0200
***************
*** 38,40 ****
--- 38,55 ----
    call setwinvar(1, 'myvar', 1)
    bwipe!
  endfunc
+ 
+ func Test_nested_backrefs()
+   " Check example in change.txt.
+   new
+   for re in range(0, 2)
+     exe 'set re=' . re
+     call setline(1, 'aa ab x')
+     1s/\(\(a[a-d] \)*\)\(x\)/-\1- -\2- -\3-/
+     call assert_equal('-aa ab - -ab - -x-', getline(1))
+ 
+     call assert_equal('-aa ab - -ab - -x-', substitute('aa ab x', '\(\(a[a-d] 
\)*\)\(x\)', '-\1- -\2- -\3-', ''))
+   endfor
+   bwipe!
+   set re=0
+ endfunc
*** ../vim-7.4.2353/src/version.c       2016-09-09 16:59:04.465154483 +0200
--- src/version.c       2016-09-09 17:58:09.543149388 +0200
***************
*** 765,766 ****
--- 765,768 ----
  {   /* Add new patch number below this line */
+ /**/
+     2354,
  /**/

-- 
I noticed my daughter's Disney-net password on a sticky note:
"MickeyMinnieGoofyPluto".  I asked her why it was so long.
"Because they say it has to have at least four characters."

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui