Fix "print" pretty-printing

Precedence was previously ignored.
This commit is contained in:
Nikita Popov 2015-04-26 11:52:40 +02:00
parent ab80054e97
commit 338bc1f8e7
3 changed files with 8 additions and 4 deletions

View File

@ -316,6 +316,10 @@ class Standard extends PrettyPrinterAbstract
return $this->pPrefixOp('Expr_YieldFrom', 'yield from ', $node->expr);
}
public function pExpr_Print(Expr\Print_ $node) {
return $this->pPrefixOp('Expr_Print', 'print ', $node->expr);
}
// Casts
public function pExpr_Cast_Int(Cast\Int_ $node) {
@ -376,10 +380,6 @@ class Standard extends PrettyPrinterAbstract
return 'isset(' . $this->pCommaSeparated($node->vars) . ')';
}
public function pExpr_Print(Expr\Print_ $node) {
return 'print ' . $this->p($node->expr);
}
public function pExpr_Eval(Expr\Eval_ $node) {
return 'eval(' . $this->p($node->expr) . ')';
}

View File

@ -67,6 +67,7 @@ abstract class PrettyPrinterAbstract
'Expr_AssignOp_ShiftRight' => array(160, 1),
'Expr_AssignOp_Pow' => array(160, 1),
'Expr_YieldFrom' => array(165, 1),
'Expr_Print' => array(168, 1),
'Expr_BinaryOp_LogicalAnd' => array(170, -1),
'Expr_BinaryOp_LogicalXor' => array(180, -1),
'Expr_BinaryOp_LogicalOr' => array(190, -1),

View File

@ -36,6 +36,8 @@ $a ** $b ** $c;
yield from $a and yield from $b;
yield from ($a and yield from $b);
print ($a and print $b);
// The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment
// and incdec only work on variables.
!$a = $b;
@ -67,6 +69,7 @@ $a ** $b ** $c;
-1 ** 2;
yield from $a and yield from $b;
yield from ($a and yield from $b);
print ($a and print $b);
// The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment
// and incdec only work on variables.
!($a = $b);