Skip to content

Commit c844eac

Browse files
committed
B::Deparse: teach Deparse about ^^ (high-precedence xor)
1 parent f651c04 commit c844eac

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

lib/B/Deparse-core.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ sub testit {
123123

124124

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

128128
# Test a keyword that is a binary infix operator, like 'cmp'.
129129
# $parens - "$a op $b" is deparsed as "($a op $b)"
@@ -686,4 +686,4 @@ wantarray 0 -
686686
warn @ p1
687687
write 01 -
688688
x B -
689-
xor B p
689+
xor B -

lib/B/Deparse.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This is based on the module of the same name by Malcolm Beattie,
88
# but essentially none of his code remains.
99

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

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

32823282
sub logassignop {
32833283
my $self = shift;

lib/B/Deparse.t

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,10 +1879,10 @@ CORE::do({});
18791879
>>>>
18801880
() = (return 1);
18811881
() = (return ($1 + $2) * $3);
1882-
() = (return ($a xor $b));
1882+
() = (return $a ^^ $b);
18831883
() = (do 'file') + time;
18841884
() = (do ($1 + $2) * $3) + time;
1885-
() = (do ($1 xor $2)) + time;
1885+
() = (do ($1 ^^ $2)) + time;
18861886
() = (goto 1);
18871887
() = (require 'foo') + 3;
18881888
() = (require foo) + 3;
@@ -1911,6 +1911,8 @@ require v5.16;
19111911
####
19121912
# [perl #97476] not() *does* follow the llafr
19131913
$_ = ($a xor not +($1 || 2) ** 2);
1914+
>>>>
1915+
$_ = $a ^^ !($1 || 2) ** 2;
19141916
####
19151917
# Precedence conundrums with argument-less function calls
19161918
() = (eof) + 1;

0 commit comments

Comments
 (0)