Skip to content

Commit

Permalink
fix R to reverse associativity
Browse files Browse the repository at this point in the history
[R**] 2,3,4 and 2 R** 3 R** 4 now both consistently mean 4 ** 3 ** 2.
  • Loading branch information
TimToady committed Mar 30, 2015
1 parent ee7a375 commit 02e1e99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Perl6/Grammar.nqp
Expand Up @@ -3946,6 +3946,16 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
$cur
}

method revO($from) {
my $O := nqp::clone($from<OPER><O>);
my $cur := self.'!cursor_start_cur'();
$cur.'!cursor_pass'(self.pos());
if $O<assoc> eq 'right' { $O<assoc> := 'left' }
elsif $O<assoc> eq 'left' { $O<assoc> := 'right' }
nqp::bindattr($cur, NQPCursor, '$!match', $O);
$cur
}

proto token dotty { <...> }
token dotty:sym<.> {
<sym> <dottyop>
Expand Down Expand Up @@ -4224,7 +4234,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
token infix_prefix_meta_operator:sym<R> {
<sym> <infixish('R')> {}
<.can_meta($<infixish>, "reverse the args of")>
<O=.copyO($<infixish>)>
<O=.revO($<infixish>)>
}

token infix_prefix_meta_operator:sym<S> {
Expand Down
2 changes: 1 addition & 1 deletion src/core/metaops.pm
Expand Up @@ -12,7 +12,7 @@ sub METAOP_NEGATE(\op) {
}

sub METAOP_REVERSE(\op) {
-> Mu \a, Mu \b { op.(b, a) }
-> |args { op.(|args.reverse) }
}

sub METAOP_CROSS(\op, &reduce) {
Expand Down

0 comments on commit 02e1e99

Please sign in to comment.