/** * Check if the next token matches the expected type and data. If it does, then consume it, otherwise * return false. * * @param int $type The expected token type * @param null|string $data The expected token data or null * * @return boolean|Token */ protected function checkAndExpectToken($type, $data = null) { if ($this->checkToken($type, $data)) { $token = $this->tokenQueue->peek(); $this->tokenQueue->next(); return $token; } return false; }
protected function assertTokens($tokens, TokenQueue $queue) { $queue->reset(); $it = new \ArrayIterator($tokens); $token = $queue->peek(); while ($it->valid()) { $expectedToken = $it->current(); $this->assertFalse($queue->isEof(), 'There is no more tokens, expected = ' . $expectedToken[1]); $this->assertToken($expectedToken[0], $expectedToken[1], $token); $token = $queue->next(); $it->next(); } $this->assertTrue($queue->isEof(), 'There are more unexpected tokens.'); }