def expand_body(node, cont): if is_bitand(node): def right_side(rightmost_of_left_side): return conjunction( rightmost_of_left_side, expand_body(node.right, cont)) return expand_body(node.left, right_side) elif is_list(node): return expand_terminals(node, cont) elif is_set(node): assert len(node.elts) == 1 return cont(unit(node.elts[0])) else: return cont(expand_call(node))
def expand_clause(node): head = node.left body = node.right if is_bitand(head): def pushback(rightmost_of_body): return conjunction( rightmost_of_body, expand_pushbacks(head.right)) return rule( expand_call(head.left), expand_body(body, pushback)) else: return rule( expand_call(head), expand_body(body, identity))