Since PHP 7.0 yield is a proper expression, so print it with
proper precedence. If the pretty printer is configured for
older version (non-default), then always print parentheses.
There is an interesting interaction here, in that => is resolved
in favor of yield if the yield occurs as part of an array (or
outer yield). This kind of bypasses the entire precedence hierarchy
and *only* affects yield expressions. For the sake of simplicity
this is modeled via normal LHS precedence, because this will only
add unnecessary parentheses to a handful of low precedence unary
operators. If desired, a special marker for this purpose could be
added though.
The pretty printer is supposed to produce a minimal-parentheses
printing for expressions. However, for prefix operators, we were
failing to do so in ways that are practically meaningful, e.g.
$a = yield from $b produced redundant parentheses around the
yield from.
For prefix operators, the precedence of the direct parent operator
is not actually relevant: What matters is the precedence of any
infix operator whose LHS it appears on. For example, $a . include $b
does not require parentheses, but (include $a) . $b does.
To handle this, keep separate track of the parent operator
precedence, and a special LHS precedence which is used for unary
operator printing only. Because the LHS precedence may not come
from the direct parent, we have to pass it down the call stack.
And if we do that, we may as well do the same for the parent
precedence.
This also fixes an integration test failure with php-src, because
arrow function precedence was previously not respected (and would
be ugly to respect without this change).
If dropping a node would drop PHP tags, bail out of formatting
preservation. This will lose formatting, but at least produce
legal code.
Closes GH-884.
The formatting in this project has become something of a mess,
because it changed over time. Add a CS fixer config and reformat
to the desired style, which is PSR-12, but with sane brace placement.
This is currently just used to initialize the default for short
array syntax.
The default target version in 7.0, which also means that the
default for short arrays is flipped to on.
Instead of checking whether there is a {/} before/after the removed
note, check whether {/} occurs in the between-node range. Dropping
that is what we're really concerned about here.