Skip to content

Commit b1b90f0

Browse files
committed
updated for version 7.4.037
Problem: Using "\ze" in a sub-pattern does not result in the end of the match to be set. (Axel Bender) Solution: Copy the end of match position when a recursive match was successful.
1 parent a162bc2 commit b1b90f0

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/regexp_nfa.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,6 +3822,7 @@ static void copy_pim __ARGS((nfa_pim_T *to, nfa_pim_T *from));
38223822
static void clear_sub __ARGS((regsub_T *sub));
38233823
static void copy_sub __ARGS((regsub_T *to, regsub_T *from));
38243824
static void copy_sub_off __ARGS((regsub_T *to, regsub_T *from));
3825+
static void copy_ze_off __ARGS((regsub_T *to, regsub_T *from));
38253826
static int sub_equal __ARGS((regsub_T *sub1, regsub_T *sub2));
38263827
static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen));
38273828
static int has_state_with_pos __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim));
@@ -3908,6 +3909,29 @@ copy_sub_off(to, from)
39083909
}
39093910
}
39103911

3912+
/*
3913+
* Like copy_sub() but only do the end of the main match if \ze is present.
3914+
*/
3915+
static void
3916+
copy_ze_off(to, from)
3917+
regsub_T *to;
3918+
regsub_T *from;
3919+
{
3920+
if (nfa_has_zend)
3921+
{
3922+
if (REG_MULTI)
3923+
{
3924+
if (from->list.multi[0].end.lnum >= 0)
3925+
to->list.multi[0].end = from->list.multi[0].end;
3926+
}
3927+
else
3928+
{
3929+
if (from->list.line[0].end != NULL)
3930+
to->list.line[0].end = from->list.line[0].end;
3931+
}
3932+
}
3933+
}
3934+
39113935
/*
39123936
* Return TRUE if "sub1" and "sub2" have the same start positions.
39133937
*/
@@ -5308,6 +5332,7 @@ find_match_text(startcol, regstart, match_text)
53085332
* When "nfa_endp" is not NULL it is a required end-of-match position.
53095333
*
53105334
* Return TRUE if there is a match, FALSE otherwise.
5335+
* When there is a match "submatch" contains the positions.
53115336
* Note: Caller must ensure that: start != NULL.
53125337
*/
53135338
static int
@@ -5633,6 +5658,9 @@ nfa_regmatch(prog, start, submatch, m)
56335658
if (nfa_has_zsubexpr)
56345659
copy_sub_off(&t->subs.synt, &m->synt);
56355660
#endif
5661+
/* If the pattern has \ze and it matched in the
5662+
* sub pattern, use it. */
5663+
copy_ze_off(&t->subs.norm, &m->norm);
56365664

56375665
/* t->state->out1 is the corresponding
56385666
* END_INVISIBLE node; Add its out to the current

src/testdir/test64.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ STARTTEST
425425
:"
426426
:" complicated look-behind match
427427
:call add(tl, [2, '\(r\@<=\|\w\@<!\)\/', 'x = /word/;', '/'])
428+
:call add(tl, [2, '^[a-z]\+\ze \&\(asdf\)\@<!', 'foo bar', 'foo'])
428429
:"
429430
:""""" \@>
430431
:call add(tl, [2, '\(a*\)\@>a', 'aaaa'])

src/testdir/test64.ok

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,9 @@ OK 2 - \(foo\)\@<=.*
983983
OK 0 - \(r\@<=\|\w\@<!\)\/
984984
OK 1 - \(r\@<=\|\w\@<!\)\/
985985
OK 2 - \(r\@<=\|\w\@<!\)\/
986+
OK 0 - ^[a-z]\+\ze \&\(asdf\)\@<!
987+
OK 1 - ^[a-z]\+\ze \&\(asdf\)\@<!
988+
OK 2 - ^[a-z]\+\ze \&\(asdf\)\@<!
986989
OK 0 - \(a*\)\@>a
987990
OK 1 - \(a*\)\@>a
988991
OK 2 - \(a*\)\@>a

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static char *(features[]) =
738738

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
37,
741743
/**/
742744
36,
743745
/**/

0 commit comments

Comments
 (0)