diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-01-22 16:00:10 +0100 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-01-22 16:41:25 +0100 |
commit | b7c6f3ec72c831c2af20eb5320d5f51b52d79227 (patch) | |
tree | c7d77532371251aefcdbe45cfb74113337340375 /mesonbuild/ast | |
parent | e089eb7665ca9dfb28e740829652add666f4a2f0 (diff) | |
download | meson-b7c6f3ec72c831c2af20eb5320d5f51b52d79227.zip meson-b7c6f3ec72c831c2af20eb5320d5f51b52d79227.tar.gz meson-b7c6f3ec72c831c2af20eb5320d5f51b52d79227.tar.bz2 |
Can now rewrite files
Diffstat (limited to 'mesonbuild/ast')
-rw-r--r-- | mesonbuild/ast/printer.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/mesonbuild/ast/printer.py b/mesonbuild/ast/printer.py index aab5a30..1f58146 100644 --- a/mesonbuild/ast/printer.py +++ b/mesonbuild/ast/printer.py @@ -17,6 +17,7 @@ from .. import mparser from . import AstVisitor +import re arithmic_map = { 'add': '+', @@ -33,11 +34,18 @@ class AstPrinter(AstVisitor): self.arg_newline_cutoff = arg_newline_cutoff self.ci = '' self.is_newline = True + self.last_level = 0 + + def post_process(self): + self.result = re.sub(r'\s+\n', '\n', self.result) def append(self, data: str, node: mparser.BaseNode): level = 0 if node and hasattr(node, 'level'): level = node.level + else: + level = self.last_level + self.last_level = level if self.is_newline: self.result += ' ' * (level * self.indent) self.result += data @@ -179,13 +187,17 @@ class AstPrinter(AstVisitor): self.newline() for i in node.arguments: i.accept(self) - self.append(',', node) + self.append(', ', node) if break_args: self.newline() for key, val in node.kwargs.items(): self.append(key, node) self.appendS(':', node) val.accept(self) - self.append(',', node) + self.append(', ', node) if break_args: self.newline() + if break_args: + self.result = re.sub(r', \n$', '\n', self.result) + else: + self.result = re.sub(r', $', '', self.result) |