public function parse(string $html) : TokenCollection
    {
        self::$allHtml = $html;
        $tokens = new TokenCollection();
        $remainingHtml = trim($html);
        while (mb_strlen($remainingHtml) > 0) {
            $token = TokenFactory::buildFromHtml(
                $remainingHtml,
                null,
                $this->throwOnError
            );
            if (!$token instanceof Token) {
                // Error has occurred, so we stop.
                break;
            }

            $remainingHtml = $token->parse($remainingHtml);
            $tokens[] = $token;
        }

        return $tokens;
    }