diff options
author | oni-link <knil.ino@gmail.com> | 2014-05-22 12:41:41 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-06-06 19:38:06 -0400 |
commit | 057e36ea1975bc0da720593e60407263bcb25806 (patch) | |
tree | 82a547af78d1bb8dd6aa9dd0b6aa87258901b168 | |
parent | 37fe5aa44452d351b6c0ad6a4b2aa75f10540d22 (diff) | |
download | rneovim-057e36ea1975bc0da720593e60407263bcb25806.tar.gz rneovim-057e36ea1975bc0da720593e60407263bcb25806.tar.bz2 rneovim-057e36ea1975bc0da720593e60407263bcb25806.zip |
vim-patch:7.4.290 #753
Problem: A non-greedy match followed by a branch is too greedy. (Ingo
Karkat)
Solution: Add NFA_MATCH when it is already in the state list if the position
differs.
https://code.google.com/p/vim/source/detail?r=b871734bf54ea185dbd2cc759d86dbfbe21cde26
-rw-r--r-- | src/nvim/regexp_nfa.c | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test64.in | 16 | ||||
-rw-r--r-- | src/nvim/testdir/test64.ok | 12 | ||||
-rw-r--r-- | src/nvim/version.c | 2 |
4 files changed, 27 insertions, 9 deletions
diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index a4e7f1df13..8781e06649 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -3877,8 +3877,10 @@ addstate ( if (state->lastlist[nfa_ll_index] == l->id && state->c != NFA_SKIP) { /* This state is already in the list, don't add it again, * unless it is an MOPEN that is used for a backreference or - * when there is a PIM. */ - if (!nfa_has_backref && pim == NULL && !l->has_pim) { + * when there is a PIM. For NFA_MATCH check the position, + * lower position is preferred. */ + if (!nfa_has_backref && pim == NULL && !l->has_pim + && state->c != NFA_MATCH) { skip_add: #ifdef REGEXP_DEBUG nfa_set_code(state->c); diff --git a/src/nvim/testdir/test64.in b/src/nvim/testdir/test64.in index e3f5d82a4d..2abdcd1c08 100644 --- a/src/nvim/testdir/test64.in +++ b/src/nvim/testdir/test64.in @@ -238,7 +238,11 @@ STARTTEST :call add(tl, [2, '\vx(.{-,8})yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz','ayxa','xayzxayz']) :call add(tl, [2, '\vx(.*)yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz', 'ayxayzxayzxa','']) :call add(tl, [2, '\v(a{1,2}){-2,3}','aaaaaaa','aaaa','aa']) -:call add(tl, [2, '\v(a{-1,3})+','aa','aa','a']) +:call add(tl, [2, '\v(a{-1,3})+', 'aa', 'aa', 'a']) +:call add(tl, [2, '^\s\{-}\zs\( x\|x$\)', ' x', ' x', ' x']) +:call add(tl, [2, '^\s\{-}\zs\(x\| x$\)', ' x', ' x', ' x']) +:call add(tl, [2, '^\s\{-}\ze\(x\| x$\)', ' x', '', ' x']) +:call add(tl, [2, '^\(\s\{-}\)\(x\| x$\)', ' x', ' x', '', ' x']) :" :" Test Character classes :call add(tl, [2, '\d\+e\d\d','test 10e23 fd','10e23']) @@ -462,15 +466,15 @@ STARTTEST : try : let l = matchlist(text, pat) : catch -: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", caused an exception: \"' . v:exception . '\"' +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", caused an exception: \"' . v:exception . '\"' : endtry :" check the match itself : if len(l) == 0 && len(t) > matchidx -: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"' +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"' : elseif len(l) > 0 && len(t) == matchidx -: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match' +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match' : elseif len(t) > matchidx && l[0] != t[matchidx] -: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"' +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"' : else : $put ='OK ' . engine . ' - ' . pat : endif @@ -483,7 +487,7 @@ STARTTEST : let e = t[matchidx + i] : endif : if l[i] != e -: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"' +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"' : endif : endfor : unlet i diff --git a/src/nvim/testdir/test64.ok b/src/nvim/testdir/test64.ok index 9fb6c60b9d..e7d173141a 100644 --- a/src/nvim/testdir/test64.ok +++ b/src/nvim/testdir/test64.ok @@ -533,6 +533,18 @@ OK 2 - \v(a{1,2}){-2,3} OK 0 - \v(a{-1,3})+ OK 1 - \v(a{-1,3})+ OK 2 - \v(a{-1,3})+ +OK 0 - ^\s\{-}\zs\( x\|x$\) +OK 1 - ^\s\{-}\zs\( x\|x$\) +OK 2 - ^\s\{-}\zs\( x\|x$\) +OK 0 - ^\s\{-}\zs\(x\| x$\) +OK 1 - ^\s\{-}\zs\(x\| x$\) +OK 2 - ^\s\{-}\zs\(x\| x$\) +OK 0 - ^\s\{-}\ze\(x\| x$\) +OK 1 - ^\s\{-}\ze\(x\| x$\) +OK 2 - ^\s\{-}\ze\(x\| x$\) +OK 0 - ^\(\s\{-}\)\(x\| x$\) +OK 1 - ^\(\s\{-}\)\(x\| x$\) +OK 2 - ^\(\s\{-}\)\(x\| x$\) OK 0 - \d\+e\d\d OK 1 - \d\+e\d\d OK 2 - \d\+e\d\d diff --git a/src/nvim/version.c b/src/nvim/version.c index 32dcfbe575..d1054bf23d 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -228,7 +228,7 @@ static int included_patches[] = { //293, 292, //291, - //290, + 290, 289, 288, //287, |