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

Commit

Permalink
Handle immediate blocks (in 'if' statements, at least).
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 23, 2009
1 parent b7a03fc commit f8fb418
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/NQP/Actions.pm
@@ -1,5 +1,7 @@
class NQP::Actions is HLL::Actions;

our @BLOCK := Q:PIR { %r = new ['ResizablePMCArray'] };
method TOP($/) { make $<statementlist>.ast; }
method statementlist($/) {
Expand All @@ -20,7 +22,7 @@ method statement($/) {

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

Expand All @@ -29,7 +31,16 @@ method pblock($/) {
}

method blockoid($/) {
make $<statementlist>.ast;
my $past := $<statementlist>.ast;
my $BLOCK := @BLOCK.shift;
$BLOCK.push($past);
$BLOCK.node($/);
make $BLOCK;
}

method newpad($/) {
our @BLOCK;
@BLOCK.unshift( PAST::Block.new( PAST::Stmts.new() ) );
}

## Statement control
Expand All @@ -39,7 +50,7 @@ method statement_control:sym<if>($/) {
my $past := $<xblock>[$count].ast;
if $<else> {
my $else := $<else>[0].ast;
# $else.blocktype('immediate');
$else.blocktype('immediate');
$past.push($else);
}
# build if/then/elsif structure
Expand Down
10 changes: 8 additions & 2 deletions src/NQP/Grammar.pm
@@ -1,6 +1,6 @@
grammar NQP::Grammar is HLL::Grammar;

token TOP { <?DEBUG> <statementlist> <?DUMP_TOKRX: 'noun'> [ $ || <.panic: 'Confused'> ] }
token TOP { <statementlist> [ $ || <.panic: 'Confused'> ] }

rule statementlist {
| $
Expand All @@ -26,13 +26,19 @@ token xblock {
}

token pblock {
<?[{]> <blockoid>
<?[{]>
<.newpad>
<blockoid>
}

token blockoid {
<.finishpad>
'{' ~ '}' <statementlist>
}

token newpad { <?> }
token finishpad { <?> }

proto token terminator { <...> }

token terminator:sym<;> { <?[;]> }
Expand Down

0 comments on commit f8fb418

Please sign in to comment.