private function parseFunction(Lexer $lexer, $delimiter = Lexer::T_COLON, $return = Lexer::T_CLOSE_BRACKET) { $function = null; $arguments = array(); $expected = Lexer::T_STRING; $optional = null; while ($lexer->moveNext()) { $token = $lexer->lookahead; if ($token['type'] === $delimiter || $token['type'] === $return) { return array('function' => $function, 'arguments' => $arguments); } if ($token['type'] !== $expected && $token['type'] !== $optional) { var_dump($token); throw new ProcessorException('Unexpected token' . ', expected ' . $lexer->getLiteral($expected) . ', got ' . $lexer->getLiteral($token['type'])); } $optional = null; // Reset as we passed through switch ($token['type']) { case Lexer::T_STRING: // Function id if ($function === null) { $function = $token['value']; $expected = Lexer::T_OPEN_PARENTHESIS; $optional = null; break; } // Fall for arguments parsing $arguments[] = $token['value']; $expected = Lexer::T_CLOSE_PARENTHESIS; $optional = Lexer::T_COMMA; break; case Lexer::T_COMMA: $expected = Lexer::T_STRING; break; case Lexer::T_OPEN_PARENTHESIS: $expected = Lexer::T_CLOSE_PARENTHESIS; $optional = Lexer::T_STRING; break; case Lexer::T_CLOSE_PARENTHESIS: $expected = $return; $optional = $delimiter; break; } } return array('function' => $function, 'arguments' => $arguments); // IDE fix }