Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement operator adverb processing
  • Loading branch information
sorear committed Aug 23, 2010
1 parent eb16e02 commit f61a6db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Niecza/Actions.pm
Expand Up @@ -898,7 +898,6 @@ sub circumfix__S_Cur_Ly { my ($cl, $M) = @_;

sub infixish { my ($cl, $M) = @_;
$M->sorry("Metaoperators NYI") if $M->{infix_postfix_meta_operator}[0];
$M->sorry("Adverbs NYI") if $M->{colonpair};
}

sub INFIX { my ($cl, $M) = @_;
Expand Down Expand Up @@ -1023,7 +1022,15 @@ sub POSTFIX { my ($cl, $M) = @_;
$M->{_ast} = Op::CallSub->new(node($M),
invocant => $arg,
args => ($op->{postcall}[0] // []));
} elsif ($M->{colonpair}) {
if ($arg->isa('Op::CallLike')) {
$M->{_ast} = $arg->adverb($M->{colonpair}{_ast}{term});
} else {
$M->sorry("You can't adverb that");
return;
}
} else {
say join(" ", %$M);
$M->sorry("Unhandled postop type");
}
$M->{_ast} = $cl->whatever_postcheck($M, $st, $M->{_ast});
Expand Down
13 changes: 13 additions & 0 deletions src/Op.pm
Expand Up @@ -101,6 +101,19 @@ use CgOp;
has args => (isa => 'ArrayRef[Op]', is => 'ro');
sub zyg { @{ $_[0]->args // $_[0]->positionals } }

sub getargs {
$_[0]->args ? @{ $_[0]->args } :
map { Op::Paren->new(inside => $_) } @{ $_[0]->positionals };
}

sub adverb {
my ($self, $adv) = @_;
my %h = %$self;
delete $h{args};
delete $h{positionals};
blessed($self)->new(args => [ $self->getargs, $adv ], %h);
}

sub argblock {
my ($self, $body) = @_;
if (! $self->args) {
Expand Down
5 changes: 5 additions & 0 deletions test2.pl
Expand Up @@ -19,4 +19,9 @@
'xxy' ~~ /x { $a = ($¢ ~~ Cursor) }/;
is $a, True, '$¢ isa Cursor';

{
sub infix:<@>($x, $y, :$z) { $x, $y, $z }
is (1 @ 2 :z(3)).join("|"), "1|2|3", "adverbs on infix ops work";
}

done-testing;

0 comments on commit f61a6db

Please sign in to comment.