public function parse($input = null, $options = 0)
    {
        if (!is_null($input)) {
            $this->setInput($input);
        }
        if (is_null($this->input)) {
            throw new EofException('End of input stream, or no input supplied');
        }

        if (0 !== $options) {
            $this->options = $options;
        }

        switch ($this->input[0]) {
            case 'vcalendar':
                $this->root = new VCalendar([], false);
                break;
            case 'vcard':
                $this->root = new VCard([], false);
                break;
            default:
                throw new ParseException('The root component must either be a vcalendar, or a vcard');
        }
        foreach ($this->input[1] as $prop) {
            $this->root->add($this->parseProperty($prop));
        }
        if (isset($this->input[2])) {
            foreach ($this->input[2] as $comp) {
                $this->root->add($this->parseComponent($comp));
            }
        }

        // Resetting the input so we can throw an feof exception the next time.
        $this->input = null;

        return $this->root;
    }