Skip to content

Commit

Permalink
Show ';;' in signatures if they need to be
Browse files Browse the repository at this point in the history
Fixes #125482
  • Loading branch information
lizmat committed Jun 25, 2015
1 parent 4e1fa3c commit f43725a
Showing 1 changed file with 18 additions and 37 deletions.
55 changes: 18 additions & 37 deletions src/core/Signature.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,52 +88,33 @@ my class Signature { # declared in BOOTSTRAP
nqp::p6list(nqp::clone($!params), List, Mu);
}

# XXX TODO: Parameter separators.
multi method perl(Signature:D:) {
method !gistperl(Signature:D: $perl) {
# Opening.
my $perl = ':(';
my $text = $perl ?? ':(' !! '(';

# Parameters.
my $params = self.params();
my $sep = '';
my int $i = 0;
while $i < $params.elems {
my $param := $params[$i];
$perl = $perl ~ $sep ~ $param.perl;
# this works because methods always have at least one
# other parameter, *%_
$sep = ($i == 0 && $param.invocant) ?? ': ' !! ', ';
$i = $i + 1;
if self.params -> @params {
$text = $text ~ @params.shift.perl ~ ': ' if @params[0].invocant;
$text = $text ~ ';; ' if !@params[0].multi-invocant;

my $sep = '';
for @params.kv -> $i, $param {
$text = $text ~ $sep
~ ($perl ?? $param.perl !! $param.perl.subst(/' $'$/,''));
$sep = $param.multi-invocant && !@params[$i+1].?multi-invocant
?? ';; '
!! ', '
}
}
if !nqp::isnull($!returns) && $!returns !=:= Mu {
$perl ~= ' --> ' ~ $!returns.perl
$text = $text ~ ' --> ' ~ $!returns.perl
}
# Closer.
$perl ~ ')'
$text ~ ')'
}

multi method gist(Signature:D:) {
# Opening.
my $perl = '(';

# Parameters.
my $params = self.params();
my $sep = '';
my int $i = 0;
while $i < $params.elems {
my $param := $params[$i];
$perl = $perl ~ $sep ~ $param.perl.subst(/' $'$/,'');
# this works because methods always have at least one
# other parameter, *%_
$sep = ($i == 0 && $param.invocant) ?? ': ' !! ', ';
$i = $i + 1;
}
if !nqp::isnull($!returns) && $!returns !=:= Mu {
$perl ~= ' --> ' ~ $!returns.perl
}
# Closer.
$perl ~ ')'
}
multi method perl(Signature:D:) { self!gistperl(True) }
multi method gist(Signature:D:) { self!gistperl(False) }

method returns() { $!returns }
}
Expand Down

0 comments on commit f43725a

Please sign in to comment.