def relex_import(self, startnode, version = 0): """ Replace a node with the tokens of its name :param startnode: node to expand :param version: version assigned to each created node :return: """ success = self.lex(startnode.symbol.name) bos = startnode.prev_term # bos startnode.parent.remove_child(startnode) parent = bos.parent eos = parent.children.pop() last_node = bos for match in success: node = TextNode(Terminal(match[0])) node.version = version node.lookup = match[1] parent.children.append(node) last_node.next_term = node last_node.right = node node.left = last_node node.prev_term = last_node node.parent = parent last_node = node parent.children.append(eos) last_node.right = eos # link to eos last_node.next_term = eos eos.left = last_node eos.prev_term = last_node
def relex_import(self, startnode, version=0): success = self.lex(startnode.symbol.name) bos = startnode.prev_term # bos startnode.parent.remove_child(startnode) parent = bos.parent eos = parent.children.pop() last_node = bos for match in success: node = TextNode(Terminal(match[0])) node.version = version node.lookup = match[1] parent.children.append(node) last_node.next_term = node last_node.right = node node.left = last_node node.prev_term = last_node node.parent = parent last_node = node parent.children.append(eos) last_node.right = eos # link to eos last_node.next_term = eos eos.left = last_node eos.prev_term = last_node
def relex_import(self, startnode, version = 0): success = self.lex(startnode.symbol.name) bos = startnode.prev_term # bos startnode.parent.remove_child(startnode) parent = bos.parent eos = parent.children.pop() last_node = bos for match in success: node = TextNode(Terminal(match[0])) node.version = version node.lookup = match[1] parent.children.append(node) last_node.next_term = node last_node.right = node node.left = last_node node.prev_term = last_node node.parent = parent last_node = node parent.children.append(eos) last_node.right = eos # link to eos last_node.next_term = eos eos.left = last_node eos.prev_term = last_node