Moved color logging to separate library for reusing it in PDDL parser.
This commit is contained in:
parent
595891f040
commit
e93085d88a
@ -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)
|
||||
|
@ -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
|
||||
)
|
||||
|
48
app/main.cpp
48
app/main.cpp
@ -4,16 +4,18 @@
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
#include <colorlog/Logger.h>
|
||||
#include <colorlog/Priority.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/Exception.h>
|
||||
#include <pddlparse/Mode.h>
|
||||
#include <pddlparse/Parse.h>
|
||||
|
||||
#include <plasp/LanguageDetection.h>
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <plasp/output/Logger.h>
|
||||
#include <plasp/output/Priority.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/TranslatorASP.h>
|
||||
#include <plasp/sas/Description.h>
|
||||
#include <plasp/sas/TranslatorASP.h>
|
||||
@ -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<std::string>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
#ifndef __PLASP__LANGUAGE_DETECTION_H
|
||||
#define __PLASP__LANGUAGE_DETECTION_H
|
||||
|
||||
#include <plasp/Language.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/Language.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
|
||||
|
@ -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 <exception>
|
||||
#include <string>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -50,7 +48,6 @@ class TranslatorException: public std::exception
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATOR_ASP_H
|
||||
#define __PLASP__PDDL__TRANSLATOR_ASP_H
|
||||
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Parse.h>
|
||||
@ -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;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__EFFECT_H
|
||||
#define __PLASP__PDDL__TRANSLATION__EFFECT_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
@ -21,25 +22,25 @@ namespace pddl
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename PrintObjectName>
|
||||
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 << ").";
|
||||
};
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__GOAL_H
|
||||
#define __PLASP__PDDL__TRANSLATION__GOAL_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
@ -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 << ").";
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__PRECONDITION_H
|
||||
#define __PLASP__PDDL__TRANSLATION__PRECONDITION_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
@ -21,22 +22,22 @@ namespace pddl
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename PrintObjectName>
|
||||
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 << ").";
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__PREDICATE_H
|
||||
#define __PLASP__PDDL__TRANSLATION__PREDICATE_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/Parse.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
#include <plasp/pddl/translation/Variables.h>
|
||||
|
||||
@ -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 << ")";
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__PRIMITIVES_H
|
||||
#define __PLASP__PDDL__TRANSLATION__PRIMITIVES_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__VARIABLES_H
|
||||
#define __PLASP__PDDL__TRANSLATION__VARIABLES_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/Parse.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -19,14 +20,14 @@ namespace pddl
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
void translateVariablesForRuleHead(output::ColorStream &outputStream, const T &variables);
|
||||
void translateVariablesForRuleHead(colorlog::ColorStream &outputStream, const T &variables);
|
||||
template<class T>
|
||||
void translateVariablesForRuleBody(output::ColorStream &outputStream, const T &variables);
|
||||
void translateVariablesForRuleBody(colorlog::ColorStream &outputStream, const T &variables);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
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<class T>
|
||||
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") << "))";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,11 @@
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/Value.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
|
@ -3,11 +3,11 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <plasp/sas/Description.h>
|
||||
|
||||
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);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AxiomRule.h>
|
||||
#include <plasp/sas/Goal.h>
|
||||
#include <plasp/sas/InitialState.h>
|
||||
@ -13,8 +15,6 @@
|
||||
#include <plasp/sas/Operator.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
|
@ -3,11 +3,11 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
|
@ -1,10 +1,10 @@
|
||||
#ifndef __PLASP__SAS__GOAL_H
|
||||
#define __PLASP__SAS__GOAL_H
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
|
@ -1,10 +1,10 @@
|
||||
#ifndef __PLASP__SAS__INITIAL_STATE_H
|
||||
#define __PLASP__SAS__INITIAL_STATE_H
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
|
@ -4,13 +4,15 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Effect.h>
|
||||
#include <plasp/sas/Predicate.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
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;
|
||||
|
@ -5,10 +5,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/output/ColorStream.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
@ -28,8 +28,8 @@ class Predicate
|
||||
using Arguments = std::vector<std::string>;
|
||||
|
||||
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;
|
||||
|
@ -3,7 +3,8 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <plasp/sas/Description.h>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -5,10 +5,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/output/ColorStream.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
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;
|
||||
|
@ -5,11 +5,12 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <plasp/sas/Value.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <plasp/sas/Value.h>
|
||||
|
||||
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;
|
||||
|
@ -3,11 +3,11 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/Value.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
|
23
lib/colorlog/CMakeLists.txt
Normal file
23
lib/colorlog/CMakeLists.txt
Normal file
@ -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)
|
@ -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 <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -288,7 +286,6 @@ ColorStream &ColorStream::operator<<(unsigned char value)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -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 <iostream>
|
||||
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -307,7 +305,6 @@ inline ColorStream &operator<<(ColorStream &stream, const Heading2 &heading2)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -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 <string>
|
||||
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <plasp/output/Priority.h>
|
||||
#include <colorlog/ColorStream.h>
|
||||
#include <colorlog/Priority.h>
|
||||
|
||||
#include <tokenize/Location.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -50,7 +48,6 @@ class Logger
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -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 <cstring>
|
||||
#include <exception>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -60,7 +58,6 @@ inline Priority priorityFromName(const char *priorityName)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
21
lib/colorlog/src/CMakeLists.txt
Normal file
21
lib/colorlog/src/CMakeLists.txt
Normal file
@ -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})
|
@ -1,10 +1,8 @@
|
||||
#include <plasp/output/Logger.h>
|
||||
#include <colorlog/Logger.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -165,4 +163,3 @@ void Logger::log(Priority priority, const tokenize::Location &location, const st
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
)
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/Effect.h>
|
||||
#include <plasp/pddl/translation/Goal.h>
|
||||
@ -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
|
||||
|
@ -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;
|
||||
|
@ -5,10 +5,10 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <plasp/sas/VariableTransition.h>
|
||||
|
||||
#include <tokenize/TokenizerException.h>
|
||||
|
||||
#include <plasp/sas/VariableTransition.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
|
@ -3,7 +3,8 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <plasp/sas/VariableTransition.h>
|
||||
|
||||
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 << ")";
|
||||
}
|
||||
|
@ -4,10 +4,10 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
|
||||
#include <tokenize/TokenizerException.h>
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
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 << ")";
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
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<decltype(currentEffectID)>(currentEffectID) << "), ";
|
||||
m_outputStream << ", " << colorlog::Keyword("effect") << "(" << colorlog::Number<decltype(currentEffectID)>(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<decltype(currentEffectID)>(currentEffectID) << "), ";
|
||||
<< colorlog::Function("precondition") << "("
|
||||
<< colorlog::Keyword("effect") << "(" << colorlog::Number<decltype(currentEffectID)>(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<decltype(operator_.costs())>(operator_.costs()) << ")." << std::endl;
|
||||
m_outputStream << ", " << colorlog::Number<decltype(operator_.costs())>(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<decltype(mutexGroupID)>(mutexGroupID)
|
||||
<< colorlog::Function("mutexGroup") << "("
|
||||
<< colorlog::Keyword("mutexGroup") << "("
|
||||
<< colorlog::Number<decltype(mutexGroupID)>(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<decltype(mutexGroupID)>(mutexGroupID) << "), ";
|
||||
m_outputStream << colorlog::Function("contains") << "(" << colorlog::Keyword("mutexGroup") << "(" << colorlog::Number<decltype(mutexGroupID)>(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<decltype(axiomRuleID)>(axiomRuleID)
|
||||
<< colorlog::Function("axiomRule") << "("
|
||||
<< colorlog::Keyword("axiomRule") << "("
|
||||
<< colorlog::Number<decltype(axiomRuleID)>(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<decltype(axiomRuleID)>(axiomRuleID) << "), ";
|
||||
<< colorlog::Function("precondition") << "("
|
||||
<< colorlog::Keyword("axiomRule") << "(" << colorlog::Number<decltype(axiomRuleID)>(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<decltype(axiomRuleID)>(axiomRuleID) << "), "
|
||||
<< output::Keyword("effect") << "(" << output::Reserved("unconditional") << "), ";
|
||||
<< colorlog::Function("postcondition") << "("
|
||||
<< colorlog::Keyword("axiomRule") << "(" << colorlog::Number<decltype(axiomRuleID)>(axiomRuleID) << "), "
|
||||
<< colorlog::Keyword("effect") << "(" << colorlog::Reserved("unconditional") << "), ";
|
||||
postcondition.variable().printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
postcondition.value().printAsASPPredicate(m_outputStream);
|
||||
|
@ -2,11 +2,12 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
#include <tokenize/TokenizerException.h>
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
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 ";
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
|
||||
#include <tokenize/TokenizerException.h>
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
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<std::string>(m_name) << ")";
|
||||
stream << colorlog::Keyword("variable") << "(" << colorlog::Number<std::string>(m_name) << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -3,10 +3,11 @@
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <boost/iostreams/device/null.hpp>
|
||||
|
||||
#include <colorlog/Logger.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/Parse.h>
|
||||
|
||||
#include <plasp/output/Logger.h>
|
||||
#include <plasp/pddl/TranslatorASP.h>
|
||||
|
||||
boost::iostreams::stream<boost::iostreams::null_sink> 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);
|
||||
|
||||
|
Reference in New Issue
Block a user