Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[PATCH] Allow negative indexing in recursive patterns

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


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/"
Attachments: relative_recursion.patch (6.17 KB)


rgarciasuarez at gmail

Nov 13, 2006, 10:59 PM

Post #2 of 2 (305 views)
Permalink
Re: [PATCH] Allow negative indexing in recursive patterns [In reply to]

On 13/11/06, demerphq <demerphq [at] gmail> wrote:
> 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.

Thanks, applied as change #29267.

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.