diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bb1e5f..2e76c1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ if (CMAKE_GENERATOR STREQUAL "Ninja" AND endif() add_subdirectory(lib/tokenize) +add_subdirectory(lib/colorlog) add_subdirectory(lib/pddlparse) add_subdirectory(src) add_subdirectory(app) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index f035153..d2002e2 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -7,6 +7,7 @@ set(includes ${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/lib/tokenize/include + ${PROJECT_SOURCE_DIR}/lib/colorlog/include ${PROJECT_SOURCE_DIR}/lib/variant/include ${PROJECT_SOURCE_DIR}/lib/pddlparse/include ) diff --git a/app/main.cpp b/app/main.cpp index 02c804e..8bd0111 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -4,16 +4,18 @@ #include +#include +#include +#include + #include #include #include #include #include -#include -#include -#include -#include +#include + #include #include #include @@ -49,7 +51,7 @@ int main(int argc, char **argv) std::cout << description; }; - plasp::output::Logger logger; + colorlog::Logger logger; try { @@ -62,7 +64,7 @@ int main(int argc, char **argv) } catch (const po::error &e) { - logger.log(plasp::output::Priority::Error, e.what()); + logger.log(colorlog::Priority::Error, e.what()); std::cout << std::endl; printHelp(); return EXIT_FAILURE; @@ -81,7 +83,7 @@ int main(int argc, char **argv) } if (warningsAsErrors) - logger.setAbortPriority(plasp::output::Priority::Warning); + logger.setAbortPriority(colorlog::Priority::Warning); auto parsingMode = pddl::Mode::Strict; @@ -91,7 +93,7 @@ int main(int argc, char **argv) parsingMode = pddl::Mode::Compatibility; else if (parsingModeString != "strict") { - logger.log(plasp::output::Priority::Error, "unknown parsing mode “" + parsingModeString + "”"); + logger.log(colorlog::Priority::Error, "unknown parsing mode “" + parsingModeString + "”"); std::cout << std::endl; printHelp(); return EXIT_FAILURE; @@ -101,20 +103,20 @@ int main(int argc, char **argv) [&]() { if (parsingMode != pddl::Mode::Compatibility) - logger.log(plasp::output::Priority::Info, "try using --parsing-mode=compatibility for extended legacy feature support"); + logger.log(colorlog::Priority::Info, "try using --parsing-mode=compatibility for extended legacy feature support"); }; const auto colorPolicy = variablesMap["color"].as(); if (colorPolicy == "auto") - logger.setColorPolicy(plasp::output::ColorStream::ColorPolicy::Auto); + logger.setColorPolicy(colorlog::ColorStream::ColorPolicy::Auto); else if (colorPolicy == "never") - logger.setColorPolicy(plasp::output::ColorStream::ColorPolicy::Never); + logger.setColorPolicy(colorlog::ColorStream::ColorPolicy::Never); else if (colorPolicy == "always") - logger.setColorPolicy(plasp::output::ColorStream::ColorPolicy::Always); + logger.setColorPolicy(colorlog::ColorStream::ColorPolicy::Always); else { - logger.log(plasp::output::Priority::Error, "unknown color policy “" + colorPolicy + "”"); + logger.log(colorlog::Priority::Error, "unknown color policy “" + colorPolicy + "”"); std::cout << std::endl; printHelp(); return EXIT_FAILURE; @@ -124,12 +126,12 @@ int main(int argc, char **argv) try { - const auto logPriority = plasp::output::priorityFromName(logPriorityString.c_str()); + const auto logPriority = colorlog::priorityFromName(logPriorityString.c_str()); logger.setLogPriority(logPriority); } catch (const std::exception &e) { - logger.log(plasp::output::Priority::Error, ("unknown log priorty “" + logPriorityString + "”").c_str()); + logger.log(colorlog::Priority::Error, ("unknown log priorty “" + logPriorityString + "”").c_str()); logger.errorStream() << std::endl; printHelp(); return EXIT_FAILURE; @@ -168,7 +170,7 @@ int main(int argc, char **argv) if (language == plasp::Language::Type::Unknown) { - logger.log(plasp::output::Priority::Error, "unknown input language"); + logger.log(colorlog::Priority::Error, "unknown input language"); std::cout << std::endl; printHelp(); return EXIT_FAILURE; @@ -179,7 +181,7 @@ int main(int argc, char **argv) const auto logWarning = [&](const auto &location, const auto &warning) { - logger.log(plasp::output::Priority::Warning, location, warning); + logger.log(colorlog::Priority::Warning, location, warning); }; auto context = pddl::Context(std::move(tokenizer), logWarning); @@ -197,7 +199,7 @@ int main(int argc, char **argv) } catch (const tokenize::TokenizerException &e) { - logger.log(plasp::output::Priority::Error, e.location(), e.message().c_str()); + logger.log(colorlog::Priority::Error, e.location(), e.message().c_str()); printCompatibilityInfo(); @@ -206,22 +208,22 @@ int main(int argc, char **argv) catch (const pddl::ParserException &e) { if (e.location()) - logger.log(plasp::output::Priority::Error, e.location().value(), e.message().c_str()); + logger.log(colorlog::Priority::Error, e.location().value(), e.message().c_str()); else - logger.log(plasp::output::Priority::Error, e.message().c_str()); + logger.log(colorlog::Priority::Error, e.message().c_str()); printCompatibilityInfo(); return EXIT_FAILURE; } - catch (const plasp::output::TranslatorException &e) + catch (const plasp::TranslatorException &e) { - logger.log(plasp::output::Priority::Error, e.what()); + logger.log(colorlog::Priority::Error, e.what()); return EXIT_FAILURE; } catch (const std::exception &e) { - logger.log(plasp::output::Priority::Error, e.what()); + logger.log(colorlog::Priority::Error, e.what()); return EXIT_FAILURE; } diff --git a/include/plasp/LanguageDetection.h b/include/plasp/LanguageDetection.h index c3b78b0..f88904c 100644 --- a/include/plasp/LanguageDetection.h +++ b/include/plasp/LanguageDetection.h @@ -1,10 +1,10 @@ #ifndef __PLASP__LANGUAGE_DETECTION_H #define __PLASP__LANGUAGE_DETECTION_H -#include - #include +#include + namespace plasp { diff --git a/include/plasp/output/TranslatorException.h b/include/plasp/TranslatorException.h similarity index 88% rename from include/plasp/output/TranslatorException.h rename to include/plasp/TranslatorException.h index 46cf4db..b076860 100644 --- a/include/plasp/output/TranslatorException.h +++ b/include/plasp/TranslatorException.h @@ -1,13 +1,11 @@ -#ifndef __PLASP__OUTPUT__TRANSLATOR_EXCEPTION_H -#define __PLASP__OUTPUT__TRANSLATOR_EXCEPTION_H +#ifndef __PLASP__TRANSLATOR_EXCEPTION_H +#define __PLASP__TRANSLATOR_EXCEPTION_H #include #include namespace plasp { -namespace output -{ //////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -50,7 +48,6 @@ class TranslatorException: public std::exception //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/include/plasp/pddl/TranslatorASP.h b/include/plasp/pddl/TranslatorASP.h index 37abc4e..4107a64 100644 --- a/include/plasp/pddl/TranslatorASP.h +++ b/include/plasp/pddl/TranslatorASP.h @@ -1,7 +1,7 @@ #ifndef __PLASP__PDDL__TRANSLATOR_ASP_H #define __PLASP__PDDL__TRANSLATOR_ASP_H -#include +#include #include #include @@ -20,7 +20,7 @@ namespace pddl class TranslatorASP { public: - explicit TranslatorASP(const ::pddl::ast::Description &description, output::ColorStream &outputStream); + explicit TranslatorASP(const ::pddl::ast::Description &description, colorlog::ColorStream &outputStream); void translate() const; @@ -36,7 +36,7 @@ class TranslatorASP void translateConstants(const std::string &heading, const ::pddl::ast::ConstantDeclarations &constants) const; const ::pddl::ast::Description &m_description; - output::ColorStream &m_outputStream; + colorlog::ColorStream &m_outputStream; }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/plasp/pddl/translation/Effect.h b/include/plasp/pddl/translation/Effect.h index 0bdae6e..d35ff35 100644 --- a/include/plasp/pddl/translation/Effect.h +++ b/include/plasp/pddl/translation/Effect.h @@ -1,10 +1,11 @@ #ifndef __PLASP__PDDL__TRANSLATION__EFFECT_H #define __PLASP__PDDL__TRANSLATION__EFFECT_H +#include + #include -#include -#include +#include #include #include @@ -21,25 +22,25 @@ namespace pddl //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline void translateEffect(output::ColorStream &outputStream, const ::pddl::ast::Effect &effect, const std::string &objectType, PrintObjectName printObjectName) +inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::ast::Effect &effect, const std::string &objectType, PrintObjectName printObjectName) { const auto handleUnsupported = [](const auto &) { - throw output::TranslatorException("only “and” expressions and (negated) predicates supported as action effects currently"); + throw TranslatorException("only “and” expressions and (negated) predicates supported as action effects currently"); }; const auto handlePredicate = [&](const ::pddl::ast::PredicatePointer &predicate, bool isPositive = true) { - outputStream << std::endl << output::Function("postcondition") << "("; + outputStream << std::endl << colorlog::Function("postcondition") << "("; printObjectName(); outputStream - << ", " << output::Keyword("effect") << "(" - << output::Reserved("unconditional") << ")" + << ", " << colorlog::Keyword("effect") << "(" + << colorlog::Reserved("unconditional") << ")" << ", "; translatePredicateToVariable(outputStream, *predicate, isPositive); - outputStream << ") :- " << output::Function(objectType.c_str()) << "("; + outputStream << ") :- " << colorlog::Function(objectType.c_str()) << "("; printObjectName(); outputStream << ")."; }; diff --git a/include/plasp/pddl/translation/Goal.h b/include/plasp/pddl/translation/Goal.h index 45094fa..c48dd52 100644 --- a/include/plasp/pddl/translation/Goal.h +++ b/include/plasp/pddl/translation/Goal.h @@ -1,10 +1,11 @@ #ifndef __PLASP__PDDL__TRANSLATION__GOAL_H #define __PLASP__PDDL__TRANSLATION__GOAL_H +#include + #include -#include -#include +#include #include #include @@ -20,18 +21,18 @@ namespace pddl // //////////////////////////////////////////////////////////////////////////////////////////////////// -inline void translateGoal(output::ColorStream &outputStream, const ::pddl::ast::Goal &goal) +inline void translateGoal(colorlog::ColorStream &outputStream, const ::pddl::ast::Goal &goal) { const auto handleUnsupported = [](const auto &) { - throw output::TranslatorException("only “and” expressions and (negated) predicates supported as goals currently"); + throw TranslatorException("only “and” expressions and (negated) predicates supported as goals currently"); }; const auto handlePredicate = [&](const ::pddl::ast::PredicatePointer &predicate, bool isPositive = true) { - outputStream << std::endl << output::Function("goal") << "("; + outputStream << std::endl << colorlog::Function("goal") << "("; // TODO: assert that goal is variable-free translatePredicateToVariable(outputStream, *predicate, isPositive); outputStream << ")."; diff --git a/include/plasp/pddl/translation/Precondition.h b/include/plasp/pddl/translation/Precondition.h index 95c2912..4b8ed31 100644 --- a/include/plasp/pddl/translation/Precondition.h +++ b/include/plasp/pddl/translation/Precondition.h @@ -1,10 +1,11 @@ #ifndef __PLASP__PDDL__TRANSLATION__PRECONDITION_H #define __PLASP__PDDL__TRANSLATION__PRECONDITION_H +#include + #include -#include -#include +#include #include #include @@ -21,22 +22,22 @@ namespace pddl //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline void translatePrecondition(output::ColorStream &outputStream, const ::pddl::ast::Precondition &precondition, const std::string &objectType, PrintObjectName printObjectName) +inline void translatePrecondition(colorlog::ColorStream &outputStream, const ::pddl::ast::Precondition &precondition, const std::string &objectType, PrintObjectName printObjectName) { const auto handleUnsupported = [](const auto &) { - throw output::TranslatorException("only “and” expressions and (negated) predicates supported as action preconditions currently"); + throw TranslatorException("only “and” expressions and (negated) predicates supported as action preconditions currently"); }; const auto handlePredicate = [&](const ::pddl::ast::PredicatePointer &predicate, bool isPositive = true) { - outputStream << std::endl << output::Function("precondition") << "("; + outputStream << std::endl << colorlog::Function("precondition") << "("; printObjectName(); outputStream << ", "; translatePredicateToVariable(outputStream, *predicate, isPositive); - outputStream << ") :- " << output::Function(objectType.c_str()) << "("; + outputStream << ") :- " << colorlog::Function(objectType.c_str()) << "("; printObjectName(); outputStream << ")."; }; diff --git a/include/plasp/pddl/translation/Predicate.h b/include/plasp/pddl/translation/Predicate.h index f35b7ac..ea5e243 100644 --- a/include/plasp/pddl/translation/Predicate.h +++ b/include/plasp/pddl/translation/Predicate.h @@ -1,11 +1,11 @@ #ifndef __PLASP__PDDL__TRANSLATION__PREDICATE_H #define __PLASP__PDDL__TRANSLATION__PREDICATE_H +#include + #include #include -#include - #include #include @@ -20,12 +20,12 @@ namespace pddl // //////////////////////////////////////////////////////////////////////////////////////////////////// -void translatePredicate(output::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate); -void translatePredicateDeclaration(output::ColorStream &outputStream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration); +void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate); +void translatePredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration); //////////////////////////////////////////////////////////////////////////////////////////////////// -inline void translatePredicate(output::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate) +inline void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate) { const auto &arguments = predicate.arguments; @@ -44,7 +44,7 @@ inline void translatePredicate(output::ColorStream &outputStream, const ::pddl:: const auto handleConstant = [&](const ::pddl::ast::ConstantPointer &constant) { - outputStream << output::Keyword("constant") << "(" << *constant << ")"; + outputStream << colorlog::Keyword("constant") << "(" << *constant << ")"; }; const auto handleVariable = @@ -56,7 +56,7 @@ inline void translatePredicate(output::ColorStream &outputStream, const ::pddl:: const auto handleUnsupported = [&](const auto &) { - throw output::TranslatorException("only variables and constants supported in predicates currently"); + throw TranslatorException("only variables and constants supported in predicates currently"); }; argument.match(handleConstant, handleVariable, handleUnsupported); @@ -67,9 +67,9 @@ inline void translatePredicate(output::ColorStream &outputStream, const ::pddl:: //////////////////////////////////////////////////////////////////////////////////////////////////// -inline void translatePredicateDeclaration(output::ColorStream &outputStream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration) +inline void translatePredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration) { - outputStream << output::Keyword("variable") << "("; + outputStream << colorlog::Keyword("variable") << "("; if (predicateDeclaration.parameters.empty()) { @@ -84,18 +84,18 @@ inline void translatePredicateDeclaration(output::ColorStream &outputStream, con //////////////////////////////////////////////////////////////////////////////////////////////////// -void translatePredicateToVariable(output::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate, bool isPositive = true) +void translatePredicateToVariable(colorlog::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate, bool isPositive = true) { - outputStream << output::Keyword("variable") << "("; + outputStream << colorlog::Keyword("variable") << "("; translatePredicate(outputStream, predicate); - outputStream << "), " << output::Keyword("value") << "("; + outputStream << "), " << colorlog::Keyword("value") << "("; translatePredicate(outputStream, predicate); outputStream << ", "; if (isPositive) - outputStream << output::Boolean("true"); + outputStream << colorlog::Boolean("true"); else - outputStream << output::Boolean("false"); + outputStream << colorlog::Boolean("false"); outputStream << ")"; } diff --git a/include/plasp/pddl/translation/Primitives.h b/include/plasp/pddl/translation/Primitives.h index ae10470..d70d2b0 100644 --- a/include/plasp/pddl/translation/Primitives.h +++ b/include/plasp/pddl/translation/Primitives.h @@ -1,10 +1,11 @@ #ifndef __PLASP__PDDL__TRANSLATION__PRIMITIVES_H #define __PLASP__PDDL__TRANSLATION__PRIMITIVES_H +#include + #include -#include -#include +#include namespace plasp { @@ -17,16 +18,16 @@ namespace pddl // //////////////////////////////////////////////////////////////////////////////////////////////////// -inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::ConstantDeclaration &constantDeclaration) +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::ConstantDeclaration &constantDeclaration) { assert(!constantDeclaration.name.empty()); - return (stream << output::String(constantDeclaration.name.c_str())); + return (stream << colorlog::String(constantDeclaration.name.c_str())); } //////////////////////////////////////////////////////////////////////////////////////////////////// -inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::Constant &constant) +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::Constant &constant) { assert(constant.declaration != nullptr); @@ -35,16 +36,16 @@ inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl //////////////////////////////////////////////////////////////////////////////////////////////////// -inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::PrimitiveTypeDeclaration &primitiveTypeDeclaration) +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::PrimitiveTypeDeclaration &primitiveTypeDeclaration) { assert(!primitiveTypeDeclaration.name.empty()); - return (stream << output::String(primitiveTypeDeclaration.name.c_str())); + return (stream << colorlog::String(primitiveTypeDeclaration.name.c_str())); } //////////////////////////////////////////////////////////////////////////////////////////////////// -inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::PrimitiveType &primitiveType) +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::PrimitiveType &primitiveType) { assert(primitiveType.declaration != nullptr); @@ -53,7 +54,7 @@ inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl //////////////////////////////////////////////////////////////////////////////////////////////////// -inline output::ColorStream &operator<<(output::ColorStream &stream, ::pddl::ast::VariableDeclaration &variableDeclaration) +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, ::pddl::ast::VariableDeclaration &variableDeclaration) { assert(!variableDeclaration.name.empty()); assert(std::isalpha(variableDeclaration.name[0])); @@ -62,14 +63,14 @@ inline output::ColorStream &operator<<(output::ColorStream &stream, ::pddl::ast: variableDeclaration.name[0] = std::toupper(variableDeclaration.name[0]); return (stream - << output::Format({output::Color::Green, output::FontWeight::Bold}) + << colorlog::Format({colorlog::Color::Green, colorlog::FontWeight::Bold}) << variableDeclaration.name - << output::ResetFormat()); + << colorlog::ResetFormat()); } //////////////////////////////////////////////////////////////////////////////////////////////////// -inline output::ColorStream &operator<<(output::ColorStream &stream, ::pddl::ast::Variable &variable) +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, ::pddl::ast::Variable &variable) { assert(variable.declaration != nullptr); @@ -79,23 +80,23 @@ inline output::ColorStream &operator<<(output::ColorStream &stream, ::pddl::ast: //////////////////////////////////////////////////////////////////////////////////////////////////// // TODO: move to appropriate header -inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::Action &action) +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::Action &action) { - return (stream << output::String(action.name.c_str())); + return (stream << colorlog::String(action.name.c_str())); } //////////////////////////////////////////////////////////////////////////////////////////////////// // TODO: move to appropriate header -inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration) +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration) { - return (stream << output::String(predicateDeclaration.name.c_str())); + return (stream << colorlog::String(predicateDeclaration.name.c_str())); } //////////////////////////////////////////////////////////////////////////////////////////////////// // TODO: move to appropriate header -inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::Predicate &predicate) +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::Predicate &predicate) { return (stream << *predicate.declaration); } diff --git a/include/plasp/pddl/translation/Variables.h b/include/plasp/pddl/translation/Variables.h index e39e085..ffa767a 100644 --- a/include/plasp/pddl/translation/Variables.h +++ b/include/plasp/pddl/translation/Variables.h @@ -1,11 +1,12 @@ #ifndef __PLASP__PDDL__TRANSLATION__VARIABLES_H #define __PLASP__PDDL__TRANSLATION__VARIABLES_H +#include + #include #include -#include -#include +#include namespace plasp { @@ -19,14 +20,14 @@ namespace pddl //////////////////////////////////////////////////////////////////////////////////////////////////// template -void translateVariablesForRuleHead(output::ColorStream &outputStream, const T &variables); +void translateVariablesForRuleHead(colorlog::ColorStream &outputStream, const T &variables); template -void translateVariablesForRuleBody(output::ColorStream &outputStream, const T &variables); +void translateVariablesForRuleBody(colorlog::ColorStream &outputStream, const T &variables); //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline void translateVariablesForRuleHead(output::ColorStream &outputStream, const T &variables) +inline void translateVariablesForRuleHead(colorlog::ColorStream &outputStream, const T &variables) { if (variables.empty()) return; @@ -38,7 +39,7 @@ inline void translateVariablesForRuleHead(output::ColorStream &outputStream, con //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline void translateVariablesForRuleBody(output::ColorStream &outputStream, const T &variables) +inline void translateVariablesForRuleBody(colorlog::ColorStream &outputStream, const T &variables) { if (variables.empty()) return; @@ -53,18 +54,18 @@ inline void translateVariablesForRuleBody(output::ColorStream &outputStream, con if (variable->type) { if (!variable->type.value().template is<::pddl::ast::PrimitiveTypePointer>()) - throw output::TranslatorException("only primitive types supported currently"); + throw TranslatorException("only primitive types supported currently"); const auto &type = variable->type.value().template get<::pddl::ast::PrimitiveTypePointer>(); - outputStream << output::Function("has") << "(" - << *variable << ", " << output::Keyword("type") << "(" << *type << "))"; + outputStream << colorlog::Function("has") << "(" + << *variable << ", " << colorlog::Keyword("type") << "(" << *type << "))"; } else { - outputStream << output::Function("has") << "(" + outputStream << colorlog::Function("has") << "(" << *variable << ", " - << output::Keyword("type") << "(" << output::String("object") << "))"; + << colorlog::Keyword("type") << "(" << colorlog::String("object") << "))"; } } } diff --git a/include/plasp/sas/AssignedVariable.h b/include/plasp/sas/AssignedVariable.h index e665661..2302fe2 100644 --- a/include/plasp/sas/AssignedVariable.h +++ b/include/plasp/sas/AssignedVariable.h @@ -4,11 +4,11 @@ #include #include +#include + #include #include -#include - namespace plasp { namespace sas diff --git a/include/plasp/sas/AxiomRule.h b/include/plasp/sas/AxiomRule.h index 62da187..dc3513d 100644 --- a/include/plasp/sas/AxiomRule.h +++ b/include/plasp/sas/AxiomRule.h @@ -3,11 +3,11 @@ #include +#include + #include #include -#include - namespace plasp { namespace sas diff --git a/include/plasp/sas/Debugging.h b/include/plasp/sas/Debugging.h index 5b00f16..427e23a 100644 --- a/include/plasp/sas/Debugging.h +++ b/include/plasp/sas/Debugging.h @@ -3,6 +3,8 @@ #include +#include + #include namespace plasp @@ -16,7 +18,7 @@ namespace sas // //////////////////////////////////////////////////////////////////////////////////////////////////// -output::ColorStream &operator<<(output::ColorStream &ostream, const Description &description); +colorlog::ColorStream &operator<<(colorlog::ColorStream &ostream, const Description &description); //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/plasp/sas/Description.h b/include/plasp/sas/Description.h index fd4313d..1c9e8cf 100644 --- a/include/plasp/sas/Description.h +++ b/include/plasp/sas/Description.h @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -14,8 +15,6 @@ #include #include -#include - namespace plasp { namespace sas diff --git a/include/plasp/sas/Effect.h b/include/plasp/sas/Effect.h index cf46da7..8236a41 100644 --- a/include/plasp/sas/Effect.h +++ b/include/plasp/sas/Effect.h @@ -3,11 +3,11 @@ #include +#include + #include #include -#include - namespace plasp { namespace sas diff --git a/include/plasp/sas/Goal.h b/include/plasp/sas/Goal.h index f9a8cab..b73591a 100644 --- a/include/plasp/sas/Goal.h +++ b/include/plasp/sas/Goal.h @@ -1,10 +1,10 @@ #ifndef __PLASP__SAS__GOAL_H #define __PLASP__SAS__GOAL_H -#include - #include +#include + namespace plasp { namespace sas diff --git a/include/plasp/sas/InitialState.h b/include/plasp/sas/InitialState.h index 2c702aa..c2fb785 100644 --- a/include/plasp/sas/InitialState.h +++ b/include/plasp/sas/InitialState.h @@ -1,10 +1,10 @@ #ifndef __PLASP__SAS__INITIAL_STATE_H #define __PLASP__SAS__INITIAL_STATE_H -#include - #include +#include + namespace plasp { namespace sas diff --git a/include/plasp/sas/MutexGroup.h b/include/plasp/sas/MutexGroup.h index 78ed9b1..95cd8cf 100644 --- a/include/plasp/sas/MutexGroup.h +++ b/include/plasp/sas/MutexGroup.h @@ -3,10 +3,10 @@ #include -#include - #include +#include + namespace plasp { namespace sas diff --git a/include/plasp/sas/Operator.h b/include/plasp/sas/Operator.h index b232615..52e0d7f 100644 --- a/include/plasp/sas/Operator.h +++ b/include/plasp/sas/Operator.h @@ -4,13 +4,15 @@ #include #include -#include +#include + +#include + #include #include #include #include -#include namespace plasp { @@ -37,7 +39,7 @@ class Operator static Operator fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables); public: - void printPredicateAsASP(output::ColorStream &stream) const; + void printPredicateAsASP(colorlog::ColorStream &stream) const; const Predicate &predicate() const; const Conditions &preconditions() const; diff --git a/include/plasp/sas/Predicate.h b/include/plasp/sas/Predicate.h index 7d6e9aa..76e23f7 100644 --- a/include/plasp/sas/Predicate.h +++ b/include/plasp/sas/Predicate.h @@ -5,10 +5,10 @@ #include #include -#include - #include +#include + namespace plasp { namespace sas @@ -28,8 +28,8 @@ class Predicate using Arguments = std::vector; public: - void printAsSAS(output::ColorStream &stream) const; - void printAsASP(output::ColorStream &stream) const; + void printAsSAS(colorlog::ColorStream &stream) const; + void printAsASP(colorlog::ColorStream &stream) const; const std::string &name() const; const Arguments &arguments() const; diff --git a/include/plasp/sas/TranslatorASP.h b/include/plasp/sas/TranslatorASP.h index a2283e9..0690b58 100644 --- a/include/plasp/sas/TranslatorASP.h +++ b/include/plasp/sas/TranslatorASP.h @@ -3,7 +3,8 @@ #include -#include +#include + #include namespace plasp @@ -20,7 +21,7 @@ namespace sas class TranslatorASP { public: - explicit TranslatorASP(const Description &description, output::ColorStream &outputStream); + explicit TranslatorASP(const Description &description, colorlog::ColorStream &outputStream); void translate() const; @@ -34,7 +35,7 @@ class TranslatorASP void translateAxiomRules() const; const Description &m_description; - output::ColorStream &m_outputStream; + colorlog::ColorStream &m_outputStream; }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/plasp/sas/Value.h b/include/plasp/sas/Value.h index 4165a6f..0d8851c 100644 --- a/include/plasp/sas/Value.h +++ b/include/plasp/sas/Value.h @@ -5,10 +5,10 @@ #include #include -#include - #include +#include + namespace plasp { namespace sas @@ -46,8 +46,8 @@ struct Value public: Value negated() const; - void printAsSAS(output::ColorStream &stream) const; - void printAsASPPredicate(output::ColorStream &stream) const; + void printAsSAS(colorlog::ColorStream &stream) const; + void printAsASPPredicate(colorlog::ColorStream &stream) const; Sign sign() const; const std::string &name() const; diff --git a/include/plasp/sas/Variable.h b/include/plasp/sas/Variable.h index 4ddbd74..9c233d5 100644 --- a/include/plasp/sas/Variable.h +++ b/include/plasp/sas/Variable.h @@ -5,11 +5,12 @@ #include #include -#include -#include - #include +#include + +#include + namespace plasp { namespace sas @@ -33,7 +34,7 @@ class Variable static const Variable &referenceFromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables); public: - void printNameAsASPPredicate(output::ColorStream &outputStream) const; + void printNameAsASPPredicate(colorlog::ColorStream &outputStream) const; const std::string &name() const; int axiomLayer() const; diff --git a/include/plasp/sas/VariableTransition.h b/include/plasp/sas/VariableTransition.h index 9d287fa..457ddaf 100644 --- a/include/plasp/sas/VariableTransition.h +++ b/include/plasp/sas/VariableTransition.h @@ -3,11 +3,11 @@ #include +#include + #include #include -#include - namespace plasp { namespace sas diff --git a/lib/colorlog/CMakeLists.txt b/lib/colorlog/CMakeLists.txt new file mode 100644 index 0000000..7555f01 --- /dev/null +++ b/lib/colorlog/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 2.6) +project(colorlog) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Werror ${CMAKE_CXX_FLAGS}") +set(CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_CXX_FLAGS_DEBUG}") + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +if (CMAKE_GENERATOR STREQUAL "Ninja" AND + ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))) + # Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support. + # Rationale in https://github.com/ninja-build/ninja/issues/814 + set(CMAKE_CXX_FLAGS "-fdiagnostics-color=always ${CMAKE_CXX_FLAGS}") +endif() + +add_subdirectory(src) diff --git a/include/plasp/output/ColorStream.h b/lib/colorlog/include/colorlog/ColorStream.h similarity index 98% rename from include/plasp/output/ColorStream.h rename to lib/colorlog/include/colorlog/ColorStream.h index feecaa8..de00103 100644 --- a/include/plasp/output/ColorStream.h +++ b/lib/colorlog/include/colorlog/ColorStream.h @@ -1,12 +1,10 @@ -#ifndef __PLASP__OUTPUT__COLOR_STREAM_H -#define __PLASP__OUTPUT__COLOR_STREAM_H +#ifndef __COLOR_LOG__COLOR_STREAM_H +#define __COLOR_LOG__COLOR_STREAM_H #include #include -namespace plasp -{ -namespace output +namespace colorlog { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -288,7 +286,6 @@ ColorStream &ColorStream::operator<<(unsigned char value) //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/include/plasp/output/Formatting.h b/lib/colorlog/include/colorlog/Formatting.h similarity index 97% rename from include/plasp/output/Formatting.h rename to lib/colorlog/include/colorlog/Formatting.h index 147809c..3e5435f 100644 --- a/include/plasp/output/Formatting.h +++ b/lib/colorlog/include/colorlog/Formatting.h @@ -1,13 +1,11 @@ -#ifndef __PLASP__OUTPUT__FORMATTING_H -#define __PLASP__OUTPUT__FORMATTING_H +#ifndef __COLOR_LOG__FORMATTING_H +#define __COLOR_LOG__FORMATTING_H #include -#include +#include -namespace plasp -{ -namespace output +namespace colorlog { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -89,7 +87,7 @@ struct Function Function(const char *name) : name{name} { - }; + } const char *name; }; @@ -111,7 +109,7 @@ struct Keyword Keyword(const char *name) : name{name} { - }; + } const char *name; }; @@ -133,7 +131,7 @@ struct Operator Operator(const char *name) : name{name} { - }; + } const char *name; }; @@ -153,7 +151,7 @@ struct Number Number(T value) : value{value} { - }; + } T value; }; @@ -176,7 +174,7 @@ struct Variable Variable(const char *name) : name{name} { - }; + } const char *name; }; @@ -198,7 +196,7 @@ struct String String(const char *content) : content{content} { - }; + } const char *content; }; @@ -220,7 +218,7 @@ struct Boolean Boolean(const char *value) : value{value} { - }; + } const char *value; }; @@ -242,7 +240,7 @@ struct Reserved Reserved(const char *name) : name{name} { - }; + } const char *name; }; @@ -264,7 +262,7 @@ struct Heading1 Heading1(const char *content) : content{content} { - }; + } const char *content; }; @@ -289,7 +287,7 @@ struct Heading2 Heading2(const char *content) : content{content} { - }; + } const char *content; }; @@ -307,7 +305,6 @@ inline ColorStream &operator<<(ColorStream &stream, const Heading2 &heading2) //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/include/plasp/output/Logger.h b/lib/colorlog/include/colorlog/Logger.h similarity index 88% rename from include/plasp/output/Logger.h rename to lib/colorlog/include/colorlog/Logger.h index c732b0b..5b65b86 100644 --- a/include/plasp/output/Logger.h +++ b/lib/colorlog/include/colorlog/Logger.h @@ -1,16 +1,14 @@ -#ifndef __PLASP__OUTPUT__LOGGER_H -#define __PLASP__OUTPUT__LOGGER_H +#ifndef __COLOR_LOG__LOGGER_H +#define __COLOR_LOG__LOGGER_H #include -#include -#include +#include +#include #include -namespace plasp -{ -namespace output +namespace colorlog { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -50,7 +48,6 @@ class Logger //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/include/plasp/output/Priority.h b/lib/colorlog/include/colorlog/Priority.h similarity index 92% rename from include/plasp/output/Priority.h rename to lib/colorlog/include/colorlog/Priority.h index ff1baed..b04a789 100644 --- a/include/plasp/output/Priority.h +++ b/lib/colorlog/include/colorlog/Priority.h @@ -1,12 +1,10 @@ -#ifndef __PLASP__OUTPUT__PRIORITY_H -#define __PLASP__OUTPUT__PRIORITY_H +#ifndef __COLOR_LOG__PRIORITY_H +#define __COLOR_LOG__PRIORITY_H #include #include -namespace plasp -{ -namespace output +namespace colorlog { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -60,7 +58,6 @@ inline Priority priorityFromName(const char *priorityName) //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/lib/colorlog/src/CMakeLists.txt b/lib/colorlog/src/CMakeLists.txt new file mode 100644 index 0000000..ac13a4b --- /dev/null +++ b/lib/colorlog/src/CMakeLists.txt @@ -0,0 +1,21 @@ +set(target colorlog) + +file(GLOB core_sources "colorlog/*.cpp") +file(GLOB core_headers "../include/colorlog/*.h") + +set(includes + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/../../lib/tokenize/include +) + +set(sources + ${core_sources} + ${core_headers} +) + +set(libraries +) + +add_library(${target} ${sources}) +target_include_directories(${target} PRIVATE ${includes}) +target_link_libraries(${target} ${libraries}) diff --git a/src/plasp/output/Logger.cpp b/lib/colorlog/src/colorlog/Logger.cpp similarity index 97% rename from src/plasp/output/Logger.cpp rename to lib/colorlog/src/colorlog/Logger.cpp index 9f2b3f7..b82d0da 100644 --- a/src/plasp/output/Logger.cpp +++ b/lib/colorlog/src/colorlog/Logger.cpp @@ -1,10 +1,8 @@ -#include +#include -#include +#include -namespace plasp -{ -namespace output +namespace colorlog { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -165,4 +163,3 @@ void Logger::log(Priority priority, const tokenize::Location &location, const st //////////////////////////////////////////////////////////////////////////////////////////////////// } -} diff --git a/lib/pddlparse/include/pddlparse/AST.h b/lib/pddlparse/include/pddlparse/AST.h index d08e18c..eceed10 100644 --- a/lib/pddlparse/include/pddlparse/AST.h +++ b/lib/pddlparse/include/pddlparse/AST.h @@ -61,23 +61,6 @@ struct ConstantDeclaration //////////////////////////////////////////////////////////////////////////////////////////////////// -struct Dummy -{ - explicit Dummy(std::string name) - : name{name} - { - } - - Dummy(const Dummy &other) = delete; - Dummy &operator=(const Dummy &&other) = delete; - Dummy(Dummy &&other) = default; - Dummy &operator=(Dummy &&other) = default; - - std::string name; -}; - -//////////////////////////////////////////////////////////////////////////////////////////////////// - struct PrimitiveType { explicit PrimitiveType(PrimitiveTypeDeclaration *declaration) @@ -288,6 +271,7 @@ struct And: public NAry, Argument> //////////////////////////////////////////////////////////////////////////////////////////////////// +// TODO: make binary expression template struct At { diff --git a/lib/pddlparse/include/pddlparse/ASTOutput.h b/lib/pddlparse/include/pddlparse/ASTOutput.h new file mode 100644 index 0000000..f880ba9 --- /dev/null +++ b/lib/pddlparse/include/pddlparse/ASTOutput.h @@ -0,0 +1,728 @@ +#ifndef __PDDL_PARSE__AST_OUTPUT_H +#define __PDDL_PARSE__AST_OUTPUT_H + +#include +#include + +#include +#include + +namespace pddl +{ +namespace ast +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Output +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace detail +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct PrintContext +{ + size_t indentationLevel{0}; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct Identifier +{ + Identifier(const char *content) + : content{content} + { + } + + Identifier(const std::string &content) + : content{content.c_str()} + { + } + + const char *content; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Identifier &identifier) +{ + return (stream + << colorlog::Format({colorlog::Color::Green, colorlog::FontWeight::Normal}) + << identifier.content << colorlog::ResetFormat()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct Type +{ + Type(const char *name) + : name{name} + { + } + + Type(const std::string &name) + : name{name.c_str()} + { + } + + const char *name; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Type &type) +{ + return (stream + << colorlog::Format({colorlog::Color::Red, colorlog::FontWeight::Normal}) + << type.name << colorlog::ResetFormat()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct Constant +{ + Constant(const char *name) + : name{name} + { + } + + Constant(const std::string &name) + : name{name.c_str()} + { + } + + const char *name; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Constant &constant) +{ + return (stream + << colorlog::Format({colorlog::Color::Yellow, colorlog::FontWeight::Normal}) + << constant.name << colorlog::ResetFormat()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +colorlog::ColorStream &printIndentedNewline(colorlog::ColorStream &stream, detail::PrintContext &printContext) +{ + stream << std::endl; + + for (size_t i = 0; i < printContext.indentationLevel; i++) + stream << "\t"; + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Forward declarations +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Constant &constant, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ConstantDeclaration &constantDeclaration, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveType &primitiveType, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveTypeDeclaration &primitiveTypeDeclaration, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variable &variable, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const VariableDeclaration &variableDeclaration, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predicate &predicate, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PredicateDeclaration &predicateDeclaration, detail::PrintContext &printContext); + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Binary &binary, detail::PrintContext &printContext); +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const NAry &nAry, detail::PrintContext &printContext); +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Quantified &quantified, detail::PrintContext &printContext); + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const At &at, detail::PrintContext &printContext); +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Not ¬_, detail::PrintContext &printContext); + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Action &action, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Domain &domain, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const InitialState &initialState, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Problem &problem, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Requirement &requirement, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Description &description, detail::PrintContext &printContext); + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::unique_ptr &variant, detail::PrintContext &printContext); +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::vector &variant, detail::PrintContext &printContext); +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variant &variant, detail::PrintContext &printContext); + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Primitives +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Constant &constant, detail::PrintContext &) +{ + return stream << detail::Constant(constant.declaration->name); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ConstantDeclaration &constantDeclaration, detail::PrintContext &printContext) +{ + stream << detail::Constant(constantDeclaration.name); + + if (constantDeclaration.type) + { + stream << " - "; + print(stream, constantDeclaration.type.value(), printContext); + } + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveType &primitiveType, detail::PrintContext &) +{ + return stream << detail::Type(primitiveType.declaration->name); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveTypeDeclaration &primitiveTypeDeclaration, detail::PrintContext &printContext) +{ + if (primitiveTypeDeclaration.parentTypes.empty()) + return (stream << detail::Type(primitiveTypeDeclaration.name)); + + if (!primitiveTypeDeclaration.parentTypes.empty()) + for (const auto &parentType : primitiveTypeDeclaration.parentTypes) + { + if (&parentType != &primitiveTypeDeclaration.parentTypes.front()) + printIndentedNewline(stream, printContext); + + stream << detail::Type(primitiveTypeDeclaration.name) << " - " << detail::Type(parentType->declaration->name); + } + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Unsupported &unsupported, detail::PrintContext &) +{ + const auto unsupportedName = ""; + + return (stream << colorlog::Reserved(unsupportedName.c_str())); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variable &variable, detail::PrintContext &) +{ + const auto variableName = "?" + variable.declaration->name; + + return (stream << colorlog::Variable(variableName.c_str())); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const VariableDeclaration &variableDeclaration, detail::PrintContext &printContext) +{ + const auto variableName = "?" + variableDeclaration.name; + + stream << colorlog::Variable(variableName.c_str()); + + if (variableDeclaration.type) + { + stream << " - "; + print(stream, *variableDeclaration.type, printContext); + } + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Compounds +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predicate &predicate, detail::PrintContext &printContext) +{ + stream << "(" << detail::Identifier(predicate.declaration->name) << " "; + + for (const auto &argument : predicate.arguments) + { + if (&argument != &predicate.arguments.front()) + stream << " "; + + print(stream, argument, printContext); + } + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PredicateDeclaration &predicateDeclaration, detail::PrintContext &printContext) +{ + stream << "(" << detail::Identifier(predicateDeclaration.name); + + for (const auto ¶meter : predicateDeclaration.parameters) + { + stream << " "; + print(stream, *parameter, printContext); + } + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Expressions: Base Classes +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Binary &binary, detail::PrintContext &printContext) +{ + stream << "(" << colorlog::Keyword(Derived::Identifier); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, binary.argumentLeft, printContext); + printIndentedNewline(stream, printContext); + print(stream, binary.argumentRight, printContext); + + printContext.indentationLevel--; + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const NAry &nAry, detail::PrintContext &printContext) +{ + stream << "(" << colorlog::Keyword(Derived::Identifier); + + printContext.indentationLevel++; + + for (const auto &argument : nAry.arguments) + { + printIndentedNewline(stream, printContext); + print(stream, argument, printContext); + } + + printContext.indentationLevel--; + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Quantified &quantified, detail::PrintContext &printContext) +{ + stream << "(" << colorlog::Keyword(Derived::Identifier); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, quantified.parameters, printContext); + printIndentedNewline(stream, printContext); + print(stream, quantified.argument, printContext); + + printContext.indentationLevel--; + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Expressions +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const And &and_, detail::PrintContext &printContext) +{ + return print(stream, static_cast, Argument> &>(and_), printContext); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const At &at, detail::PrintContext &printContext) +{ + stream << "(" << colorlog::Keyword("at"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + stream << colorlog::Number(at.timePoint); + printIndentedNewline(stream, printContext); + print(stream, at.argument, printContext); + + printContext.indentationLevel--; + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Either &either, detail::PrintContext &printContext) +{ + return print(stream, static_cast, Argument> &>(either), printContext); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Exists &exists, detail::PrintContext &printContext) +{ + return print(stream, static_cast, Argument> &>(exists), printContext); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ForAll &forAll, detail::PrintContext &printContext) +{ + return print(stream, static_cast, Argument> &>(forAll), printContext); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Imply &imply, detail::PrintContext &printContext) +{ + return print(stream, static_cast, Argument> &>(imply), printContext); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Not ¬_, detail::PrintContext &printContext) +{ + stream << "(" << colorlog::Keyword("not"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, not_.argument, printContext); + + printContext.indentationLevel--; + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Or &or_, detail::PrintContext &printContext) +{ + return print(stream, static_cast, Argument> &>(or_), printContext); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const When &when, detail::PrintContext &printContext) +{ + return print(stream, static_cast, ArgumentLeft, ArgumentRight> &>(when), printContext); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// PDDL Structure +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Action &action, detail::PrintContext &printContext) +{ + stream << "(" << colorlog::Keyword(":action") << " " << detail::Identifier(action.name); + + printContext.indentationLevel++; + + if (!action.parameters.empty()) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":parameters"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, action.parameters, printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + if (action.precondition) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":precondition"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, action.precondition.value(), printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + if (action.effect) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":effect"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, action.effect.value(), printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + printContext.indentationLevel--; + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Domain &domain, detail::PrintContext &printContext) +{ + stream << "(" << colorlog::Keyword("define") << " (" << colorlog::Keyword("domain") << " " << detail::Identifier(domain.name) << ")"; + + printContext.indentationLevel++; + + if (!domain.requirements.empty()) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":requirements"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, domain.requirements, printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + if (!domain.types.empty()) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":types"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, domain.types, printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + if (!domain.constants.empty()) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":constants"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, domain.constants, printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + if (!domain.predicates.empty()) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":predicates"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, domain.predicates, printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + if (!domain.actions.empty()) + { + printIndentedNewline(stream, printContext); + print(stream, domain.actions, printContext); + } + + printContext.indentationLevel--; + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const InitialState &initialState, detail::PrintContext &printContext) +{ + assert(!initialState.facts.empty()); + + stream << "(" << colorlog::Keyword(":init"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, initialState.facts, printContext); + + printContext.indentationLevel--; + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Problem &problem, detail::PrintContext &printContext) +{ + stream << "(" << colorlog::Keyword("define") << " (" << colorlog::Keyword("problem") << " " << detail::Identifier(problem.name) << ")"; + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":domain") << " " << detail::Identifier(problem.domain->name) << ")"; + + if (!problem.requirements.empty()) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":requirements"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, problem.requirements, printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + if (!problem.objects.empty()) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":objects"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, problem.objects, printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + if (!problem.initialState.facts.empty()) + { + printIndentedNewline(stream, printContext); + print(stream, problem.initialState, printContext); + } + + if (problem.goal) + { + printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":goal"); + + printContext.indentationLevel++; + + printIndentedNewline(stream, printContext); + print(stream, problem.goal.value(), printContext); + stream << ")"; + + printContext.indentationLevel--; + } + + printContext.indentationLevel--; + + return (stream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Requirement &requirement, detail::PrintContext &) +{ + auto requirementName = std::string(":") + pddl::detail::toString(requirement); + + return (stream << detail::Identifier(requirementName.c_str())); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Description &description, detail::PrintContext &printContext) +{ + print(stream, *description.domain, printContext); + stream << std::endl; + + if (description.problem) + { + stream << std::endl; + print(stream, *description.problem.value(), printContext); + stream << std::endl; + } + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Description &description) +{ + detail::PrintContext printContext; + + return print(stream, description, printContext); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Variants +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::unique_ptr &uniquePointer, detail::PrintContext &printContext) +{ + assert(uniquePointer); + return print(stream, *uniquePointer, printContext); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::vector &vector, detail::PrintContext &printContext) +{ + for (const auto &element : vector) + { + if (&element != &vector.front()) + printIndentedNewline(stream, printContext); + + print(stream, element, printContext); + } + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variant &variant, detail::PrintContext &printContext) +{ + variant.match([&](const auto &x){return print(stream, x, printContext);}); + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif diff --git a/lib/pddlparse/src/CMakeLists.txt b/lib/pddlparse/src/CMakeLists.txt index 58421ff..0eb1160 100644 --- a/lib/pddlparse/src/CMakeLists.txt +++ b/lib/pddlparse/src/CMakeLists.txt @@ -11,6 +11,7 @@ file(GLOB detail_parsing_headers "../include/pddlparse/detail/parsing/*.h") set(includes ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/../../lib/colorlog/include ${PROJECT_SOURCE_DIR}/../../lib/tokenize/include ${PROJECT_SOURCE_DIR}/../../lib/variant/include ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d1f47a6..ed28563 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,28 +6,17 @@ file(GLOB core_headers "../include/plasp/*.h") file(GLOB pddl_sources "plasp/pddl/*.cpp") file(GLOB pddl_headers "../include/plasp/pddl/*.h") -file(GLOB pddl_expressions_sources "plasp/pddl/expressions/*.cpp") -file(GLOB pddl_expressions_headers "../include/plasp/pddl/expressions/*.h") - file(GLOB pddl_translation_sources "plasp/pddl/translation/*.cpp") file(GLOB pddl_translation_headers "../include/plasp/pddl/translation/*.h") file(GLOB sas_sources "plasp/sas/*.cpp") file(GLOB sas_headers "../include/plasp/sas/*.h") -file(GLOB input_sources "plasp/input/*.cpp") -file(GLOB input_headers "../include/plasp/input/*.h") - -file(GLOB output_sources "plasp/output/*.cpp") -file(GLOB output_headers "../include/plasp/output/*.h") - -file(GLOB utils_sources "plasp/utils/*.cpp") -file(GLOB utils_headers "../include/plasp/utils/*.h") - set(includes ${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/lib/tokenize/include + ${PROJECT_SOURCE_DIR}/lib/colorlog/include ${PROJECT_SOURCE_DIR}/lib/variant/include ${PROJECT_SOURCE_DIR}/lib/pddlparse/include ) @@ -60,6 +49,7 @@ set(sources set(libraries ${Boost_LIBRARIES} + colorlog pddlparse pthread ) diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp index 2896fd8..425c7da 100644 --- a/src/plasp/pddl/TranslatorASP.cpp +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -2,10 +2,11 @@ #include +#include + #include -#include -#include +#include #include #include @@ -25,7 +26,7 @@ namespace pddl // //////////////////////////////////////////////////////////////////////////////////////////////////// -TranslatorASP::TranslatorASP(const ::pddl::ast::Description &description, output::ColorStream &outputStream) +TranslatorASP::TranslatorASP(const ::pddl::ast::Description &description, colorlog::ColorStream &outputStream) : m_description{description}, m_outputStream(outputStream) { @@ -48,7 +49,7 @@ void TranslatorASP::translate() const void TranslatorASP::translateDomain() const { - m_outputStream << output::Heading1("domain"); + m_outputStream << colorlog::Heading1("domain"); const auto &domain = m_description.domain; @@ -82,7 +83,7 @@ void TranslatorASP::translateDomain() const void TranslatorASP::translateTypes() const { - m_outputStream << output::Heading2("types"); + m_outputStream << colorlog::Heading2("types"); m_outputStream << std::endl; @@ -91,8 +92,8 @@ void TranslatorASP::translateTypes() const if (types.empty()) { m_outputStream - << output::Function("type") << "(" - << output::Keyword("type") << "(" << output::String("object") << "))." << std::endl; + << colorlog::Function("type") << "(" + << colorlog::Keyword("type") << "(" << colorlog::String("object") << "))." << std::endl; return; } @@ -100,8 +101,8 @@ void TranslatorASP::translateTypes() const for (const auto &type : types) { m_outputStream - << output::Function("type") << "(" - << output::Keyword("type") << "(" + << colorlog::Function("type") << "(" + << colorlog::Keyword("type") << "(" << *type << "))." << std::endl; @@ -111,23 +112,23 @@ void TranslatorASP::translateTypes() const [&](const auto &parentType) { m_outputStream - << output::Function("inherits") << "(" << output::Keyword("type") - << "(" << *type << "), " << output::Keyword("type") + << colorlog::Function("inherits") << "(" << colorlog::Keyword("type") + << "(" << *type << "), " << colorlog::Keyword("type") << "(" << *parentType << "))." << std::endl; }); } m_outputStream << std::endl - << output::Function("has") << "(" - << output::Variable("X") << ", " - << output::Keyword("type") << "(" << output::Variable("T2") << ")) :- " - << output::Function("has") << "(" - << output::Variable("X") << ", " - << output::Keyword("type") << "(" << output::Variable("T1") << ")), " - << output::Function("inherits") << "(" - << output::Keyword("type") << "(" << output::Variable("T1") << "), " - << output::Keyword("type") << "(" << output::Variable("T2") << "))." + << colorlog::Function("has") << "(" + << colorlog::Variable("X") << ", " + << colorlog::Keyword("type") << "(" << colorlog::Variable("T2") << ")) :- " + << colorlog::Function("has") << "(" + << colorlog::Variable("X") << ", " + << colorlog::Keyword("type") << "(" << colorlog::Variable("T1") << ")), " + << colorlog::Function("inherits") << "(" + << colorlog::Keyword("type") << "(" << colorlog::Variable("T1") << "), " + << colorlog::Keyword("type") << "(" << colorlog::Variable("T2") << "))." << std::endl; } @@ -135,13 +136,13 @@ void TranslatorASP::translateTypes() const void TranslatorASP::translatePredicates() const { - m_outputStream << output::Heading2("variables"); + m_outputStream << colorlog::Heading2("variables"); const auto &predicates = m_description.domain->predicates; for (const auto &predicate : predicates) { - m_outputStream << std::endl << output::Function("variable") << "("; + m_outputStream << std::endl << colorlog::Function("variable") << "("; translatePredicateDeclaration(m_outputStream, *predicate); @@ -154,14 +155,14 @@ void TranslatorASP::translatePredicates() const m_outputStream << std::endl << std::endl - << output::Function("boolean") << "(" << output::Boolean("true") << ")." << std::endl - << output::Function("boolean") << "(" << output::Boolean("false") << ")." << std::endl + << colorlog::Function("boolean") << "(" << colorlog::Boolean("true") << ")." << std::endl + << colorlog::Function("boolean") << "(" << colorlog::Boolean("false") << ")." << std::endl << std::endl - << output::Function("contains") << "(" - << output::Keyword("variable") << "(" << output::Variable("X") << "), " - << output::Keyword("value") << "(" << output::Variable("X") << ", " << output::Variable("B") << ")) :- " - << output::Function("variable") << "(" << output::Keyword("variable") << "(" << output::Variable("X") << ")), " - << output::Function("boolean") << "(" << output::Variable("B") << ")." + << colorlog::Function("contains") << "(" + << colorlog::Keyword("variable") << "(" << colorlog::Variable("X") << "), " + << colorlog::Keyword("value") << "(" << colorlog::Variable("X") << ", " << colorlog::Variable("B") << ")) :- " + << colorlog::Function("variable") << "(" << colorlog::Keyword("variable") << "(" << colorlog::Variable("X") << ")), " + << colorlog::Function("boolean") << "(" << colorlog::Variable("B") << ")." << std::endl; } @@ -169,7 +170,7 @@ void TranslatorASP::translatePredicates() const void TranslatorASP::translateActions() const { - m_outputStream << output::Heading2("actions"); + m_outputStream << colorlog::Heading2("actions"); const auto &actions = m_description.domain->actions; @@ -178,7 +179,7 @@ void TranslatorASP::translateActions() const const auto printActionName = [&]() { - m_outputStream << output::Keyword("action") << "("; + m_outputStream << colorlog::Keyword("action") << "("; if (action->parameters.empty()) { @@ -194,7 +195,7 @@ void TranslatorASP::translateActions() const m_outputStream << std::endl; // Name - m_outputStream << output::Function("action") << "("; + m_outputStream << colorlog::Function("action") << "("; printActionName(); m_outputStream << ")"; @@ -217,13 +218,13 @@ void TranslatorASP::translateActions() const void TranslatorASP::translateConstants(const std::string &heading, const ::pddl::ast::ConstantDeclarations &constants) const { - m_outputStream << output::Heading2(heading.c_str()); + m_outputStream << colorlog::Heading2(heading.c_str()); for (const auto &constant : constants) { m_outputStream << std::endl - << output::Function("constant") << "(" - << output::Keyword("constant") << "(" + << colorlog::Function("constant") << "(" + << colorlog::Keyword("constant") << "(" << *constant << "))." << std::endl; @@ -232,19 +233,19 @@ void TranslatorASP::translateConstants(const std::string &heading, const ::pddl: if (type) { if (!type.value().is<::pddl::ast::PrimitiveTypePointer>()) - throw output::TranslatorException("only primitive types supported currently"); + throw TranslatorException("only primitive types supported currently"); const auto &primitveType = type.value().get<::pddl::ast::PrimitiveTypePointer>(); - m_outputStream << output::Function("has") << "(" - << output::Keyword("constant") << "(" << *constant << "), " - << output::Keyword("type") << "(" << *primitveType << "))." << std::endl; + m_outputStream << colorlog::Function("has") << "(" + << colorlog::Keyword("constant") << "(" << *constant << "), " + << colorlog::Keyword("type") << "(" << *primitveType << "))." << std::endl; } else { - m_outputStream << output::Function("has") << "(" - << output::Keyword("constant") << "(" << *constant << "), " - << output::Keyword("type") << "(" << output::String("object") << "))." << std::endl; + m_outputStream << colorlog::Function("has") << "(" + << colorlog::Keyword("constant") << "(" << *constant << "), " + << colorlog::Keyword("type") << "(" << colorlog::String("object") << "))." << std::endl; } } } @@ -255,7 +256,7 @@ void TranslatorASP::translateProblem() const { assert(m_description.problem); - m_outputStream << output::Heading1("problem"); + m_outputStream << colorlog::Heading1("problem"); const auto &problem = m_description.problem.value(); @@ -284,13 +285,13 @@ void TranslatorASP::translateInitialState() const { assert(m_description.problem); - m_outputStream << output::Heading2("initial state"); + m_outputStream << colorlog::Heading2("initial state"); const auto &facts = m_description.problem.value()->initialState.facts; for (const auto &fact : facts) { - m_outputStream << std::endl << output::Function("initialState") << "("; + m_outputStream << std::endl << colorlog::Function("initialState") << "("; // Translate single predicate if (fact.is<::pddl::ast::AtomicFormula>() && fact.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>()) @@ -305,28 +306,28 @@ void TranslatorASP::translateInitialState() const const auto ¬Expression = fact.get<::pddl::ast::NotPointer<::pddl::ast::Fact>>(); if (!notExpression->argument.is<::pddl::ast::AtomicFormula>() || !notExpression->argument.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>()) - throw output::TranslatorException("only negations of simple predicates supported in initial state currently"); + throw TranslatorException("only negations of simple predicates supported in initial state currently"); const auto &predicate = notExpression->argument.get<::pddl::ast::AtomicFormula>().get<::pddl::ast::PredicatePointer>(); translatePredicateToVariable(m_outputStream, *predicate, false); } else - throw output::TranslatorException("only predicates and their negations supported in initial state currently"); + throw TranslatorException("only predicates and their negations supported in initial state currently"); m_outputStream << ")."; } m_outputStream << std::endl << std::endl - << output::Function("initialState") << "(" - << output::Keyword("variable") << "(" << output::Variable("X") << "), " - << output::Keyword("value") << "(" << output::Variable("X") << ", " << output::Boolean("false") << ")) :- " - << output::Function("variable") << "(" << output::Keyword("variable") << "(" << output::Variable("X") << ")), " - << output::Keyword("not") << " " - << output::Function("initialState") << "(" - << output::Keyword("variable") << "(" << output::Variable("X") << "), " - << output::Keyword("value") << "(" << output::Variable("X") << ", " << output::Boolean("true") << "))." + << colorlog::Function("initialState") << "(" + << colorlog::Keyword("variable") << "(" << colorlog::Variable("X") << "), " + << colorlog::Keyword("value") << "(" << colorlog::Variable("X") << ", " << colorlog::Boolean("false") << ")) :- " + << colorlog::Function("variable") << "(" << colorlog::Keyword("variable") << "(" << colorlog::Variable("X") << ")), " + << colorlog::Keyword("not") << " " + << colorlog::Function("initialState") << "(" + << colorlog::Keyword("variable") << "(" << colorlog::Variable("X") << "), " + << colorlog::Keyword("value") << "(" << colorlog::Variable("X") << ", " << colorlog::Boolean("true") << "))." << std::endl; } @@ -337,7 +338,7 @@ void TranslatorASP::translateGoal() const assert(m_description.problem); assert(m_description.problem.value()->goal); - m_outputStream << output::Heading2("goal"); + m_outputStream << colorlog::Heading2("goal"); const auto &goal = m_description.problem.value()->goal.value(); // TODO: refactor diff --git a/src/plasp/sas/Debugging.cpp b/src/plasp/sas/Debugging.cpp index d12fcf4..444b248 100644 --- a/src/plasp/sas/Debugging.cpp +++ b/src/plasp/sas/Debugging.cpp @@ -13,7 +13,7 @@ namespace sas // //////////////////////////////////////////////////////////////////////////////////////////////////// -output::ColorStream &operator<<(output::ColorStream &stream, const Description &description) +colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Description &description) { // Metric section stream << "uses action costs: " << (description.usesActionCosts() ? "yes" : "no") << std::endl; diff --git a/src/plasp/sas/Description.cpp b/src/plasp/sas/Description.cpp index 6e8384b..04e344b 100644 --- a/src/plasp/sas/Description.cpp +++ b/src/plasp/sas/Description.cpp @@ -5,10 +5,10 @@ #include #include -#include - #include +#include + namespace plasp { namespace sas diff --git a/src/plasp/sas/Operator.cpp b/src/plasp/sas/Operator.cpp index 83a9802..4a12596 100644 --- a/src/plasp/sas/Operator.cpp +++ b/src/plasp/sas/Operator.cpp @@ -3,7 +3,8 @@ #include #include -#include +#include + #include namespace plasp @@ -46,9 +47,9 @@ Operator Operator::fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &va //////////////////////////////////////////////////////////////////////////////////////////////////// -void Operator::printPredicateAsASP(output::ColorStream &stream) const +void Operator::printPredicateAsASP(colorlog::ColorStream &stream) const { - stream << output::Keyword("action") << "("; + stream << colorlog::Keyword("action") << "("; m_predicate.printAsASP(stream); stream << ")"; } diff --git a/src/plasp/sas/Predicate.cpp b/src/plasp/sas/Predicate.cpp index 4c61d64..f6b44c8 100644 --- a/src/plasp/sas/Predicate.cpp +++ b/src/plasp/sas/Predicate.cpp @@ -4,10 +4,10 @@ #include #include -#include - #include +#include + namespace plasp { namespace sas @@ -66,7 +66,7 @@ const Predicate::Arguments &Predicate::arguments() const //////////////////////////////////////////////////////////////////////////////////////////////////// -void Predicate::printAsSAS(output::ColorStream &stream) const +void Predicate::printAsSAS(colorlog::ColorStream &stream) const { if (m_arguments.empty()) { @@ -84,18 +84,18 @@ void Predicate::printAsSAS(output::ColorStream &stream) const } //////////////////////////////////////////////////////////////////////////////////////////////////// -void Predicate::printAsASP(output::ColorStream &stream) const +void Predicate::printAsASP(colorlog::ColorStream &stream) const { if (m_arguments.empty()) { - stream << output::String(m_name.c_str()); + stream << colorlog::String(m_name.c_str()); return; } - stream << "(" << output::String(m_name.c_str()); + stream << "(" << colorlog::String(m_name.c_str()); for (size_t i = 0; i < m_arguments.size(); i++) - stream << ", " << output::String(m_arguments[i].c_str()); + stream << ", " << colorlog::String(m_arguments[i].c_str()); stream << ")"; } diff --git a/src/plasp/sas/TranslatorASP.cpp b/src/plasp/sas/TranslatorASP.cpp index c152f12..dbe7d46 100644 --- a/src/plasp/sas/TranslatorASP.cpp +++ b/src/plasp/sas/TranslatorASP.cpp @@ -2,7 +2,7 @@ #include -#include +#include namespace plasp { @@ -15,7 +15,7 @@ namespace sas // //////////////////////////////////////////////////////////////////////////////////////////////////// -TranslatorASP::TranslatorASP(const Description &description, output::ColorStream &outputStream) +TranslatorASP::TranslatorASP(const Description &description, colorlog::ColorStream &outputStream) : m_description(description), m_outputStream(outputStream) { @@ -58,30 +58,30 @@ void TranslatorASP::translate() const void TranslatorASP::translateRequirements() const { - m_outputStream << output::Heading2("feature requirements") << std::endl; + m_outputStream << colorlog::Heading2("feature requirements") << std::endl; if (m_description.usesActionCosts()) - m_outputStream << output::Function("requires") << "(" << output::Keyword("feature") << "(" << output::Reserved("actionCosts") << "))." << std::endl; + m_outputStream << colorlog::Function("requires") << "(" << colorlog::Keyword("feature") << "(" << colorlog::Reserved("actionCosts") << "))." << std::endl; if (m_description.usesAxiomRules()) - m_outputStream << output::Function("requires") << "(" << output::Keyword("feature") << "(" << output::Reserved("axiomRules") << "))." << std::endl; + m_outputStream << colorlog::Function("requires") << "(" << colorlog::Keyword("feature") << "(" << colorlog::Reserved("axiomRules") << "))." << std::endl; if (m_description.usesConditionalEffects()) - m_outputStream << output::Function("requires") << "(" << output::Keyword("feature") << "(" << output::Reserved("conditionalEffects") << "))." << std::endl; + m_outputStream << colorlog::Function("requires") << "(" << colorlog::Keyword("feature") << "(" << colorlog::Reserved("conditionalEffects") << "))." << std::endl; } //////////////////////////////////////////////////////////////////////////////////////////////////// void TranslatorASP::translateInitialState() const { - m_outputStream << output::Heading2("initial state") << std::endl; + m_outputStream << colorlog::Heading2("initial state") << std::endl; const auto &initialStateFacts = m_description.initialState().facts(); std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(), [&](const auto &fact) { - m_outputStream << output::Function("initialState") << "("; + m_outputStream << colorlog::Function("initialState") << "("; fact.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; fact.value().printAsASPPredicate(m_outputStream); @@ -93,14 +93,14 @@ void TranslatorASP::translateInitialState() const void TranslatorASP::translateGoal() const { - m_outputStream << output::Heading2("goal") << std::endl; + m_outputStream << colorlog::Heading2("goal") << std::endl; const auto &goalFacts = m_description.goal().facts(); std::for_each(goalFacts.cbegin(), goalFacts.cend(), [&](const auto &fact) { - m_outputStream << output::Function("goal") << "("; + m_outputStream << colorlog::Function("goal") << "("; fact.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; fact.value().printAsASPPredicate(m_outputStream); @@ -112,7 +112,7 @@ void TranslatorASP::translateGoal() const void TranslatorASP::translateVariables() const { - m_outputStream << output::Heading2("variables"); + m_outputStream << colorlog::Heading2("variables"); const auto &variables = m_description.variables(); @@ -123,14 +123,14 @@ void TranslatorASP::translateVariables() const BOOST_ASSERT(!values.empty()); - m_outputStream << std::endl << output::Function("variable") << "("; + m_outputStream << std::endl << colorlog::Function("variable") << "("; variable.printNameAsASPPredicate(m_outputStream); m_outputStream << ")." << std::endl; std::for_each(values.cbegin(), values.cend(), [&](const auto &value) { - m_outputStream << output::Function("contains") << "("; + m_outputStream << colorlog::Function("contains") << "("; variable.printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; value.printAsASPPredicate(m_outputStream); @@ -143,7 +143,7 @@ void TranslatorASP::translateVariables() const void TranslatorASP::translateActions() const { - m_outputStream << output::Heading2("actions"); + m_outputStream << colorlog::Heading2("actions"); const auto &operators = m_description.operators(); @@ -152,7 +152,7 @@ void TranslatorASP::translateActions() const std::for_each(operators.cbegin(), operators.cend(), [&](const auto &operator_) { - m_outputStream << std::endl << output::Function("action") << "("; + m_outputStream << std::endl << colorlog::Function("action") << "("; operator_.printPredicateAsASP(m_outputStream); m_outputStream << ")." << std::endl; @@ -161,7 +161,7 @@ void TranslatorASP::translateActions() const std::for_each(preconditions.cbegin(), preconditions.cend(), [&](const auto &precondition) { - m_outputStream << output::Function("precondition") << "("; + m_outputStream << colorlog::Function("precondition") << "("; operator_.printPredicateAsASP(m_outputStream); m_outputStream << ", "; precondition.variable().printNameAsASPPredicate(m_outputStream); @@ -177,13 +177,13 @@ void TranslatorASP::translateActions() const { const auto &conditions = effect.conditions(); - m_outputStream << output::Function("postcondition") << "("; + m_outputStream << colorlog::Function("postcondition") << "("; operator_.printPredicateAsASP(m_outputStream); if (conditions.empty()) - m_outputStream << ", " << output::Keyword("effect") << "(" << output::Reserved("unconditional") << "), "; + m_outputStream << ", " << colorlog::Keyword("effect") << "(" << colorlog::Reserved("unconditional") << "), "; else - m_outputStream << ", " << output::Keyword("effect") << "(" << output::Number(currentEffectID) << "), "; + m_outputStream << ", " << colorlog::Keyword("effect") << "(" << colorlog::Number(currentEffectID) << "), "; effect.postcondition().variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; @@ -195,8 +195,8 @@ void TranslatorASP::translateActions() const { // Conditions of conditional effects m_outputStream - << output::Function("precondition") << "(" - << output::Keyword("effect") << "(" << output::Number(currentEffectID) << "), "; + << colorlog::Function("precondition") << "(" + << colorlog::Keyword("effect") << "(" << colorlog::Number(currentEffectID) << "), "; condition.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; condition.value().printAsASPPredicate(m_outputStream); @@ -207,9 +207,9 @@ void TranslatorASP::translateActions() const currentEffectID++; }); - m_outputStream << output::Function("costs") << "("; + m_outputStream << colorlog::Function("costs") << "("; operator_.printPredicateAsASP(m_outputStream); - m_outputStream << ", " << output::Number(operator_.costs()) << ")." << std::endl; + m_outputStream << ", " << colorlog::Number(operator_.costs()) << ")." << std::endl; }); } @@ -217,7 +217,7 @@ void TranslatorASP::translateActions() const void TranslatorASP::translateMutexes() const { - m_outputStream << output::Heading2("mutex groups"); + m_outputStream << colorlog::Heading2("mutex groups"); const auto &mutexGroups = m_description.mutexGroups(); @@ -231,9 +231,9 @@ void TranslatorASP::translateMutexes() const m_outputStream << std::endl - << output::Function("mutexGroup") << "(" - << output::Keyword("mutexGroup") << "(" - << output::Number(mutexGroupID) + << colorlog::Function("mutexGroup") << "(" + << colorlog::Keyword("mutexGroup") << "(" + << colorlog::Number(mutexGroupID) << "))." << std::endl; const auto &facts = mutexGroup.facts(); @@ -241,7 +241,7 @@ void TranslatorASP::translateMutexes() const std::for_each(facts.cbegin(), facts.cend(), [&](const auto &fact) { - m_outputStream << output::Function("contains") << "(" << output::Keyword("mutexGroup") << "(" << output::Number(mutexGroupID) << "), "; + m_outputStream << colorlog::Function("contains") << "(" << colorlog::Keyword("mutexGroup") << "(" << colorlog::Number(mutexGroupID) << "), "; fact.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; fact.value().printAsASPPredicate(m_outputStream); @@ -254,7 +254,7 @@ void TranslatorASP::translateMutexes() const void TranslatorASP::translateAxiomRules() const { - m_outputStream << output::Heading2("axiom rules"); + m_outputStream << colorlog::Heading2("axiom rules"); const auto &axiomRules = m_description.axiomRules(); @@ -268,9 +268,9 @@ void TranslatorASP::translateAxiomRules() const m_outputStream << std::endl - << output::Function("axiomRule") << "(" - << output::Keyword("axiomRule") << "(" - << output::Number(axiomRuleID) + << colorlog::Function("axiomRule") << "(" + << colorlog::Keyword("axiomRule") << "(" + << colorlog::Number(axiomRuleID) << "))." << std::endl; // TODO: Translate axiom rule layer @@ -281,8 +281,8 @@ void TranslatorASP::translateAxiomRules() const [&](const auto &condition) { m_outputStream - << output::Function("precondition") << "(" - << output::Keyword("axiomRule") << "(" << output::Number(axiomRuleID) << "), "; + << colorlog::Function("precondition") << "(" + << colorlog::Keyword("axiomRule") << "(" << colorlog::Number(axiomRuleID) << "), "; condition.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; condition.value().printAsASPPredicate(m_outputStream); @@ -292,9 +292,9 @@ void TranslatorASP::translateAxiomRules() const const auto &postcondition = axiomRule.postcondition(); m_outputStream - << output::Function("postcondition") << "(" - << output::Keyword("axiomRule") << "(" << output::Number(axiomRuleID) << "), " - << output::Keyword("effect") << "(" << output::Reserved("unconditional") << "), "; + << colorlog::Function("postcondition") << "(" + << colorlog::Keyword("axiomRule") << "(" << colorlog::Number(axiomRuleID) << "), " + << colorlog::Keyword("effect") << "(" << colorlog::Reserved("unconditional") << "), "; postcondition.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; postcondition.value().printAsASPPredicate(m_outputStream); diff --git a/src/plasp/sas/Value.cpp b/src/plasp/sas/Value.cpp index 18f9f6d..c3d17b0 100644 --- a/src/plasp/sas/Value.cpp +++ b/src/plasp/sas/Value.cpp @@ -2,11 +2,12 @@ #include -#include -#include - #include +#include + +#include + namespace plasp { namespace sas @@ -128,22 +129,22 @@ const std::string &Value::name() const //////////////////////////////////////////////////////////////////////////////////////////////////// -void Value::printAsASPPredicate(output::ColorStream &stream) const +void Value::printAsASPPredicate(colorlog::ColorStream &stream) const { // TODO: do not compare by value if (*this == Value::None) { - stream << output::Keyword("value") << "(" << output::Reserved("none") << ")"; + stream << colorlog::Keyword("value") << "(" << colorlog::Reserved("none") << ")"; return; } - stream << output::Keyword("value") << "(" << output::String(m_name.c_str()) << ", " - << (m_sign == Sign::Positive ? output::Boolean("true") : output::Boolean("false")) << ")"; + stream << colorlog::Keyword("value") << "(" << colorlog::String(m_name.c_str()) << ", " + << (m_sign == Sign::Positive ? colorlog::Boolean("true") : colorlog::Boolean("false")) << ")"; } //////////////////////////////////////////////////////////////////////////////////////////////////// -void Value::printAsSAS(output::ColorStream &stream) const +void Value::printAsSAS(colorlog::ColorStream &stream) const { if (m_sign == Value::Sign::Positive) stream << "Atom "; diff --git a/src/plasp/sas/Variable.cpp b/src/plasp/sas/Variable.cpp index 92fc02d..d717a92 100644 --- a/src/plasp/sas/Variable.cpp +++ b/src/plasp/sas/Variable.cpp @@ -2,10 +2,10 @@ #include -#include - #include +#include + namespace plasp { namespace sas @@ -53,10 +53,10 @@ Variable Variable::fromSAS(tokenize::Tokenizer<> &tokenizer) //////////////////////////////////////////////////////////////////////////////////////////////////// -void Variable::printNameAsASPPredicate(output::ColorStream &stream) const +void Variable::printNameAsASPPredicate(colorlog::ColorStream &stream) const { // TODO: assert that name is a number indeed - stream << output::Keyword("variable") << "(" << output::Number(m_name) << ")"; + stream << colorlog::Keyword("variable") << "(" << colorlog::Number(m_name) << ")"; } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1db7bc5..fdbd602 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,7 @@ set(includes ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/lib/catch/single_include ${PROJECT_SOURCE_DIR}/lib/tokenize/include + ${PROJECT_SOURCE_DIR}/lib/colorlog/include ${PROJECT_SOURCE_DIR}/lib/variant/include ${PROJECT_SOURCE_DIR}/lib/pddlparse/include ) diff --git a/tests/TestPDDLTranslation.cpp b/tests/TestPDDLTranslation.cpp index aa817b2..de2fce6 100644 --- a/tests/TestPDDLTranslation.cpp +++ b/tests/TestPDDLTranslation.cpp @@ -3,10 +3,11 @@ #include #include +#include + #include #include -#include #include boost::iostreams::stream nullStream((boost::iostreams::null_sink())); @@ -17,7 +18,7 @@ const pddl::Context::WarningCallback ignoreWarnings = [](const auto &, const aut TEST_CASE("[PDDL translation] Former issues are fixed", "[PDDL translation]") { // TODO: refactor - plasp::output::Logger logger(nullStream, nullStream); + colorlog::Logger logger(nullStream, nullStream); pddl::Tokenizer tokenizer; pddl::Context context(std::move(tokenizer), ignoreWarnings);