PhpParser\Lexer\Emulative::emulateTokens PHP Method

emulateTokens() protected method

* Emulates tokens for newer PHP versions.
protected emulateTokens ( )
    protected function emulateTokens()
    {
        // We need to manually iterate and manage a count because we'll change
        // the tokens array on the way
        $line = 1;
        for ($i = 0, $c = count($this->tokens); $i < $c; ++$i) {
            $replace = null;
            if (isset($this->tokens[$i + 1])) {
                if ($this->tokens[$i] === '?' && $this->tokens[$i + 1] === '?') {
                    array_splice($this->tokens, $i, 2, array(array(self::T_COALESCE, '??', $line)));
                    $c--;
                    continue;
                }
                if ($this->tokens[$i][0] === T_IS_SMALLER_OR_EQUAL && $this->tokens[$i + 1] === '>') {
                    array_splice($this->tokens, $i, 2, array(array(self::T_SPACESHIP, '<=>', $line)));
                    $c--;
                    continue;
                }
                if ($this->tokens[$i] === '*' && $this->tokens[$i + 1] === '*') {
                    array_splice($this->tokens, $i, 2, array(array(self::T_POW, '**', $line)));
                    $c--;
                    continue;
                }
                if ($this->tokens[$i] === '*' && $this->tokens[$i + 1][0] === T_MUL_EQUAL) {
                    array_splice($this->tokens, $i, 2, array(array(self::T_POW_EQUAL, '**=', $line)));
                    $c--;
                    continue;
                }
            }
            if (isset($this->tokens[$i + 2])) {
                if ($this->tokens[$i][0] === T_YIELD && $this->tokens[$i + 1][0] === T_WHITESPACE && $this->tokens[$i + 2][0] === T_STRING && !strcasecmp($this->tokens[$i + 2][1], 'from')) {
                    array_splice($this->tokens, $i, 3, array(array(self::T_YIELD_FROM, $this->tokens[$i][1] . $this->tokens[$i + 1][1] . $this->tokens[$i + 2][1], $line)));
                    $c -= 2;
                    $line += substr_count($this->tokens[$i][1], "\n");
                    continue;
                }
                if ($this->tokens[$i] === '.' && $this->tokens[$i + 1] === '.' && $this->tokens[$i + 2] === '.') {
                    array_splice($this->tokens, $i, 3, array(array(self::T_ELLIPSIS, '...', $line)));
                    $c -= 2;
                    continue;
                }
            }
            if (\is_array($this->tokens[$i])) {
                $line += substr_count($this->tokens[$i][1], "\n");
            }
        }
    }