protected function expect($type)
    {
        if ($this->token->getType() !== $type) {
            throw new \Exception(sprintf('Expected %s, found %s', Token::typeToString($type), (string) $this->token));
        }

        $token = $this->token;
        $this->advance();
        return $token;
    }