public function write($mask)
{
$mask = preg_replace('#%(node|\\d+)\\.#', '%$1_', $mask);
$mask = preg_replace_callback('#%escape(\\(([^()]*+|(?1))+\\))#', function ($m) {
return $this->escapePass(new MacroTokens(substr($m[1], 1, -1)))->joinAll();
}, $mask);
$mask = preg_replace_callback('#%modify(Content)?(\\(([^()]*+|(?2))+\\))#', function ($m) {
return $this->formatModifiers(substr($m[2], 1, -1), (bool) $m[1]);
}, $mask);
$args = func_get_args();
$pos = $this->tokens->position;
$word = strpos($mask, '%node_word') === FALSE ? NULL : $this->tokens->fetchWord();
$code = preg_replace_callback('#([,+]\\s*)?%(node_|\\d+_|)(word|var|raw|array|args)(\\?)?(\\s*\\+\\s*)?()#', function ($m) use($word, &$args) {
list(, $l, $source, $format, $cond, $r) = $m;
switch ($source) {
case 'node_':
$arg = $word;
break;
case '':
$arg = next($args);
break;
default:
$arg = $args[(int) $source + 1];
break;
}
switch ($format) {
case 'word':
$code = $this->formatWord($arg);
break;
case 'args':
$code = $this->formatArgs();
break;
case 'array':
$code = $this->formatArray();
$code = $cond && $code === '[]' ? '' : $code;
break;
case 'var':
$code = var_export($arg, TRUE);
break;
case 'raw':
$code = (string) $arg;
break;
}
if ($cond && $code === '') {
return $r ? $l : $r;
} else {
return $l . $code . $r;
}
}, $mask);
$this->tokens->position = $pos;
return $code;
}