def decode_tree_to_python_ast(decode_tree): from lang.py.unaryclosure import compressed_ast_to_normal compressed_ast_to_normal(decode_tree) decode_tree = decode_tree.children[0] terminals = decode_tree.get_leaves() for terminal in terminals: if terminal.value is not None and type(terminal.value) is str: if terminal.value.endswith('<eos>'): terminal.value = terminal.value[:-5] if terminal.type in {int, float, str, bool}: # cast to target data type terminal.value = terminal.type(terminal.value) ast_tree = parse_tree_to_python_ast(decode_tree) return ast_tree
def decode_tree_to_python_ast(decode_tree): from lang.py.unaryclosure import compressed_ast_to_normal ast_tree = ASTNode('root') compressed_ast_to_normal(decode_tree) for t in decode_tree.children: #print(t) terminals = t.get_leaves() for terminal in terminals: if terminal.value is not None and type(terminal.value) is str: if terminal.value.endswith('<eos>'): terminal.value = terminal.value[:-5] if terminal.type in {int, float, str, bool}: # cast to target data type terminal.value = terminal.type(terminal.value) #print(decode_tree) #root_node.add_child(tree) pt = parse_tree_to_python_ast(t) # print(pt) #print('ptya') ast_tree.add_child(pt) #print(ast_tree) return ast_tree