public function expect($type, $value = null, $message = null) { $token = $this->getCurrent(); if (!$token->test($type, $value)) { throw new SyntaxException('%sUnexpected token "%s" of value "%s" ("%s" expected%s) , on "%s" at line %d column %d', $message, TokenTypes::getName($token->getType()), $token->getName(), TokenTypes::getName($type), $value ? sprintf(' with value "%s"', $value) : '', $this->fileName, $token->getLine(), $token->getColumn()); } $this->next(); return $token; }
/** * Token constructor. * * @param TokenCollection $list Token Collection * @param string $name Token content * @param int $tokenType Token type * @param int $line Token line * @param int $column Token column offset */ public function __construct(TokenCollection $list = null, $name, $tokenType, $line, $column) { $this->name = $name; $this->tokenType = $tokenType; $this->tokenName = TokenTypes::getName($tokenType); $this->line = $line; $this->column = $column; $this->list = $list; $this->index = count($list); }
/** * @param $tokenType * @return bool|int|string */ public function getTokenName($tokenType) { return TokenTypes::getName($tokenType); }