Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[GGE] Further adaptions to Rakudo master

- Rewrote CodeString.emit to do string plumbing instead of using .subst --
  slightly more kosher, but still uses /\d/ and /\w/ for convenience.

- Changed a class-bound variable from 'my' to 'our'. (The alpha branch of
  Rakudo wrongly accepted the former variant.)

- Added an extra layer of parens in the parameter list of
  GGE::Perl6Regex.postcircumfix:<( )>

- Worked around the <-[\t]> bug. \T is a much better way to write this
  anyway.

- Put in a few stringifications where they were suddenly needed.

- Cured a case of sudden overinterpolation in a qq string.

- Replaced two well-placed Str.trans calls with a lot of Str.subst calls,
  since we don't have the former properly yet in Rakudo master.
  • Loading branch information...
commit 29b63609b710e7b4e44274682bf07b1d9fd32efc 1 parent 5f369ef
Carl Mäsak authored April 17, 2010
17  lib/GGE/Exp.pm
@@ -5,10 +5,17 @@ class CodeString {
5 5
     has Str $!contents = '';
6 6
     my $counter = 0;
7 7
 
8  
-    method emit($string, *@args, *%kwargs) {
9  
-        $!contents ~= $string\
10  
-                        .subst(/\%(\d)/, {   @args[$0] // '...' }, :g)\
11  
-                        .subst(/\%(\w)/, { %kwargs{$0} // '...' }, :g);
  8
+    method emit($string is copy, *@args, *%kwargs) {
  9
+        while index($string, '%') -> $pos {
  10
+            my $new;
  11
+            given substr($string, $pos + 1, 1) {
  12
+                when /\d/ { $new = @args[$_.Int] // '...' }
  13
+                when /\w/ { $new = %kwargs{$_} // '...' }
  14
+                default   { die "Illegal subststr %" ~ $_ }
  15
+            }
  16
+            $string = $string.substr(0, $pos) ~ $new ~ $string.substr($pos + 2)
  17
+        }
  18
+        $!contents ~= $string;
12 19
     }
13 20
 
14 21
     method escape($string) {
@@ -51,7 +58,7 @@ sub NONE   { 2 }
51 58
 #>;
52 59
 
53 60
 class GGE::Exp is GGE::Match {
54  
-    my $group;
  61
+    our $group;
55 62
 
56 63
     method structure($indent = 0) {
57 64
         # RAKUDO: The below was originally written as a map, but there's
5  lib/GGE/Perl6Regex.pm
@@ -131,7 +131,10 @@ class GGE::Perl6Regex {
131 131
         return self.bless(*, :$exp, :$binary);
132 132
     }
133 133
 
134  
-    method postcircumfix:<( )>($target, :$debug) {
  134
+    # Why the double parens in the parameter list? Apparently, the
  135
+    # postcircumfix:<( )> method gets called with a Capture, so we have to
  136
+    # unpack that.
  137
+    method postcircumfix:<( )>( ($target, :$debug) ) {
135 138
         $!binary($target, :$debug);
136 139
     }
137 140
 
14  t/perl6regex/01-regex.t
@@ -30,12 +30,12 @@ for @test-files -> $test-file {
30 30
         }
31 31
         next if $line ~~ /^ \#/;
32 32
         $i++;
33  
-        $line ~~ /^ (<-[\t]>*) \t+ (<-[\t]>+) \t+ (<-[\t]>+) \t+ (.*) $/
  33
+        $line ~~ /^ (\T*) \t+ (\T+) \t+ (\T+) \t+ (.*) $/
34 34
             or die "Unrecognized line format: $line";
35 35
         my ($pattern, $target, $result, $description) = $0, $1, $2, $3;
36  
-        $target  = $target eq q[''] ?? '' !! backslash_escape($target);
37  
-        $result  = backslash_escape($result);
38  
-        my $full-description = "[$test-file:$i] $description";
  36
+        $target  = $target eq q[''] ?? '' !! backslash_escape(~$target);
  37
+        $result  = backslash_escape(~$result);
  38
+        my $full-description = "[$test-file" ~ ":$i] $description";
39 39
         my $match;
40 40
         my $failed = 1; # RAKUDO: Manual CATCH workaround
41 41
         try {
@@ -75,8 +75,10 @@ sub match_perl6regex($pattern, $target) {
75 75
 }
76 76
 
77 77
 sub backslash_escape($string) {
78  
-    return $string.trans(['\n', '\r', '\e', '\t', '\f'] =>
79  
-                         ["\n", "\r", "\e", "\t", "\f"])\
  78
+    # RAKUDO: No .trans again yet
  79
+    #return $string.trans(['\n', '\r', '\e', '\t', '\f'] =>
  80
+    #                     ["\n", "\r", "\e", "\t", "\f"])\
  81
+    return $string.subst(/\\n/, "\n", :g).subst(/\\r/, "\r", :g).subst(/\\e/, "\e", :g).subst(/\\t/, "\t", :g).subst(/\\f/, "\f", :g)\
80 82
                   .subst(/'\\x' (<[0..9a..f]>**{2..4})/, { chr(:16($0)) }, :g);
81 83
 }
82 84
 
8  test-regex
@@ -13,7 +13,9 @@ my GGE::Match $match
13 13
 say $match ?? $match.dump_str('mob', ' ', '') !! "No match\n";
14 14
 
15 15
 sub backslash_escape($string) {
16  
-    return $string.trans(['\n', '\r', '\e', '\t', '\f'] =>
17  
-                         ["\n", "\r", "\e", "\t", "\f"])\
18  
-                  .subst(/'\\x' (<[0..9a..f]>**{4})/, { chr(:16($0)) }, :g);
  16
+    # RAKUDO: No .trans again yet
  17
+    #return $string.trans(['\n', '\r', '\e', '\t', '\f'] =>
  18
+    #                     ["\n", "\r", "\e", "\t", "\f"])\
  19
+    return $string.subst(/\\n/, "\n", :g).subst(/\\r/, "\r", :g).subst(/\\e/, "\e", :g).subst(/\\t/, "\t", :g).subst(/\\f/, "\f", :g)\
  20
+                  .subst(/'\\x' (<[0..9a..f]>**{2..4})/, { chr(:16($0)) }, :g);
19 21
 }

0 notes on commit 29b6360

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