def parse_leaf(node: Leaf, data: dict, context: Context) -> EvalObject: if node.typ == 'SIGNATURE': sig, params = node.value[:-1].split("(") sig_types, tuples = data.get(sig) params = params.split(",") if params == ['']: params = [] if len(sig_types) != len(params): #print(sig_types, params) raise RuntimeError("Node " + node.to_str() + " does not match signature ") if not params: if tuples == [[False]]: return Bool(False) else: return Bool(True) else: for i, param in enumerate(params): if sig_types[i] == 'INT': try: const = int(param) for k, e in enumerate(tuples): if e[i] != const: tuples.pop(k) params[i] = context.get_var_name() except ValueError: pass elif sig_types[i] == 'VARCHAR': if param[0] == "\"" and param[-1] == "\"": const = param[1:-1] for k, e in enumerate(tuples): if e[i] != const: tuples.pop(k) params[i] = context.get_var_name() fv = list(zip(params, sig_types)) #print("here ", end="") #print(fv, tuples) return Table(table_from_tuples(fv, tuples, context), set(fv), False) else: raise RuntimeError("Unhandled type for Leaf outside condition: " + node.typ)