Author: pmichaud
Date: Sun Nov 9 10:41:16 2008
New Revision: 32469
Modified:
trunk/languages/perl6/src/parser/actions.pm
trunk/languages/perl6/src/parser/grammar.pg
Log:
[rakudo]: Add pointy blocks to if/unless statements (partial RT #58008)
Modified: trunk/languages/perl6/src/parser/actions.pm
==============================================================================
--- trunk/languages/perl6/src/parser/actions.pm (original)
+++ trunk/languages/perl6/src/parser/actions.pm Sun Nov 9 10:41:16 2008
@@ -161,51 +161,31 @@
method if_statement($/) {
- my $count := +$<EXPR> - 1;
- my $expr := $( $<EXPR>[$count] );
- my $then := $( $<block>[$count] );
- $then.blocktype('immediate');
- declare_implicit_immediate_vars($then);
- my $past := PAST::Op.new(
- $expr, $then,
- :pasttype('if'),
- :node( $/ )
- );
- if $<else> {
- my $else := $( $<else>[0] );
+ my $count := +$<xblock> - 1;
+ my $past := $( $<xblock>[$count] );
+ ## add any 'else' clause
+ if $<pblock> {
+ my $else := $( $<pblock>[0] );
$else.blocktype('immediate');
declare_implicit_immediate_vars($else);
$past.push( $else );
}
+ ## build if/then/elsif structure
while $count != 0 {
- $count := $count - 1;
- $expr := $( $<EXPR>[$count] );
- $then := $( $<block>[$count] );
- $then.blocktype('immediate');
- declare_implicit_immediate_vars($then);
- $past := PAST::Op.new(
- $expr, $then, $past,
- :pasttype('if'),
- :node( $/ )
- );
+ $count--;
+ my $else := $past;
+ $past := $( $<xblock>[$count] );
+ $past.push($else);
}
make $past;
}
-
method unless_statement($/) {
- my $then := $( $<block> );
- $then.blocktype('immediate');
- declare_implicit_immediate_vars($then);
- my $past := PAST::Op.new(
- $( $<EXPR> ), $then,
- :pasttype('unless'),
- :node( $/ )
- );
+ my $past := $( $<xblock> );
+ $past.pasttype('unless');
make $past;
}
-
method while_statement($/) {
my $cond := $( $<EXPR> );
my $block := $( $<block> );
@@ -300,6 +280,18 @@
make $block;
}
+method xblock($/) {
+ my $pblock := $( $<pblock> );
+ $pblock.blocktype('immediate');
+ declare_implicit_immediate_vars($pblock);
+ my $past := PAST::Op.new(
+ $( $<EXPR> ), $pblock,
+ :pasttype('if'),
+ :node( $/ )
+ );
+ make $past;
+}
+
method use_statement($/) {
my $name := ~$<name>;
my $past;
Modified: trunk/languages/perl6/src/parser/grammar.pg
==============================================================================
--- trunk/languages/perl6/src/parser/grammar.pg (original)
+++ trunk/languages/perl6/src/parser/grammar.pg Sun Nov 9 10:41:16 2008
@@ -146,6 +146,8 @@
token pblock { [ <lambda> <.ws> <signature> ]? <.ws> <block> {*} }
+token xblock { <EXPR> <.ws> <pblock> {*} }
+
## Blocks can also have an implied statement end if the
## closing brace is the last non-ws thing on the line.
@@ -244,16 +246,14 @@
rule if_statement {
$<sym>=[if]
- <EXPR> <block>
- [ 'elsif' <EXPR> <block> ]*
- [ 'else' <else=block> ]?
+ <xblock>
+ [ 'elsif' <xblock> ]*
+ [ 'else' <pblock> ]?
{*}
}
rule unless_statement {
- $<sym>=[unless]
- <EXPR> <block>
- {*}
+ $<sym>=[unless] <xblock> {*}
}
rule repeat_statement {