#include #include #include #include #include #include #include #include #include namespace anthem { //////////////////////////////////////////////////////////////////////////////////////////////////// // // Translation // //////////////////////////////////////////////////////////////////////////////////////////////////// void translate(const std::vector &fileNames, Context &context) { for (const auto &fileName : fileNames) { std::ifstream file(fileName, std::ios::in); translate(fileName.c_str(), file, context); } } //////////////////////////////////////////////////////////////////////////////////////////////////// void translate(const char *fileName, std::istream &stream, Context &context) { // TODO: refactor context.logger.log(output::Priority::Info, (std::string("reading ") + fileName).c_str()); auto fileContent = std::string(std::istreambuf_iterator(stream), {}); const auto translateStatement = [&context](const Clingo::AST::Statement &statement) { auto formula = statement.data.accept(StatementVisitor(), statement, context); if (!formula) return; if (!context.simplify) { context.logger.outputStream() << formula.value() << std::endl; return; } simplify(formula.value()); context.logger.outputStream() << formula.value() << std::endl; }; const auto logger = [&context](const Clingo::WarningCode, const char *text) { context.logger.log(output::Priority::Error, text); }; Clingo::parse_program(fileContent.c_str(), translateStatement, logger); } //////////////////////////////////////////////////////////////////////////////////////////////////// }