Beispiel #1
0
 def wrapper(self, *args, **kwargs):
     root_node = parse_string(f.__doc__).get_tree()
     root_node_t = transformer.transform(root_node)
     class_ = root_node_t["CLASS"]
     lines_seg = class_.compile()
     lines = [l[0] for l in lines_seg.lines]
     try:
         f(self, lines, *args, **kwargs)
     except:
         print_tree(root_node_t)
         raise
Beispiel #2
0
 def wrapper(self, *args, **kwargs):
     root_node = parse_string(f.__doc__).get_tree()
     root_node_t = transformer.transform(root_node)
     body_block = root_node_t.match("FUNCTION|body/BLOCK")
     try:
         lines_seg = body_block.compile()
     except:
         print_tree(root_node)
         print("------------------")
         print_tree(root_node_t)
         raise
     lines = [l[0] for l in lines_seg.lines[1:]]
     f(self, lines, *args, **kwargs)
Beispiel #3
0
 def wrapper(self, *args, **kwargs):
     root_node = parse_string(f.__doc__).get_tree()
     try:
         root_node_t = transformer.transform(root_node)
     except:
         print_tree(root_node)
         raise
     try:
         f(self, root_node_t, *args, **kwargs)
     except:
         print_tree(root_node)
         print("------------------")
         print_tree(root_node_t)
         raise
Beispiel #4
0
    def compile(self, tree=None) -> str:
        if tree is None:
            tree = self.tree
        tree = transformer.transform(tree)

        if not tree.kind == "ROOT":
            raise CompilationFailure("Must pass instance of RootNode to compile")
        success = True
        errors = []
        for c in tree:
            try:
                self.compiled.append(c.compile())
            except CompileError as e:
                success = False
                errors.append(e)
            self.compiled.br()
        if not success:
            raise CompilationFailure("Compilation failed with {} errors".format(len(errors)), errors)
        self.generic_footer_compile()

        for i, v in self.imports.items():
            self.add_import(i, v)
        return str(self)