#include #include #include #include #include int main(int argc, char **argv) { anthem::Context context; namespace po = boost::program_options; po::options_description description("Allowed options"); description.add_options() ("help,h", "Display this help message") ("version,v", "Display version information") ("input,i", po::value>(), "Input files") ("simplify,s", po::bool_switch(&context.performSimplification), "Simplify the output") ("complete,c", po::bool_switch(&context.performCompletion), "Perform completion") ("color", po::value()->default_value("auto"), "Colorize output (always, never, auto)") ("parentheses", po::value()->default_value("normal"), "Parenthesis style (normal, full)") ("log-priority,p", po::value()->default_value("warning"), "Log messages starting from this priority (debug, info, warning, error)"); po::positional_options_description positionalOptionsDescription; positionalOptionsDescription.add("input", -1); po::variables_map variablesMap; const auto printHelp = [&]() { std::cout << "Usage: anthem [options] file..." << std::endl << "Translate ASP programs to the language of first-order theorem provers." << std::endl << std::endl << description; }; try { po::store(po::command_line_parser(argc, argv) .options(description) .positional(positionalOptionsDescription) .run(), variablesMap); po::notify(variablesMap); } catch (const po::error &e) { context.logger.log(anthem::output::Priority::Error) << e.what(); printHelp(); return EXIT_FAILURE; } if (variablesMap.count("help")) { printHelp(); return EXIT_SUCCESS; } if (variablesMap.count("version")) { std::cout << "anthem version 0.1.7-git" << std::endl; return EXIT_SUCCESS; } const auto colorPolicyString = variablesMap["color"].as(); 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; } const auto parenthesisStyle = variablesMap["parentheses"].as(); if (parenthesisStyle == "normal") context.parenthesisStyle = anthem::ast::ParenthesisStyle::Normal; else if (parenthesisStyle == "full") context.parenthesisStyle = anthem::ast::ParenthesisStyle::Full; else { context.logger.log(anthem::output::Priority::Error) << "unknown parenthesis style “" << parenthesisStyle << "”"; context.logger.errorStream() << std::endl; printHelp(); return EXIT_FAILURE; } const auto logPriorityString = variablesMap["log-priority"].as(); 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 (variablesMap.count("input")) { const auto &inputFiles = variablesMap["input"].as>(); 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; }