Skip to content

Commit

Permalink
Move "cool_constant" logic to Main
Browse files Browse the repository at this point in the history
Thereby effectively hiding it from the outside world.  ugexe++
  • Loading branch information
lizmat committed Mar 22, 2019
1 parent dd1c805 commit 2b99166
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
20 changes: 18 additions & 2 deletions src/core/Main.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,30 @@ my sub RUN-MAIN(&main, $mainline, :$in-as-argsfiles) {
?? "-e '...'"
!! strip_path_prefix($prog-name);

# return the Cool constant if the post_constraints of a Parameter is
# a single Cool constant, else Nil
sub cool_constant(Parameter:D $p) {
nqp::not_i(
nqp::isnull(
(my \post_constraints :=
nqp::getattr($p,Parameter,'@!post_constraints'))
)
) && nqp::elems(post_constraints) == 1
&& nqp::istype((my \value := nqp::atpos(post_constraints,0)),Cool)
?? value
!! Nil
}

# Select candidates for which to create USAGE string
sub usage-candidates($capture) {
my @candidates = &main.candidates.grep: { !.?is-hidden-from-USAGE }
if $capture.list -> @positionals {
my $first := @positionals[0];
if @candidates.grep: -> $sub {
if $sub.signature.params[0].cool_constant -> $literal {
$literal.ACCEPTS($first)
if $sub.signature.params[0] -> $param {
if cool_constant($param) -> $literal {
$literal.ACCEPTS($first)
}
}
} -> @candos {
return @candos;
Expand Down
9 changes: 0 additions & 9 deletions src/core/Parameter.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -630,15 +630,6 @@ my class Parameter { # declared in BOOTSTRAP
$perl ~ $rest;
}

# return the cool constant if the post_constraint is a single Cool constant
method cool_constant() {
nqp::not_i(nqp::isnull(@!post_constraints))
&& nqp::elems(@!post_constraints) == 1
&& nqp::istype((my \value := nqp::atpos(@!post_constraints,0)),Cool)
?? value
!! Nil
}

method sub_signature(Parameter:D:) {
nqp::isnull($!sub_signature) ?? Any !! $!sub_signature
}
Expand Down

0 comments on commit 2b99166

Please sign in to comment.