def parse_streams(streams, rules, stream_pddl, procedure_map, procedure_info, use_functions=True): stream_iter = iter(parse_lisp(stream_pddl)) assert('define' == next(stream_iter)) pddl_type, pddl_name = next(stream_iter) assert('stream' == pddl_type) for lisp_list in stream_iter: name = lisp_list[0] # TODO: refactor at this point if name in (':stream', ':wild-stream'): externals = [parse_stream(lisp_list, procedure_map, procedure_info)] elif name == ':rule': externals = [parse_rule(lisp_list, procedure_map, procedure_info)] elif name == ':function': if not use_functions: continue externals = [parse_function(lisp_list, procedure_map, procedure_info)] elif name == ':predicate': # Cannot just use args if want a bound externals = [parse_predicate(lisp_list, procedure_map, procedure_info)] elif name == ':optimizer': externals = parse_optimizer(lisp_list, procedure_map, procedure_info) else: raise ValueError(name) for external in externals: if any(e.name == external.name for e in streams): raise ValueError('Stream [{}] is not unique'.format(external.name)) if name == ':rule': rules.append(external) external.pddl_name = pddl_name # TODO: move within constructors streams.append(external)
def parse_stream_pddl(stream_pddl, stream_map, stream_info): streams = [] if stream_pddl is None: return None, streams if all(isinstance(e, External) for e in stream_pddl): return None, stream_pddl if stream_map != DEBUG: stream_map = {k.lower(): v for k, v in stream_map.items()} stream_info = {k.lower(): v for k, v in stream_info.items()} stream_iter = iter(parse_lisp(stream_pddl)) assert ('define' == next(stream_iter)) pddl_type, stream_name = next(stream_iter) assert ('stream' == pddl_type) for lisp_list in stream_iter: name = lisp_list[0] if name == ':stream': external = parse_stream(lisp_list, stream_map, stream_info) elif name == ':wild': raise NotImplementedError(name) elif name == ':rule': continue # TODO: implement rules # TODO: add eager stream if multiple conditions otherwise apply and add to stream effects elif name == ':function': external = parse_function(lisp_list, stream_map, stream_info) elif name == ':predicate': # Cannot just use args if want a bound external = parse_predicate(lisp_list, stream_map, stream_info) else: raise ValueError(name) if any(e.name == external.name for e in streams): raise ValueError('Stream [{}] is not unique'.format(external.name)) streams.append(external) return stream_name, streams