Пример #1
0
 public function visit(Node $visitable)
 {
     // node format
     if ($visitable instanceof Terminal || $visitable instanceof Identifier) {
         $this->leafFormatDecl .= " n{$this->currentNumber};";
     } else {
         $this->nodeFormatDecl .= " n{$this->currentNumber};";
     }
     // node decl
     if ($visitable instanceof Terminal || $visitable instanceof Identifier) {
         $label = "{{$visitable->getNodeName()}|" . addcslashes($visitable->value, '"{}|') . "}";
     } else {
         if ($visitable instanceof Rule) {
             $label = "{{$visitable->getNodeName()}|{$visitable->name}}";
         } else {
             $label = $visitable->getNodeName();
         }
     }
     $this->nodeDecl .= "    n{$this->currentNumber} [label=\"{$label}\"];" . PHP_EOL;
     // collect for edge decl
     $this->idNodeMap[$this->currentNumber] = $visitable;
     // next
     $this->currentNumber++;
 }
Пример #2
0
 /**
  * Formats nodes two strings.
  *
  * {@link Rule}, {@link Terminal} ans {@link Identifier} nodes will be
  * rendered with their attributes name or value.
  *
  * @param Node $n Formatted node.
  *
  * @return string
  */
 public static function formatNode(Node $n)
 {
     $text = "[{$n->getNodeName()}";
     if ($n instanceof Rule && !empty($n->name)) {
         $text .= "='{$n->name}'";
     } else {
         if ($n instanceof Terminal || $n instanceof Identifier) {
             if (!empty($n->value)) {
                 $text .= "='{$n->value}'";
             }
         }
     }
     $text .= "]";
     return $text;
 }
Пример #3
0
 /**
  * Generates closing tags for composite nodes.
  *
  * @param Node $visitable Visited node.
  *
  * @return void
  */
 public function afterVisit(Node $visitable)
 {
     if ($visitable instanceof Composite && $visitable->hasChildren()) {
         $this->indentationLevel--;
         $this->append("\n" . $this->indent() . self::createCloseTag($visitable->getNodeName()));
     }
 }