Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adaptations to the new Rakudo master

- Named enums are not in place yet; swapped them out for simple subroutines.

- As a consequence, needed to put parens in some places where subs would
  otherwise gobble up things as arguments.

- The quote qq[<$prefix\[$list\]>] is now interpreted as an indexing into
  $prefix, what with the new correct-er interpolator and all. (jnthn++) But
  that wasn't at all what was intended -- the inner brackets are escaped in
  a misguided attempt to have them not be interpolated. Split the string up
  into smaller ones for clarity.

- Changed one 'class ... is also' into a stub class and a real declaration,
  and another one into a class declaration and an 'augment class'. Had to
  add 'use MONKEY_TYPING;' for the latter.

- Changed a large number of subs in a class (which were already a workaround
  for constants) into 'our sub' declarations.

- Became a bit more honest with a hash parameter %opts, which was detected to
  be changing inside the method even though it was readonly. We got away with
  this earlier, because assignment to elements of a hash wasn't checked.

- Removed an 'undef'. Since the method body is empty, it should now return
  Nil instead, which should work just as well.

- Removed a no-longer-necessary workaround with '// undef' on hash lookups
  which might return a miss. Such return values used to be nuclear, but that
  problem has since been fixed.

- Workedaround the lack of '<->' signatures. The code didn't become *that*
  much more repetitious.

- Switched the engine over from 'alpha' to 'perl6'.
  • Loading branch information...
