the populate_children(function is quite shortbut also rather subtle def populate_children(itemsstack)for item in itemsif isinstance(itemblock block)stack[- children append(itemelif isinstance(itemlistand itemstack append(stack[- children[- ]populate_children(itemstackstack pop(elif isinstance(itemint)if item =emptyblockstack[- children append(block get_empty_block()elsefor in range(item)stack[- children append(block get_new_row()we iterate over every item in the results list if the item is block we append it to the stack' last (topblock' child list (recall that the stack is initialized with single root block item if the item is nonempty listthen it is child list that belongs to the previous block so we append the previous block ( the top block' last childto the stack to make it the top of the stackand then recursively call populate_children(on the list item and the stack this ensures that the list item ( its child itemsis appended to the correct item' child list once the recursive call is finishedwe pop the top of the stackready for the next item if the item is an integer then it is either an empty block ( emptyblockor count of new rows if it is an empty block we append an empty block to the stack' top block' list of children if the item is new row countwe append that number of new rows to the stack' top block' list of children if the item is an empty list this signifies an empty child list and we do nothingsince by default all blocks are initialized to have an empty child list at the end the stack' top item is still the root blockbut now it has children (which may have their own childrenand so onfor the hierarchy blk examplethe populate_children(function produces the structure illustrated in figure ( and for the messagebox blk examplethe function produces the structure illustrated in figure ( the conversion into an svg file using the blockoutput save_blocks_as_svg(function is the same for all the blocks parserssince they all produce the same root block and children structures