2016-11-21 17:51:14 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
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;
|
|
|
|
|
2016-11-21 17:51:14 +01:00
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
|
|
po::options_description description("Allowed options");
|
|
|
|
description.add_options()
|
2016-11-23 03:36:48 +01:00
|
|
|
("help,h", "Display this help message")
|
|
|
|
("version,v", "Display version information")
|
2016-11-24 15:01:37 +01:00
|
|
|
("input,i", po::value<std::vector<std::string>>(), "Input files")
|
2017-06-06 01:44:44 +02:00
|
|
|
("simplify,s", po::bool_switch(&context.performSimplification), "Simplify the output")
|
|
|
|
("complete,c", po::bool_switch(&context.performCompletion), "Perform completion")
|
2017-04-05 18:15:42 +02:00
|
|
|
("color", po::value<std::string>()->default_value("auto"), "Colorize output (always, never, auto)")
|
2017-06-06 02:02:26 +02:00
|
|
|
("parentheses", po::value<std::string>()->default_value("normal"), "Parenthesis style (normal, full)")
|
2016-11-24 23:34:43 +01:00
|
|
|
("log-priority,p", po::value<std::string>()->default_value("warning"), "Log messages starting from this priority (debug, info, warning, error)");
|
2016-11-21 17:51:14 +01:00
|
|
|
|
|
|
|
po::positional_options_description positionalOptionsDescription;
|
|
|
|
positionalOptionsDescription.add("input", -1);
|
|
|
|
|
|
|
|
po::variables_map variablesMap;
|
|
|
|
|
|
|
|
const auto printHelp =
|
|
|
|
[&]()
|
|
|
|
{
|
2016-11-24 02:57:33 +01:00
|
|
|
std::cout
|
2016-11-24 23:34:43 +01:00
|
|
|
<< "Usage: anthem [options] file..." << std::endl
|
2016-11-24 02:57:33 +01:00
|
|
|
<< "Translate ASP programs to the language of first-order theorem provers." << std::endl << std::endl
|
|
|
|
<< description;
|
2016-11-21 17:51:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
po::store(po::command_line_parser(argc, argv)
|
|
|
|
.options(description)
|
|
|
|
.positional(positionalOptionsDescription)
|
|
|
|
.run(),
|
|
|
|
variablesMap);
|
|
|
|
po::notify(variablesMap);
|
|
|
|
}
|
|
|
|
catch (const po::error &e)
|
|
|
|
{
|
2017-05-30 17:19:26 +02:00
|
|
|
context.logger.log(anthem::output::Priority::Error) << e.what();
|
2016-11-21 17:51:14 +01:00
|
|
|
printHelp();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variablesMap.count("help"))
|
|
|
|
{
|
|
|
|
printHelp();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variablesMap.count("version"))
|
|
|
|
{
|
2017-06-13 00:14:16 +02:00
|
|
|
std::cout << "anthem version 0.1.7-git" << std::endl;
|
2016-11-21 17:51:14 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-11-24 23:25:53 +01:00
|
|
|
const auto colorPolicyString = variablesMap["color"].as<std::string>();
|
2016-11-24 15:01:37 +01:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-06 02:02:26 +02:00
|
|
|
const auto parenthesisStyle = variablesMap["parentheses"].as<std::string>();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-24 23:25:53 +01:00
|
|
|
const auto logPriorityString = variablesMap["log-priority"].as<std::string>();
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
if (variablesMap.count("input"))
|
|
|
|
{
|
|
|
|
const auto &inputFiles = variablesMap["input"].as<std::vector<std::string>>();
|
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;
|
|
|
|
}
|