develooper Front page | perl.perl5.porters | Postings from December 2009

Re: [perl #71136] failure of (?|pattern) and (?<NAME>pattern) to DWAW

Thread Next
From:
David Nicol
Date:
December 9, 2009 10:02
Subject:
Re: [perl #71136] failure of (?|pattern) and (?<NAME>pattern) to DWAW
Message ID:
934f64a20912091001t50fc2687q2fbf974117207638@mail.gmail.com
perldoc perlre:
(?<NAME>pattern)
A named capture buffer. Identical in every respect to normal capturing
parentheses () but for the additional fact that %+ or %- may be used
after a successful match to refer to a named buffer.

Inside (?|pattern) the "branch reset" pattern, the capture buffers are
numbered from the same starting point in each alternation branch.

Apparently the branch reset pattern is implemented by aliasing the
capture buffers in the alternate branches to each other, and this
aliasing also happens with the named capture buffers, causing buffers
which would be separate inside (?:pat) to be aliases for the same
buffer inside (?|pat).

possible paths forward:

1: document that using named capture buffers within the branch reset
pattern is inadvisable, possibly including issuing an optional runtime
warning

2: modify the branch reset pattern to respect the uniqueness of named
capture buffers, by introducing yet another additional level of
indirection, deferring the assignment of captured values into named
and numbered buffers until afterwards, in a new "renumbering step",
instead of aliasing the buffers in advance (which must be what
currently happens.)

3: make use of a named capture buffer within a branch reset pattern a
fatal compile-time error

4: ?



-- 
intake, compression, power, exhaust, repeat.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About