diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-10-15 09:31:57 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-10-15 09:31:57 -0400 |
commit | 1997205c35faba1e872390da3196796e071e4f99 (patch) | |
tree | d4a52df96006b10024341c46041c616e959ee53c /coverage/parser.py | |
parent | 0245e5c6a827fda49d466f2deae3944b020e2ab6 (diff) | |
download | python-coveragepy-git-1997205c35faba1e872390da3196796e071e4f99.tar.gz |
More refactoring of the use of analysis objects.
Diffstat (limited to 'coverage/parser.py')
-rw-r--r-- | coverage/parser.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index 4087d2f0..ba281024 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -45,6 +45,16 @@ class CodeParser: # The line numbers that start statements. self.statement_starts = set() + # Lazily-created ByteParser + self._byte_parser = None + + def _get_byte_parser(self): + """Create a ByteParser on demand.""" + if not self._byte_parser: + self._byte_parser = ByteParser(text=self.text, filename=self.filename) + return self._byte_parser + byte_parser = property(_get_byte_parser) + def _raw_parse(self): """Parse the source to find the interesting facts about its lines. @@ -114,8 +124,7 @@ class CodeParser: prev_toktype = toktype # Find the starts of the executable statements. - byte_parser = ByteParser(text=self.text, filename=self.filename) - self.statement_starts.update(byte_parser._find_statements()) + self.statement_starts.update(self.byte_parser._find_statements()) def _map_to_first_line(self, lines, ignore=None): """Map the line numbers in `lines` to the correct first line of the @@ -158,6 +167,10 @@ class CodeParser: return lines, excluded_lines, self.multiline + def arc_info(self): + """Get information about the arcs available in the code.""" + return self.byte_parser._all_arcs() + class ByteParser: |