Skip to content

Commit

Permalink
B::Deparse: teach Deparse about ^^ (high-precedence xor)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauke committed Jul 11, 2024
1 parent f651c04 commit c844eac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/B/Deparse-core.t
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ sub testit {


# Deparse can't distinguish 'and' from '&&' etc
my %infix_map = qw(and && or ||);
my %infix_map = (and => '&&', or => '||', xor => '^^');

# Test a keyword that is a binary infix operator, like 'cmp'.
# $parens - "$a op $b" is deparsed as "($a op $b)"
Expand Down Expand Up @@ -686,4 +686,4 @@ wantarray 0 -
warn @ p1
write 01 -
x B -
xor B p
xor B -
4 changes: 2 additions & 2 deletions lib/B/Deparse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# This is based on the module of the same name by Malcolm Beattie,
# but essentially none of his code remains.

package B::Deparse 1.76;
package B::Deparse 1.77;
use strict;
use Carp;
use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
Expand Down Expand Up @@ -3277,7 +3277,7 @@ sub pp_dor { logop(@_, "//", 10) }

# xor is syntactically a logop, but it's really a binop (contrary to
# old versions of opcode.pl). Syntax is what matters here.
sub pp_xor { logop(@_, "xor", 2, "", 0, "") }
sub pp_xor { logop(@_, "xor", 2, "^^", 10, "") }

sub logassignop {
my $self = shift;
Expand Down
6 changes: 4 additions & 2 deletions lib/B/Deparse.t
Original file line number Diff line number Diff line change
Expand Up @@ -1879,10 +1879,10 @@ CORE::do({});
>>>>
() = (return 1);
() = (return ($1 + $2) * $3);
() = (return ($a xor $b));
() = (return $a ^^ $b);
() = (do 'file') + time;
() = (do ($1 + $2) * $3) + time;
() = (do ($1 xor $2)) + time;
() = (do ($1 ^^ $2)) + time;
() = (goto 1);
() = (require 'foo') + 3;
() = (require foo) + 3;
Expand Down Expand Up @@ -1911,6 +1911,8 @@ require v5.16;
####
# [perl #97476] not() *does* follow the llafr
$_ = ($a xor not +($1 || 2) ** 2);
>>>>
$_ = $a ^^ !($1 || 2) ** 2;
####
# Precedence conundrums with argument-less function calls
() = (eof) + 1;
Expand Down

0 comments on commit c844eac

Please sign in to comment.