'Divide the given string into examples and intervening text,
and return them as a list of alternating Examples and strings.
Line numbers for the Examples are 0-based.  The optional
argument `name` is a name identifying this string, and is only
used for error messages.'

def parse(self, string, name='<string>'):

    string = string.expandtabs()
    min_indent = self._min_indent(string)
    if (min_indent > 0):
        string = '\n'.join([l[min_indent:] for l in string.split('\n')])
    output = []
    (charno, lineno) = (0, 0)
    if self._RANDOM_TEST.search(string):
        random_marker = '\n#    random'
    else:
        random_marker = ''
    ip2py = False
    terms = list(self._EXAMPLE_RE_PY.finditer(string))
    if terms:
        Example = doctest.Example
    else:
        terms = list(self._EXAMPLE_RE_IP.finditer(string))
        if self._EXTERNAL_IP.search(string):
            Example = IPExternalExample
        else:
            Example = IPExample
            ip2py = True
    for m in terms:
        output.append(string[charno:m.start()])
        lineno += string.count('\n', charno, m.start())
        (source, options, want, exc_msg) = self._parse_example(m, name, lineno, ip2py)
        want += random_marker
        if (Example is IPExternalExample):
            options[doctest.NORMALIZE_WHITESPACE] = True
            want += '\n'
        if (not self._IS_BLANK_OR_COMMENT(source)):
            output.append(Example(source, want, exc_msg, lineno=lineno, indent=(min_indent + len(m.group('indent'))), options=options))
        lineno += string.count('\n', m.start(), m.end())
        charno = m.end()
    output.append(string[charno:])
    return output
