| 209 | last_char = '\n' |
| 210 | |
| 211 | def write(text): |
| 212 | global last_char |
| 213 | for line in text.splitlines(True): |
| 214 | line = line.lstrip(' ') |
| 215 | if len(line.strip()) == 0 and last_char == '\n': |
| 216 | continue |
| 217 | if last_char == '\n': |
| 218 | initial_closing = 0 |
| 219 | for c in line: |
| 220 | if c in ']}': |
| 221 | initial_closing += 1 |
| 222 | else: |
| 223 | break |
| 224 | if initial_closing: |
| 225 | sys.stdout.write(''.join(indentation[:-initial_closing])) |
| 226 | else: |
| 227 | sys.stdout.write(''.join(indentation)) |
| 228 | elif last_char not in ' \n' and len(line) > 0 and line[0] not in ' \n;': |
| 229 | sys.stdout.write(' ') |
| 230 | sys.stdout.write(line) |
| 231 | min_indent_level = len(indentation) |
| 232 | for c in line: |
| 233 | if c in '[{': |
| 234 | if len(indentation) > min_indent_level: |
| 235 | indentation.append('') |
| 236 | else: |
| 237 | indentation.append(' ') |
| 238 | elif c in ']}': |
| 239 | indentation.pop() |
| 240 | if len(indentation) < min_indent_level: |
| 241 | min_indent_level = len(indentation) |
| 242 | last_char = line[-1] |
| 243 | |
| 244 | slot_groups = ( |
| 245 | ('tp', 'type_slots', None), |