develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33989 - trunk/languages/perl6/src/parser

From:
tene
Date:
December 16, 2008 14:27
Subject:
[svn:parrot] r33989 - trunk/languages/perl6/src/parser
Message ID:
20081216222749.A3EB7CBA12@x12.develooper.com
Author: tene
Date: Tue Dec 16 14:27:48 2008
New Revision: 33989

Modified:
   trunk/languages/perl6/src/parser/actions.pm
   trunk/languages/perl6/src/parser/grammar.pg

Log:
[rakudo]: CONTROL blocks

Modified: trunk/languages/perl6/src/parser/actions.pm
==============================================================================
--- trunk/languages/perl6/src/parser/actions.pm	(original)
+++ trunk/languages/perl6/src/parser/actions.pm	Tue Dec 16 14:27:48 2008
@@ -447,6 +447,11 @@
             PAST::Var.new( :name('$_'), :scope('lexical') ),
             PAST::Var.new( :name('exception'), :scope('register') )
         ),
+        PAST::Op.new(
+            :pasttype('bind'),
+            PAST::Var.new( :name('$!'), :scope('lexical') ),
+            PAST::Var.new( :name('exception'), :scope('register') )
+        ),
         $past
     );
     our $?BLOCK;
@@ -460,6 +465,36 @@
     make PAST::Stmts.new();
 }
 
+method control_statement($/) {
+    my $past := $( $<block> );
+    $past.blocktype('immediate');
+    $past := PAST::Stmts.new(
+        PAST::Op.new(
+            :pasttype('bind'),
+            PAST::Var.new( :name('$_'), :scope('lexical') ),
+            PAST::Var.new( :name('exception'), :scope('register') )
+        ),
+        PAST::Op.new(
+            :pasttype('bind'),
+            PAST::Var.new( :name('$!'), :scope('lexical') ),
+            PAST::Var.new( :name('exception'), :scope('register') )
+        ),
+        $past
+    );
+    our $?BLOCK;
+    my $eh := PAST::Control.new(
+        $past,
+        :handle_types('CONTROL')
+    );
+    my @handlers;
+    if $?BLOCK.handlers() {
+        @handlers := $?BLOCK.handlers();
+    }
+    @handlers.unshift($eh);
+    $?BLOCK.handlers(@handlers);
+    make PAST::Stmts.new();
+}
+
 method statement_mod_loop($/) {
     my $expr := $( $<EXPR> );
     my $sym := ~$<sym>;

Modified: trunk/languages/perl6/src/parser/grammar.pg
==============================================================================
--- trunk/languages/perl6/src/parser/grammar.pg	(original)
+++ trunk/languages/perl6/src/parser/grammar.pg	Tue Dec 16 14:27:48 2008
@@ -243,6 +243,7 @@
     | <begin_statement> {*}                      #= begin_statement
     | <end_statement> {*}                        #= end_statement
     | <catch_statement> {*}                      #= catch_statement
+    | <control_statement> {*}                    #= control_statement
 }
 
 rule if_statement {
@@ -332,6 +333,12 @@
     {*}
 }
 
+rule control_statement {
+    $<sym>=[CONTROL]
+    <block>
+    {*}
+}
+
 rule statement_mod_loop {
     $<sym>=[while|until|for|given] <EXPR> {*}
 }



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About