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

Commit

Permalink
[nqp]: Add 'for' statement and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 26, 2009
1 parent 01986c7 commit d9b2cc4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/NQP/Actions.pm
Expand Up @@ -105,6 +105,16 @@ method statement_control:sym<repeat>($/) {
make $past;
}

method statement_control:sym<for>($/) {
my $past := $<xblock>.ast;
$past.pasttype('for');
my $block := $past[1];
$block[0].push( PAST::Var.new( :name('$_'), :scope('parameter') ) );
$block.symbol('$_', :scope('lexical') );
$block.arity(1);
make $past;
}

## Terms

method noun:sym<variable>($/) { make $<variable>.ast; }
Expand Down
5 changes: 5 additions & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -82,6 +82,11 @@ token statement_control:sym<repeat> {
]
}

token statement_control:sym<for> {
<sym> :s
<xblock>
}

## Terms

token noun:sym<variable> { <variable> }
Expand Down
12 changes: 12 additions & 0 deletions t/nqp/15-list.t
@@ -0,0 +1,12 @@
#!./parrot nqp.pbc

# lists and for

plan(3);

my $list := (1,2,3);
my $indexer := 0;

for $list {
print("ok "); print($_); say(" checking loop via indices");
}

0 comments on commit d9b2cc4

Please sign in to comment.