develooper Front page | perl.perl5.porters | Postings from August 2013

Re: Perl 5.18 and Regexp::Grammars

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
August 6, 2013 18:19
Subject:
Re: Perl 5.18 and Regexp::Grammars
Message ID:
20130806181911.GG2177@iabyn.com
On Mon, Jul 15, 2013 at 04:57:43PM +0400, Damian Conway wrote:
>     package RegexProcessor;
>     use overload (
>         q{""} => sub {
>                         my ($pat) = @_;
>                         return $pat->[0];
>                  },
>         q{.}  => sub {
>                         my ($a1, $a2) = @_;
>                         $a1 = $a1->[0] if ref $a1;
>                         $a2 = $a2->[0] if ref $a2;
>                         return bless [ "$a1$a2" ], 'RegexProcessor';
>                  },
>     );
> 
>     package main;
>     use re 'eval';
> 
>     BEGIN {
>         overload::constant qr => sub { return bless [ $_[0] ],
> 'RegexProcessor' };
>     }
> 
>     my %hash = ( a => 1, b => 2, c => 3);
> 
>     "" =~ m{ (?{say join ', ', keys %hash}) }xms;
> 

Fixed in blead with the following commit; suitable for pack-porting to
5.18.2/

commit c3923c33af542d8764d5a1e4eb5d7b311f443b89
Author:     David Mitchell <davem@iabyn.com>
AuthorDate: Tue Aug 6 16:34:50 2013 +0100
Commit:     David Mitchell <davem@iabyn.com>
CommitDate: Tue Aug 6 16:44:12 2013 +0100

    reparse compile-time /(?{})/ in right scope
    
    When a compile-time regex like /...(?{ code-block }) .../
    is compiled in the presence of constant and concat overloading,
    this can cause (still at compile-time) for the pattern to be evaled and
    re-compiled, in order to re-compile any code-blocks that got messed up
    during the overloading and thus whose text no longer matches that which
    the perl parser previously compiled.
    
    When this happens, eval_sv() happens to be called when the perl parser is
    still in compiling state; normally its called from running state.
    This tickles an undiscovered bug in Perl_find_runcv_where(), which
    finds the current cop sequence by looking at PL_curcop->cop_seq.
    At compile time, we need to get it from PL_cop_seqmax instead.

M       pp_ctl.c
M       t/re/overload.t


-- 
In economics, the exam questions are the same every year.
They just change the answers.

Thread Previous | 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