public function expandCastPass(MacroTokens $tokens)
{
$res = new MacroTokens('[');
$expand = NULL;
while ($tokens->nextToken()) {
if ($tokens->isCurrent('(expand)') && $tokens->depth === 0) {
$expand = TRUE;
$res->append('],');
} elseif ($expand && $tokens->isCurrent(',') && !$tokens->depth) {
$expand = FALSE;
$res->append(', [');
} else {
$res->append($tokens->currentToken());
}
}
if ($expand === NULL) {
$res->append(']');
} else {
$res->prepend('array_merge(')->append($expand ? ', [])' : '])');
}
return $res;
}