Skip to content

Commit

Permalink
[GGE::Match] updated dump_str
Browse files Browse the repository at this point in the history
It's now more in line with PGE's dump_str output. Need to make it recurse
when showing captures, but no need to do that before actually implementing
the captures.

Also added vertical whitespace here and there in the debug output so that
things group better visually.
  • Loading branch information
Carl Masak committed Jan 4, 2010
1 parent f465b90 commit dcd1e60
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
16 changes: 12 additions & 4 deletions lib/GGE/Match.pm
Expand Up @@ -38,10 +38,18 @@ class GGE::Match {
return $!to >= $!from;
}

method dump_str() {
?self.true()
?? sprintf '<%s @ 0>', $!target.substr($!from, $!to - $!from)
!! '';
method dump_str($prefix?, $b1 = '[', $b2 = ']') {
my $out = sprintf "%s: <%s @ %d> \n",
$prefix,
$!target.substr($!from, $!to - $!from),
$!from;
if self.llist {
for self.llist.kv -> $index, $elem {
$out ~= [~] $prefix, $b1, $index, $b2;
$out ~= ': ', '...', "\n";
}
}
$out
}

method Str() {
Expand Down
1 change: 1 addition & 0 deletions lib/GGE/Perl6Regex.pm
Expand Up @@ -138,6 +138,7 @@ class GGE::Perl6Regex {
method postcircumfix:<( )>($target, :$debug) {
if $debug {
say $!regex.structure;
say '';
}
GGE::TreeSpider.new(:$!regex, :$target, :pos(*)).crawl(:$debug);
}
Expand Down
3 changes: 2 additions & 1 deletion t/perl6regex/01-regex.t
Expand Up @@ -54,7 +54,8 @@ for @test-files -> $test-file {
}
else {
$result .= substr(1,-1); # remove /'s
ok defined($match.dump_str.index($result)), $full-description;
ok defined($match.dump_str('mob', ' ', '').index($result)),
$full-description;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion test-regex
Expand Up @@ -8,7 +8,9 @@ die "Usage: ./test-regex <pattern> <target>"
my ($pattern, $target) = @*ARGS;
my GGE::Match $match
= GGE::Perl6Regex.new($pattern).(backslash_escape($target), :debug);
say $match.dump_str() || 'No match';

say '';
say $match.dump_str('mob', ' ', '') || 'No match';

sub backslash_escape($string) {
return $string.trans(['\n', '\r', '\e', '\t', '\f'] =>
Expand Down

0 comments on commit dcd1e60

Please sign in to comment.