public function expect($primary, $secondary = null)
{
$token = $this->getCurrentToken();
if (is_null($secondary) && !is_int($primary)) {
$secondary = $primary;
$primary = Token::NAME;
}
if (!$token->test($primary, $secondary)) {
if (is_null($secondary)) {
$expecting = Token::getTypeError($primary);
} elseif (is_array($secondary)) {
$expecting = '"' . implode('" or "', $secondary) . '"';
} else {
$expecting = '"' . $secondary . '"';
}
if ($token->getType() === Token::EOF) {
throw new SyntaxError('unexpected end of file', $token);
} else {
throw new SyntaxError(sprintf('unexpected "%s", expecting %s', str_replace("\n", '\\n', $token->getValue()), $expecting), $token);
}
}
$this->next();
return $token;
}