Finds the variable name of the object for the method call
that is currently being processed.

@param  array   $tokens
@param  integer $start
@return mixed
486040
protected function findVariableName(array $tokens, $start) {
        for ($i = $start - 1; $i >= 0; $i--) {
            if (is_array($tokens[$i]) && $tokens[$i][0] == T_VARIABLE) {
                $variable = $tokens[$i][1];

                if (is_array($tokens[$i+1]) &&
                    $tokens[$i+1][0] == T_OBJECT_OPERATOR &&
                    $tokens[$i+2] != '(' &&
                    $tokens[$i+3] != '(') {
                    $variable .= '->' . $tokens[$i+2][1];
                }

                return $variable;
            }
        }

        return false;
    }
368381
public function isNextTokenAny(array $tokenNames)
    {
        return null !== $this->lookahead && in_array($this->lookahead->getName(), $tokenNames, true);
    }
342066
protected function expandNames(array & $tokens, NamespaceContext $context)
	{
		// Expand name if one of these tokens is found before the name.
		static $beforeTokens = [
			T_NEW, // Object instantiation
			T_INSTANCEOF // Instanceof check
		];
		
		// Expand name if one of these tokens is found after the name
		static $afterTokens = [
			T_DOUBLE_COLON, // Static access or class constant lookup
			T_VARIABLE // Type-hinted function / method argument
		];
		
		$count = count($tokens) - 1;
		$buffer = '';
		
		for($size = count($tokens), $i = 0; $i < $size; $i++)
		{
			if(is_array($tokens[$i]) && ($tokens[$i][0] == T_STRING || $tokens[$i][0] == T_NS_SEPARATOR))
			{
				$pos = $i;
				$before = $pos - 1;
				$after = $pos + 1;
				$name = $tokens[$i][1];
				
				$i++;
				
				// Read name with namespace parts if needed.
				for(; $i < $size; $i++)
				{
					if(is_array($tokens[$i]))
					{
						switch($tokens[$i][0])
						{
							case T_WHITESPACE:
							case T_COMMENT:
							case T_DOC_COMMENT:
								continue 2;
							case T_NS_SEPARATOR:
							case T_STRING:
								$name .= $tokens[$i][1];
								continue 2;
						}
					}
					
					break;
				}
				
				// Read first significant token before the name.
				$prev = NULL;
				while($before >= 0)
				{
					$prev = $tokens[$before];
					
					if(is_array($prev))
					{
						switch($prev[0])
						{
							case T_WHITESPACE:
							case T_COMMENT:
							case T_DOC_COMMENT:
								$before--;
								continue 2;
						}
					}
					
					break;
				}
				
				// Read first significant token after the name.
				$next = NULL;
				while($after < $count)
				{
					$next = $tokens[$after];
						
					if(is_array($next))
					{
						switch($next[0])
						{
							case T_WHITESPACE:
							case T_COMMENT:
							case T_DOC_COMMENT:
								$after++;
								continue 2;
						}
					}
						
					break;
				}
				
				// Expand names as needed.
				$expand = false;
				
				if(is_array($prev) && in_array($prev[0], $beforeTokens))
				{
					$expand = true;
				}
				
				if(is_array($next) && in_array($next[0], $afterTokens))
				{
					$expand = true;
				}
				
				if($expand)
				{
					$buffer .= '\\' . ltrim($context->lookup($name), '\\');
				}
				else
				{
					$buffer .= $name;
				}
			}
			
			if(is_array($tokens[$i]))
			{
				$buffer .= $tokens[$i][1];
			}
			else
			{
				$buffer .= $tokens[$i];
			}
		}
		
		return $buffer;
	}
448134
public function apply(array &$tokens)
		{
		$r = 0;
		for ($i = 0, $l = count($tokens); $i < $l; $i++)
			{
			if (get_class($tokens[$i]) === "CssCommentToken")
				{
				$tokens[$i] = null;
				$r++;
				}
			}
		return $r;
		}
778472
private void findTokens() {
        mergedTokens = new TokenList();
        variable = null;
        state = TokenizerState.START;
        index = -1;

        while (index < rawTokens.length) {
            switch (state) {
            case START:
                next(TokenizerState.OUTSIDE_VARIABLE_CONTEXT);
                break;
            case OUTSIDE_VARIABLE_CONTEXT:
                handleTokenOutsideOfVariableContext();
                break;
            case INSIDE_VARIABLE_CONTEXT:
                handleTokenInsideOfVariableContext();
                break;
            default:
                break;
            }
        }
    }
383803
public function peekWhileTokens(array $tokenNames)
    {
        while ($token = $this->peek()) {
            if (!in_array($token->getName(), $tokenNames, true)) {
                break;
            }
        }

        return $token;
    }
693297
public static function to_assoc($start = 1)
	{
		$segments = array_slice(static::segments(), ($start - 1));
		count($segments) % 2 and $segments[] = null;

		return \Arr::to_assoc($segments);
	}
