def parse_all(lines, imports=None): # Act: if imports is None: imports = [] parser = CatsParser(imports.append) for line in lines: parser.process_line(line) return parser.type_descriptors()
class MultiFileParser: """CATS parser that resolves imports in global namespace""" def __init__(self): self.cats_parser = CatsParser(self._process_import_file) self.dirname = None self.imported_filenames = [] def set_include_path(self, include_path): self.dirname = include_path def parse(self, schema_filename): self._process_file(schema_filename) def _process_import_file(self, filename): if filename in self.imported_filenames: return self.imported_filenames.append(filename) filename = os.path.join(self.dirname, filename) self._process_file(filename) def _process_file(self, filename): self.cats_parser.push_scope(filename) with open(filename) as input_file: lines = input_file.readlines() for line in lines: self.cats_parser.process_line(line) self.cats_parser.commit() self.cats_parser.pop_scope()
def _assert_parse_delayed_exception(self, lines): # Arrange: imports = [] parser = CatsParser(imports.append) for line in lines[:-1]: parser.process_line(line) # Act + Assert: with self.assertRaises(CatsParseException): parser.process_line(lines[-1])
class MultiFileParser: """CATS parser that resolves imports in global namespace""" def __init__(self): self.cats_parser = CatsParser(self._process_import_file) self.dirname = None def parse(self, filename): self.dirname = os.path.dirname(filename) self._process_file(filename) def _process_import_file(self, filename): filename = os.path.join(self.dirname, filename) self._process_file(filename) def _process_file(self, filename): self.cats_parser.push_scope(filename) with open(filename) as input_file: lines = input_file.readlines() for line in lines: self.cats_parser.process_line(line) self.cats_parser.pop_scope()
def __init__(self): self.cats_parser = CatsParser(self._process_import_file) self.dirname = None
def test_no_types_are_exposed_initially(self): # Act: parser = CatsParser(None) # Assert: self.assertEqual(0, len(parser.type_descriptors()))