示例#1
0
 def compile(self):
     cs = CompiledSegment()
     line = self.child.compile()
     if self.comment is not None:
         if line == "":
             line = self.comment.compile()
         else:
             line = "{} {}".format(line, self.comment.compile())
     cs.append(line)
     return cs
示例#2
0
 def compile(self) -> CompiledSegment:
     cs = CompiledSegment()
     cs.indent()
     for c in self:
         cs.append(c.compile())
     cs.dedent()
     return cs
示例#3
0
 def compile(self):
     cs = CompiledSegment()
     cs.append("try:")
     cs.append(self.block.compile())
     for c in self.catches:
         cs.append(c.compile())
     return cs
示例#4
0
 def compile(self):
     cs = CompiledSegment()
     cs.append("if {}:".format(self.condition.compile()))
     cs.append(self.block.compile())
     for e in self.elses:
         cs.append(e.compile())
     return cs
示例#5
0
 def compile(self):
     cs = CompiledSegment()
     cs.append("class {}({}):".format(self.value, self.parent.compile()))
     cs.indent()
     # TODO: Move as appropriate to __init__
     cs.append(self.body.compile())
     return cs
示例#6
0
    def compile(self):
        cs = CompiledSegment()
        if len(self.exceptions) > 1:
            exceptions = "({})".format(", ".join([e.compile() for e in self.exceptions]))
        else:
            exceptions = self.exceptions[0].compile()

        if self.exc_name is None:
            cs.append("except {}:".format(exceptions))
        else:
            cs.append("except {} as {}:".format(exceptions, self.exc_name.compile()))
        cs.append(self.block.compile())
        return cs
示例#7
0
 def compile(self) -> CompiledSegment:
     cs = CompiledSegment()
     cs.append("_app_.write({})".format(repr(self.value)))
     return cs
示例#8
0
 def compile(self):
     cs = CompiledSegment()
     cs.append("for {} in {}:".format(self.thing.compile(), self.items.compile()))
     cs.append(self.block.compile())
     return cs
示例#9
0
 def compile(self):
     cs = CompiledSegment()
     cs.append("while {}:".format(self.condition.compile()))
     cs.append(self.block.compile())
     return cs
示例#10
0
 def compile(self):
     cs = CompiledSegment()
     cs.append("else:")
     cs.append(self.block.compile())
     return cs
示例#11
0
 def compile(self):
     cs = CompiledSegment()
     cs.append("return {}".format(self.child.compile()))
     # TODO: Comments
     return cs
示例#12
0
 def compile(self):
     cs = CompiledSegment()
     args = ", ".join([a.compile() for a in self.args])
     cs.append("def {}({}):".format(self.value, args))
     cs.append(self.body.compile())
     return cs