Skip to content

Commit

Permalink
RakuAST: support calling prefix ops as postfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Mar 6, 2023
1 parent 93609de commit 9d55cb2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
32 changes: 29 additions & 3 deletions src/Raku/Actions.nqp
Expand Up @@ -783,9 +783,15 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
make $/[0].ast;
}
else {
self.attach: $/, self.r('ApplyPostfix').new:
postfix => $ast // self.r('Postfix').new($<postfix><sym>),
operand => $/[0].ast;
if nqp::istype($ast, self.r('Call', 'Name')) {
$ast.args.push: $/[0].ast;
self.attach: $/, $ast;
}
else {
self.attach: $/, self.r('ApplyPostfix').new:
postfix => $ast // self.r('Postfix').new($<postfix><sym>),
operand => $/[0].ast;
}
}
}
else {
Expand Down Expand Up @@ -903,6 +909,26 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
elsif $<postop> {
self.attach: $/, $<postop>.ast;
}
elsif $<colonpair> {
if $<colonpair><identifier> eq "" && $<colonpair><coloncircumfix> -> $cf {
if $cf<circumfix> -> $op_name {
self.attach: $/, self.r('Call', 'Name').new(
:name(
self.r('Name').from-identifier(
'prefix:' ~ self.r('ColonPairish').IMPL-QUOTE-VALUE(
($op_name<nibble> // $op_name<semilist> // $op_name<pblock>).Str
)
)
)
);
}
else {
nqp::die('NYI kind of dottyop with coloncircumfix');
}
} else {
self.attach: $/, $<colonpair>.ast;
}
}
else {
nqp::die('NYI kind of dottyop');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Raku/Grammar.nqp
Expand Up @@ -1263,7 +1263,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
<.unsp>?
[
| <methodop($special)>
# | <colonpair>
| <colonpair>
| <!alpha> <postop> $<O> = {$<postop><O>} $<sym> = {$<postop><sym>}
<.dotty-non-ident($special)>
]
Expand Down
2 changes: 2 additions & 0 deletions src/Raku/ast/call.rakumod
Expand Up @@ -26,6 +26,8 @@ class RakuAST::ArgList
$obj
}

method push($arg) { nqp::push($!args, $arg) }

method has-args() { nqp::elems($!args) }

method args() {
Expand Down

0 comments on commit 9d55cb2

Please sign in to comment.