Pretty prints an array of statements.
public prettyPrint ( array $stmts ) : string | ||
$stmts | array | Array of statements |
Résultat | string | Pretty printed statements |
/** * Prints information about a single recursive call. Override to change format. * * @param RecursiveCall $call */ public function printSingleRecursiveCall(RecursiveCall $call) { // Get the code for the recursive call, but strip out comment lines $code = $this->nodePrinter->prettyPrint(array($call->getUsageNode())); $code = implode("\n", array_filter(explode("\n", $code), function ($line) { return !preg_match('#^[\\t ]*//#', $line); })); // Create the output that indicates where the recursive call was found echo "LOCATED IN FILE: " . $call->getFile()->getRealPath() . "\n"; echo "DECLARED ON LINE #" . $call->getDeclarationNode()->getLine() . " "; echo "AND CALLED ON LINE #" . $call->getUsageNode()->getLine() . "\n"; echo "CALLING CODE: {$code}\n\n"; }
private function recursiveStructParse(Node $stmts, $isNestedKeysName, $parentKey = null) { $pattern = []; $previousKey = null; /** @var Node $var */ foreach ($stmts->vars as $var) { if ($var->getType() === 'Expr_Variable') { list($current, $parent) = $this->parseKeyName($var->name, $isNestedKeysName); $pattern[$current] = null; if ($isNestedKeysName && !is_null($parentKey)) { $previousKey = $current; } else { $previousKey = $var->name; } } elseif ($var->getType() === 'Expr_List' && !is_null($previousKey)) { $pattern[$previousKey] = $this->recursiveStructParse($var, $isNestedKeysName, $previousKey); } elseif ($var->getType() === 'Expr_List' && is_null($previousKey)) { throw new \Exception("Parsing list(): syntax error. Nested list() without key. Code: " . $this->prettyPrinter->prettyPrint($var)); } } return $pattern; }
public function prettyPrint(array $stmts) { $output = ""; $output .= "digraph G {\n"; $output .= " rankdir=LR;\n"; $output .= " node [shape=record];\n"; $output .= "\n"; $output .= parent::prettyPrint($stmts); $output .= "\n"; $output .= "\n"; $output .= "}\n"; return $output; }
/** * @param Node $node * * @return string */ private function getSource(Node $node) { return $this->printer->prettyPrint([$node]); }