Skip to content

Commit

Permalink
RakuAST: support .&{...} method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Apr 4, 2024
1 parent 65f349a commit ea0aa21
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Raku/Actions.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,9 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
:name($<quote>.ast), :$args
);
}
elsif $<variable> {
$ast := Nodify('Call','BlockMethod').new(:block($<variable>.ast), :$args);
}
else {
nqp::die('NYI kind of methodop');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Raku/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
self.malformed("class-qualified postfix call")
if $<longname> eq '::';
}
# | <?[$@&]> <variable> { self.check-variable($<variable>) }
| <?[$@&]> <variable> { self.check-variable($<variable>) }
| <?['"]>
[ <!{$*QSIGIL}> || <!before '"' <.-["]>*? [\s|$] > ] # dwim on "$foo."
<quote>
Expand Down
41 changes: 41 additions & 0 deletions src/Raku/ast/call.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,47 @@ class RakuAST::Call::VarMethod
}
}

class RakuAST::Call::BlockMethod
is RakuAST::Call::Methodish
{
has RakuAST::Block $.block;

method new(RakuAST::Block :$block!, RakuAST::ArgList :$args) {
my $obj := nqp::create(self);
nqp::bindattr($obj, RakuAST::Call::BlockMethod, '$!block', $block);
nqp::bindattr($obj, RakuAST::Call, '$!args', $args // RakuAST::ArgList.new);
$obj
}

method can-be-used-with-hyper() { True }

method visit-children(Code $visitor) {
$visitor($!block);
$visitor(self.args);
}

method default-operator-properties() {
OperatorProperties.postfix('.&')
}

method IMPL-POSTFIX-QAST(RakuAST::IMPL::QASTContext $context, Mu $invocant-qast) {
my $call := QAST::Op.new(:op<call>, $!block.IMPL-EXPR-QAST($context), $invocant-qast);
self.args.IMPL-ADD-QAST-ARGS($context, $call);
$call
}

method IMPL-POSTFIX-HYPER-QAST(RakuAST::IMPL::QASTContext $context, Mu $operand-qast) {
my $call := QAST::Op.new:
:op('callmethod'), :name('dispatch:<hyper>'),
$operand-qast,
$!block.IMPL-EXPR-QAST($context),
QAST::SVal.new( :value('dispatch:<var>') ),
$!block.IMPL-EXPR-QAST($context);
self.args.IMPL-ADD-QAST-ARGS($context, $call);
$call
}
}

# Base role for all stubs
class RakuAST::Stub
is RakuAST::ImplicitLookups
Expand Down

0 comments on commit ea0aa21

Please sign in to comment.