Moved color logging to separate library for reusing it in PDDL parser.
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
@@ -1,168 +0,0 @@
|
||||
#include <plasp/output/Logger.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Logger
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
constexpr Format priorityFormat(Priority priority)
|
||||
{
|
||||
switch (priority)
|
||||
{
|
||||
case Priority::Debug:
|
||||
return {Color::Green, FontWeight::Bold};
|
||||
case Priority::Info:
|
||||
return {Color::Blue, FontWeight::Bold};
|
||||
case Priority::Warning:
|
||||
return {Color::Magenta, FontWeight::Bold};
|
||||
case Priority::Error:
|
||||
return {Color::Red, FontWeight::Bold};
|
||||
}
|
||||
|
||||
return {Color::White, FontWeight::Bold};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
constexpr const Format MessageBodyFormat = {Color::White, FontWeight::Bold};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
constexpr const Format LocationFormat = {Color::White, FontWeight::Bold};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger()
|
||||
: Logger(std::cout, std::cerr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger(ColorStream &&outputStream)
|
||||
: Logger(std::forward<ColorStream &&>(outputStream), std::cerr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger(ColorStream &&outputStream, ColorStream &&errorStream)
|
||||
: m_outputStream{outputStream},
|
||||
m_errorStream{errorStream},
|
||||
m_logPriority{Priority::Info},
|
||||
m_abortPriority{Priority::Error}
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &Logger::outputStream()
|
||||
{
|
||||
return m_outputStream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &Logger::errorStream()
|
||||
{
|
||||
return m_errorStream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::setLogPriority(Priority logPriority)
|
||||
{
|
||||
m_logPriority = logPriority;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::setAbortPriority(Priority abortPriority)
|
||||
{
|
||||
m_abortPriority = abortPriority;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::setColorPolicy(ColorStream::ColorPolicy colorPolicy)
|
||||
{
|
||||
m_outputStream.setColorPolicy(colorPolicy);
|
||||
m_errorStream.setColorPolicy(colorPolicy);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const char *message)
|
||||
{
|
||||
const auto priorityID = static_cast<int>(priority);
|
||||
|
||||
if (priorityID < static_cast<int>(m_logPriority) &&
|
||||
priorityID < static_cast<int>(m_abortPriority))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_errorStream
|
||||
<< priorityFormat(priority) << priorityName(priority) << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< MessageBodyFormat << message
|
||||
<< ResetFormat() << std::endl;
|
||||
|
||||
if (priority != Priority::Error && priorityID >= static_cast<int>(m_abortPriority))
|
||||
throw std::runtime_error("received warning (treated as error by configuration)");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const std::string &message)
|
||||
{
|
||||
log(priority, message.c_str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const tokenize::Location &location, const char *message)
|
||||
{
|
||||
const auto priorityID = static_cast<int>(priority);
|
||||
|
||||
// Always show messages that lead to program termination
|
||||
if (priorityID < static_cast<int>(m_logPriority) &&
|
||||
priorityID < static_cast<int>(m_abortPriority))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_errorStream
|
||||
<< LocationFormat
|
||||
<< location.sectionStart << ":" << location.rowStart << ":" << location.columnStart << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< priorityFormat(priority) << priorityName(priority) << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< MessageBodyFormat << message
|
||||
<< ResetFormat() << std::endl;
|
||||
|
||||
// TODO: print original warning message
|
||||
// TODO: refactor
|
||||
if (priority != Priority::Error && priorityID >= static_cast<int>(m_abortPriority))
|
||||
throw std::runtime_error("received warning (treated as error by configuration)");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const tokenize::Location &location, const std::string &message)
|
||||
{
|
||||
log(priority, location, message.c_str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
@@ -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) << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user