Skip to content

Commit

Permalink
Add Parameter.prefix and Parameter.suffix
Browse files Browse the repository at this point in the history
The prefix method returns the *, **, or + markers a parameter was
declared with, if any, and the suffix method returns the ? or !
marker a parameter was declared with, if any.
  • Loading branch information
Kaiepi committed Jan 17, 2020
1 parent 8c0a5d6 commit bd68955
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/core.c/Parameter.pm6
Expand Up @@ -283,6 +283,28 @@ my class Parameter { # declared in BOOTSTRAP
?? '*'
!! ''
}

method prefix(Parameter:D: --> Str:D) {
nqp::bitand_i($!flags, nqp::bitor_i($SIG_ELEM_SLURPY_POS, $SIG_ELEM_SLURPY_NAMED))
?? '*'
!! nqp::bitand_i($!flags, $SIG_ELEM_SLURPY_LOL)
?? '**'
!! nqp::bitand_i($!flags, $SIG_ELEM_SLURPY_ONEARG)
?? '+'
!! ''
}

method suffix(Parameter:D: --> Str:D) {
nqp::isnull(@!named_names)
?? nqp::bitand_i($!flags, $SIG_ELEM_IS_OPTIONAL)
&& nqp::not_i(nqp::bitand_i($!flags, $SIG_ELEM_HAS_DEFAULT))
?? '?'
!! ''
!! nqp::bitand_i($!flags, nqp::bitor_i($SIG_ELEM_IS_OPTIONAL, $SIG_ELEM_HAS_DEFAULT))
?? ''
!! '!'
}

method modifier() {
nqp::bitand_i($!flags,$SIG_ELEM_DEFINED_ONLY)
?? ':D'
Expand Down

0 comments on commit bd68955

Please sign in to comment.