Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[GGE::Exp] moved enum types into classes

The longer names make it clearer where they belong. Also, they're not enums
yet because I couldn't get named enums to work in this situation.
  • Loading branch information...
commit 8677a652791bce4cc76d3859f000dc76240686fd 1 parent 466b14f
Carl Mäsak authored May 30, 2010
57  lib/GGE/Exp.pm
@@ -37,29 +37,32 @@ role GGE::ShowContents {
37 37
     }
38 38
 }
39 39
 
40  
-# RAKUDO: Could name this one GGE::Exp::CUT or something, if enums
41  
-#         with '::' in them worked, which they don't. [perl #71460]
42  
-our sub CUT_GROUP { -1 }
43  
-our sub CUT_RULE  { -2 }
44  
-our sub CUT_MATCH { -3 }
45  
-#enum CUT (
46  
-#    CUT_GROUP => -1,
47  
-#    CUT_RULE  => -2,
48  
-#    CUT_MATCH => -3,
49  
-#);
50  
-
51  
-our sub GREEDY { 0 }
52  
-our sub EAGER  { 1 }
53  
-our sub NONE   { 2 }
54  
-#enum GGE_BACKTRACK <
55  
-#    GREEDY
56  
-#    EAGER
57  
-#    NONE
58  
-#>;
59 40
 
60 41
 class GGE::Exp is GGE::Match {
61 42
     our $group;
62 43
 
  44
+    # RAKUDO: Should be just 'CutType' [RT #75454]
  45
+    package GGE::Exp::CutType {
  46
+        our sub CUT_GROUP { -1 }
  47
+        our sub CUT_RULE  { -2 }
  48
+        our sub CUT_MATCH { -3 }
  49
+    }
  50
+    # RAKUDO: Enums don't work enough yet.
  51
+    # our enum GGE::Exp::CutType (
  52
+    #     CUT_GROUP => -1,
  53
+    #     CUT_RULE  => -2,
  54
+    #     CUT_MATCH => -3,
  55
+    # );
  56
+
  57
+    # RAKUDO: Should be just 'Backtracking' [RT #75454]
  58
+    package GGE::Exp::Backtracking {
  59
+        our sub GREEDY { 0 }
  60
+        our sub EAGER  { 1 }
  61
+        our sub NONE   { 2 }
  62
+    }
  63
+    # RAKUDO: Enums don't work enough yet.
  64
+    # our enum GGE::Exp::Backtracking <GREEDY EAGER NONE>;
  65
+
63 66
     method structure($indent = 0) {
64 67
         # RAKUDO: The below was originally written as a map, but there's
65 68
         #         a bug somewhere in &map and lexical pads. The workaround
@@ -148,7 +151,7 @@ class GGE::Exp is GGE::Match {
148 151
             }
149 152
             when 'fail' {
150 153
                 local-return();
151  
-            } ]], CUT_RULE);
  154
+            } ]], GGE::Exp::CutType::CUT_RULE);
152 155
         my $explabel = 'R';
153 156
         $GGE::Exp::group = self;
154 157
         my $exp = self.reduce;
@@ -180,7 +183,8 @@ class GGE::Exp is GGE::Match {
180 183
             %hash<n> = $quant<max>;
181 184
             %hash<N> = %hash<n> == Inf ?? '### ' !! '';
182 185
             # RAKUDO: Waiting for named enums for this one
183  
-            # my $bt = ($quant<backtrack> // GREEDY).name.lc;
  186
+            # my $bt = ($quant<backtrack>
  187
+            #           // GGE::Exp::Backtracking::GREEDY).name.lc;
184 188
             my $bt = 'no idea';
185 189
             %hash<Q> = sprintf '%s..%s (%s)', %hash<m>, %hash<n>, $bt;
186 190
         }
