PrettyPrinter
in
Table of Contents
Methods
- prettyPrint() : string
- Pretty prints an array of statements.
- prettyPrintExpr() : string
- Pretty prints an expression.
- prettyPrintFile() : string
- Pretty prints a file of statements (includes the opening <?php tag if it is required).
- printFormatPreserving() : string
- Perform a format-preserving pretty print of an AST.
Methods
prettyPrint()
Pretty prints an array of statements.
public
prettyPrint(array<string|int, Node> $stmts) : string
Parameters
- $stmts : array<string|int, Node>
-
Array of statements
Return values
string —Pretty printed statements
prettyPrintExpr()
Pretty prints an expression.
public
prettyPrintExpr(Expr $node) : string
Parameters
- $node : Expr
-
Expression node
Return values
string —Pretty printed node
prettyPrintFile()
Pretty prints a file of statements (includes the opening <?php tag if it is required).
public
prettyPrintFile(array<string|int, Node> $stmts) : string
Parameters
- $stmts : array<string|int, Node>
-
Array of statements
Return values
string —Pretty printed statements
printFormatPreserving()
Perform a format-preserving pretty print of an AST.
public
printFormatPreserving(array<string|int, Node> $stmts, array<string|int, Node> $origStmts, array<string|int, Token> $origTokens) : string
The format preservation is best effort. For some changes to the AST the formatting will not be preserved (at least not locally).
In order to use this method a number of prerequisites must be satisfied:
- The startTokenPos and endTokenPos attributes in the lexer must be enabled.
- The CloningVisitor must be run on the AST prior to modification.
- The original tokens must be provided, using the getTokens() method on the lexer.
Parameters
- $stmts : array<string|int, Node>
-
Modified AST with links to original AST
- $origStmts : array<string|int, Node>
-
Original AST with token offset information
- $origTokens : array<string|int, Token>
-
Tokens of the original code