public static function nodeToString($node, $name = null, int $indent = 0) : string
{
$string = str_repeat("\t", $indent);
if ($name !== null) {
$string .= "{$name} => ";
}
if (is_string($node)) {
return $string . $node . "\n";
}
if (!$node) {
return $string . 'null' . "\n";
}
if (!is_object($node)) {
return $string . $node . "\n";
}
$string .= \ast\get_kind_name($node->kind);
$string .= ' [' . self::astFlagDescription($node->flags ?? 0) . ']';
if (isset($node->lineno)) {
$string .= ' #' . $node->lineno;
}
if ($node instanceof Decl) {
if (isset($node->endLineno)) {
$string .= ':' . $node->endLineno;
}
}
if (isset($node->name)) {
$string .= ' name:' . $node->name;
}
$string .= "\n";
foreach ($node->children ?? [] as $name => $child_node) {
$string .= self::nodeToString($child_node, $name, $indent + 1);
}
return $string;
}