prettyPrint() 공개 메소드

Pretty prints an array of statements.
public prettyPrint ( array $stmts ) : string
$stmts array Array of statements
리턴 string Pretty printed statements
예제 #1
0
 /**
  * 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";
 }
예제 #2
0
 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;
 }
예제 #3
0
 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;
 }
예제 #4
0
 /**
  * @param Node $node
  *
  * @return string
  */
 private function getSource(Node $node)
 {
     return $this->printer->prettyPrint([$node]);
 }