From 1997205c35faba1e872390da3196796e071e4f99 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 15 Oct 2009 09:31:57 -0400 Subject: More refactoring of the use of analysis objects. --- coverage/parser.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'coverage/parser.py') 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: -- cgit v1.2.1