commit 839bd22dd4745679cb393f1d751df67d1e9560c9 1 parent c4fb5b3
Carl Mäsak authored April 10, 2010
36  lib/GGE/Exp.pm
@@ -32,17 +32,23 @@ role GGE::ShowContents {
32 32
 
33 33
 # RAKUDO: Could name this one GGE::Exp::CUT or something, if enums
34 34
 #         with '::' in them worked, which they don't. [perl #71460]
35  
-enum CUT (
36  
-    CUT_GROUP => -1,
37  
-    CUT_RULE  => -2,
38  
-    CUT_MATCH => -3,
39  
-);
40  
-
41  
-enum GGE_BACKTRACK <
42  
-    GREEDY
43  
-    EAGER
44  
-    NONE
45  
->;
  35
+sub CUT_GROUP { -1 }
  36
+sub CUT_RULE  { -2 }
  37
+sub CUT_MATCH { -3 }
  38
+#enum CUT (
  39
+#    CUT_GROUP => -1,
  40
+#    CUT_RULE  => -2,
  41
+#    CUT_MATCH => -3,
  42
+#);
  43
+
  44
+sub GREEDY { 0 }
  45
+sub EAGER  { 1 }
  46
+sub NONE   { 2 }
  47
+#enum GGE_BACKTRACK <
  48
+#    GREEDY
  49
+#    EAGER
  50
+#    NONE
  51
+#>;
46 52
 
47 53
 class GGE::Exp is GGE::Match {
48 54
     my $group;
@@ -252,7 +258,7 @@ class GGE::Exp::Quant is GGE::Exp {
252 258
         }
253 259
         %args<c C> = 0, '### ';
254 260
         given self.hash-access('backtrack') {
255  
-            when EAGER {
  261
+            when EAGER() {
256 262
                 $code.emit( q[[
257 263
             when '%L' { # quant %Q eager
258 264
                 push @gpad, 0;
@@ -283,7 +289,7 @@ class GGE::Exp::Quant is GGE::Exp {
283 289
                 goto('%1');
284 290
             } ]], $replabel, $nextlabel, |%args);
285 291
             }
286  
-            when NONE {
  292
+            when NONE() {
287 293
                 %args<c C> = $code.unique(), '';
288 294
                 if self.hash-access('min') != 0
289 295
                    || self.hash-access('max') != Inf {
@@ -516,7 +522,7 @@ class GGE::Exp::EnumCharList is GGE::Exp does GGE::ShowContents {
516 522
             }
517 523
         }
518 524
         my $list = self.ast;
519  
-        qq[<$prefix\[$list\]>]
  525
+        "<$prefix" ~ '[' ~ "$list]>";
520 526
     }
521 527
 
522 528
     method p6($code, $label, $next) {
@@ -677,7 +683,7 @@ class GGE::Exp::CGroup is GGE::Exp::Group {
677 683
 
678 684
 class GGE::Exp::Cut is GGE::Exp {
679 685
     method reduce() {
680  
-        if self.hash-access('cutmark') > CUT_RULE {
  686
+        if self.hash-access('cutmark') > CUT_RULE() {
681 687
             my $group = $GGE::Exp::group;
682 688
             if !$group.hash-access('cutmark') {
683 689
                 $group.hash-access('cutmark') = CodeString.unique();
3  lib/GGE/Match.pm
... ...
@@ -1,7 +1,6 @@
1 1
 use v6;
2 2
 
3  
-# XXX: See the file lib/GGE/Perl6Regex.pm for an explanation.
4  
-class GGE::Perl6Regex {}
  3
+class GGE::Perl6Regex { ... }
5 4
 
6 5
 # This is a workaround. See the postcircumfix:<{ }> comments below.
7 6
 class Store {
20  lib/GGE/OPTable.pm
@@ -15,16 +15,16 @@ class GGE::OPTable {
15 15
     ##constant GGE_OPTABLE_INFIX         = 0x60;
16 16
     ##constant GGE_OPTABLE_POSTCIRCUMFIX = 0x80;
17 17
     ##constant GGE_OPTABLE_CIRCUMFIX     = 0x90;
18  
-    sub GGE_OPTABLE_EXPECT_TERM { 0x01 }
19  
-    sub GGE_OPTABLE_EXPECT_OPER { 0x02 }
  18
+    our sub GGE_OPTABLE_EXPECT_TERM { 0x01 }
  19
+    our sub GGE_OPTABLE_EXPECT_OPER { 0x02 }
20 20
 
21  
-    sub GGE_OPTABLE_TERM          { 0x10 }
22  
-    sub GGE_OPTABLE_POSTFIX       { 0x20 }
23  
-    sub GGE_OPTABLE_CLOSE         { 0x30 }
24  
-    sub GGE_OPTABLE_PREFIX        { 0x40 }
25  
-    sub GGE_OPTABLE_INFIX         { 0x60 }
26  
-    sub GGE_OPTABLE_POSTCIRCUMFIX { 0x80 }
27  
-    sub GGE_OPTABLE_CIRCUMFIX     { 0x90 }
  21
+    our sub GGE_OPTABLE_TERM          { 0x10 }
  22
+    our sub GGE_OPTABLE_POSTFIX       { 0x20 }
  23
+    our sub GGE_OPTABLE_CLOSE         { 0x30 }
  24
+    our sub GGE_OPTABLE_PREFIX        { 0x40 }
  25
+    our sub GGE_OPTABLE_INFIX         { 0x60 }
  26
+    our sub GGE_OPTABLE_POSTCIRCUMFIX { 0x80 }
  27
+    our sub GGE_OPTABLE_CIRCUMFIX     { 0x90 }
28 28
 
29 29
     has %!tokens;
30 30
     has %!keys;
@@ -47,7 +47,7 @@ class GGE::OPTable {
47 47
                                   expect => 0x0101, arity => 1 },
48 48
     ;
49 49
 
50  
-    method newtok($name, *%opts) {
  50
+    method newtok($name, *%opts is copy) {
51 51
         my $category = $name.substr(0, $name.index(':') + 1);
52 52
         if %!sctable{$category} -> %defaults {
53 53
             %opts{$_} //= %defaults{$_} for %defaults.keys;
27  lib/GGE/Perl6Regex.pm
@@ -3,8 +3,10 @@ use GGE::Match;
3 3
 use GGE::Exp;
4 4
 use GGE::OPTable;
5 5
 
  6
+use MONKEY_TYPING;
  7
+
6 8
 class GGE::Exp::WS is GGE::Exp::Subrule {
7  
-    method contents() { undef }
  9
+    method contents() {}
8 10
 }
9 11
 
10 12
 # XXX: why 'is also'? Because we'd really like to do something like
@@ -12,7 +14,7 @@ class GGE::Exp::WS is GGE::Exp::Subrule {
12 14
 # that syntax isn't implemented yet. Thus, we do the next best thing and
13 15
 # declare the GGE::Perl6Regex class in the GGE::Match module, and re-open it
14 16
 # here.
15  
-class GGE::Perl6Regex is also {
  17
+class GGE::Perl6Regex {
16 18
     has GGE::Exp $!exp;
17 19
     has Callable $!binary;
18 20
 
@@ -613,10 +615,7 @@ class GGE::Perl6Regex is also {
613 615
         if $key eq 's' {
614 616
             $key = 'sigspace';
615 617
         }
616  
-        # RAKUDO: Looks odd with the '// undef', doesn't it? Well, without
617  
-        #         it, things blow up badly if we try to inspect the value
618  
-        #         of a hash miss.
619  
-        my $temp = %pad{$key} // undef;
  618
+        my $temp = %pad{$key};
620 619
         %pad{$key} = $exp.ast;
621 620
         $exp[0] = perl6exp($exp[0], %pad);
622 621
         %pad{$key} = $temp;
@@ -640,14 +639,14 @@ class GGE::Perl6Regex is also {
640 639
     }
641 640
 
642 641
     multi sub perl6exp(GGE::Exp::Quant $exp is rw, %pad) {
643  
-        my $isarray = %pad<isarray> // undef;
  642
+        my $isarray = %pad<isarray>;
644 643
         %pad<isarray> = True;
645 644
         $exp[0] = perl6exp($exp[0], %pad);
646  
-        if $exp.hash-access('sep') <-> $sep {
647  
-            $sep = perl6exp($sep, %pad);
  645
+        if $exp.hash-access('sep') -> $sep {
  646
+            $exp.hash-access('sep') = perl6exp($sep, %pad);
648 647
         }
649 648
         %pad<isarray> = $isarray;
650  
-        $exp.hash-access('backtrack') //= %pad<ratchet> ?? NONE !! GREEDY;
  649
+        $exp.hash-access('backtrack') //= %pad<ratchet> ?? NONE() !! GREEDY;
651 650
         return $exp;
652 651
     }
653 652
 
@@ -713,7 +712,7 @@ class GGE::Perl6Regex is also {
713 712
 
714 713
     multi sub perl6exp(GGE::Exp::Subrule $exp is rw, %pad) {
715 714
         my $cname = $exp.hash-access('cname');
716  
-        my $isarray = %pad<isarray> // undef;
  715
+        my $isarray = %pad<isarray>;
717 716
         if %pad<lexscope>.exists($cname) {
718 717
             %pad<lexscope>{$cname}.hash-access('isarray') = True;
719 718
             $isarray = True;
@@ -725,8 +724,8 @@ class GGE::Perl6Regex is also {
725 724
 
726 725
     multi sub perl6exp(GGE::Exp::Cut $exp is rw, %pad) {
727 726
         $exp.hash-access('cutmark') =
728  
-               $exp.ast eq '::'  ?? CUT_GROUP
729  
-            !! $exp.ast eq ':::' ?? CUT_RULE
  727
+               $exp.ast eq '::'  ?? CUT_GROUP()
  728
+            !! $exp.ast eq ':::' ?? CUT_RULE()
730 729
             !!                      CUT_MATCH;
731 730
         return $exp;
732 731
     }
@@ -772,7 +771,7 @@ class GGE::Perl6Regex is also {
772 771
     }
773 772
 }
774 773
 
775  
-class GGE::Match is also {
  774
+augment class GGE::Match {
776 775
     multi method before() {
777 776
         return GGE::Match.new(self); # a failure
778 777
     }
2  test-regex
... ...
@@ -1,4 +1,4 @@
1  
-#!/usr/bin/alpha
  1
+#!/usr/local/bin/perl6
2 2
 use v6;
3 3
 use GGE;
4 4
 

0 notes on commit 839bd22

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