'Write part of a backwards edge in the graph.
Writes single- or multi-line backward edges in an ascii graph.
For example, a single line edge::
| | | | o |
| | | |/ /  <-- single-line edge connects two nodes.
| | | o |
Or a multi-line edge (requires two calls to back_edge)::
| | | | o |
| |_|_|/ /   <-- multi-line edge crosses vertical edges.
o | | | |
Also handles "pipelined" edges, where the same line contains
parts of multiple edges::
o start
|/| | |_|/| <-- this line has parts of 2 edges.
o   o
Arguments:
prev_ends -- indices in frontier of previous edges that need
to be finished on this line.
end -- end of the current edge on this line.
start -- start index of the current edge.
collapse -- whether the graph will be collapsing (i.e. whether
to slant the end of the line or keep it straight)
label -- optional debug label to print after the line.'

def _back_edge_line(self, prev_ends, end, start, collapse, label=None):

    def advance(to_pos, edges):
        'Write    edges    up    to    <to_pos>.'
        for i in range(self._pos, to_pos):
            for e in edges():
                self._write_edge(*e)
            self._pos += 1
    flen = len(self._frontier)
    self._pos = 0
    self._indent()
    for p in prev_ends:
        advance(p, (lambda : [('|    ', self._pos)]))
        advance((p + 1), (lambda : [('|/', self._pos)]))
    if (end >= 0):
        advance((end + 1), (lambda : [('|    ', self._pos)]))
        advance((start - 1), (lambda : [('|', self._pos), ('_', end)]))
    else:
        advance((start - 1), (lambda : [('|    ', self._pos)]))
    if (start >= 0):
        advance(start, (lambda : [('|', self._pos), ('/', end)]))
    if collapse:
        advance(flen, (lambda : [('    /', self._pos)]))
    else:
        advance(flen, (lambda : [('|    ', self._pos)]))
    self._set_state(BACK_EDGE, end, label)
    self._out.write('\n')
