From aff396d919a3a93b7e99e87a9415de7c2bbf6d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 14 Jun 2016 17:41:41 +0200 Subject: [PATCH] Colorizing numbers in translated SAS output. --- include/plasp/utils/Formatting.h | 20 ++++++++++++++++++++ src/plasp/sas/TranslatorASP.cpp | 14 +++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/plasp/utils/Formatting.h b/include/plasp/utils/Formatting.h index b0a69e1..90c6a2e 100644 --- a/include/plasp/utils/Formatting.h +++ b/include/plasp/utils/Formatting.h @@ -113,6 +113,26 @@ inline LogStream &operator<<(LogStream &stream, const Keyword &keyword) //////////////////////////////////////////////////////////////////////////////////////////////////// +struct Number: public Token +{ + Number(const std::string &name) + : Token(name) + { + } +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline LogStream &operator<<(LogStream &stream, const Number &number) +{ + return (stream + << utils::Format(utils::Color::Yellow, utils::FontWeight::Bold) + << number.name + << utils::ResetFormat()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + struct Variable: public Token { Variable(const std::string &name) diff --git a/src/plasp/sas/TranslatorASP.cpp b/src/plasp/sas/TranslatorASP.cpp index 6713de5..bd9dd51 100644 --- a/src/plasp/sas/TranslatorASP.cpp +++ b/src/plasp/sas/TranslatorASP.cpp @@ -168,7 +168,7 @@ void TranslatorASP::translateActions() const { m_outputStream << utils::Keyword("effectCondition") << "("; operator_.printPredicateAsASP(m_outputStream); - m_outputStream << ", " << utils::Keyword("effect") << "(" << currentEffectID << "), "; + m_outputStream << ", " << utils::Keyword("effect") << "(" << utils::Number(std::to_string(currentEffectID)) << "), "; condition.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; condition.value().printAsASPPredicate(m_outputStream); @@ -177,7 +177,7 @@ void TranslatorASP::translateActions() const m_outputStream << utils::Keyword("postcondition") << "("; operator_.printPredicateAsASP(m_outputStream); - m_outputStream << ", " << utils::Keyword("effect") << "(" << currentEffectID << "), "; + m_outputStream << ", " << utils::Keyword("effect") << "(" << utils::Number(std::to_string(currentEffectID)) << "), "; effect.postcondition().variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; effect.postcondition().value().printAsASPPredicate(m_outputStream); @@ -210,14 +210,14 @@ void TranslatorASP::translateMutexes() const const auto mutexGroupID = std::to_string(currentMutexGroupID); currentMutexGroupID++; - m_outputStream << std::endl << utils::Keyword("mutexGroup") << "(" << mutexGroupID << ")." << std::endl; + m_outputStream << std::endl << utils::Keyword("mutexGroup") << "(" << utils::Number(mutexGroupID) << ")." << std::endl; const auto &facts = mutexGroup.facts(); std::for_each(facts.cbegin(), facts.cend(), [&](const auto &fact) { - m_outputStream << utils::Keyword("contains") << "(" << utils::Keyword("mutexGroup") << "(" << mutexGroupID << "), "; + m_outputStream << utils::Keyword("contains") << "(" << utils::Keyword("mutexGroup") << "(" << utils::Number(mutexGroupID) << "), "; fact.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; fact.value().printAsASPPredicate(m_outputStream); @@ -246,14 +246,14 @@ void TranslatorASP::translateAxiomRules() const const auto axiomRuleID = std::to_string(currentAxiomRuleID); currentAxiomRuleID++; - m_outputStream << std::endl << utils::Keyword("axiomRule") << "(" << axiomRuleID << ")." << std::endl; + m_outputStream << std::endl << utils::Keyword("axiomRule") << "(" << utils::Number(axiomRuleID) << ")." << std::endl; const auto &conditions = axiomRule.conditions(); std::for_each(conditions.cbegin(), conditions.cend(), [&](const auto &condition) { - m_outputStream << utils::Keyword("condition") << "(" << utils::Keyword("axiomRule") << "(" << axiomRuleID << "), "; + m_outputStream << utils::Keyword("condition") << "(" << utils::Keyword("axiomRule") << "(" << utils::Number(axiomRuleID) << "), "; condition.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; condition.value().printAsASPPredicate(m_outputStream); @@ -262,7 +262,7 @@ void TranslatorASP::translateAxiomRules() const const auto &postcondition = axiomRule.postcondition(); - m_outputStream << utils::Keyword("postcondition") << "(" << utils::Keyword("axiomRule") << "(" << axiomRuleID << "), "; + m_outputStream << utils::Keyword("postcondition") << "(" << utils::Keyword("axiomRule") << "(" << utils::Number(axiomRuleID) << "), "; postcondition.variable().printNameAsASPPredicate(m_outputStream); m_outputStream << ", "; postcondition.value().printAsASPPredicate(m_outputStream);