def expand_subparts(self, lines, block_name): leading = () parts = () while 1: if len(lines) == 0: if len(leading) > 0: back = Block.with_lines(None, leading) parts = parts + (back,) break else: head = lines[0] rest = lines[1:] match = re.match(r'^\s*\<\<\<([^\>]*)\>\>\>\s*$', head) if match != None: back = Block.with_lines(None, leading) leading = () takeout = Block.empty(match.groups(1)[0]) parts = parts + (back,takeout) else: head = re.subn(r'\<\<\<\<([^\>]*)\>\>\>\>', r'<<<\1>>>', head)[0] leading = leading + (head,) lines = rest return Block.with_parts(block_name, parts)