Ejemplo n.º 1
0
 /**
  * {var ...}
  * {default ...}
  */
 public function macroVar(MacroNode $node, PhpWriter $writer)
 {
     if ($node->modifiers) {
         trigger_error("Modifiers are not allowed in {{$node->name}}", E_USER_WARNING);
     }
     if ($node->args === '' && $node->parentNode && $node->parentNode->name === 'switch') {
         return '} else {';
     }
     $var = TRUE;
     $tokens = $writer->preprocess();
     $res = new Latte\MacroTokens();
     while ($tokens->nextToken()) {
         if ($var && $tokens->isCurrent(Latte\MacroTokens::T_SYMBOL, Latte\MacroTokens::T_VARIABLE)) {
             if ($node->name === 'default') {
                 $res->append("'" . ltrim($tokens->currentValue(), '$') . "'");
             } else {
                 $res->append('$' . ltrim($tokens->currentValue(), '$'));
             }
             $var = NULL;
         } elseif ($tokens->isCurrent('=', '=>') && $tokens->depth === 0) {
             $res->append($node->name === 'default' ? '=>' : '=');
             $var = FALSE;
         } elseif ($tokens->isCurrent(',') && $tokens->depth === 0) {
             if ($var === NULL) {
                 $res->append($node->name === 'default' ? '=>NULL' : '=NULL');
             }
             $res->append($node->name === 'default' ? ',' : ';');
             $var = TRUE;
         } elseif ($var === NULL && $node->name === 'default' && !$tokens->isCurrent(Latte\MacroTokens::T_WHITESPACE)) {
             throw new CompileException("Unexpected '{$tokens->currentValue()}' in {default {$node->args}}");
         } else {
             $res->append($tokens->currentToken());
         }
     }
     if ($var === NULL) {
         $res->append($node->name === 'default' ? '=>NULL' : '=NULL');
     }
     $out = $writer->quoteFilter($res)->joinAll();
     return $node->name === 'default' ? "extract(array({$out}), EXTR_SKIP)" : $out;
 }