Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement [ 1, 2, 3 ] syntax
  • Loading branch information
sorear committed Oct 15, 2010
1 parent 1e0987f commit 22a529d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Niecza/Actions.pm
Expand Up @@ -979,6 +979,14 @@ sub circumfix__S_Paren_Thesis { my ($cl, $M) = @_;
}
}

sub circumfix__S_Bra_Ket { my ($cl, $M) = @_;
my @kids = grep { defined } @{ $M->{semilist}{_ast} };
$M->{_ast} = Op::CallSub->new(node($M),
invocant => Op::Lexical->new(node($M), name => '&_array_constructor'),
args => [Op::StatementList->new(node($M), children =>
[ map { Op::Paren->new(inside => $_) } @kids ])]);
}

sub circumfix__S_Cur_Ly { my ($cl, $M) = @_;
$M->{pblock}{_ast}->type('bare');
$M->{_ast} = Op::BareBlock->new(node($M), var => $cl->gensym,
Expand Down
7 changes: 7 additions & 0 deletions test2.pl
Expand Up @@ -40,6 +40,8 @@ sub infix:<lt>($s1, $s2) { ($s1 leg $s2) < 0 }
sub sort(*@bits) { @bits.sort }
sub _array_constructor(\$parcel) { anon @new = $parcel }
ok 'cow' le 'sow', 'cow le sow';
ok !('sow' le 'cow'), 'sow !le cow';
ok 'row' lt 'tow', 'row lt tow';
Expand All @@ -52,6 +54,11 @@ sub infix:<lt>($s1, $s2) { ($s1 leg $s2) < 0 }
is ("yayay" ~~ /y\w*?y/), "yay", "minimal matching works";
is ("yayay" ~~ /y**?a/), "y", "minimal matching works with **";
is +[ 2 ], 1, "array construction w/ one argument";
is +[ ], 0, "array construction w/ no arguments";
is +[ 3, 4 ], 2, "array construction w/ two";
is +[ $( 3, 4 ) ], 1, "array construction w/ scalar argument";
{
sub bar { $*x + $*x }
sub foo($*x) { bar }
Expand Down

0 comments on commit 22a529d

Please sign in to comment.