def parse_products(self, infile, classes_dir): """An efficient parser of just the products section.""" with raise_on_eof(infile): try: return self._underlying_parser.parse_products(infile) except UnderlyingParser.ParseError as e: raise ParseError(e)
def _parse_num_items(self, lines_iter): """Parse a line of the form '<num> items' and returns <num> as an int.""" line = lines_iter.next() matchobj = self._num_items_re.match(line) if not matchobj: raise ParseError('Expected: "<num> items". Found: "%s"' % line) return int(matchobj.group(1))
def parse(self, infile): """Parse a ZincAnalysis instance from an open text file.""" with raise_on_eof(infile): try: return ZincAnalysis(self._underlying_parser.parse(infile)) except UnderlyingParser.ParseError as e: raise ParseError(e)
def parse(self, lines_iter): self._expect_header(next(lines_iter), 'pcd entries') num_pcd_entries = self.parse_num_items(next(lines_iter)) pcd_entries = [] for _ in range(0, num_pcd_entries): line = next(lines_iter) tpl = line.split(b'\t') if len(tpl) != 5: raise ParseError('Line must contain 5 tab-separated fields: {}'.format(line)) pcd_entries.append(tpl) # Note: we preserve the \n on the last entry. src_to_deps = self._parse_deps_at_position(lines_iter) return JMakeAnalysis(pcd_entries, src_to_deps)
def parse(self, infile): self._expect_header(infile.readline(), 'pcd entries') num_pcd_entries = self.parse_num_items(infile.readline()) pcd_entries = [] for i in xrange(0, num_pcd_entries): line = infile.readline() tpl = line.split('\t') if len(tpl) != 5: raise ParseError('Line must contain 5 tab-separated fields: %s' % line) pcd_entries.append(tpl) # Note: we preserve the \n on the last entry. src_to_deps = self._parse_deps_at_position(infile) return JMakeAnalysis(pcd_entries, src_to_deps)
def rebase(self, infile, outfile, pants_home_from, pants_home_to, java_home=None): with raise_on_eof(infile): try: self._underlying_parser.rebase(infile, outfile, pants_home_from, pants_home_to, java_home) except UnderlyingParser.ParseError as e: raise ParseError(e)
def _parse_section(self, lines_iter, expected_header=None): """Parse a single section.""" if expected_header: line = lines_iter.next() if expected_header + ':\n' != line: raise ParseError('Expected: "%s:". Found: "%s"' % (expected_header, line)) n = self._parse_num_items(lines_iter) relation = defaultdict( list) # Values are lists, to accommodate relations. for i in xrange(n): k, _, v = lines_iter.next().partition(' -> ') if len(v) == 1: # Value on its own line. v = lines_iter.next() relation[k].append(v[:-1]) return relation
def _verify_version(self, lines_iter): version_line = lines_iter.next() if version_line != ZincAnalysis.FORMAT_VERSION_LINE: raise ParseError('Unrecognized version line: ' + version_line)
def _expect_header(self, line, header): expected = header + ':\n' if line != expected: raise ParseError('Expected: %s. Found: %s' % (expected, line))
def _parse_num_items(self, line): """Parse a line of the form '<num> items' and returns <num> as an int.""" matchobj = JMakeAnalysisParser.num_items_re.match(line) if not matchobj: raise ParseError('Expected: "<num> items". Found: "%s"' % line) return int(matchobj.group(1))
def parse_deps(self, infile): with raise_on_eof(infile): try: return self._underlying_parser.parse_deps(infile, "") except UnderlyingParser.ParseError as e: raise ParseError(e)
def _expect_header(self, line, header): expected = header + b':\n' if line != expected: raise ParseError('Expected: {}. Found: {}'.format(expected, line))
def parse_deps(self, infile, classpath_indexer, classes_dir): with raise_on_eof(infile): try: return self._underlying_parser.parse_deps(infile, classes_dir) except UnderlyingParser.ParseError as e: raise ParseError(e)