develooper Front page | perl.perl5.porters | Postings from April 2007

Re: Proposed changes and to regular expression interfaces in core

Thread Previous | Thread Next
April 2, 2007 11:52
Re: Proposed changes and to regular expression interfaces in core
Message ID:
On 4/2/07, Ævar Arnfjörð Bjarmason <> wrote:
> With regards to modifying the default Tie::Hash::NamedCapture
> semantics which mirror how named captures work in the perl5 engine
> I've come up with an implementation plan that's not as insane as it
> could be.
> In the case of qr// the package that the regex is being blessed into
> is part of the regex structure via engine callbacks, but since %+ and
> %- are globals you can't bind these lexically to a regex or have some
> comfortable way to associate them with a single regex.
> The workaround for this is to continue to bless %+ and %- into
> Tie::Hash::NamedCapture but alter the routines so that
> they use the p5 semantics in the default case as they do now OR if a
> custom engine has been defined call engine->tie_pkg (or somesuch)
> which is the real Tied package to use, so for instance FETCH migh
> become something like:
> # pseudocode
> sub FETCH {
>     if (my $pkg = re::tie_pkg($_[0]->{all})) {
>         goto &{"$pkg\::FETCH"};
>     }
>     return re::regname( ... );
> }
> This solution seems pretty clean to me and wouldn't impose any penalty
> on $+{foo}  lookups using a custom engine other than seeing if they
> need to be dispatching to a user-defined Tie::Hash package.

I have to say im not keen on this.

It seems to me the proper way to do this is to make the routines in
universal.c dispatch to the appropriate handler in the engine struct.

BUT, the question I have is: why is this needed? Why is such an
interface better than actually populating rx->paren_names()?

And actually this question applies retroactively to CALLREG_NAMEDBUF()
hook as well. Why isnt it sufficient to require compiled regexes
populate the hash and mandate a  fixed relationship between numbered
buffers and named buffers?

Im really worried that your thinking is aimed way to much at "how can
I write an engine with the least hassle" and not enough at "how does
the engine fit together with the rest of perl".

Please can you explain in more detail what you want to do and why the
existing interfaces arent enough.


perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About