public function __toString()
{
if (null === $this->code) {
return 'unknown';
}
switch ($this->code) {
case NativeQuackType::T_STR:
return 'string';
case NativeQuackType::T_INT:
return 'integer';
case NativeQuackType::T_DOUBLE:
return 'double';
case NativeQuackType::T_BOOL:
return 'boolean';
case NativeQuackType::T_ATOM:
return 'atom';
case NativeQuackType::T_REGEX:
return 'regex';
case NativeQuackType::T_LIST:
return "list.of({$this->subtype})";
case NativeQuackType::T_LAZY:
return '?';
case NativeQuackType::T_BLOCK:
return 'block';
case NativeQuackType::T_ENUM:
return 'enum.of(' . $this->subtype . ')';
case NativeQuackType::T_OBJ:
// TODO: Implement indent-level for types
$space = sizeof($this->props) > 0 ? " " : "";
$src = "object.of(?).with {{$space}";
foreach ($this->props as $key => $value) {
$src .= "{$key} :: {$value}";
// When is not the last one, append comma
if ($key !== key(array_slice($this->props, -1, 1, true))) {
$src .= ', ';
}
}
$src .= "{$space}}";
return $src;
case NativeQuackType::T_MAP:
return "map.of({$this->subtype['key']} -> {$this->subtype['value']})";
default:
return 'unknown';
}
}