Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[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
@masak authored
View
17 lib/GGE/Exp.pm
@@ -5,10 +5,17 @@ class CodeString {
has Str $!contents = '';
my $counter = 0;
- method emit($string, *@args, *%kwargs) {
- $!contents ~= $string\
- .subst(/\%(\d)/, { @args[$0] // '...' }, :g)\
- .subst(/\%(\w)/, { %kwargs{$0} // '...' }, :g);
+ method emit($string is copy, *@args, *%kwargs) {
+ while index($string, '%') -> $pos {
+ my $new;
+ given substr($string, $pos + 1, 1) {
+ when /\d/ { $new = @args[$_.Int] // '...' }
+ when /\w/ { $new = %kwargs{$_} // '...' }
+ default { die "Illegal subststr %" ~ $_ }
+ }
+ $string = $string.substr(0, $pos) ~ $new ~ $string.substr($pos + 2)
+ }
+ $!contents ~= $string;
}
method escape($string) {
@@ -51,7 +58,7 @@ sub NONE { 2 }
#>;
class GGE::Exp is GGE::Match {
- my $group;
+ our $group;
method structure($indent = 0) {
# RAKUDO: The below was originally written as a map, but there's
View
5 lib/GGE/Perl6Regex.pm
@@ -131,7 +131,10 @@ class GGE::Perl6Regex {
return self.bless(*, :$exp, :$binary);
}
- method postcircumfix:<( )>($target, :$debug) {
+ # Why the double parens in the parameter list? Apparently, the
+ # postcircumfix:<( )> method gets called with a Capture, so we have to
+ # unpack that.
+ method postcircumfix:<( )>( ($target, :$debug) ) {
$!binary($target, :$debug);
}
View
14 t/perl6regex/01-regex.t
@@ -30,12 +30,12 @@ for @test-files -> $test-file {
}
next if $line ~~ /^ \#/;
$i++;
- $line ~~ /^ (<-[\t]>*) \t+ (<-[\t]>+) \t+ (<-[\t]>+) \t+ (.*) $/
+ $line ~~ /^ (\T*) \t+ (\T+) \t+ (\T+) \t+ (.*) $/
or die "Unrecognized line format: $line";
my ($pattern, $target, $result, $description) = $0, $1, $2, $3;
- $target = $target eq q[''] ?? '' !! backslash_escape($target);
- $result = backslash_escape($result);
- my $full-description = "[$test-file:$i] $description";
+ $target = $target eq q[''] ?? '' !! backslash_escape(~$target);
+ $result = backslash_escape(~$result);
+ my $full-description = "[$test-file" ~ ":$i] $description";
my $match;
my $failed = 1; # RAKUDO: Manual CATCH workaround
try {
@@ -75,8 +75,10 @@ sub match_perl6regex($pattern, $target) {
}
sub backslash_escape($string) {
- return $string.trans(['\n', '\r', '\e', '\t', '\f'] =>
- ["\n", "\r", "\e", "\t", "\f"])\
+ # RAKUDO: No .trans again yet
+ #return $string.trans(['\n', '\r', '\e', '\t', '\f'] =>
+ # ["\n", "\r", "\e", "\t", "\f"])\
+ return $string.subst(/\\n/, "\n", :g).subst(/\\r/, "\r", :g).subst(/\\e/, "\e", :g).subst(/\\t/, "\t", :g).subst(/\\f/, "\f", :g)\
.subst(/'\\x' (<[0..9a..f]>**{2..4})/, { chr(:16($0)) }, :g);
}
View
8 test-regex
@@ -13,7 +13,9 @@ my GGE::Match $match
say $match ?? $match.dump_str('mob', ' ', '') !! "No match\n";
sub backslash_escape($string) {
- return $string.trans(['\n', '\r', '\e', '\t', '\f'] =>
- ["\n", "\r", "\e", "\t", "\f"])\
- .subst(/'\\x' (<[0..9a..f]>**{4})/, { chr(:16($0)) }, :g);
+ # RAKUDO: No .trans again yet
+ #return $string.trans(['\n', '\r', '\e', '\t', '\f'] =>
+ # ["\n", "\r", "\e", "\t", "\f"])\
+ return $string.subst(/\\n/, "\n", :g).subst(/\\r/, "\r", :g).subst(/\\e/, "\e", :g).subst(/\\t/, "\t", :g).subst(/\\f/, "\f", :g)\
+ .subst(/'\\x' (<[0..9a..f]>**{2..4})/, { chr(:16($0)) }, :g);
}

0 comments on commit 29b6360

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