Skip to content

Commit

Permalink
[rakudo] Implement => infix operator, for constructing more complex p…
Browse files Browse the repository at this point in the history
…airs. Make them work in calls when you just have a string literal there.

git-svn-id: http://svn.perl.org/parrot/trunk/languages/perl6@27699 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
jnthn committed May 21, 2008
1 parent fb788d3 commit dfed26f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/parser/actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,24 @@ method EXPR($/, $key) {
}
}

# If it's infix:=> then we want to build a pair.
if $past.name() eq 'infix:=>' {
$past[0].named( PAST::Val.new( :value('key') ) );
$past[1].named( PAST::Val.new( :value('value') ) );
$past := PAST::Op.new(
:node($/),
:pasttype('callmethod'),
:name('new'),
:returns('Pair'),
PAST::Var.new(
:name('Pair'),
:scope('package')
),
$past[0],
$past[1]
);
}

make $past;
}
}
Expand Down Expand Up @@ -2196,6 +2214,15 @@ method capture($/) {
sub process_arguments($call_past, $args) {
for @($args) {
if $_.returns() eq 'Pair' {
# It's a pair. If the name is not just a simple value (e.g if it
# will create a PMC type), we must make it just a string or give
# an error.
if $_[1].WHAT() eq 'Val' && $_[1].returns() eq 'Perl6Str' {
$_[1].returns(undef);
}
elsif $_[1].WHAT() ne 'Val' || $_[1].returns() ne '' {
$call_past.panic("Cannot use complex pair key in a call.");
}
$_[2].named($_[1]);
$call_past.push($_[2]);
}
Expand Down
1 change: 1 addition & 0 deletions src/parser/grammar-oper.pg
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ proto infix:<?^=> is equiv(infix:<=>) { ... }
proto infix:<|=> is equiv(infix:<=>) { ... }
proto infix:<&=> is equiv(infix:<=>) { ... }
proto infix:<^=> is equiv(infix:<=>) { ... }
proto infix:«=>» is equiv(infix:<=>) { ... }

## loose unary
proto prefix:<true> is precedence('h=') { ... }
Expand Down

0 comments on commit dfed26f

Please sign in to comment.