Skip to content

Commit

Permalink
Implement calls of postcircumfix operators
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Aug 7, 2010
1 parent 8c9188f commit ed4b778
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Niecza/Actions.pm
Expand Up @@ -525,6 +525,11 @@ sub POSTFIX { my ($cl, $M) = @_;
$M->{_ast} = Op::CallSub->new(node($M),
invocant => Op::Lexical->new(name => '&postfix:<' . $op->{postfix} . '>'),
positionals => [ $arg ]);
} elsif ($op->{postcircumfix}) {
$M->{_ast} = Op::CallSub->new(node($M),
invocant => Op::Lexical->new(name => '&postcircumfix:<' .
$op->{postcircumfix} . '>'),
positionals => [ $arg, @{ $op->{args} } ]);
} elsif ($op->{name} && $op->{name} =~ /^(?:HOW|WHAT)$/) {
if ($op->{args}) {
$M->sorry("Interrogative operator " . $op->{name} .
Expand Down Expand Up @@ -581,6 +586,31 @@ sub postcircumfix__S_Paren_Thesis { my ($cl, $M) = @_;
$M->{_ast} = { postcall => $M->{semiarglist}{_ast} };
}

sub semilist_to_args { my ($cl, $M) = @_;
if (@{ $M->{_ast} } > 1) {
$M->sorry('Slice lookups NYI');
return;
}
my ($al) = @{ $M->{_ast} };

if (!defined $al) {
return [];
} elsif ($al && $al->splittable_parcel) {
return $al->positionals;
} else {
return [$al];
}
}

sub postcircumfix__S_Bra_Ket { my ($cl, $M) = @_;
$M->{_ast} = { postcircumfix => '[ ]',
args => $cl->semilist_to_args($M->{semilist}) };
}
sub postcircumfix__S_Cur_Ly { my ($cl, $M) = @_;
$M->{_ast} = { postcircumfix => '{ }',
args => $cl->semilist_to_args($M->{semilist}) };
}

sub postop { my ($cl, $M) = @_;
$M->{_ast} = $M->{postcircumfix} ? $M->{postcircumfix}{_ast} :
{ postfix => $M->{sym} };
Expand Down
10 changes: 10 additions & 0 deletions test2.pl
Expand Up @@ -45,6 +45,16 @@ sub postcircumfix:<[ ]> is rawcall {
});
}

{
sub postcircumfix:<[ ]>($a, $b, $c) { $a ~ "|" ~ $b ~ "|" ~ $c }
is 1[2,3], "1|2|3", "can call postcircumfix [ ]";
}

{
sub postcircumfix:<{ }>($a, $b, $c) { $a ~ "|" ~ $b ~ "|" ~ $c }
is 1{2,3}, "1|2|3", 'can call postcircumfix { }';
}

my @arr = <a b c>;
is @arr.join("|"), 'a|b|c', "word splitter works";

Expand Down

0 comments on commit ed4b778

Please sign in to comment.