PhpCss\Parser::lookahead PHP Method

lookahead() protected method

This method tries to match the current token stream at the provided lookahead position against all of the provided tokens. If a match is found it simply returned. The token stream remains unchanged. If no match can be found a PhpCssParserException will thrown indicating what has been expected and what was found. The $expectedTokens parameter may be an array of tokens or a scalar value, which is handled the same way an array with only one entry would be. The special Token Scanner\Token::ANY may be used to indicate everything is valid and may be matched. However if it is used no other token may be specified, which does not make any sense, anyway. The position parameter may be provided to enforce a match on an arbitrary token stream position. Therefore unlimited lookahead is provided.
protected lookahead ( array | integer | string $expectedTokens, integer $position, boolean $allowEndOfTokens = FALSE ) : Token | null
$expectedTokens array | integer | string
$position integer
$allowEndOfTokens boolean
return PhpCss\Scanner\Token | null
    protected function lookahead($expectedTokens, $position = 0, $allowEndOfTokens = FALSE)
    {
        // Allow scalar token values for better readability
        if (!is_array($expectedTokens)) {
            return $this->lookahead(array($expectedTokens), $position, $allowEndOfTokens);
        }
        // If the the requested characters is not available on the token stream
        // and this state is allowed return a special ANY token
        if ($allowEndOfTokens === TRUE && !isset($this->_tokens[$position])) {
            return new Scanner\Token(Scanner\Token::ANY, '', 0);
        }
        foreach ($expectedTokens as $token) {
            if ($this->matchToken($position, $token)) {
                return $this->_tokens[$position];
            }
        }
        // None of the given tokens matched
        throw $this->handleMismatch($expectedTokens, $position);
    }