Skip to content

Commit

Permalink
implement :$var colonpair syntax
Browse files Browse the repository at this point in the history
Also adds a single test.
  • Loading branch information
moritz committed Feb 22, 2012
1 parent 052bc4b commit 7b8137f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/NQP/Actions.pm
Expand Up @@ -420,11 +420,16 @@ class NQP::Actions is HLL::Actions {
}

method colonpair($/) {
my $past := $<circumfix>
?? $<circumfix>[0].ast
!! PAST::Val.new( :value( !$<not> ) );
$past.named( ~$<identifier> );
make $past;
if $<variable> {
$<variable>.ast.named(~$<variable><desigilname>);
make $<variable>.ast;
} else {
my $past := $<circumfix>
?? $<circumfix>[0].ast
!! PAST::Val.new( :value( !$<not> ) );
$past.named( ~$<identifier> );
make $past;
}
}

method variable($/) {
Expand Down
1 change: 1 addition & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -286,6 +286,7 @@ grammar NQP::Grammar is HLL::Grammar {
| $<not>='!' <identifier>
| <identifier> <circumfix>?
| <circumfix>
| <variable>
]
}

Expand Down
5 changes: 4 additions & 1 deletion t/nqp/23-named-args.t
Expand Up @@ -2,7 +2,7 @@

# test named parameters and arguments

plan(4);
plan(5);

sub f1 ($x, :$y) { $x - $y; }
say('ok ', f1(2, :y(1)), ' # named args passable');
Expand All @@ -16,5 +16,8 @@ say('ok ', f3(:y(2), :x(5)), ' # args reorderable');
sub f4 ($w, $x, :$y, :$z) { $w + $x + $y + $z; }
say('ok ', f4(:z(2), -3, :y(1), 4), ' # named/positional intermixable');

my $y := 5;
say('ok ', f1(10, :$y), ' - :$x colonpair syntax');


# XXX: test mandatory named args are actually mandatory

0 comments on commit 7b8137f

Please sign in to comment.