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

Commit

Permalink
Add some (non-working) block rules to NQP.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 21, 2009
1 parent 4ed10a8 commit 31f8ae7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/NQP/Actions.pm
Expand Up @@ -10,7 +10,25 @@ method statementlist($/) {
make $past;
}

method statement($/) { make $<EXPR>.ast; }
method statement($/) {
my $past;
if $<EXPR> { $past := $<EXPR>.ast; }
elsif $<statement_control> { $past := $<statement_control>.ast; }
else { $past := 0; }
make $past;
}

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

method pblock($/) {
make $<blockoid>.ast;
}

method blockoid($/) {
make $<statementlist>.ast;
}

## Terms

Expand Down Expand Up @@ -41,6 +59,8 @@ method circumfix:sym<( )>($/) { make $<EXPR>.ast; }

method circumfix:sym<ang>($/) { make $<quote_EXPR>.ast; }

method circumfix:sym<{ }>($/) { make $<pblock>.ast; }

method postcircumfix:sym<[ ]>($/) {
make PAST::Var.new( $<EXPR>.ast , :scope('keyed_int') );
}
Expand Down
24 changes: 24 additions & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -8,6 +8,7 @@ rule statementlist {
}

token statement {
| <statement_control>
| <EXPR>
}

Expand All @@ -16,6 +17,29 @@ token eat_terminator {
| $
}

token xblock {
<EXPR> <.ws> <pblock>
}

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

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

## Statement control

proto token statement_control { <...> }

token statement_control:sym<if> {
$<sym>=['if']
<xblock>
}



## Terms

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

0 comments on commit 31f8ae7

Please sign in to comment.