mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
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)
This commit is contained in:
@@ -4354,7 +4354,7 @@ addstate(
|
|||||||
{
|
{
|
||||||
int subidx;
|
int subidx;
|
||||||
nfa_thread_T *thread;
|
nfa_thread_T *thread;
|
||||||
lpos_T save_lpos;
|
struct multipos save_multipos;
|
||||||
int save_in_use;
|
int save_in_use;
|
||||||
char_u *save_ptr;
|
char_u *save_ptr;
|
||||||
int i;
|
int i;
|
||||||
@@ -4572,8 +4572,7 @@ skip_add:
|
|||||||
|
|
||||||
/* avoid compiler warnings */
|
/* avoid compiler warnings */
|
||||||
save_ptr = NULL;
|
save_ptr = NULL;
|
||||||
save_lpos.lnum = 0;
|
vim_memset(&save_multipos, 0, sizeof(save_multipos));
|
||||||
save_lpos.col = 0;
|
|
||||||
|
|
||||||
/* Set the position (with "off" added) in the subexpression. Save
|
/* Set the position (with "off" added) in the subexpression. Save
|
||||||
* and restore it when it was in use. Otherwise fill any gap. */
|
* and restore it when it was in use. Otherwise fill any gap. */
|
||||||
@@ -4581,8 +4580,7 @@ skip_add:
|
|||||||
{
|
{
|
||||||
if (subidx < sub->in_use)
|
if (subidx < sub->in_use)
|
||||||
{
|
{
|
||||||
save_lpos.lnum = sub->list.multi[subidx].start_lnum;
|
save_multipos = sub->list.multi[subidx];
|
||||||
save_lpos.col = sub->list.multi[subidx].start_col;
|
|
||||||
save_in_use = -1;
|
save_in_use = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -4640,10 +4638,7 @@ skip_add:
|
|||||||
if (save_in_use == -1)
|
if (save_in_use == -1)
|
||||||
{
|
{
|
||||||
if (REG_MULTI)
|
if (REG_MULTI)
|
||||||
{
|
sub->list.multi[subidx] = save_multipos;
|
||||||
sub->list.multi[subidx].start_lnum = save_lpos.lnum;
|
|
||||||
sub->list.multi[subidx].start_col = save_lpos.col;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
sub->list.line[subidx].start = save_ptr;
|
sub->list.line[subidx].start = save_ptr;
|
||||||
}
|
}
|
||||||
@@ -4707,8 +4702,7 @@ skip_add:
|
|||||||
sub->in_use = subidx + 1;
|
sub->in_use = subidx + 1;
|
||||||
if (REG_MULTI)
|
if (REG_MULTI)
|
||||||
{
|
{
|
||||||
save_lpos.lnum = sub->list.multi[subidx].end_lnum;
|
save_multipos = sub->list.multi[subidx];
|
||||||
save_lpos.col = sub->list.multi[subidx].end_col;
|
|
||||||
if (off == -1)
|
if (off == -1)
|
||||||
{
|
{
|
||||||
sub->list.multi[subidx].end_lnum = reglnum + 1;
|
sub->list.multi[subidx].end_lnum = reglnum + 1;
|
||||||
@@ -4728,8 +4722,7 @@ skip_add:
|
|||||||
save_ptr = sub->list.line[subidx].end;
|
save_ptr = sub->list.line[subidx].end;
|
||||||
sub->list.line[subidx].end = reginput + off;
|
sub->list.line[subidx].end = reginput + off;
|
||||||
/* avoid compiler warnings */
|
/* avoid compiler warnings */
|
||||||
save_lpos.lnum = 0;
|
vim_memset(&save_multipos, 0, sizeof(save_multipos));
|
||||||
save_lpos.col = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subs = addstate(l, state->out, subs, pim, off);
|
subs = addstate(l, state->out, subs, pim, off);
|
||||||
@@ -4742,10 +4735,7 @@ skip_add:
|
|||||||
sub = &subs->norm;
|
sub = &subs->norm;
|
||||||
|
|
||||||
if (REG_MULTI)
|
if (REG_MULTI)
|
||||||
{
|
sub->list.multi[subidx] = save_multipos;
|
||||||
sub->list.multi[subidx].end_lnum = save_lpos.lnum;
|
|
||||||
sub->list.multi[subidx].end_col = save_lpos.col;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
sub->list.line[subidx].end = save_ptr;
|
sub->list.line[subidx].end = save_ptr;
|
||||||
sub->in_use = save_in_use;
|
sub->in_use = save_in_use;
|
||||||
|
@@ -38,3 +38,18 @@ func Test_recursive_substitute()
|
|||||||
call setwinvar(1, 'myvar', 1)
|
call setwinvar(1, 'myvar', 1)
|
||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
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
|
||||||
|
@@ -763,6 +763,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2354,
|
||||||
/**/
|
/**/
|
||||||
2353,
|
2353,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user