Does the main work of indenting the input based on the brace counts.
(lines)
| 114 | |
| 115 | |
| 116 | def prettyprint_input(lines): |
| 117 | """Does the main work of indenting the input based on the brace counts.""" |
| 118 | indent = 0 |
| 119 | basic_offset = 2 |
| 120 | for line in lines: |
| 121 | if COMMENT_RE.match(line): |
| 122 | print(line) |
| 123 | else: |
| 124 | line = line.strip("\r\n\t ") # Otherwise doesn't strip \r on Unix. |
| 125 | if len(line) > 0: |
| 126 | (brace_diff, after) = count_braces(line) |
| 127 | if brace_diff != 0: |
| 128 | if after: |
| 129 | print(" " * (basic_offset * indent) + line) |
| 130 | indent += brace_diff |
| 131 | else: |
| 132 | indent += brace_diff |
| 133 | print(" " * (basic_offset * indent) + line) |
| 134 | else: |
| 135 | print(" " * (basic_offset * indent) + line) |
| 136 | else: |
| 137 | print() |
| 138 | |
| 139 | |
| 140 | def main(): |
no test coverage detected