def insert_pragma_marks(marks, outline_tree, tree_end=None):
    new_result = []
    for node in outline_tree:
        while (len(marks) > 0):
            if (marks[(- 1)]['extent']['start']['row'] > node['extent']['start']['row']):
                break
            new_result.append(marks.pop())
        children = node.get('children')
        if children:
            children[:] = insert_pragma_marks(marks, children, node['extent']['end']['row'])
        new_result.append(node)
    while (len(marks) > 0):
        if ((tree_end is not None) and (marks[(- 1)]['extent']['start']['row'] > tree_end)):
            break
        new_result.append(marks.pop())
    return new_result
def insert_pragma_marks(marks, outline_tree, tree_end=None):
    new_result = []
    for node in outline_tree:
        while (len(marks) > 0):
            if (marks[(- 1)]['extent']['start']['row'] > node['extent']['start']['row']):
                break
            new_result.append(marks.pop())
        children = node.get('children')
        if children:
            children[:] = insert_pragma_marks(marks, children, node['extent']['end']['row'])
        new_result.append(node)
    while (len(marks) > 0):
        if ((tree_end is not None) and (marks[(- 1)]['extent']['start']['row'] > tree_end)):
            break
        new_result.append(marks.pop())
    return new_result