Changeset 21573 for perl5

Show
Ignore:
Timestamp:
07/27/08 17:44:55 (6 months ago)
Author:
fglock
Message:

[v6.pm] fixed 'if'

Location:
perl5/Pugs-Compiler-Perl6/lib/Pugs
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • perl5/Pugs-Compiler-Perl6/lib/Pugs/Emitter/Perl6/Perl5.pm

    r21572 r21573  
    10431043 
    10441044    if ( # XXX: obsoleted, fix unless to use new structure 
    1045          $n->{statement} eq 'unless' ) { 
     1045         $n->{statement} eq 'unless' )  
     1046    { 
    10461047        return  " " . $n->{statement} . 
    10471048                emit_parenthesis( $n->{exp1} ) . 
     
    10531054                emit_parenthesis( $n->{exp1} ) . 
    10541055                emit_block( $n->{exp2} ) . "\n"; 
    1055         for (@{$n->{exp3} || []}) { 
    1056             if (ref($_) eq 'ARRAY') { 
    1057                 $ret .= 'elsif '.emit_parenthesis( $_->[0] ) . 
    1058                     emit_block( $_->[1] ) . "\n"; 
    1059             } 
    1060             else { 
    1061                 $ret .= 'else '. emit_block( $_ ) . "\n"; 
    1062             } 
    1063         } 
    1064         return $ret; 
     1056        if ( $n->{elsif} ) { 
     1057            my ($exps, $blocks) = @{$n->{elsif}}; 
     1058            for (0 .. $#$exps) { 
     1059                $ret .= 'elsif '.emit_parenthesis( ${$exps}[$_]->() ) . 
     1060                            emit_block( ${$blocks}[$_]->() ) . "\n"; 
     1061            } 
     1062        } 
     1063        if ( $n->{else} ) { 
     1064            $ret .= 'else '. emit_block( $n->{else} ) . "\n"; 
     1065        } 
     1066        return $ret; 
    10651067    } 
    10661068 
  • perl5/Pugs-Compiler-Perl6/lib/Pugs/Grammar/StatementControl.pm

    r15805 r21573  
    190190        ) ); 
    191191    __PACKAGE__->add_rule( 
     192        'else' =>  q(  
     193            { die "bare 'else'" } 
     194        ) ); 
     195    __PACKAGE__->add_rule( 
    192196        'if' =>  q(  
    193197            <?ws>  
     
    201205                    exp1 => $_[0]{exp1}->(), 
    202206                    exp2 => $_[0]{exp2}->(), 
    203                     exp3 => [ $_[0]{exp3}->() ], 
    204                 } } 
    205         | 
    206             <?ws>? elsif <?ws>?  
    207             $<exp3> := <Pugs::Grammar::Expression.parse('no_blocks',0)> <?ws>? 
    208             $<exp4> := <Pugs::Grammar::Perl6.block> 
     207                    else => $_[0]{exp3}->(), 
     208                } } 
     209        | 
     210            [ 
     211                <?ws>? elsif <?ws>?  
     212                $<exp3> := <Pugs::Grammar::Expression.parse('no_blocks',0)> <?ws>? 
     213                $<exp4> := <Pugs::Grammar::Perl6.block> 
     214            ]+ 
     215             
    209216            [ 
    210217                <?ws>? else <?ws>?  
     
    214221                    exp1 => $_[0]{exp1}->(), 
    215222                    exp2 => $_[0]{exp2}->(), 
    216                     exp3 => [ [ $_[0]{exp3}->(), $_[0]{exp4}->() ], 
    217                               $_[0]{exp5}->() ], 
    218                 } } 
    219                  
    220                 # TODO: elsif ... 
    221             | 
    222                 { return {  
    223                     statement => 'if', 
    224                     exp1 => $_[0]{exp1}->(), 
    225                     exp2 => $_[0]{exp2}->(), 
    226                     exp3 => [ [$_[0]{exp3}->(), $_[0]{exp4}->() ] ], 
     223                    elsif => [ $_[0]{exp3}, $_[0]{exp4} ], 
     224                    else => $_[0]{exp5}->(), 
     225                } } 
     226            | 
     227                { return {  
     228                    statement => 'if', 
     229                    exp1 => $_[0]{exp1}->(), 
     230                    exp2 => $_[0]{exp2}->(), 
     231                    elsif => [ $_[0]{exp3}, $_[0]{exp4} ], 
    227232                } } 
    228233            ]