- Timestamp:
- 07/27/08 17:44:55 (6 months ago)
- Location:
- perl5/Pugs-Compiler-Perl6/lib/Pugs
- Files:
-
- 2 modified
-
Emitter/Perl6/Perl5.pm (modified) (2 diffs)
-
Grammar/StatementControl.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
perl5/Pugs-Compiler-Perl6/lib/Pugs/Emitter/Perl6/Perl5.pm
r21572 r21573 1043 1043 1044 1044 if ( # XXX: obsoleted, fix unless to use new structure 1045 $n->{statement} eq 'unless' ) { 1045 $n->{statement} eq 'unless' ) 1046 { 1046 1047 return " " . $n->{statement} . 1047 1048 emit_parenthesis( $n->{exp1} ) . … … 1053 1054 emit_parenthesis( $n->{exp1} ) . 1054 1055 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; 1065 1067 } 1066 1068 -
perl5/Pugs-Compiler-Perl6/lib/Pugs/Grammar/StatementControl.pm
r15805 r21573 190 190 ) ); 191 191 __PACKAGE__->add_rule( 192 'else' => q( 193 { die "bare 'else'" } 194 ) ); 195 __PACKAGE__->add_rule( 192 196 'if' => q( 193 197 <?ws> … … 201 205 exp1 => $_[0]{exp1}->(), 202 206 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 209 216 [ 210 217 <?ws>? else <?ws>? … … 214 221 exp1 => $_[0]{exp1}->(), 215 222 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} ], 227 232 } } 228 233 ]