@@ -256,7 +260,7 @@ class GGE::Exp::Quant is GGE::Exp {
256 260
     method contents() {
257 261
         my ($min, $max, $bt) = map { self{$_} },
258 262
                                    <min max backtrack>;
259  
-        $bt //= GREEDY;
  263
+        $bt //= GGE::Exp::Backtracking::GREEDY;
260 264
         # RAKUDO: Named enums
261 265
         # "{$bt.name.lc} $min..$max"
262 266
         "no idea $min..$max"
@@ -277,7 +281,7 @@ class GGE::Exp::Quant is GGE::Exp {
277 281
         %args<c> = 0;
278 282
         %args<C> = '### ';
279 283
         given self<backtrack> {
280  
-            when EAGER() {
  284
+            when GGE::Exp::Backtracking::EAGER() {
281 285
                 $code.emit( q[[
282 286
             when '%L' { # quant %Q eager
283 287
                 push @gpad, 0;
@@ -308,7 +312,7 @@ class GGE::Exp::Quant is GGE::Exp {
308 312
                 goto('%1');
309 313
             } ]], $replabel, $nextlabel, |%args);
310 314
             }
311  
-            when NONE() {
  315
+            when GGE::Exp::Backtracking::NONE() {
312 316
                 # RAKUDO: Hash slices not implemented yet
313 317
                 # %args<c C> = $code.unique(), '';
314 318
                 %args<c> = $code.unique();
@@ -709,7 +713,7 @@ class GGE::Exp::CGroup is GGE::Exp::Group {
709 713
 
710 714
 class GGE::Exp::Cut is GGE::Exp {
711 715
     method reduce() {
712  
-        if self<cutmark> > CUT_RULE() {
  716
+        if self<cutmark> > GGE::Exp::CutType::CUT_RULE() {
713 717
             my $group = $GGE::Exp::group;
714 718
             if !$group<cutmark> {
715 719
                 $group<cutmark> = CodeString.unique();
@@ -802,7 +806,8 @@ class GGE::Exp::Subrule is GGE::Exp does GGE::ShowContents {
802 806
             when '%L_cont' {
803 807
                 %4
804 808
                 goto('fail');
805  
-            } ]], CUT_MATCH, $next, $captgen, $captsave, $captback, |%args);
  809
+            } ]], GGE::Exp::CutType::CUT_MATCH, $next,
  810
+                  $captgen, $captsave, $captback, |%args);
806 811
         }
807 812
     }
808 813
 }
20  lib/GGE/Perl6Regex.pm
@@ -471,23 +471,23 @@ class GGE::Perl6Regex {
471 471
 
472 472
         $m.to = $mob.to;
473 473
         if $mod2 eq ':?' {
474  
-            $m<backtrack> = EAGER;
  474
+            $m<backtrack> = GGE::Exp::Backtracking::EAGER;
475 475
             $m.to += 2;
476 476
         }
477 477
         elsif $mod2 eq ':!' {
478  
-            $m<backtrack> = GREEDY;
  478
+            $m<backtrack> = GGE::Exp::Backtracking::GREEDY;
479 479
             $m.to += 2;
480 480
         }
481 481
         elsif $mod1 eq '?' {
482  
-            $m<backtrack> = EAGER;
  482
+            $m<backtrack> = GGE::Exp::Backtracking::EAGER;
483 483
             ++$m.to;
484 484
         }
485 485
         elsif $mod1 eq '!' {
486  
-            $m<backtrack> = GREEDY;
  486
+            $m<backtrack> = GGE::Exp::Backtracking::GREEDY;
487 487
             ++$m.to;
488 488
         }
489 489
         elsif $mod1 eq ':' || $key eq ':' {
490  
-            $m<backtrack> = NONE;
  490
+            $m<backtrack> = GGE::Exp::Backtracking::NONE;
491 491
             ++$m.to;
492 492
         }
493 493
 
@@ -652,7 +652,9 @@ class GGE::Perl6Regex {
652 652
             $exp<sep> = perl6exp($sep, %pad);
653 653
         }
654 654
         %pad<isarray> = $isarray;
655  
-        $exp<backtrack> //= %pad<ratchet> ?? NONE() !! GREEDY;
  655
+        $exp<backtrack> //= %pad<ratchet>
  656
+            ?? GGE::Exp::Backtracking::NONE()
  657
+            !! GGE::Exp::Backtracking::GREEDY;
656 658
         return $exp;
657 659
     }
658 660
 
@@ -730,9 +732,9 @@ class GGE::Perl6Regex {
730 732
 
731 733
     multi sub perl6exp(GGE::Exp::Cut $exp is rw, %pad) {
732 734
         $exp<cutmark> =
733  
-               $exp.ast eq '::'  ?? CUT_GROUP()
734  
-            !! $exp.ast eq ':::' ?? CUT_RULE()
735  
-            !!                      CUT_MATCH;
  735
+               $exp.ast eq '::'  ?? GGE::Exp::CutType::CUT_GROUP()
  736
+            !! $exp.ast eq ':::' ?? GGE::Exp::CutType::CUT_RULE()
  737
+            !!                      GGE::Exp::CutType::CUT_MATCH;
736 738
         return $exp;
737 739
     }
738 740
 

0 notes on commit 8677a65

Please sign in to comment.
Something went wrong with that request. Please try again.