Skip to content

Commit

Permalink
Capture.perl must distinguish sublists
Browse files Browse the repository at this point in the history
Also, not much point in having a shorter gist on Captures so make
identical to .perl.
  • Loading branch information
TimToady committed Apr 2, 2015
1 parent 4bd7152 commit 2c4bd6b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/core/Capture.pm
Expand Up @@ -89,24 +89,24 @@ my class Capture { # declared in BOOTSTRAP
}
nqp::p6box_s(nqp::join(' ', $str))
}
multi method gist(Capture:D:) {
my @list := self.list;
my %hash := self.hash;
'\('
~ (@list.map( {.gist} ).join: ', ' if +@list)
~ (', ' if +@list and +%hash)
~ (%hash.keys.sort.map( { $_.gist ~ ' => ' ~ %hash{$_}.gist } ).join: ', ' if +%hash)
~ ')';
}
multi method gist(Capture:D:) { self.perl }
multi method perl(Capture:D:) {
my @list := self.list;
my %hash := self.hash;
self.^name
~ '.new('
~ ( 'list => (' ~ @list.map( {.perl} ).join(', ') ~ ',)' if +@list)
~ (', ' if +@list and +%hash)
~ ( 'hash => {' ~ %hash.keys.pick(*).map( { $_.perl ~ ' => ' ~ %hash{$_}.perl } ).join(', ') ~ '}' if +%hash)
~ ')';
if self.^name eq 'Capture' {
"\\({
join ', ',
(@list[$_].perl for ^@list.elems),
%hash.sort.map( *.perl )
})";
} else {
self.^name
~ '.new('
~ ( 'list => (' ~ (@list[$_].perl for ^@list.elems).join(', ') ~ ',)' if +@list)
~ (', ' if +@list and +%hash)
~ ( 'hash => {' ~ %hash.sort.map( *.perl ).join(', ') ~ '}' if +%hash)
~ ')';
}
}
multi method Bool(Capture:D:) {
$!list || $!hash ?? True !! False
Expand Down

0 comments on commit 2c4bd6b

Please sign in to comment.