From 8ef874eb22890685a09008bbeb550f5825cc23be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Fri, 10 Jun 2016 00:59:44 +0200 Subject: [PATCH] Simplified plasp application by initializing parser externally. --- apps/plasp-app/main.cpp | 45 +++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/apps/plasp-app/main.cpp b/apps/plasp-app/main.cpp index ea9040f..447d86d 100644 --- a/apps/plasp-app/main.cpp +++ b/apps/plasp-app/main.cpp @@ -61,37 +61,34 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } + plasp::utils::Parser parser; + + parser.setCaseSensitive(false); + + if (variablesMap.count("input")) + { + const auto &inputFiles = variablesMap["input"].as>(); + + std::for_each(inputFiles.cbegin(), inputFiles.cend(), + [&](const auto &inputFile) + { + parser.readFile(inputFile); + }); + } + else + parser.readStream("std::cin", std::cin); + auto format = variablesMap["format"].as(); std::transform(format.begin(), format.end(), format.begin(), ::tolower); if (format == "sas") { - if (variablesMap.count("input")) - { - const auto &inputFiles = variablesMap["input"].as>(); - const auto sasDescription = plasp::sas::Description::fromFile(inputFiles.front()); - const auto sasTranslator = plasp::sas::TranslatorASP(sasDescription); - sasTranslator.translate(std::cout); - } - else - { - const auto sasDescription = plasp::sas::Description::fromStream(std::cin); - const auto sasTranslator = plasp::sas::TranslatorASP(sasDescription); - sasTranslator.translate(std::cout); - } + const auto sasDescription = plasp::sas::Description::fromParser(std::move(parser)); + const auto sasTranslator = plasp::sas::TranslatorASP(sasDescription); + sasTranslator.translate(std::cout); } else if (format == "pddl") - { - if (variablesMap.count("input")) - { - const auto &inputFiles = variablesMap["input"].as>(); - const auto pddlDescription = plasp::pddl::Description::fromFiles(inputFiles); - } - else - const auto pddlDescription = plasp::pddl::Description::fromStream(std::cin); - - //std::cout << pddlDescription << std::endl; - } + plasp::pddl::Description::fromParser(std::move(parser)); return EXIT_SUCCESS; }