/** * Quotes symbols to strings. * @return MacroTokens */ public function quoteFilter(MacroTokens $tokens) { $res = new MacroTokens(); while ($tokens->nextToken()) { $res->append($tokens->isCurrent(MacroTokens::T_SYMBOL) && (!$tokens->isPrev() || $tokens->isPrev(',', '(', '[', '=>', ':', '?', '.', '<', '>', '<=', '>=', '===', '!==', '==', '!=', '<>', '&&', '||', '=', 'and', 'or', 'xor', '??')) && (!$tokens->isNext() || $tokens->isNext(',', ';', ')', ']', '=>', ':', '?', '.', '<', '>', '<=', '>=', '===', '!==', '==', '!=', '<>', '&&', '||', 'and', 'or', 'xor', '??')) ? "'" . $tokens->currentValue() . "'" : $tokens->currentToken()); } return $res; }
private function inlineModifiersFilterInner(MacroTokens $tokens) { $isFunctionOrArray = $tokens->isPrev(MacroTokens::T_VARIABLE, MacroTokens::T_SYMBOL) || $tokens->isCurrent('['); $result = new MacroTokens(); $args = new MacroTokens(); $modifiers = new MacroTokens(); $current = $args; $anyModifier = FALSE; $result->append($tokens->currentToken()); while ($tokens->nextToken()) { if ($tokens->isCurrent('(', '[')) { $current->tokens = array_merge($current->tokens, $this->inlineModifiersFilterInner($tokens)); } elseif ($current !== $modifiers && $tokens->isCurrent('|')) { $anyModifier = TRUE; $current = $modifiers; } elseif ($tokens->isCurrent(')', ']') || $isFunctionOrArray && $tokens->isCurrent(',')) { $partTokens = count($modifiers->tokens) ? $this->modifiersFilter($modifiers, $args->tokens)->tokens : $args->tokens; $result->tokens = array_merge($result->tokens, $partTokens); if ($tokens->isCurrent(',')) { $result->append($tokens->currentToken()); $args = new MacroTokens(); $modifiers = new MacroTokens(); $current = $args; continue; } elseif ($isFunctionOrArray || !$anyModifier) { $result->append($tokens->currentToken()); } else { array_shift($result->tokens); } return $result->tokens; } else { $current->append($tokens->currentToken()); } } throw new CompileException('Unbalanced brackets.'); }