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