'Add an object to the parse tree.'

def object_was_parsed(self, o, parent=None, most_recent_element=None):

    parent = (parent or self.currentTag)
    previous_element = (most_recent_element or self._most_recent_element)
    next_element = previous_sibling = next_sibling = None
    if isinstance(o, Tag):
        next_element = o.next_element
        next_sibling = o.next_sibling
        previous_sibling = o.previous_sibling
        if (not previous_element):
            previous_element = o.previous_element
    o.setup(parent, previous_element, next_element, previous_sibling, next_sibling)
    self._most_recent_element = o
    parent.contents.append(o)
    if parent.next_sibling:
        index = parent.contents.index(o)
        if (index == 0):
            previous_element = parent
            previous_sibling = None
        else:
            previous_element = previous_sibling = parent.contents[(index - 1)]
        if (index == (len(parent.contents) - 1)):
            next_element = parent.next_sibling
            next_sibling = None
        else:
            next_element = next_sibling = parent.contents[(index + 1)]
        o.previous_element = previous_element
        if previous_element:
            previous_element.next_element = o
        o.next_element = next_element
        if next_element:
            next_element.previous_element = o
        o.next_sibling = next_sibling
        if next_sibling:
            next_sibling.previous_sibling = o
        o.previous_sibling = previous_sibling
        if previous_sibling:
            previous_sibling.next_sibling = o
