Example #1
0
File: ir.py Project: gdrius/kajiki
def generate_python(ir):
    cur_indent = 0
    for node in flattener(ir):
        if isinstance(node, IndentNode):
            cur_indent += 4
        elif isinstance(node, DedentNode):
            cur_indent -= 4
        for line in node.py():
            yield line.indent(cur_indent)
Example #2
0
 def _bind_globals(self, globals):
     '''Return a function which has the globals dict set to 'globals' and which
     flattens the result of self._func'.
     '''
     func = types.FunctionType(
         self._func.func_code,
         globals,
         self._func.func_name,
         self._func.func_defaults,
         self._func.func_closure
         )
     return update_wrapper(
         lambda *a,**kw:flattener(func(*a,**kw)),
         func)
Example #3
0
File: ir.py Project: gdrius/kajiki
 def __iter__(self):
     for x in flattener(self.mod_py):
         yield x
     for x in super(TemplateNode, self).__iter__():
         yield x
     yield self.TemplateTail()
Example #4
0
File: ir.py Project: gdrius/kajiki
 def body_iter(self):
     for x in optimize(flattener(map(flattener, self.body))):
         yield x