[svn:parrot] r47571 - branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern

tcurtis at svn.parrot.org tcurtis at svn.parrot.org
Sat Jun 12 19:07:26 UTC 2010


Author: tcurtis
Date: Sat Jun 12 19:07:25 2010
New Revision: 47571
URL: https://trac.parrot.org/parrot/changeset/47571

Log:
Factor out ACCEPTSGLOBALLY.

Modified:
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Node.nqp

Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Node.nqp
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Node.nqp	Sat Jun 12 18:09:26 2010	(r47570)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Node.nqp	Sat Jun 12 19:07:25 2010	(r47571)
@@ -126,10 +126,28 @@
     }
 
     method ACCEPTS ($node, *%opts) {
-        my $global := ?%opts<g>;
+        my $global := ?%opts<g> || ?%opts<global>;
+        return self.ACCEPTSGLOBALLY($node) if $global;
+        my $/ := self.ACCEPTSEXACTLY($node);
+        if (!$/ && ($node ~~ PAST::Node)) {
+            my $index := 0;
+            my $max := pir::elements__IP($node);
+            until ($index == $max) {
+                $/ := $node[$index] ~~ self;
+                return $/ if $/;
+                $index++;
+            }
+            $/ := PAST::Pattern::Match.new(0);
+        }
+        $/;
+    }
+
+    method ACCEPTSGLOBALLY ($node) {
+        say("Accepting globally");
         my $/;
         my $first := self.ACCEPTSEXACTLY($node);
-        if ($global && $node ~~ PAST::Node) {
+        if ($node ~~ PAST::Node) {
+            say('$node is a node.');
             my $matches := ?$first;
             my $index := 0;
             my $max := pir::elements__IP($node);
@@ -156,21 +174,8 @@
             }
             $/ := $/[0] if $matches == 1;
         }
-        elsif ($first) {
+        else {
             $/ := $first;
-        } else {
-            if ($node ~~ PAST::Node) {
-                my $index := 0;
-                my $max := pir::elements__IP($node);
-                until ($index == $max) {
-                    $/ := $node[$index] ~~ self;
-                    return $/ if $/;
-                    $index++;
-                }
-                $/ := PAST::Pattern::Match.new(0);
-            } else {
-                $/ := PAST::Pattern::Match.new(0);
-            }
         }
         $/;
     }


More information about the parrot-commits mailing list