mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:7.4.2355
Problem: Regexp fails to match when using "\>\)\?". (Ramel)
Solution: When a state is already in the list, but addstate_here() is used
and the existing state comes later, add the new state anyway.
16b3578f35
This commit is contained in:
parent
53ccd07fa1
commit
929859ed81
@ -3893,21 +3893,25 @@ state_in_list (
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Offset used for "off" by addstate_here().
|
||||||
* Add "state" and possibly what follows to state list ".".
|
#define ADDSTATE_HERE_OFFSET 10
|
||||||
* Returns "subs_arg", possibly copied into temp_subs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
// Add "state" and possibly what follows to state list ".".
|
||||||
|
// Returns "subs_arg", possibly copied into temp_subs.
|
||||||
static regsubs_T *
|
static regsubs_T *
|
||||||
addstate (
|
addstate (
|
||||||
nfa_list_T *l, /* runtime state list */
|
nfa_list_T *l, /* runtime state list */
|
||||||
nfa_state_T *state, /* state to update */
|
nfa_state_T *state, /* state to update */
|
||||||
regsubs_T *subs_arg, /* pointers to subexpressions */
|
regsubs_T *subs_arg, /* pointers to subexpressions */
|
||||||
nfa_pim_T *pim, /* postponed look-behind match */
|
nfa_pim_T *pim, /* postponed look-behind match */
|
||||||
int off /* byte offset, when -1 go to next line */
|
int off_arg) /* byte offset, when -1 go to next line */
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int subidx;
|
int subidx;
|
||||||
|
int off = off_arg;
|
||||||
|
int add_here = FALSE;
|
||||||
|
int listindex = 0;
|
||||||
|
int k;
|
||||||
|
int found = FALSE;
|
||||||
nfa_thread_T *thread;
|
nfa_thread_T *thread;
|
||||||
lpos_T save_lpos;
|
lpos_T save_lpos;
|
||||||
int save_in_use;
|
int save_in_use;
|
||||||
@ -3920,6 +3924,12 @@ addstate (
|
|||||||
int did_print = FALSE;
|
int did_print = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (off_arg <= -ADDSTATE_HERE_OFFSET) {
|
||||||
|
add_here = true;
|
||||||
|
off = 0;
|
||||||
|
listindex = -(off_arg + ADDSTATE_HERE_OFFSET);
|
||||||
|
}
|
||||||
|
|
||||||
switch (state->c) {
|
switch (state->c) {
|
||||||
case NFA_NCLOSE:
|
case NFA_NCLOSE:
|
||||||
case NFA_MCLOSE:
|
case NFA_MCLOSE:
|
||||||
@ -3996,13 +4006,28 @@ addstate (
|
|||||||
* lower position is preferred. */
|
* lower position is preferred. */
|
||||||
if (!nfa_has_backref && pim == NULL && !l->has_pim
|
if (!nfa_has_backref && pim == NULL && !l->has_pim
|
||||||
&& state->c != NFA_MATCH) {
|
&& state->c != NFA_MATCH) {
|
||||||
|
|
||||||
|
/* When called from addstate_here() do insert before
|
||||||
|
* existing states. */
|
||||||
|
if (add_here) {
|
||||||
|
for (k = 0; k < l->n && k < listindex; ++k) {
|
||||||
|
if (l->t[k].state->id == state->id) {
|
||||||
|
found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!add_here || found) {
|
||||||
skip_add:
|
skip_add:
|
||||||
#ifdef REGEXP_DEBUG
|
#ifdef REGEXP_DEBUG
|
||||||
nfa_set_code(state->c);
|
nfa_set_code(state->c);
|
||||||
fprintf(log_fd, "> Not adding state %d to list %d. char %d: %s\n",
|
fprintf(log_fd, "> Not adding state %d to list %d. char %d: %s pim: %s has_pim: %d found: %d\n",
|
||||||
abs(state->id), l->id, state->c, code);
|
abs(state->id), l->id, state->c, code,
|
||||||
|
pim == NULL ? "NULL" : "yes", l->has_pim, found);
|
||||||
#endif
|
#endif
|
||||||
return subs;
|
return subs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do not add the state again when it exists with the same
|
/* Do not add the state again when it exists with the same
|
||||||
@ -4058,14 +4083,14 @@ skip_add:
|
|||||||
|
|
||||||
case NFA_SPLIT:
|
case NFA_SPLIT:
|
||||||
/* order matters here */
|
/* order matters here */
|
||||||
subs = addstate(l, state->out, subs, pim, off);
|
subs = addstate(l, state->out, subs, pim, off_arg);
|
||||||
subs = addstate(l, state->out1, subs, pim, off);
|
subs = addstate(l, state->out1, subs, pim, off_arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NFA_EMPTY:
|
case NFA_EMPTY:
|
||||||
case NFA_NOPEN:
|
case NFA_NOPEN:
|
||||||
case NFA_NCLOSE:
|
case NFA_NCLOSE:
|
||||||
subs = addstate(l, state->out, subs, pim, off);
|
subs = addstate(l, state->out, subs, pim, off_arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NFA_MOPEN:
|
case NFA_MOPEN:
|
||||||
@ -4145,7 +4170,7 @@ skip_add:
|
|||||||
sub->list.line[subidx].start = reginput + off;
|
sub->list.line[subidx].start = reginput + off;
|
||||||
}
|
}
|
||||||
|
|
||||||
subs = addstate(l, state->out, subs, pim, off);
|
subs = addstate(l, state->out, subs, pim, off_arg);
|
||||||
/* "subs" may have changed, need to set "sub" again */
|
/* "subs" may have changed, need to set "sub" again */
|
||||||
if (state->c >= NFA_ZOPEN && state->c <= NFA_ZOPEN9)
|
if (state->c >= NFA_ZOPEN && state->c <= NFA_ZOPEN9)
|
||||||
sub = &subs->synt;
|
sub = &subs->synt;
|
||||||
@ -4168,7 +4193,7 @@ skip_add:
|
|||||||
? subs->norm.list.multi[0].end_lnum >= 0
|
? subs->norm.list.multi[0].end_lnum >= 0
|
||||||
: subs->norm.list.line[0].end != NULL)) {
|
: subs->norm.list.line[0].end != NULL)) {
|
||||||
/* Do not overwrite the position set by \ze. */
|
/* Do not overwrite the position set by \ze. */
|
||||||
subs = addstate(l, state->out, subs, pim, off);
|
subs = addstate(l, state->out, subs, pim, off_arg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NFA_MCLOSE1:
|
case NFA_MCLOSE1:
|
||||||
@ -4228,7 +4253,7 @@ skip_add:
|
|||||||
save_lpos.col = 0;
|
save_lpos.col = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
subs = addstate(l, state->out, subs, pim, off);
|
subs = addstate(l, state->out, subs, pim, off_arg);
|
||||||
/* "subs" may have changed, need to set "sub" again */
|
/* "subs" may have changed, need to set "sub" again */
|
||||||
if (state->c >= NFA_ZCLOSE && state->c <= NFA_ZCLOSE9)
|
if (state->c >= NFA_ZCLOSE && state->c <= NFA_ZCLOSE9)
|
||||||
sub = &subs->synt;
|
sub = &subs->synt;
|
||||||
@ -4266,8 +4291,10 @@ addstate_here (
|
|||||||
int count;
|
int count;
|
||||||
int listidx = *ip;
|
int listidx = *ip;
|
||||||
|
|
||||||
/* first add the state(s) at the end, so that we know how many there are */
|
/* First add the state(s) at the end, so that we know how many there are.
|
||||||
addstate(l, state, subs, pim, 0);
|
* Pass the listidx as offset (avoids adding another argument to
|
||||||
|
* addstate(). */
|
||||||
|
addstate(l, state, subs, pim, -listidx - ADDSTATE_HERE_OFFSET);
|
||||||
|
|
||||||
/* when "*ip" was at the end of the list, nothing to do */
|
/* when "*ip" was at the end of the list, nothing to do */
|
||||||
if (listidx + 1 == tlen)
|
if (listidx + 1 == tlen)
|
||||||
|
@ -97,3 +97,12 @@ func Test_recursive_substitute()
|
|||||||
call setwinvar(1, 'myvar', 1)
|
call setwinvar(1, 'myvar', 1)
|
||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_eow_with_optional()
|
||||||
|
let expected = ['abc def', 'abc', 'def', '', '', '', '', '', '', '']
|
||||||
|
for re in range(0, 2)
|
||||||
|
exe 'set re=' . re
|
||||||
|
let actual = matchlist('abc def', '\(abc\>\)\?\s*\(def\)')
|
||||||
|
call assert_equal(expected, actual)
|
||||||
|
endfor
|
||||||
|
endfunc
|
||||||
|
@ -86,7 +86,7 @@ static int included_patches[] = {
|
|||||||
// 2358 NA
|
// 2358 NA
|
||||||
// 2357,
|
// 2357,
|
||||||
// 2356,
|
// 2356,
|
||||||
// 2355,
|
2355,
|
||||||
// 2354,
|
// 2354,
|
||||||
2353,
|
2353,
|
||||||
// 2352 NA
|
// 2352 NA
|
||||||
|
Loading…
Reference in New Issue
Block a user