Commit Graph

14 Commits

Author SHA1 Message Date
nikic
fc56da59ce Rename pSafe to pNoIndent
Matches the function more closely
2012-10-31 17:50:54 +01:00
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
nikic
81e53ce0ff Insert comments when pretty printing
This changset also adds unit tests for Comments and adds a way to test the
pretty printer.
2012-05-11 16:18:14 +02:00
nikic
9ed77427a2 Rename Expr_List to Expr_AssignList 2011-10-16 14:49:13 +02:00
nikic
43f9c37c7f Add operator precedence for list() assignments 2011-10-16 14:44:39 +02:00
nikic
ea65ea7a32 Make some doc comments more precise
Additionally add two further constructors
2011-09-23 18:45:29 +02:00
nikic
a551bbc5a4 Add PHPParser_Node interface 2011-09-21 21:43:19 +02:00
nikic
e0fe21287d Add specialized constructors for all expression nodes apart from lambda 2011-08-11 10:25:51 +02:00
nikic
22b507e9f4 Rename Bin[ary] to Bitwise (which is the correct name) 2011-08-11 08:42:28 +02:00
nikic
ffecbf8ca5 Let the pretty printing methods for statements decide for themselves whether or not they add a semicolon. Only automatically add semicolons for expressions. 2011-08-04 18:44:21 +02:00
nikic
684a638f46 Add possibility to pretty print expressions to PrettyPrinter 2011-08-04 18:19:45 +02:00
nikic
78f15cd50b Associate last encountered doccomment with next node 2011-07-03 16:35:45 +02:00
nikic
fb45e8a30c Put statements belonging to a namespace statement into its stmt property, add some further checks against invalid namespace usage and fix the pretty printer to print global namespaces 2011-06-26 18:41:01 +02:00
nikic
620525a5da Prefix all classes with PHPParser_ 2011-06-05 18:40:04 +02:00