BUG: NFA-regexp discrepancy with \@<= and \1 backreference

62 views
Skip to first unread message

Ingo Karkat

unread,
Jul 24, 2014, 4:47:13 AM7/24/14
to vim...@googlegroups.com
Hello Vim developers,

there's yet another discrepancy between the regular expression engines:

for n in [1,2] | echo match('",abc" in "abc,abc"', '\%#=' . n .
'\1\@<=,\([a-z]\+\)') | endfor

I actually found this while checking out an example from the help
(trying to understand why a regexp I use in a plugin didn't work):

,----[ :help /\@<= ]----
| The part of the pattern after "\@<=" and "\@<!" are checked for a
| match first, thus things like "\1" don't work to reference \(\) inside
| the preceding atom. It does work the other way around:
| Example matches ~
| \1\@<=,\([a-z]\+\) ",abc" in "abc,abc"
`----

The NFA engine somehow doesn't properly handle the backreference
assertion and finds a match where it shouldn't.

To reproduce, use above scriptlet or the identical attached script:

vim -N -u NONE -S bad-re5.vim
14
1

This is with a huge build of Vim 7.4.383, running in an Ubuntu 13.10 x64
VM.

-- regards, ingo
bad-re5.vim

Bram Moolenaar

unread,
Jul 26, 2014, 8:23:52 AM7/26/14
to Ingo Karkat, vim...@googlegroups.com
Thanks, I'll add it to the todo list.

Keep in mind that NFA does not actually support backreferences, that it
works at all in Vim is a bit of a miracle :-).

--
ARTHUR: Now stand aside worthy adversary.
BLACK KNIGHT: (Glancing at his shoulder) 'Tis but a scratch.
ARTHUR: A scratch? Your arm's off.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- 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 ///
Reply all
Reply to author
Forward
0 new messages