Front page | perl.perl5.porters |
Postings from January 2012
Re: [perl #108780] overload::StrVal and qr//
Thread Previous
|
Thread Next
From:
Dave Mitchell
Date:
January 29, 2012 12:32
Subject:
Re: [perl #108780] overload::StrVal and qr//
Message ID:
20120129203224.GA2981@iabyn.com
On Wed, Jan 25, 2012 at 02:02:14PM -0800, Father Chrysostomos via RT wrote:
> It will conflict with his changes (which will render this redundant,
> once complete),
Not necessarily redundant, although different; regexes will still be
string-concatenated and qr// objects stringified.
> but that has already happened before. All he has to do
> is revert the commit when rebasing (which, too, has already happened
> before).
yes, but it makes my life harder: I effectively have to throw your patch
away, then write a new fix in a different way (grumble grumble).
On Thu, Jan 26, 2012 at 01:44:19PM -0800, Father Chrysostomos via RT wrote:
> The PL_reginterp_cnt hack in sv_2pv_flags seems to have been added for
> regcomp’s sake to begin with. So why wasn’t it just added to regcomp?
> For overloading? The commit that added it (2cd61cdbd) mentions no such
> thing.
>
> My patch moves that hack into regcomp, where it arguably belongs.
My code will eventually remove PL_reginterp_cnt altogether.
Just for the record, when I've finished, the way run-time patterns with
multiple components (i.e. /foo$a.{?{})$b$qr_obj/ etc) will be handled is
roughly:
for (@args) {
do get magic, and apply qr// overloading to each one
}
my $pat;
for (@args) {
if $_ is associated with some code blocks, grab them and add to a list;
if $_ is a REGEXP; extract code blocks from it and add to the list;
$pat .= $_ (with '.' overloading, and fallback to "" overloading)
if we used '.' overload above, discard list of compile-time code blocks;
}
regex-compile $pat; for each '(?{})' encountered, if there is a
corresponding pre-compiled code-block, use that, otherwise treat it as
a run-time code block and compile it just there.
Note that I still expect to stringify and interpolate everything,
including REGEXP objects; the only difference is that the (?{})'s in them
may not necessarily be recompiled; instead, previously-compiled code-blocks
may be reused, depending on scoping, closures etc. And the concatenating
now takes place in Perl_re_compile (renamed to Perl_re_op_compile and with
a different signature, with Perl_re_compile as a back-compat wrapper),
rather than in pp_regcomp as before.
Note also that there are three types of overloading involved when
assembling a pattern string:
qr overloading, which expects an overloaded obj to return a qr//;
'.' overloading, to concatenate two adjacent elements;
'""' overloading, for fallback stringification when concatenating.
--
The crew of the Enterprise encounter an alien life form which is
surprisingly neither humanoid nor made from pure energy.
-- Things That Never Happen in "Star Trek" #22
Thread Previous
|
Thread Next