2016-11-21 17:51:14 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2018-03-25 16:59:15 +02:00
|
|
|
#include <cxxopts.hpp>
|
2016-11-21 17:51:14 +01:00
|
|
|
|
2017-05-30 03:53:51 +02:00
|
|
|
#include <anthem/AST.h>
|
2016-11-24 02:42:32 +01:00
|
|
|
#include <anthem/Context.h>
|
2016-11-22 03:15:52 +01:00
|
|
|
#include <anthem/Translation.h>
|
|
|
|
|
2016-11-21 17:51:14 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2016-11-24 02:57:33 +01:00
|
|
|
anthem::Context context;
|
|
|
|
|
2018-03-25 16:59:15 +02:00
|
|
|
cxxopts::Options options("anthem", "Translate ASP programs to the language of first-order theorem provers.");
|
2016-11-21 17:51:14 +01:00
|
|
|
|
2018-03-25 16:59:15 +02:00
|
|
|
options.add_options()
|
|
|
|
("h,help", "Display this help message")
|
|
|
|
("v,version", "Display version information")
|
|
|
|
("i,input", "Input files", cxxopts::value<std::vector<std::string>>())
|
2018-05-04 15:59:14 +02:00
|
|
|
("no-simplify", "Do not simplify the output")
|
|
|
|
("no-complete", "Do not perform completion")
|
|
|
|
("no-detect-integers", "Do not detect integer variables")
|
2018-03-25 16:59:15 +02:00
|
|
|
("color", "Colorize output (always, never, auto)", cxxopts::value<std::string>()->default_value("auto"))
|
|
|
|
("parentheses", "Parenthesis style (normal, full)", cxxopts::value<std::string>()->default_value("normal"))
|
|
|
|
("p,log-priority", "Log messages starting from this priority (debug, info, warning, error)", cxxopts::value<std::string>()->default_value("info"));
|
2016-11-21 17:51:14 +01:00
|
|
|
|
2018-03-25 16:59:15 +02:00
|
|
|
options.parse_positional("input");
|
|
|
|
options.positional_help("[<input file...>]");
|
2016-11-21 17:51:14 +01:00
|
|
|
|
|
|
|
const auto printHelp =
|
|
|
|
[&]()
|
|
|
|
{
|
2018-03-25 16:59:15 +02:00
|
|
|
std::cout << options.help();
|
2016-11-21 17:51:14 +01:00
|
|
|
};
|
|
|
|
|
2018-03-25 16:59:15 +02:00
|
|
|
bool help;
|
|
|
|
bool version;
|
|
|
|
std::vector<std::string> inputFiles;
|
|
|
|
std::string colorPolicyString;
|
|
|
|
std::string parenthesisStyleString;
|
|
|
|
std::string logPriorityString;
|
|
|
|
|
2016-11-21 17:51:14 +01:00
|
|
|
try
|
|
|
|
{
|
2018-03-25 16:59:15 +02:00
|
|
|
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<std::vector<std::string>>();
|
|
|
|
|
2018-05-04 15:59:14 +02:00
|
|
|
context.performSimplification = (parseResult.count("no-simplify") == 0);
|
|
|
|
context.performCompletion = (parseResult.count("no-complete") == 0);
|
|
|
|
context.performIntegerDetection = (parseResult.count("no-detect-integers") == 0);
|
2018-03-25 16:59:15 +02:00
|
|
|
colorPolicyString = parseResult["color"].as<std::string>();
|
|
|
|
parenthesisStyleString = parseResult["parentheses"].as<std::string>();
|
|
|
|
logPriorityString = parseResult["log-priority"].as<std::string>();
|
2016-11-21 17:51:14 +01:00
|
|
|
}
|
2018-03-25 16:59:15 +02:00
|
|
|
catch (const std::exception &exception)
|
2016-11-21 17:51:14 +01:00
|
|
|
{
|
2018-03-25 16:59:15 +02:00
|
|
|
context.logger.log(anthem::output::Priority::Error) << exception.what();
|
|
|
|
context.logger.errorStream() << std::endl;
|
2016-11-21 17:51:14 +01:00
|
|
|
printHelp();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-03-25 16:59:15 +02:00
|
|
|
if (help)
|
2016-11-21 17:51:14 +01:00
|
|
|
{
|
|
|
|
printHelp();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-03-25 16:59:15 +02:00
|
|
|
if (version)
|
2016-11-21 17:51:14 +01:00
|
|
|
{
|
2018-04-20 16:37:03 +02:00
|
|
|
std::cout << "anthem version 0.1.8+git" << std::endl;
|
2016-11-21 17:51:14 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-11-24 23:25:53 +01:00
|
|
|
if (colorPolicyString == "auto")
|
2016-11-24 15:01:37 +01:00
|
|
|
context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Auto);
|
2016-11-24 23:25:53 +01:00
|
|
|
else if (colorPolicyString == "never")
|
2016-11-24 15:01:37 +01:00
|
|
|
context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Never);
|
2016-11-24 23:25:53 +01:00
|
|
|
else if (colorPolicyString == "always")
|
2016-11-24 15:01:37 +01:00
|
|
|
context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Always);
|
|
|
|
else
|
|
|
|
{
|
2017-05-30 17:19:26 +02:00
|
|
|
context.logger.log(anthem::output::Priority::Error) << "unknown color policy “" << colorPolicyString << "”";
|
2016-11-24 23:25:53 +01:00
|
|
|
context.logger.errorStream() << std::endl;
|
|
|
|
printHelp();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-03-25 16:59:15 +02:00
|
|
|
if (parenthesisStyleString == "normal")
|
2017-06-06 02:02:26 +02:00
|
|
|
context.parenthesisStyle = anthem::ast::ParenthesisStyle::Normal;
|
2018-03-25 16:59:15 +02:00
|
|
|
else if (parenthesisStyleString == "full")
|
2017-06-06 02:02:26 +02:00
|
|
|
context.parenthesisStyle = anthem::ast::ParenthesisStyle::Full;
|
|
|
|
else
|
|
|
|
{
|
2018-03-25 16:59:15 +02:00
|
|
|
context.logger.log(anthem::output::Priority::Error) << "unknown parenthesis style “" << parenthesisStyleString << "”";
|
2017-06-06 02:02:26 +02:00
|
|
|
context.logger.errorStream() << std::endl;
|
|
|
|
printHelp();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-24 23:25:53 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto logPriority = anthem::output::priorityFromName(logPriorityString.c_str());
|
|
|
|
context.logger.setLogPriority(logPriority);
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
2017-05-30 17:19:26 +02:00
|
|
|
context.logger.log(anthem::output::Priority::Error) << "unknown log priorty “" << logPriorityString << "”";
|
2016-11-24 15:01:37 +01:00
|
|
|
context.logger.errorStream() << std::endl;
|
|
|
|
printHelp();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-22 03:15:52 +01:00
|
|
|
try
|
|
|
|
{
|
2018-03-25 16:59:15 +02:00
|
|
|
if (!inputFiles.empty())
|
2016-11-24 02:42:32 +01:00
|
|
|
anthem::translate(inputFiles, context);
|
2016-11-22 03:15:52 +01:00
|
|
|
else
|
2016-11-24 02:42:32 +01:00
|
|
|
anthem::translate("std::cin", std::cin, context);
|
2016-11-22 03:15:52 +01:00
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
2017-05-30 17:19:26 +02:00
|
|
|
context.logger.log(anthem::output::Priority::Error) << e.what();
|
2016-11-22 03:15:52 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-21 17:51:14 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|