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);
}