To:
[email protected]
Subject: Patch 6.1a.009
Fcc: outbox
From: Bram Moolenaar <
[email protected]>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------
Patch 6.1a.009
Problem: When using "\@<=" or "\@<!" in a pattern, a "\1" may refer to a ()
part that follows, but it generates an error message.
Solution: Allow a forward reference when there is a following "\@<=" or
"\@<!".
Files: runtime/doc/pattern.txt, src/regexp.c
*** ../vim61a.008/runtime/doc/pattern.txt Sun Feb 24 17:14:25 2002
--- runtime/doc/pattern.txt Wed Feb 27 17:22:45 2002
***************
*** 1,4 ****
! *pattern.txt* For Vim version 6.1a. Last change: 2002 Feb 04
VIM REFERENCE MANUAL by Bram Moolenaar
--- 1,4 ----
! *pattern.txt* For Vim version 6.1a. Last change: 2002 Feb 27
VIM REFERENCE MANUAL by Bram Moolenaar
***************
*** 601,621 ****
follows. |/zero-width| {not in Vi}
Like '(?<=pattern)" in Perl, but Vim allows non-fixed-width patterns.
Example matches ~
! \(an\_s\+\)\@<=file "file" after "an" and white space or a
end-of-line
"\@<=" and "\@<!" check for matches just before what follows.
Theoretically these matches could start anywhere before this position.
But to limit the time needed, only the line where what follows matches
is searched, and one line before that (if there is one). This should
be sufficient to match most things and not be too slow.
*/\@<!*
\@<! Matches with zero width if the preceding atom does NOT match just
! before what follows. |/zero-width| {not in Vi}
Like '(?<!pattern)" in Perl, but Vim allows non-fixed-width patterns.
The match with the preceding atom is made to end just before the match
with what follows, thus an atom that ends in ".*" will work.
Example matches ~
\(foo\)\@<!bar any "bar" that's not in "foobar"
\(\/\/.*\)\@\<!in "in" which is not after "//"
--- 601,633 ----
follows. |/zero-width| {not in Vi}
Like '(?<=pattern)" in Perl, but Vim allows non-fixed-width patterns.
Example matches ~
! \(an\_s\+\)\@<=file "file" after "an" and white space or an
end-of-line
+ For speed it's often much better to avoid this multi. Try using "\zs"
+ instead |/\zs|. To match the same as the above example:
+ an\_s\+\zsfile
"\@<=" and "\@<!" check for matches just before what follows.
Theoretically these matches could start anywhere before this position.
But to limit the time needed, only the line where what follows matches
is searched, and one line before that (if there is one). This should
be sufficient to match most things and not be too slow.
+ 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"
*/\@<!*
\@<! Matches with zero width if the preceding atom does NOT match just
! before what follows. Thus this matches if there is no position in the
! current or previous line where the atom matches such that it ends just
! before what follows. |/zero-width| {not in Vi}
Like '(?<!pattern)" in Perl, but Vim allows non-fixed-width patterns.
The match with the preceding atom is made to end just before the match
with what follows, thus an atom that ends in ".*" will work.
+ Warning: This can be slow (because many positions need to be checked
+ for a match).
Example matches ~
\(foo\)\@<!bar any "bar" that's not in "foobar"
\(\/\/.*\)\@\<!in "in" which is not after "//"
*** ../vim61a.008/src/regexp.c Tue Feb 19 21:20:51 2002
--- src/regexp.c Wed Feb 27 17:13:22 2002
***************
*** 1517,1526 ****
* that is repeated (+*=): what instance of the repetition
* should we match?
*/
! if (had_endbrace[refnum])
! ret = regnode(BACKREF + refnum);
! else
! EMSG_RET_NULL("E65: Illegal back reference");
}
break;
--- 1517,1534 ----
* that is repeated (+*=): what instance of the repetition
* should we match?
*/
! if (!had_endbrace[refnum])
! {
! /* Trick: check if "@<=" or "@<!" follows, in which case
! * the \1 can appear before the referenced match. */
! for (p = regparse; *p != NUL; ++p)
! if (p[0] == '@' && p[1] == '<'
! && (p[2] == '!' || p[2] == '='))
! break;
! if (*p == NUL)
! EMSG_RET_NULL("E65: Illegal back reference");
! }
! ret = regnode(BACKREF + refnum);
}
break;
*** ../vim61a.008/src/version.c Wed Feb 27 17:26:22 2002
--- src/version.c Wed Feb 27 17:25:13 2002
***************
*** 608,609 ****
--- 608,611 ----
{ /* Add new patch number below this line */
+ /**/
+ 9,
/**/
--
hundred-and-one symptoms of being an internet addict:
58. You turn on your computer and turn off your wife.
/// Bram Moolenaar --
[email protected] --
http://www.moolenaar.net \\\
/// Creator of Vim --
http://vim.sf.net --
ftp://ftp.vim.org/pub/vim \\\
\\\ Project leader for A-A-P --
http://www.a-a-p.org ///
\\\ Help me helping AIDS orphans in Uganda -
http://iccf-holland.org ///