Esempio n. 1
0
    def preprocess_file(self, filename):
        try:
            self.__validator.validate('filename', filename)
        except Validator.ValidationError as exception:
            raise Preprocessor.ParseException(str(exception))

        o_filename = filename.replace(f'.{Semantic.get_extension()}',
                                      f'.o.{Semantic.get_extension()}')
        with open(filename) as r:
            lines = [line.rstrip() for line in r]

            w = open(o_filename, 'w')

            for idx, line in enumerate(lines):
                try:
                    self.__preprocess_line(line, w)
                except Preprocessor.ParseException as exception:
                    raise Preprocessor.ParseException(f"Line: {idx + 1}. " +
                                                      str(exception))

            w.close()

        try:
            self.__validator.validate('command_stack',
                                      DataProvider.get_command_stack())
        except Validator.ValidationError as exception:
            raise Preprocessor.ParseException(str(exception))

        DataProvider.clear_command_stack()
        DataProvider.clear_variables()
        return o_filename
Esempio n. 2
0
 def clear_variables():
     DataProvider.clear_variables()