403468
private function getQueryNorm($tokens)
    {
        $db = $this->getSearchDbHandle();
        $db->/** @scrutinizer ignore-call */
        sqliteCreateFunction('sqrt', 'sqrt', 1);
        foreach ($tokens as $key => $token) {
            $tokens[$key] = $db->quote($token);
        }
        $terms = implode(',', $tokens);
        $sql = '
			SELECT (1 / sqrt(SUM(inverseDocumentFrequency))) AS queryNorm
			  FROM inverse_document_frequency
			 WHERE term IN (' . $terms . ') 
		';
        if (!$stmt = $db->prepare($sql)) {
            throw new \RuntimeException('SQLite exception: <pre>' . print_r($db->errorInfo(),
                    true) . '</pre> for SQL:<pre>' . $sql . '</pre>');
        }
        if (!$stmt->execute()) {
            throw new \RuntimeException('SQLite exception: <pre>' . print_r($db->errorInfo(),
                    true) . '</pre> for SQL:<pre>' . $sql . '</pre>');
        }
        $result = $stmt->fetch(\PDO::FETCH_OBJ);
        return $result->queryNorm == null ? 1 : $result->queryNorm;
    }
379876
public function getTokenSelect($fields = '*')
    {
        return $this->_loadClass('Token_TokenSelect', true, array($this->db, $fields, $this->loader->getUtil()));
    }
1072698
protected function getNamespace($key, array $tokens)
    {
        $namespace = null;
        $tokenCount = count($tokens);
        for ($i = $key; $i < $tokenCount; $i++) {
            if ($this->isPartOfNamespace($tokens[$i])) {
                $namespace .= $tokens[$i][1];
            } elseif ($tokens[$i] == ';') {
                return $namespace;
            }
        }
    }
1301945
public static function label($tokenId, array $tokens) {
		$token = $tokens[$tokenId];
		$hasName = in_array($token['id'], array(
			T_FUNCTION,
			T_CLASS,
			T_INTERFACE,
			T_VARIABLE,
		));
		if ($hasName) {
			if ($token['id'] === T_VARIABLE) {
				return substr($token['content'], 1);
			}
			$total = count($tokens);
			for ($key = $tokenId; $key <= $total; $key++) {
				if ($tokens[$key]['id'] === T_STRING) {
					return $tokens[$key]['content'];
				} elseif (in_array($tokens[$key]['content'], array('(', '{', ':'))) {
					break;
				}
			}
		}
		return null;
	}
852672
protected static function parseExpression(TokenIterator $tokens, \ArrayIterator $options) {
        $seq = static::parseSequence($tokens, $options);
        if ($tokens->current() != '|')
            return $seq;

        $result = null;
        if (sizeof($seq) > 1) $result = [new Required($seq)];
        else                  $result = $seq;

        while ($tokens->current() == '|') {
            $tokens->move();
            $seq = static::parseSequence($tokens, $options);
            if (sizeof($seq) > 1) $result[] = new Required($seq);
            else                  $result   = array_merge($result, $seq);
        }

        if (sizeof($result) > 1)
            return new Either($result);
        return $result;
    }
516390
protected function createLocation(Token $start): ?Location
    {
        return !$this->lexer->getOption('noLocation', false)
            ? new Location(
                $start->getStart(),
                $this->lexer->getLastToken()->getEnd(),
                $this->lexer->getSource()
            )
            : null;
    }
788897
private function parseNamespace(\ArrayIterator $tokens)
    {
        // skip to the first string or namespace separator
        $this->skipToNextStringOrNamespaceSeparator($tokens);

        $name = '';
        while ($tokens->valid() && ($tokens->current()[0] === T_STRING || $tokens->current()[0] === T_NS_SEPARATOR)
        ) {
            $name .= $tokens->current()[1];
            $tokens->next();
        }

        return $name;
    }
584498
public function _getPrev(&$tokens, $key, $whatToGet)
    {
        $key--;
        if (!is_array($whatToGet)) $whatToGet = array($whatToGet);
        while (!is_array($tokens[$key]) || !in_array($tokens[$key][0], $whatToGet)) {
            $key--;
            if (!isset($tokens[$key])) return FALSE;
        }

        return $tokens[$key][1];
    }
594549
protected function getNamedCapturesExpressions(array $tokens)
	{
		$exprs = [];
		foreach ($tokens as $token)
		{
			if ($token['type'] !== 'capturingSubpatternStart' || !isset($token['name']))
			{
				continue;
			}

			$expr = $token['content'];
			if (strpos($expr, '|') !== false)
			{
				$expr = '(?:' . $expr . ')';
			}

			$exprs[$token['name']] = $expr;
		}

		return $exprs;
	}
222832
public function parse(array $tokens) : int
    {
        $tokensAvailable = array_flip($this->getGrammar()->getTokens());

        $length = count($tokens);

        if ($length === 0) {
            throw new Exception('Invalid Roman', Exception::INVALID_ROMAN);
        }

        foreach ($tokens as $position => $token) {
            if (! is_string($token)) {
                $exception = new Exception(
                    sprintf('Invalid token type "%s" at position %d', gettype($token), $position),
                    Exception::INVALID_TOKEN_TYPE
                );

                $exception->setPosition($position);

                throw $exception;
            }

            if (! isset($tokensAvailable[$token])) {
                $exception = new Exception(
                    sprintf('Unknown token "%s" at position %d', $token, $position),
                    Exception::UNKNOWN_TOKEN
                );

                $exception
                    ->setToken($token)
                    ->setPosition($position);

                throw $exception;
            }
        }

        return (new Automaton($this->getGrammar()))->read($tokens)->getValue();
    }