@staticmethod
def replaceNode(oldNode, newNode):
    """
        Replace instance of Nonterminal or Terminal in the tree with another one.
        :param oldNode: Old nonterminal or terminal already in the tree.
        :param newNode: Instance of nonterminal or terminal to replace with.
        :return: Instance `newNode` in the tree.
        """
    if oldNode.from_rule is not None and len(oldNode.from_rule.to_symbols) > 0:
        indexParent = oldNode.from_rule.to_symbols.index(oldNode)
        oldNode.from_rule.to_symbols[indexParent] = newNode
        newNode._set_from_rule(oldNode.from_rule)
    if oldNode.to_rule is not None and len(oldNode.to_rule.from_symbols) > 0:
        indexChild = oldNode.to_rule.from_symbols.index(oldNode)
        oldNode.to_rule._from_symbols[indexChild] = newNode
        newNode._set_to_rule(oldNode.to_rule)
    return newNode
