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++; }
/** * If as {@link Syntax} node comes around the visitor will be initializez. * Which means that the depth property is read, the matrix and level properties * will be initialized. All other {@link Node} types increment the level property. * * @param Node $visitable Visited node. * * @return void */ public function beforeVisit(Node $visitable) { if ($visitable instanceof Syntax) { $this->depth = $visitable->depth(); $this->matrix = array(); $this->level = 0; } else { $this->level++; } // While we're visiting the output will change anyway. $this->text = null; }
/** * 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())); } }