MCPcopy Index your code
hub / github.com/RustPython/RustPython / parse

Method parse

Lib/doctest.py:657–694  ·  view source on GitHub ↗

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 m

(self, string, name='<string>')

Source from the content-addressed store, hash-verified

655 _IS_BLANK_OR_COMMENT = re.compile(r'^[ ]*(#.*)?$').match
656
657 def parse(self, string, name='<string>'):
658 """
659 Divide the given string into examples and intervening text,
660 and return them as a list of alternating Examples and strings.
661 Line numbers for the Examples are 0-based. The optional
662 argument `name` is a name identifying this string, and is only
663 used for error messages.
664 """
665 string = string.expandtabs()
666 # If all lines begin with the same indentation, then strip it.
667 min_indent = self._min_indent(string)
668 if min_indent > 0:
669 string = '\n'.join([l[min_indent:] for l in string.split('\n')])
670
671 output = []
672 charno, lineno = 0, 0
673 # Find all doctest examples in the string:
674 for m in self._EXAMPLE_RE.finditer(string):
675 # Add the pre-example text to `output`.
676 output.append(string[charno:m.start()])
677 # Update lineno (lines before this example)
678 lineno += string.count('\n', charno, m.start())
679 # Extract info from the regexp match.
680 (source, options, want, exc_msg) = \
681 self._parse_example(m, name, lineno)
682 # Create an Example, and add it to the list.
683 if not self._IS_BLANK_OR_COMMENT(source):
684 output.append( Example(source, want, exc_msg,
685 lineno=lineno,
686 indent=min_indent+len(m.group('indent')),
687 options=options) )
688 # Update lineno (lines inside this example)
689 lineno += string.count('\n', m.start(), m.end())
690 # Update charno.
691 charno = m.end()
692 # Add any remaining post-example text to `output`.
693 output.append(string[charno:])
694 return output
695
696 def get_doctest(self, string, globs, name, filename, lineno):
697 """

Callers 2

get_examplesMethod · 0.95
script_from_examplesFunction · 0.45

Calls 13

_min_indentMethod · 0.95
_parse_exampleMethod · 0.95
lenFunction · 0.85
finditerMethod · 0.80
ExampleClass · 0.70
expandtabsMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45
appendMethod · 0.45
startMethod · 0.45
countMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected