/** * Syntax $entry in [item1, item2]. * @return MacroTokens */ public function inOperatorPass(MacroTokens $tokens) { while ($tokens->nextToken()) { if ($tokens->isCurrent($tokens::T_VARIABLE)) { $start = $tokens->position; $depth = $tokens->depth; $expr = $arr = []; $expr[] = $tokens->currentToken(); while ($tokens->isNext($tokens::T_VARIABLE, $tokens::T_SYMBOL, $tokens::T_NUMBER, $tokens::T_STRING, '[', ']', '(', ')', '->') && !$tokens->isNext('in')) { $expr[] = $tokens->nextToken(); } if ($depth === $tokens->depth && $tokens->nextValue('in') && ($arr[] = $tokens->nextToken('['))) { while ($tokens->isNext()) { $arr[] = $tokens->nextToken(); if ($tokens->isCurrent(']') && $tokens->depth === $depth) { $new = array_merge($tokens->parse('in_array('), $expr, $tokens->parse(', '), $arr, $tokens->parse(', TRUE)')); array_splice($tokens->tokens, $start, $tokens->position - $start + 1, $new); $tokens->position = $start + count($new) - 1; continue 2; } } } $tokens->position = $start; } } return $tokens->reset(); }