Friday, January 1, 2010

Re: Patterns, variables and strange behavior of some thing.

jojahti wrote:
> I have tried write highligting pattern, than search variables.
> "\(\(int\|long\|short\|char\|void\|double\)[[:space:]]\+\)\@<=[^[:space:]^(^).]\+\([[:space:]]\)\@
> ="
>
> Then the pattern, that search this variable in other places of the file.
> "\(\(int\|long\|short\|char\|void\|double\)\([[:space:]]\+\)\([^[:space:]^(^).]\+\)[[:sp
> ace:]].*\)\@<=\4"
> But fail.
>
> I see, that this thing have very strange behavior.
> I have made little experiment/
> I make this string:
> oo ib b oooooooooo
>
> And try serch in it, using this pattern:
> '\(i\(.\)[[:space:]]*\)\@<=/2'
> And now i have fail.
> But if i cut '\@<=' - then all work normal.
> But I need to use these things.

Jojahti,
I believe you may have uncovered a bug. It can be demonstrated with an
even simpler example...
\(i\(.\)\)\@<=\2
...which will match just after an i followed by any character, even when
the character following the i is not repeated: e.g., on the following
line...
iax ibx ic
...the pattern above matches 3 times: on the 2 x's and at the end of the
line. It shouldn't match at all, since the character captured by the 2nd
\( ... \) is never repeated.

It appears to me that the back-reference within the \( ... \)\@<= is
being cleared when the construct is exited. Since a cleared (empty)
backreference matches anywhere, the pattern doesn't work as expected.

To test my theory, I tried moving the \2 inside the \( ... \)\@<= and
found that it worked as expected:
\(i\(.\)[[:space:]]*\2\)\@<=

It's just a hunch, but I suspect that the following thread may be relevant:
http://old.nabble.com/Subject:-Apparent-regex-bug:-overlapping-text-captured-by-non-overlapping-backrefs-td15945426.html

Note that as a result of that thread, Bram implemented a fix that caused
backreferences to be cleared upon backtracking. Perhaps the fix results
in backreferences sometimes being cleared when they shouldn't be. Just a
guess...

Brett Stahlman

>
> Why behavior of it is so strange? How to me complete my quest the most
> adequate way?
>
> P.S. it's my first post in English. :thinking:
> Forums on my native language, where I can ask this question - about zero.
>
>

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: