#include #include #include #include #include int main(int argc, char **argv) { anthem::Context context; cxxopts::Options options("anthem", "Translate ASP programs to the language of first-order theorem provers."); options.add_options() ("h,help", "Display this help message") ("v,version", "Display version information") ("i,input", "Input files", cxxopts::value>()) ("no-simplify", "Do not simplify the output") ("no-complete", "Do not perform completion") ("no-detect-integers", "Do not detect integer variables") ("color", "Colorize output (always, never, auto)", cxxopts::value()->default_value("auto")) ("parentheses", "Parenthesis style (normal, full)", cxxopts::value()->default_value("normal")) ("p,log-priority", "Log messages starting from this priority (debug, info, warning, error)", cxxopts::value()->default_value("info")); options.parse_positional("input"); options.positional_help("[]"); const auto printHelp = [&]() { std::cout << options.help(); }; bool help; bool version; std::vector inputFiles; std::string colorPolicyString; std::string parenthesisStyleString; std::string logPriorityString; try { const auto parseResult = options.parse(argc, argv); help = (parseResult.count("help") > 0); version = (parseResult.count("version") > 0); if (parseResult.count("input") > 0) inputFiles = parseResult["input"].as>(); context.performSimplification = (parseResult.count("no-simplify") == 0); context.performCompletion = (parseResult.count("no-complete") == 0); context.performIntegerDetection = (parseResult.count("no-detect-integers") == 0); colorPolicyString = parseResult["color"].as(); parenthesisStyleString = parseResult["parentheses"].as(); logPriorityString = parseResult["log-priority"].as(); } catch (const std::exception &exception) { context.logger.log(anthem::output::Priority::Error) << exception.what(); context.logger.errorStream() << std::endl; printHelp(); return EXIT_FAILURE; } if (help) { printHelp(); return EXIT_SUCCESS; } if (version) { std::cout << "anthem version 0.1.8+git" << std::endl; return EXIT_SUCCESS; } if (colorPolicyString == "auto") context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Auto); else if (colorPolicyString == "never") context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Never); else if (colorPolicyString == "always") context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Always); else { context.logger.log(anthem::output::Priority::Error) << "unknown color policy “" << colorPolicyString << "”"; context.logger.errorStream() << std::endl; printHelp(); return EXIT_FAILURE; } if (parenthesisStyleString == "normal") context.parenthesisStyle = anthem::ast::ParenthesisStyle::Normal; else if (parenthesisStyleString == "full") context.parenthesisStyle = anthem::ast::ParenthesisStyle::Full; else { context.logger.log(anthem::output::Priority::Error) << "unknown parenthesis style “" << parenthesisStyleString << "”"; context.logger.errorStream() << std::endl; printHelp(); return EXIT_FAILURE; } try { const auto logPriority = anthem::output::priorityFromName(logPriorityString.c_str()); context.logger.setLogPriority(logPriority); } catch (const std::exception &e) { context.logger.log(anthem::output::Priority::Error) << "unknown log priorty “" << logPriorityString << "”"; context.logger.errorStream() << std::endl; printHelp(); return EXIT_FAILURE; } try { if (!inputFiles.empty()) anthem::translate(inputFiles, context); else anthem::translate("std::cin", std::cin, context); } catch (const std::exception &e) { context.logger.log(anthem::output::Priority::Error) << e.what(); return EXIT_FAILURE; } return EXIT_SUCCESS; }