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

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

From:
tene
Date:
December 15, 2008 18:28
Subject:
[svn:parrot] r33943 - trunk/languages/perl6/src/parser
Message ID:
20081216022811.B1451CBA12@x12.develooper.com
Author: tene
Date: Mon Dec 15 18:28:10 2008
New Revision: 33943

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

Log:
[rakudo]: Refactor some copypasta out of my last commit.

Modified: trunk/languages/perl6/src/parser/actions.pm
==============================================================================
--- trunk/languages/perl6/src/parser/actions.pm	(original)
+++ trunk/languages/perl6/src/parser/actions.pm	Mon Dec 15 18:28:10 2008
@@ -258,31 +258,12 @@
 }
 
 method when_statement($/) {
-    our $?BLOCK;
     my $block := $( $<block> );
     $block.blocktype('immediate');
 
     # Push a handler onto the innermost block so that we can exit if we
     # successfully match
-    # XXX TODO: This isn't quite the right way to check this...
-    unless $?BLOCK.handlers() {
-        my @handlers;
-        @handlers.push(
-            PAST::Control.new(
-                PAST::Op.new(
-                    :pasttype('pirop'),
-                    :pirop('return'),
-                    PAST::Var.new(
-                        :scope('keyed'),
-                        PAST::Var.new( :name('exception'), :scope('register') ),
-                        'payload',
-                    ),
-                ),
-                :handle_types('BREAK')
-            )
-        );
-        $?BLOCK.handlers(@handlers);
-    }
+    when_handler_helper();
 
     # push a control exception throw onto the end of the block so we
     # exit the innermost block in which $_ was set.
@@ -331,32 +312,13 @@
 }
 
 method default_statement($/) {
-    our $?BLOCK;
     # Always executed if reached, so just produce the block.
     my $block := $( $<block> );
     $block.blocktype('immediate');
 
     # Push a handler onto the innermost block so that we can exit if we
     # successfully match
-    # XXX TODO: This isn't quite the right way to check this...
-    unless $?BLOCK.handlers() {
-        my @handlers;
-        @handlers.push(
-            PAST::Control.new(
-                PAST::Op.new(
-                    :pasttype('pirop'),
-                    :pirop('return'),
-                    PAST::Var.new(
-                        :scope('keyed'),
-                        PAST::Var.new( :name('exception'), :scope('register') ),
-                        'payload',
-                    ),
-                ),
-                :handle_types('BREAK')
-            )
-        );
-        $?BLOCK.handlers(@handlers);
-    }
+    when_handler_helper();
 
     # push a control exception throw onto the end of the block so we
     # exit the innermost block in which $_ was set.
@@ -388,6 +350,29 @@
     make $block;
 }
 
+sub when_handler_helper() {
+    our $?BLOCK;
+    # XXX TODO: This isn't quite the right way to check this...
+    unless $?BLOCK.handlers() {
+        my @handlers;
+        @handlers.push(
+            PAST::Control.new(
+                PAST::Op.new(
+                    :pasttype('pirop'),
+                    :pirop('return'),
+                    PAST::Var.new(
+                        :scope('keyed'),
+                        PAST::Var.new( :name('exception'), :scope('register') ),
+                        'payload',
+                    ),
+                ),
+                :handle_types('BREAK')
+            )
+        );
+        $?BLOCK.handlers(@handlers);
+    }
+}
+
 method loop_statement($/) {
     my $block := $( $<block> );
     $block.blocktype('immediate');



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