Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
in the middle of allowing to have named iterators in for loops
  • Loading branch information
FROGGS committed Mar 24, 2013
1 parent 450a0e0 commit ff19c0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
24 changes: 21 additions & 3 deletions lib/Perl6/P5Actions.pm
Expand Up @@ -668,28 +668,36 @@ class Perl6::P5Actions is HLL::Actions does STDActions {
}

method sblock($/) {
say("method sblock($/)");
if $<blockoid><you_are_here> {
say("method sblock($/) you_are_here");
make $<blockoid>.ast;
}
else {
say("method sblock($/) else");
# Locate or build a set of parameters.
my %sig_info;
my @params;
my $block := $<blockoid>.ast;
if $block<placeholder_sig> && $<signature> {
say("method sblock($/) else placeholder_sig && signature");
$*W.throw($/, ['X', 'Signature', 'Placeholder'],
placeholder => $block<placeholder_sig>[0]<placeholder>,
);
}
elsif $block<placeholder_sig> {
say("method sblock($/) else placeholder_sig");
@params := $block<placeholder_sig>;
%sig_info<parameters> := @params;
}
elsif $<signature> {
say("method sblock($/) else signature");
%sig_info := $<signature>.ast;
@params := %sig_info<parameters>;
}
else {
# XXX we will always end up here, because Perl 5's b sblock has no signature.
say("method sblock($/) else else");
unless $block.symbol('$_') {
if $*IMPLICIT {
@params.push(hash(
Expand Down Expand Up @@ -850,12 +858,22 @@ class Perl6::P5Actions is HLL::Actions does STDActions {
make tweak_loop($past);
}

# method statement_control:sym<for>($/) {
# my $xblock := $<xblock>.ast;
# my $past := QAST::Op.new(
# :op<callmethod>, :name<map>, :node($/),
# QAST::Op.new(:name('&infix:<,>'), :op('call'), $xblock[0]),
# block_closure($xblock[1])
# );
# make $past;
# }
method statement_control:sym<for>($/) {
my $xblock := $<xblock>.ast;
#my $xblock := $<xblock>.ast;
# bind to $x if $x in signature, remember
my $past := QAST::Op.new(
:op<callmethod>, :name<map>, :node($/),
QAST::Op.new(:name('&infix:<,>'), :op('call'), $xblock[0]),
block_closure($xblock[1])
QAST::Op.new(:name('&infix:<,>'), :op('call'), $<EXPR>.ast),
block_closure($<sblock>.ast)
);
make $past;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/Perl6/P5Grammar.pm
Expand Up @@ -1438,8 +1438,10 @@ grammar Perl6::P5Grammar is HLL::Grammar does STD5 {
# <.typed_panic: 'X::Syntax::P5'> ]?
# [ <?before '(' <.EXPR>? ';' <.EXPR>? ';' <.EXPR>? ')' >
# <.obs('C-style "for (;;)" loop', '"loop (;;)"')> ]?
['my'? <variable_declarator>]?
<xblock(1)>
# $<signature>=[ ['my' { $*SCOPE := 'my' } ]? <variable_declarator> ]?
[ ['my' { $*SCOPE := 'my' } ]? <variable_declarator> ]?
'(' ~ ')' <EXPR>
<sblock(1)>
}

rule statement_control:sym<given> {
Expand Down
4 changes: 2 additions & 2 deletions test.pl
Expand Up @@ -30,8 +30,8 @@
sub a { say 14; }; a();
my $s = 15;
say $s;
sub b { say shift @_ }; b( 16 ); # Method 'multisig' not found for invocant of class 'Perl6::P5Grammar'
#for my $x (10..13) { say $x; } # scoped variables not yet implemented. Sorry.
sub b { say shift @_ }; b( 16 );
for my $x (10..13) { say $x; } # iterate is still $_
say "16\n", 17;
}

Expand Down

0 comments on commit ff19c0c

Please sign in to comment.