1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-02 09:17:58 +01:00
PHP-Parser/test/code/prettyPrinter
nikic ac6f221c50 Better prededence and associativity handling in pretty printer
Previously the pretty printer added unnecessary and odd-looking parentheses
when several operators with the same precedence were chained:

    'a' . 'b' . 'c' . 'd' . 'e'
    // was printed as
    'a' . ('b' . ('c' . ('d' . 'e')))

Another issue reported as part of #39 was that assignments inside closures
were wrapped in parentheses:

    function() {
        $a = $b;
    }
    // was printed as
    function() {
        ($a = $b);
    }

This was caused by the automatic precedence handling, which just regarded
the closure as an ordinal nested expression.

With the new system the $predenceMap of PrettyPrinterAbstract contains both
precedence and associativity and there is a new method pPrec() which prints
a node taking precedence and associativity into account.

For simpler usage there are additional function pInfixOp(), pPrefixOp() and
pPostfixOp().

Prints not going through pPrec() do not have any precedence handling (fixing
the closure issue).
2012-10-31 17:34:06 +01:00
..
closure.test Better prededence and associativity handling in pretty printer 2012-10-31 17:34:06 +01:00
comments.test Insert comments when pretty printing 2012-05-11 16:18:14 +02:00
parentheses.test Better prededence and associativity handling in pretty printer 2012-10-31 17:34:06 +01:00