Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
[nqp]: Add elsif/else clauses.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 22, 2009
1 parent 29e11dd commit 2577049
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/NQP/Actions.pm
Expand Up @@ -19,7 +19,9 @@ method statement($/) {
}

method xblock($/) {
make PAST::Op.new( $<EXPR>.ast, $<pblock>.ast, :pasttype('if') );
my $pblock := $<pblock>.ast;
# $pblock.blocktype('immediate');
make PAST::Op.new( $<EXPR>.ast, $pblock, :pasttype('if'), :node($/) );
}

method pblock($/) {
Expand All @@ -33,7 +35,21 @@ method blockoid($/) {
## Statement control

method statement_control:sym<if>($/) {
make $<xblock>.ast;
my $count := +$<xblock> - 1;
my $past := $<xblock>[$count].ast;
if $<else> {
my $else := $<else>[0].ast;
# $else.blocktype('immediate');
$past.push($else);
}
# build if/then/elsif structure
while $count > 0 {
$count--;
my $else := $past;
$past := $<xblock>[$count].ast;
$past.push($else);
}
make $past;
}

## Terms
Expand Down
4 changes: 2 additions & 2 deletions src/NQP/Grammar.pm
Expand Up @@ -42,10 +42,10 @@ proto token statement_control { <...> }
token statement_control:sym<if> {
$<sym>=['if'] :s
<xblock>
[ 'elsif'\s <xblock> ]*
[ 'else'\s <else=pblock> ]?
}



## Terms

proto token term { <...> }
Expand Down

0 comments on commit 2577049

Please sign in to comment.