Skip to content

Commit 7b8137f

Browse files
committed
implement :$var colonpair syntax
Also adds a single test.
1 parent 052bc4b commit 7b8137f

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/NQP/Actions.pm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,16 @@ class NQP::Actions is HLL::Actions {
420420
}
421421

422422
method colonpair($/) {
423-
my $past := $<circumfix>
424-
?? $<circumfix>[0].ast
425-
!! PAST::Val.new( :value( !$<not> ) );
426-
$past.named( ~$<identifier> );
427-
make $past;
423+
if $<variable> {
424+
$<variable>.ast.named(~$<variable><desigilname>);
425+
make $<variable>.ast;
426+
} else {
427+
my $past := $<circumfix>
428+
?? $<circumfix>[0].ast
429+
!! PAST::Val.new( :value( !$<not> ) );
430+
$past.named( ~$<identifier> );
431+
make $past;
432+
}
428433
}
429434

430435
method variable($/) {

src/NQP/Grammar.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ grammar NQP::Grammar is HLL::Grammar {
286286
| $<not>='!' <identifier>
287287
| <identifier> <circumfix>?
288288
| <circumfix>
289+
| <variable>
289290
]
290291
}
291292

t/nqp/23-named-args.t

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# test named parameters and arguments
44

5-
plan(4);
5+
plan(5);
66

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

19+
my $y := 5;
20+
say('ok ', f1(10, :$y), ' - :$x colonpair syntax');
21+
1922

2023
# XXX: test mandatory named args are actually mandatory

0 commit comments

Comments
 (0)