
demerphq at gmail
Nov 13, 2006, 9:59 AM
Post #1 of 2
(328 views)
Permalink
|
|
[PATCH] Allow negative indexing in recursive patterns
|
|
I noticed while trying to convert some code from using (??{}) to using the new recursion syntax that there is a real need for the ability to relatively address a given capture buffer. Consider our $parens; $parens = qr/ \( (?: [^()]++ | (??{$qr}) )*+ \) /x; if (/ foo $paren \s* , \s* bar $parens /x) { ... } Is tricky to convert to recursion currently. So what I've done is Ive allowed negative integers to be used so the above can be converted to my $parens = qr/ \( (?: [^()]++ | (?-1) )*+ \) /x; if (/ foo $paren \s* , \s* bar $parens /x) { ... } So a negative (?PARNO) means to recurse the N'th capturing paren before the use of the (?PARNO). Thus (?-1) is to recurse to the immediately preceding open paren. Similarly I put in support for a plus sign indicating relative forward addressing, ie, execute the pattern contained in the nth following buffer. Attached patch includes documentation and tests for the new feature. Its relative to my most recent patches as sent in, unfortunately perl-current and perl-current-diffs are out of date right now so I havent been able to synchronize up before I sent it in. Hope it applies ok. Cheers, Yves -- perl -Mre=debug -e "/just|another|perl|hacker/"
|