<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_fragment(self, fragment, as_last=True):
 """ Add the given text fragment as the first or last child of the root node of the text file tree. :param fragment: the text fragment to be added :type fragment: :class:`~aeneas.textfile.TextFragment` :param bool as_last: if ``True`` append fragment, otherwise prepend it """

        if not isinstance(fragment, TextFragment):
            self.log_exc(u"fragment is not an instance of TextFragment", None, True, TypeError)
        self.fragments_tree.add_child(Tree(value=fragment), as_last=as_last)