Permalink
Browse files

in the middle of allowing to have named iterators in for loops

  • Loading branch information...
1 parent 450a0e0 commit ff19c0c0b97409e4d378dd75cd7cdc0ee586308c @FROGGS FROGGS committed Mar 24, 2013
Showing with 27 additions and 7 deletions.
  1. +21 −3 lib/Perl6/P5Actions.pm
  2. +4 −2 lib/Perl6/P5Grammar.pm
  3. +2 −2 test.pl
View
@@ -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(
@@ -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;
}
View
@@ -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> {
View
@@ -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;
}

0 comments on commit ff19c0c

Please sign in to comment.