Subject: | Some augmented assignment operators parse as two operators |
Some augmented assignment operators like .= parse as a single
PPI::Token::Operator:
perl -MPPI::Document -MPPI::Dumper -e 'my $d = PPI::Document->new(\"$x
.= 1;"); PPI::Dumper->new($d)->print();'
PPI::Document
PPI::Token::Whitespace ' '
PPI::Statement
PPI::Token::Operator '.='
PPI::Token::Whitespace ' '
PPI::Token::Number '1'
PPI::Token::Structure ';'
and some parse as two:
perl -MPPI::Document -MPPI::Dumper -e 'my $d = PPI::Document->new(\"$x
<<= 1;"); PPI::Dumper->new($d)->print();'
PPI::Document
PPI::Token::Whitespace ' '
PPI::Statement
PPI::Token::Operator '<<'
PPI::Token::Operator '='
PPI::Token::Whitespace ' '
PPI::Token::Number '1'
PPI::Token::Structure ';'
I assume that they all should parse as a single operator.
For all 16 augmented operators in Perl 5.10:
perl -MPPI::Document -M5.10.0 -e 'print " += ops: "; my $d =
PPI::Document->new(\"my $x; $x += 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print " -= ops: "; my $d =
PPI::Document->new(\"my $x; $x -= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print " .= ops: "; my $d =
PPI::Document->new(\"my $x; $x .= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print " *= ops: "; my $d =
PPI::Document->new(\"my $x; $x *= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print " /= ops: "; my $d =
PPI::Document->new(\"my $x; $x /= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print " %= ops: "; my $d =
PPI::Document->new(\"my $x; $x %= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print " x= ops: "; my $d =
PPI::Document->new(\"my $x; $x x= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print " &= ops: "; my $d =
PPI::Document->new(\"my $x; $x &= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print " |= ops: "; my $d =
PPI::Document->new(\"my $x; $x |= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print " ^= ops: "; my $d =
PPI::Document->new(\"my $x; $x ^= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print "**= ops: "; my $d =
PPI::Document->new(\"my $x; $x **= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print "<<= ops: "; my $d =
PPI::Document->new(\"my $x; $x <<= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print ">>= ops: "; my $d =
PPI::Document->new(\"my $x; $x >>= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print "&&= ops: "; my $d =
PPI::Document->new(\"my $x; $x &&= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print "||= ops: "; my $d =
PPI::Document->new(\"my $x; $x ||= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
perl -MPPI::Document -M5.10.0 -e 'print "//= ops: "; my $d =
PPI::Document->new(\"my $x; $x //= 1;"); say scalar @{
$d->find("PPI::Token::Operator") };'
+= ops: 1
-= ops: 1
.= ops: 1
*= ops: 1
/= ops: 0
%= ops: 2
x= ops: 2
&= ops: 2
|= ops: 2
^= ops: 2
**= ops: 2
<<= ops: 2
Show quoted text
>>= ops: 2
&&= ops: 2
||= ops: 2
//= ops: 1