Changeset 22909 for src

Show
Ignore:
Timestamp:
11/07/08 05:20:25 (2 months ago)
Author:
lwall
Message:

[gimme5] move more boilerplate out of normal matcher methods

Location:
src/perl6
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/Cursor.pmc

    r22901 r22909  
    292292                    for my $method (sort $class->meta->get_method_list) { 
    293293                        if (substr($method,0,$protolen) eq $protopat) { 
    294                             my $callname = $class . '::' . $method; 
     294                            next if substr($method,-6,6) eq '__PEEK'; 
     295                            my $callname = $class . '::' . $method . '__PEEK'; 
    295296                            my $peeklex = $peek->$callname(); 
    296297                            if ($peeklex and $peeklex->{PATS}) { 
     
    918919}; 
    919920 
     921sub ${mangle}__PEEK { \$_[0]->_AUTOLEXpeek('$mangle',\$retree) } 
    920922sub $mangle { 
    921923    my \$self = shift; 
    922924    local \$CTX = \$self->callm() if \$::DEBUG & DEBUG::trace_call; 
    923     if (\$self->{_peek}) { 
    924         return \$self->_AUTOLEXpeek('$mangle',\$retree) 
    925     } 
    926925    my %args = \@_; 
    927926    my \$sym = \$args{sym} // q$sym; 
     
    12851284} 
    12861285 
     1286sub ws__PEEK { ''; } 
    12871287sub ws { 
    12881288    my $self = shift; 
    12891289 
    1290     if ($self->{_peek}) { 
    1291         return; 
    1292     } 
    12931290    local $CTX = $self->callm() if $DEBUG & DEBUG::trace_call; 
    12941291    my @stub = return $self if exists $::MEMOS[$self->{_pos}]{ws}; 
     
    13561353    local $CTX = $self->callm($names ? "@$names" : "") if $DEBUG & DEBUG::trace_call; 
    13571354    lazymap(sub { $self->cursor_bind($names, $_[0])->retm() }, 
    1358         $block->($self)); 
     1355        $block->($self->cursor_fresh())); 
    13591356} 
    13601357 
     
    13641361 
    13651362    local $CTX = $self->callm($names ? "@$names" : "") if $DEBUG & DEBUG::trace_call; 
    1366     my ($var) = $block->($self) or return (); 
     1363    my ($var) = $block->($self->cursor_fresh()) or return (); 
    13671364    $self->cursor_bind($names, $var)->retm(); 
    13681365} 
     
    21082105            { 
    21092106                local $PREFIX = ""; 
     2107                $name .= '__PEEK'; 
    21102108                $lexer = eval { $C->cursor_peek->$name() }; 
    21112109            } 
     
    21472145            } 
    21482146            else { 
     2147                $name .= '__PEEK'; 
    21492148                my $lexer = $C->cursor_peek->$name($re); 
    21502149                my @pat = @{$lexer->{PATS}}; 
  • src/perl6/gimme5

    r22891 r22909  
    9090        $f =~ s!^(".*?")!!                      and $t .= $1, next; 
    9191        $f =~ s!^ self\.WHAT!!                  and $t .= ' (ref($self)||$self)', next; 
    92         $f =~ s!^self\.pos!!                    and $t .= '$self->{_pos}', next; 
    93         $f =~ s!^\$¢\.pos!!                     and $t .= '$C->{_pos}', next; 
     92        $f =~ s!^ self\.pos\b!!                 and $t .= ' $self->{_pos}', next; 
     93        $f =~ s!^\$¢\.pos\b!!                   and $t .= '$C->{_pos}', next; 
    9494        $f =~ s!^//!!                           and $t .= "//", next;   # default operator 
    9595        $f =~ s!^m:p5(\W)(.+?)\1/!!             and $t .= "m$1$2$1", next; 
     
    138138        $f =~ s/^\.pos\b//                      and $t .= qq/->{_pos}/, next; 
    139139        $f =~ s/^self\.orig\b//                 and $t .= qq/\$::ORIG/, next; 
     140        $f =~ s!^\.pos\b!!                      and $t .= '->{_pos}', next; 
     141        $f =~ s/^(\$\w+)\.pos//                 and $t .= $1 . '->{_pos}', next; 
    140142        $f =~ s/^(\$\w+)\.//                    and $t .= qq/$1->/, next; 
    141143        $f =~ s/^(\$\w+)\(/(/                   and $t .= qq/$1->/, next; 
     
    169171        $f =~ s/^\bTrue\b//                     and $t .= qq/1/, next; 
    170172        $f =~ s/^\bFalse\b//                    and $t .= qq/0/, next; 
    171         $f =~ s/^([^\$])self\.//                and $t .= qq/$1\$self->/, next; 
    172         $f =~ s/^([^\$])self\b//                and $t .= qq/$1\$self/, next; 
     173        $f =~ s/^\$?self\.pos\b//               and $t .= qq/\$self->{_pos}/, next; 
     174        $f =~ s/^\$?self\.//                    and $t .= qq/\$self->/, next; 
     175        $f =~ s/^\$?self\b//                    and $t .= qq/\$self/, next; 
    173176        $f =~ s/^\.panic//                      and $t .= qq/->panic/, next; 
    174177        $f =~ s/^(\s)\+&(\s)/$2/                and $t .= qq/$1&/, next; 
     
    317320            $protosig{$name} = $5; 
    318321            $out .= <<"END"; 
     322sub ${name}__PEEK { \$_[0]->_AUTOLEXpeek('$name:*',\$retree); } 
    319323sub $name { 
    320324    my \$self = shift; 
     
    322326 
    323327    local \$CTX = \$self->callm() if \$::DEBUG & DEBUG::trace_call; 
    324     if (\$self->{_peek}) { 
    325         return \$self->_AUTOLEXpeek('$name:*',\$retree); 
    326     } 
    327328 
    328329    my \$C = \$self; 
     
    586587            $re->remember_alts(); 
    587588 
    588             $out .= <<"END"; 
     589            my $body = <<"END"; 
     590sub$ws${NAME}__PEEK { <<PEEK>> } 
    589591sub$ws$NAME { 
    590592    my \$self = shift; 
    591593END 
    592594            if ($NEEDORIGARGS) { 
    593                 $out .= "    my \@origargs = \@_;\n"; 
    594             } 
    595             my $body = <<'END'; 
     595                $body .= "    my \@origargs = \@_;\n"; 
     596            } 
     597            $body .= <<'END'; 
    596598    local $CTX = $self->callm() if $::DEBUG & DEBUG::trace_call; 
    597     if ($self->{_peek}) { 
    598         return <<PEEK>> 
    599     } 
    600599<<DECL>> 
    601600 
     
    646645            } 
    647646            else { 
    648                 $body =~ s/<<PEEK>>/\$self->_AUTOLEXpeek('<<NAME>>',\$retree)/; 
     647                $body =~ s/<<PEEK>>/\$_[0]->_AUTOLEXpeek('<<NAME>>',\$retree)/; 
    649648            } 
    650649            $body =~ s/<<PKG>>/$PKG/g; 
     
    15571556        $re = "\$C->_SUBSUME$ratchet([" . 
    15581557            join(',', map {"'$_'"} @BINDINGS) . 
    1559             "], sub {\n" . ::indent("my \$C = shift()->cursor_fresh;\n" . $re) . "\n})"; 
     1558            "], sub {\n" . ::indent("my \$C = shift;\n" . $re) . "\n})"; 
    15601559        @BINDINGS = (); 
    15611560        $re; 
     
    19291928    sub walk { 
    19301929        my $self = shift; 
     1930        local $NEEDMATCH = 0; 
    19311931        my $rest = ::un6($$self{rest}) // ''; 
    19321932        my $name = $$self{name};