2012-10-31 17:34:06 +01:00
|
|
|
Pretty printer generates least-parentheses output
|
|
|
|
-----
|
|
|
|
<?php
|
|
|
|
|
|
|
|
echo 'abc' . 'cde' . 'fgh';
|
|
|
|
echo 'abc' . ('cde' . 'fgh');
|
|
|
|
|
|
|
|
echo 'abc' . 1 + 2 . 'fgh';
|
|
|
|
echo 'abc' . (1 + 2) . 'fgh';
|
|
|
|
|
|
|
|
echo 1 * 2 + 3 / 4 % 5 . 6;
|
|
|
|
echo 1 * (2 + 3) / (4 % (5 . 6));
|
|
|
|
|
|
|
|
$a = $b = $c = $d = $f && true;
|
|
|
|
($a = $b = $c = $d = $f) && true;
|
|
|
|
$a = $b = $c = $d = $f and true;
|
|
|
|
$a = $b = $c = $d = ($f and true);
|
|
|
|
|
|
|
|
$a ? $b : $c ? $d : $e ? $f : $g;
|
|
|
|
$a ? $b : ($c ? $d : ($e ? $f : $g));
|
|
|
|
$a ? $b ? $c : $d : $f;
|
|
|
|
|
2015-03-12 22:45:38 +01:00
|
|
|
$a ?? $b ?? $c;
|
|
|
|
($a ?? $b) ?? $c;
|
|
|
|
$a ?? ($b ? $c : $d);
|
|
|
|
$a || ($b ?? $c);
|
|
|
|
|
2012-10-31 17:34:06 +01:00
|
|
|
(1 > 0) > (1 < 0);
|
2015-01-18 19:57:09 +01:00
|
|
|
++$a + $b;
|
|
|
|
$a + $b++;
|
2012-10-31 17:34:06 +01:00
|
|
|
|
2014-03-26 19:18:16 +01:00
|
|
|
$a ** $b ** $c;
|
|
|
|
($a ** $b) ** $c;
|
2015-01-18 19:57:09 +01:00
|
|
|
-1 ** 2;
|
2014-03-26 19:18:16 +01:00
|
|
|
|
2015-04-26 11:46:23 +02:00
|
|
|
yield from $a and yield from $b;
|
|
|
|
yield from ($a and yield from $b);
|
|
|
|
|
2015-04-26 11:52:40 +02:00
|
|
|
print ($a and print $b);
|
|
|
|
|
2018-01-25 22:16:11 +01:00
|
|
|
-(-$a);
|
|
|
|
+(+$a);
|
2018-01-25 22:27:37 +01:00
|
|
|
-(--$a);
|
|
|
|
+(++$a);
|
2018-01-25 22:16:11 +01:00
|
|
|
|
2015-01-18 19:57:09 +01:00
|
|
|
// The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment
|
|
|
|
// and incdec only work on variables.
|
2012-10-31 17:34:06 +01:00
|
|
|
!$a = $b;
|
2015-01-18 19:57:09 +01:00
|
|
|
++$a ** $b;
|
|
|
|
$a ** $b++;
|
2012-10-31 17:34:06 +01:00
|
|
|
-----
|
|
|
|
echo 'abc' . 'cde' . 'fgh';
|
|
|
|
echo 'abc' . ('cde' . 'fgh');
|
|
|
|
echo 'abc' . 1 + 2 . 'fgh';
|
|
|
|
echo 'abc' . (1 + 2) . 'fgh';
|
|
|
|
echo 1 * 2 + 3 / 4 % 5 . 6;
|
|
|
|
echo 1 * (2 + 3) / (4 % (5 . 6));
|
|
|
|
$a = $b = $c = $d = $f && true;
|
|
|
|
($a = $b = $c = $d = $f) && true;
|
|
|
|
$a = $b = $c = $d = $f and true;
|
|
|
|
$a = $b = $c = $d = ($f and true);
|
|
|
|
$a ? $b : $c ? $d : $e ? $f : $g;
|
|
|
|
$a ? $b : ($c ? $d : ($e ? $f : $g));
|
|
|
|
$a ? $b ? $c : $d : $f;
|
2015-03-12 22:45:38 +01:00
|
|
|
$a ?? $b ?? $c;
|
|
|
|
($a ?? $b) ?? $c;
|
|
|
|
$a ?? ($b ? $c : $d);
|
|
|
|
$a || ($b ?? $c);
|
2012-10-31 17:34:06 +01:00
|
|
|
(1 > 0) > (1 < 0);
|
2015-01-18 19:57:09 +01:00
|
|
|
++$a + $b;
|
|
|
|
$a + $b++;
|
2014-03-26 19:18:16 +01:00
|
|
|
$a ** $b ** $c;
|
|
|
|
($a ** $b) ** $c;
|
2015-01-18 19:57:09 +01:00
|
|
|
-1 ** 2;
|
2015-04-26 11:46:23 +02:00
|
|
|
yield from $a and yield from $b;
|
|
|
|
yield from ($a and yield from $b);
|
2015-04-26 11:52:40 +02:00
|
|
|
print ($a and print $b);
|
2018-01-25 22:16:11 +01:00
|
|
|
-(-$a);
|
|
|
|
+(+$a);
|
2018-01-25 22:27:37 +01:00
|
|
|
-(--$a);
|
|
|
|
+(++$a);
|
2015-01-18 19:57:09 +01:00
|
|
|
// The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment
|
|
|
|
// and incdec only work on variables.
|
|
|
|
!($a = $b);
|
|
|
|
(++$a) ** $b;
|
|
|
|
$a ** ($b++);
|