Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
    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])
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
 def __init__(self):
     self.cats_parser = CatsParser(self._process_import_file)
     self.dirname = None
Exemplo n.º 6
0
    def test_no_types_are_exposed_initially(self):
        # Act:
        parser = CatsParser(None)

        # Assert:
        self.assertEqual(0, len(parser.type_descriptors()))