Lichen

Changeset

116:0fcb1351544e
2016-10-20 Paul Boddie raw files shortlog changelog graph Improved output indentation.
translator.py (file)
     1.1 --- a/translator.py	Thu Oct 20 14:46:34 2016 +0200
     1.2 +++ b/translator.py	Thu Oct 20 15:00:27 2016 +0200
     1.3 @@ -1094,7 +1094,15 @@
     1.4          return (self.indent + extra) * self.tabstop
     1.5  
     1.6      def indenttext(self, s, levels):
     1.7 -        return s.replace("\n", "\n%s" % (levels * self.tabstop))
     1.8 +        lines = s.split("\n")
     1.9 +        out = [lines[0]]
    1.10 +        for line in lines[1:]:
    1.11 +            out.append(levels * self.tabstop + line)
    1.12 +            if line.endswith("("):
    1.13 +                levels += 1
    1.14 +            elif line.endswith(")"):
    1.15 +                levels -= 1
    1.16 +        return "\n".join(out)
    1.17  
    1.18      def writeline(self, s):
    1.19          print >>self.out, "%s%s" % (self.pad(), self.indenttext(s, self.indent + 1))