2016-05-29 16:27:11 +02:00
|
|
|
#include <algorithm>
|
2016-05-20 15:29:24 +02:00
|
|
|
#include <iostream>
|
2016-05-29 16:27:11 +02:00
|
|
|
#include <string>
|
2016-05-20 15:29:24 +02:00
|
|
|
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
2016-06-10 01:23:41 +02:00
|
|
|
#include <plasp/LanguageDetection.h>
|
2016-05-29 16:27:11 +02:00
|
|
|
#include <plasp/pddl/Description.h>
|
2016-05-20 15:29:24 +02:00
|
|
|
#include <plasp/sas/Description.h>
|
2016-05-21 02:43:07 +02:00
|
|
|
#include <plasp/sas/TranslatorASP.h>
|
2016-05-20 15:29:24 +02:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
|
|
po::options_description description("Allowed options");
|
|
|
|
description.add_options()
|
2016-05-24 16:24:37 +02:00
|
|
|
("help,h", "Display this help message.")
|
|
|
|
("version,v", "Display version information.")
|
2016-06-07 15:54:01 +02:00
|
|
|
("input,i", po::value<std::vector<std::string>>(), "Specify the SAS input file.")
|
2016-06-10 01:28:13 +02:00
|
|
|
("language,l", po::value<std::string>(), "Specify the input language (SAS or PDDL). Omit for automatic detection.");
|
2016-05-20 15:29:24 +02:00
|
|
|
|
|
|
|
po::positional_options_description positionalOptionsDescription;
|
|
|
|
positionalOptionsDescription.add("input", -1);
|
|
|
|
|
|
|
|
po::variables_map variablesMap;
|
2016-05-24 16:24:37 +02:00
|
|
|
|
|
|
|
const auto printHelp =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
std::cout << "Usage: plasp file [options]" << std::endl;
|
|
|
|
std::cout << "Translate PDDL instances to ASP facts." << std::endl << std::endl;
|
|
|
|
|
|
|
|
std::cout << description;
|
|
|
|
};
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
po::store(po::command_line_parser(argc, argv)
|
|
|
|
.options(description)
|
|
|
|
.positional(positionalOptionsDescription)
|
|
|
|
.run(),
|
|
|
|
variablesMap);
|
|
|
|
po::notify(variablesMap);
|
|
|
|
}
|
|
|
|
catch (const po::error &e)
|
|
|
|
{
|
|
|
|
std::cerr << "Error: " << e.what() << std::endl << std::endl;
|
|
|
|
printHelp();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2016-05-20 15:29:24 +02:00
|
|
|
|
|
|
|
if (variablesMap.count("help"))
|
|
|
|
{
|
2016-05-24 16:24:37 +02:00
|
|
|
printHelp();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variablesMap.count("version"))
|
|
|
|
{
|
|
|
|
std::cout << "plasp version 3.0.0" << std::endl;
|
2016-05-20 15:29:24 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-06-10 00:59:44 +02:00
|
|
|
plasp::utils::Parser parser;
|
|
|
|
|
|
|
|
parser.setCaseSensitive(false);
|
|
|
|
|
|
|
|
if (variablesMap.count("input"))
|
|
|
|
{
|
|
|
|
const auto &inputFiles = variablesMap["input"].as<std::vector<std::string>>();
|
|
|
|
|
|
|
|
std::for_each(inputFiles.cbegin(), inputFiles.cend(),
|
|
|
|
[&](const auto &inputFile)
|
|
|
|
{
|
|
|
|
parser.readFile(inputFile);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
parser.readStream("std::cin", std::cin);
|
|
|
|
|
2016-06-10 01:23:41 +02:00
|
|
|
const auto detectLanguage =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
if (variablesMap.count("language") == 0)
|
|
|
|
return plasp::detectLanguage(parser);
|
2016-05-29 16:27:11 +02:00
|
|
|
|
2016-06-10 01:23:41 +02:00
|
|
|
const auto languageName = variablesMap["language"].as<std::string>();
|
|
|
|
|
|
|
|
return plasp::Language::fromString(languageName);
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto language = detectLanguage();
|
|
|
|
|
|
|
|
if (language == plasp::Language::Type::Unknown)
|
|
|
|
{
|
|
|
|
std::cerr << "Error: Unknown input language" << std::endl << std::endl;
|
|
|
|
printHelp();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (language == plasp::Language::Type::PDDL)
|
|
|
|
plasp::pddl::Description::fromParser(std::move(parser));
|
|
|
|
else if (language == plasp::Language::Type::SAS)
|
2016-06-09 14:39:03 +02:00
|
|
|
{
|
2016-06-10 00:59:44 +02:00
|
|
|
const auto sasDescription = plasp::sas::Description::fromParser(std::move(parser));
|
|
|
|
const auto sasTranslator = plasp::sas::TranslatorASP(sasDescription);
|
|
|
|
sasTranslator.translate(std::cout);
|
2016-05-20 16:16:56 +02:00
|
|
|
}
|
2016-05-20 15:29:24 +02:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|