예제 #1
0
 def _load_implementation(self, implementation_filename, reserved_token_names=None):
     """ Parses a file with the required implementation and replaces the
     reserved token names with user-innaccesible names """
     implementation_program = gbs_parser.parse_file(os.path.join(GbsMacrosDir, implementation_filename))
     for token_name in reserved_token_names:
         defhelper.recursive_replace_token(implementation_program, token_name, "_" + token_name)
     return implementation_program
예제 #2
0
    def _explode_interactive(self, program_tree):
        """ Replaces interactive macro with it's implementation in the program tree """
        interactive = defhelper.find_def(program_tree.children[2], defhelper.is_interactive_def)
        if interactive != None:
            if self.explicit_board:
                macro_filename = "interactive_program.gbs"
            else:
                macro_filename = "interactive_program_implicit.gbs"
            implementation_program = self._load_implementation(macro_filename, ["lastKey", "read", "Show", "FreeVars"])
            if self.explicit_board:
                refParam = interactive.children[2].children[0].value
                defhelper.recursive_replace_token(implementation_program, "t", refParam)

            interactive_impl = defhelper.find_def(implementation_program.children[2], defhelper.is_entrypoint_def)
            interactive_impl_case = defhelper.recursive_find_node(interactive_impl, functools.partial(defhelper.is_node, 'case'))
            interactive_impl_case.children = [interactive_impl_case.children[0], interactive_impl_case.children[1]]
            interactive_impl_case.children.append(defhelper.get_def_body(interactive))
            defhelper.set_def_body(interactive, defhelper.get_def_body(interactive_impl))
            defhelper.set_def_token_name(interactive, 'program')