diff --git a/lib/pddlparse/include/pddlparse/ASTOutput.h b/lib/pddlparse/include/pddlparse/ASTOutput.h index f880ba9..9e170ee 100644 --- a/lib/pddlparse/include/pddlparse/ASTOutput.h +++ b/lib/pddlparse/include/pddlparse/ASTOutput.h @@ -5,6 +5,7 @@ #include #include +#include #include namespace pddl @@ -18,163 +19,59 @@ namespace ast // //////////////////////////////////////////////////////////////////////////////////////////////////// -namespace detail -{ - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -struct PrintContext -{ - size_t indentationLevel{0}; -}; - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -struct Identifier -{ - Identifier(const char *content) - : content{content} - { - } - - Identifier(const std::string &content) - : content{content.c_str()} - { - } - - const char *content; -}; - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Identifier &identifier) -{ - return (stream - << colorlog::Format({colorlog::Color::Green, colorlog::FontWeight::Normal}) - << identifier.content << colorlog::ResetFormat()); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -struct Type -{ - Type(const char *name) - : name{name} - { - } - - Type(const std::string &name) - : name{name.c_str()} - { - } - - const char *name; -}; - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Type &type) -{ - return (stream - << colorlog::Format({colorlog::Color::Red, colorlog::FontWeight::Normal}) - << type.name << colorlog::ResetFormat()); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -struct Constant -{ - Constant(const char *name) - : name{name} - { - } - - Constant(const std::string &name) - : name{name.c_str()} - { - } - - const char *name; -}; - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Constant &constant) -{ - return (stream - << colorlog::Format({colorlog::Color::Yellow, colorlog::FontWeight::Normal}) - << constant.name << colorlog::ResetFormat()); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -colorlog::ColorStream &printIndentedNewline(colorlog::ColorStream &stream, detail::PrintContext &printContext) -{ - stream << std::endl; - - for (size_t i = 0; i < printContext.indentationLevel; i++) - stream << "\t"; - - return stream; -} - //////////////////////////////////////////////////////////////////////////////////////////////////// // Forward declarations //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Constant &constant, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ConstantDeclaration &constantDeclaration, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveType &primitiveType, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveTypeDeclaration &primitiveTypeDeclaration, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variable &variable, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const VariableDeclaration &variableDeclaration, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predicate &predicate, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PredicateDeclaration &predicateDeclaration, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Constant &constant, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ConstantDeclaration &constantDeclaration, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveType &primitiveType, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveTypeDeclaration &primitiveTypeDeclaration, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variable &variable, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const VariableDeclaration &variableDeclaration, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predicate &predicate, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PredicateDeclaration &predicateDeclaration, pddl::detail::PrintContext &printContext); template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Binary &binary, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Binary &binary, pddl::detail::PrintContext &printContext); template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const NAry &nAry, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const NAry &nAry, pddl::detail::PrintContext &printContext); template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Quantified &quantified, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Quantified &quantified, pddl::detail::PrintContext &printContext); template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const At &at, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const At &at, pddl::detail::PrintContext &printContext); template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Not ¬_, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Not ¬_, pddl::detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Action &action, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Domain &domain, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const InitialState &initialState, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Problem &problem, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Requirement &requirement, detail::PrintContext &printContext); -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Description &description, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Action &action, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Domain &domain, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const InitialState &initialState, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Problem &problem, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Requirement &requirement, pddl::detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Description &description, pddl::detail::PrintContext &printContext); template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::unique_ptr &variant, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::unique_ptr &variant, pddl::detail::PrintContext &printContext); template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::vector &variant, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::vector &variant, pddl::detail::PrintContext &printContext); template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variant &variant, detail::PrintContext &printContext); +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variant &variant, pddl::detail::PrintContext &printContext); //////////////////////////////////////////////////////////////////////////////////////////////////// // Primitives //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Constant &constant, detail::PrintContext &) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Constant &constant, pddl::detail::PrintContext &) { - return stream << detail::Constant(constant.declaration->name); + return stream << pddl::detail::Constant(constant.declaration->name); } //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ConstantDeclaration &constantDeclaration, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ConstantDeclaration &constantDeclaration, pddl::detail::PrintContext &printContext) { - stream << detail::Constant(constantDeclaration.name); + stream << pddl::detail::Constant(constantDeclaration.name); if (constantDeclaration.type) { @@ -187,25 +84,25 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Constan //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveType &primitiveType, detail::PrintContext &) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveType &primitiveType, pddl::detail::PrintContext &) { - return stream << detail::Type(primitiveType.declaration->name); + return stream << pddl::detail::Type(primitiveType.declaration->name); } //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveTypeDeclaration &primitiveTypeDeclaration, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveTypeDeclaration &primitiveTypeDeclaration, pddl::detail::PrintContext &printContext) { if (primitiveTypeDeclaration.parentTypes.empty()) - return (stream << detail::Type(primitiveTypeDeclaration.name)); + return (stream << pddl::detail::Type(primitiveTypeDeclaration.name)); if (!primitiveTypeDeclaration.parentTypes.empty()) for (const auto &parentType : primitiveTypeDeclaration.parentTypes) { if (&parentType != &primitiveTypeDeclaration.parentTypes.front()) - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); - stream << detail::Type(primitiveTypeDeclaration.name) << " - " << detail::Type(parentType->declaration->name); + stream << pddl::detail::Type(primitiveTypeDeclaration.name) << " - " << pddl::detail::Type(parentType->declaration->name); } return stream; @@ -213,7 +110,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Primiti //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Unsupported &unsupported, detail::PrintContext &) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Unsupported &unsupported, pddl::detail::PrintContext &) { const auto unsupportedName = ""; @@ -222,7 +119,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Unsuppo //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variable &variable, detail::PrintContext &) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variable &variable, pddl::detail::PrintContext &) { const auto variableName = "?" + variable.declaration->name; @@ -231,7 +128,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variabl //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const VariableDeclaration &variableDeclaration, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const VariableDeclaration &variableDeclaration, pddl::detail::PrintContext &printContext) { const auto variableName = "?" + variableDeclaration.name; @@ -250,9 +147,9 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variabl // Compounds //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predicate &predicate, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predicate &predicate, pddl::detail::PrintContext &printContext) { - stream << "(" << detail::Identifier(predicate.declaration->name) << " "; + stream << "(" << pddl::detail::Identifier(predicate.declaration->name) << " "; for (const auto &argument : predicate.arguments) { @@ -267,9 +164,9 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predica //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PredicateDeclaration &predicateDeclaration, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PredicateDeclaration &predicateDeclaration, pddl::detail::PrintContext &printContext) { - stream << "(" << detail::Identifier(predicateDeclaration.name); + stream << "(" << pddl::detail::Identifier(predicateDeclaration.name); for (const auto ¶meter : predicateDeclaration.parameters) { @@ -285,15 +182,15 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predica //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Binary &binary, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Binary &binary, pddl::detail::PrintContext &printContext) { stream << "(" << colorlog::Keyword(Derived::Identifier); printContext.indentationLevel++; - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, binary.argumentLeft, printContext); - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, binary.argumentRight, printContext); printContext.indentationLevel--; @@ -304,7 +201,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Binary< //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const NAry &nAry, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const NAry &nAry, pddl::detail::PrintContext &printContext) { stream << "(" << colorlog::Keyword(Derived::Identifier); @@ -312,7 +209,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const NAry -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Quantified &quantified, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Quantified &quantified, pddl::detail::PrintContext &printContext) { stream << "(" << colorlog::Keyword(Derived::Identifier); printContext.indentationLevel++; - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, quantified.parameters, printContext); - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, quantified.argument, printContext); printContext.indentationLevel--; @@ -345,7 +242,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Quantif //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const And &and_, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const And &and_, pddl::detail::PrintContext &printContext) { return print(stream, static_cast, Argument> &>(and_), printContext); } @@ -353,15 +250,15 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const And -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const At &at, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const At &at, pddl::detail::PrintContext &printContext) { stream << "(" << colorlog::Keyword("at"); printContext.indentationLevel++; - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); stream << colorlog::Number(at.timePoint); - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, at.argument, printContext); printContext.indentationLevel--; @@ -372,7 +269,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const At -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Either &either, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Either &either, pddl::detail::PrintContext &printContext) { return print(stream, static_cast, Argument> &>(either), printContext); } @@ -380,7 +277,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Either< //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Exists &exists, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Exists &exists, pddl::detail::PrintContext &printContext) { return print(stream, static_cast, Argument> &>(exists), printContext); } @@ -388,7 +285,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Exists< //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ForAll &forAll, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ForAll &forAll, pddl::detail::PrintContext &printContext) { return print(stream, static_cast, Argument> &>(forAll), printContext); } @@ -396,7 +293,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ForAll< //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Imply &imply, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Imply &imply, pddl::detail::PrintContext &printContext) { return print(stream, static_cast, Argument> &>(imply), printContext); } @@ -404,13 +301,13 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Imply -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Not ¬_, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Not ¬_, pddl::detail::PrintContext &printContext) { stream << "(" << colorlog::Keyword("not"); printContext.indentationLevel++; - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, not_.argument, printContext); printContext.indentationLevel--; @@ -421,7 +318,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Not -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Or &or_, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Or &or_, pddl::detail::PrintContext &printContext) { return print(stream, static_cast, Argument> &>(or_), printContext); } @@ -429,7 +326,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Or -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const When &when, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const When &when, pddl::detail::PrintContext &printContext) { return print(stream, static_cast, ArgumentLeft, ArgumentRight> &>(when), printContext); } @@ -438,20 +335,20 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Whenname) << ")"; + pddl::detail::printIndentedNewline(stream, printContext); + stream << "(" << colorlog::Keyword(":domain") << " " << pddl::detail::Identifier(problem.domain->name) << ")"; if (!problem.requirements.empty()) { - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); stream << "(" << colorlog::Keyword(":requirements"); printContext.indentationLevel++; - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, problem.requirements, printContext); stream << ")"; @@ -611,12 +508,12 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Problem if (!problem.objects.empty()) { - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); stream << "(" << colorlog::Keyword(":objects"); printContext.indentationLevel++; - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, problem.objects, printContext); stream << ")"; @@ -625,18 +522,18 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Problem if (!problem.initialState.facts.empty()) { - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, problem.initialState, printContext); } if (problem.goal) { - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); stream << "(" << colorlog::Keyword(":goal"); printContext.indentationLevel++; - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, problem.goal.value(), printContext); stream << ")"; @@ -650,16 +547,16 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Problem //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Requirement &requirement, detail::PrintContext &) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Requirement &requirement, pddl::detail::PrintContext &) { auto requirementName = std::string(":") + pddl::detail::toString(requirement); - return (stream << detail::Identifier(requirementName.c_str())); + return (stream << pddl::detail::Identifier(requirementName.c_str())); } //////////////////////////////////////////////////////////////////////////////////////////////////// -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Description &description, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Description &description, pddl::detail::PrintContext &printContext) { print(stream, *description.domain, printContext); stream << std::endl; @@ -678,7 +575,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Descrip inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Description &description) { - detail::PrintContext printContext; + pddl::detail::PrintContext printContext; return print(stream, description, printContext); } @@ -688,7 +585,7 @@ inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const De //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::unique_ptr &uniquePointer, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::unique_ptr &uniquePointer, pddl::detail::PrintContext &printContext) { assert(uniquePointer); return print(stream, *uniquePointer, printContext); @@ -697,12 +594,12 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::un //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::vector &vector, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::vector &vector, pddl::detail::PrintContext &printContext) { for (const auto &element : vector) { if (&element != &vector.front()) - printIndentedNewline(stream, printContext); + pddl::detail::printIndentedNewline(stream, printContext); print(stream, element, printContext); } @@ -713,7 +610,7 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::ve //////////////////////////////////////////////////////////////////////////////////////////////////// template -inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variant &variant, detail::PrintContext &printContext) +inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variant &variant, pddl::detail::PrintContext &printContext) { variant.match([&](const auto &x){return print(stream, x, printContext);}); diff --git a/lib/pddlparse/include/pddlparse/detail/OutputUtils.h b/lib/pddlparse/include/pddlparse/detail/OutputUtils.h new file mode 100644 index 0000000..a006299 --- /dev/null +++ b/lib/pddlparse/include/pddlparse/detail/OutputUtils.h @@ -0,0 +1,117 @@ +#ifndef __PDDL_PARSE__DETAIL__OUTPUT_UTILS_H +#define __PDDL_PARSE__DETAIL__OUTPUT_UTILS_H + +#include + +namespace pddl +{ +namespace detail +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// OutputUtils +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct PrintContext +{ + size_t indentationLevel{0}; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct Identifier +{ + Identifier(const char *content) + : content{content} + { + } + + Identifier(const std::string &content) + : content{content.c_str()} + { + } + + const char *content; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Identifier &identifier) +{ + return (stream + << colorlog::Format({colorlog::Color::Green, colorlog::FontWeight::Normal}) + << identifier.content << colorlog::ResetFormat()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct Type +{ + Type(const char *name) + : name{name} + { + } + + Type(const std::string &name) + : name{name.c_str()} + { + } + + const char *name; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Type &type) +{ + return (stream + << colorlog::Format({colorlog::Color::Red, colorlog::FontWeight::Normal}) + << type.name << colorlog::ResetFormat()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct Constant +{ + Constant(const char *name) + : name{name} + { + } + + Constant(const std::string &name) + : name{name.c_str()} + { + } + + const char *name; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Constant &constant) +{ + return (stream + << colorlog::Format({colorlog::Color::Yellow, colorlog::FontWeight::Normal}) + << constant.name << colorlog::ResetFormat()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +colorlog::ColorStream &printIndentedNewline(colorlog::ColorStream &stream, detail::PrintContext &printContext) +{ + stream << std::endl; + + for (size_t i = 0; i < printContext.indentationLevel; i++) + stream << "\t"; + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif