Commit 30949d59 authored by Pietro Saccardi's avatar Pietro Saccardi

Added fancy tree representation

parent 8e8a6d7b
......@@ -134,20 +134,23 @@ class ElementInstance {
}
}
public function printTree($indent=0) {
public function printTree($indentStr='', $isLastChild=false) {
static $stack_depth = 0; global $STACK_LIMIT;
if (++$stack_depth > $STACK_LIMIT) {
throw new RuntimeException('Stack limit exceeded.');
}
try {
if ($this->definition() !== null) {
echo str_repeat(' ', $indent) . $this->definition()->name() . "\n";
echo $indentStr . '+-' . $this->definition()->name() . "\n";
}
$extraIndentStr = ($isLastChild ? ' ' : '| ');
$argIdx = 0;
foreach ($this->args() as $arg) {
++$argIdx;
if ($arg instanceof TokenInstance) {
echo str_repeat(' ', $indent + 1) . $arg;
echo $indentStr . $extraIndentStr . '+-' . $arg;
} else {
$arg->printTree($indent + 1);
$arg->printTree($indentStr . $extraIndentStr, $argIdx == count($this->args()));
}
}
} finally {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment