Skip to content
Permalink
Browse files

Move "cool_constant" logic to Main

Thereby effectively hiding it from the outside world.  ugexe++
  • Loading branch information...
lizmat committed Mar 22, 2019
1 parent dd1c805 commit 2b991664d4158f2c750b4e6c849bfd3ae8b5817f
Showing with 18 additions and 11 deletions.
  1. +18 −2 src/core/Main.pm6
  2. +0 −9 src/core/Parameter.pm6
@@ -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;
@@ -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
}

0 comments on commit 2b99166

Please sign in to comment.
You can’t perform that action at this time.