Ejemplo n.º 1
0
def parse_term_constructor(value, setting, g, top=False):
    import builtin, runner
    def subparse(value, setting):
        return parse_term_constructor(value, setting, g)
    if isinstance(value, ast.Call):
        func = evaluate(value.func, g)
        new_args, setting = map_and_fold( value.args, setting, subparse)
        if isinstance(func, terms.Template):
            return func(*new_args), setting
        if top:
            if hasattr(func, 'template'):
                return func.template(*new_args), setting
            else:
                raise ValueError("calling function without template", value.lineno)
    if is_call_like(value) and not top:
        Q, setting = parse_term_constructor(value, setting, g, True)
        action = terms.Action.ask(Q)
        setting = take_and_save_action(setting, action)
        v, setting = get_answer(setting)
        return v, setting
    if isinstance(value, ast.List):
        elts, setting = map_and_fold(value.elts, setting, subparse)
        return builtin.lists.to_term(elts), setting
    if isinstance(value, ast.Dict):
        keys, setting = map_and_fold(value.keys, setting, subparse)
        values, setting = map_and_fold(value.values, setting, subparse)
        return builtin.dicts.to_term(dict(zip(values, keys))), setting
    if isinstance(value, ast.Name):
        try:
            return terms.RefNum(utilities.index_in(
                    value.id, [arg.name for arg in setting.args]
                )), setting
        except ValueError, exc:
            exc.args = exc.args + (value.lineno,)
            raise
Ejemplo n.º 2
0
def path_in_module(name):
    path = os.path.abspath(os.path.splitext(name)[0]).split("/")
    module_index = utilities.index_in(module_name, path)
    return path[module_index + 1 :]