• Модуль: perfmon
  • Путь к файлу: ~/bitrix/modules/perfmon/classes/general/sql_format.php
  • Класс: CSqlTokenizer
  • Вызов: CSqlTokenizer::parse
function parse($sql)
{
	$this->tokens = token_get_all("tokens);
	$this->current = 0;

	while (isset($this->tokens[$this->current]))
	{
		//Remove excessive brackets
		if (
			$this->tokens[$this->current] === "("
			&& $this->lookForwardFor("(")
		)
		{
			if ($this->removeBalancedBrackets())
				continue;
		}

		//Remove following spaces
		if ($this->tokens[$this->current][0] === T_WHITESPACE && $this->tokens[$this->current - 1][0] === T_WHITESPACE)
		{
			array_splice($this->tokens, $this->current, 1);
			continue;
		}

		$this->tokens[$this->current] = $this->transform($this->tokens[$this->current]);
		$this->current++;
	}

	//Remove leading spaces
	while (
		isset($this->tokens[0])
		&& $this->tokens[0][0] === T_WHITESPACE
	)
	{
		array_splice($this->tokens, 0, 1);
	}

	//Remove trailing spaces
	while (
		!empty($this->tokens)
		&& $this->tokens[count($this->tokens) - 1][0] === T_WHITESPACE
	)
	{
		array_splice($this->tokens, -1, 1);
	}

	return $this->tokens;
}