From c36c7670d2fa2d95bfaca247eb4f48483e82612a Mon Sep 17 00:00:00 2001 From: Dominik Drexler Date: Wed, 14 Aug 2024 00:18:47 +0200 Subject: [PATCH] removed intrusive str of pddl objects and replaced it by Formatter --- examples/multiple_problems.cpp | 6 +- examples/position_cache.cpp | 2 +- examples/single_problem.cpp | 4 +- examples/undefined_behavior.cpp | 4 +- exe/domain.cpp | 2 +- exe/problem.cpp | 4 +- include/loki/details/ast/printer.hpp | 368 ++++++++--------- include/loki/details/pddl/action.hpp | 5 - include/loki/details/pddl/atom.hpp | 5 - include/loki/details/pddl/axiom.hpp | 5 - include/loki/details/pddl/base.hpp | 23 -- include/loki/details/pddl/conditions.hpp | 37 -- include/loki/details/pddl/domain.hpp | 5 - include/loki/details/pddl/effects.hpp | 25 -- include/loki/details/pddl/formatter.hpp | 55 ++- include/loki/details/pddl/function.hpp | 5 - .../details/pddl/function_expressions.hpp | 25 -- .../loki/details/pddl/function_skeleton.hpp | 5 - include/loki/details/pddl/literal.hpp | 5 - include/loki/details/pddl/metric.hpp | 5 - include/loki/details/pddl/numeric_fluent.hpp | 5 - include/loki/details/pddl/object.hpp | 5 - include/loki/details/pddl/parameter.hpp | 5 - include/loki/details/pddl/predicate.hpp | 5 - include/loki/details/pddl/problem.hpp | 5 - include/loki/details/pddl/requirements.hpp | 5 - include/loki/details/pddl/term.hpp | 10 - include/loki/details/pddl/type.hpp | 5 - include/loki/details/pddl/variable.hpp | 5 - include/loki/details/pddl/visitors.hpp | 43 -- include/loki/details/utils/printer.hpp | 34 -- include/loki/loki.hpp | 3 +- src/ast/printer.cpp | 369 ++++++++++-------- src/pddl/action.cpp | 29 -- src/pddl/atom.cpp | 12 - src/pddl/axiom.cpp | 16 - src/pddl/conditions.cpp | 71 ---- src/pddl/domain.cpp | 129 ------ src/pddl/effects.cpp | 47 --- src/pddl/exceptions.cpp | 20 +- src/pddl/formatter.cpp | 8 +- src/pddl/function.cpp | 20 - src/pddl/function_expressions.cpp | 33 -- src/pddl/function_skeleton.cpp | 11 - src/pddl/literal.cpp | 14 - src/pddl/metric.cpp | 8 - src/pddl/numeric_fluent.cpp | 7 - src/pddl/object.cpp | 24 -- src/pddl/parameter.cpp | 24 -- src/pddl/parser/conditions.cpp | 1 - src/pddl/parser/structure.cpp | 3 +- src/pddl/predicate.cpp | 11 - src/pddl/problem.cpp | 115 ------ src/pddl/requirements.cpp | 14 - src/pddl/term.cpp | 4 - src/pddl/type.cpp | 24 -- src/pddl/variable.cpp | 2 - 57 files changed, 456 insertions(+), 1285 deletions(-) delete mode 100644 include/loki/details/pddl/visitors.hpp delete mode 100644 include/loki/details/utils/printer.hpp diff --git a/examples/multiple_problems.cpp b/examples/multiple_problems.cpp index cab1a522..caaadace 100644 --- a/examples/multiple_problems.cpp +++ b/examples/multiple_problems.cpp @@ -23,17 +23,17 @@ int main() // Parse the domain auto domain_parser = loki::DomainParser(std::string(DATA_DIR) + "gripper/domain.pddl"); const auto domain = domain_parser.get_domain(); - std::cout << *domain << std::endl; + std::cout << loki::StreamWriter(*domain) << std::endl; // Parse first problem const auto problem_parser = loki::ProblemParser(std::string(DATA_DIR) + "gripper/p-2-0.pddl", domain_parser); const auto problem1 = problem_parser.get_problem(); - std::cout << *problem1 << std::endl; + std::cout << loki::StreamWriter(*problem1) << std::endl; // Parse second problem where the constants are reordered const auto problem_parser2 = loki::ProblemParser(std::string(DATA_DIR) + "gripper/p-2-1.pddl", domain_parser); const auto problem2 = problem_parser2.get_problem(); - std::cout << *problem2 << std::endl; + std::cout << loki::StreamWriter(*problem2) << std::endl; /* Both problems are structurally equivalent */ assert(problem1 == problem2); diff --git a/examples/position_cache.cpp b/examples/position_cache.cpp index bcc95b64..dc02d9e9 100644 --- a/examples/position_cache.cpp +++ b/examples/position_cache.cpp @@ -67,7 +67,7 @@ int main() // Parse the domain auto domain_parser = loki::DomainParser(std::string(DATA_DIR) + "gripper/domain.pddl"); const auto domain = domain_parser.get_domain(); - std::cout << *domain << std::endl << std::endl; + std::cout << loki::StreamWriter(*domain) << std::endl << std::endl; const loki::PDDLPositionCache& position_cache = domain_parser.get_position_cache(); const loki::PDDLErrorHandler& error_handler = position_cache.get_error_handler(); diff --git a/examples/single_problem.cpp b/examples/single_problem.cpp index 20f6d03f..48060fec 100644 --- a/examples/single_problem.cpp +++ b/examples/single_problem.cpp @@ -23,12 +23,12 @@ int main() // Parse the domain auto domain_parser = loki::DomainParser(std::string(DATA_DIR) + "gripper/domain.pddl"); const auto domain = domain_parser.get_domain(); - std::cout << *domain << std::endl; + std::cout << loki::StreamWriter(*domain) << std::endl; // Parse the problem const auto problem_parser = loki::ProblemParser(std::string(DATA_DIR) + "gripper/p-2-0.pddl", domain_parser); const auto problem = problem_parser.get_problem(); - std::cout << *problem << std::endl; + std::cout << loki::StreamWriter(*problem) << std::endl; return 0; } diff --git a/examples/undefined_behavior.cpp b/examples/undefined_behavior.cpp index 8175d8a7..f17b8232 100644 --- a/examples/undefined_behavior.cpp +++ b/examples/undefined_behavior.cpp @@ -26,7 +26,7 @@ int main() // Parse the domain auto domain_parser = loki::DomainParser(std::string(DATA_DIR) + "gripper/domain.pddl"); domain = domain_parser.get_domain(); - std::cout << *domain << std::endl; + std::cout << loki::StreamWriter(*domain) << std::endl; /* Destructor of DomainParser is called and all domain and problem specific PDDL objects are destroyed. */ } @@ -34,7 +34,7 @@ int main() std::cout << "Bye ;(" << std::endl; /* Undefined behavior when accessing the domain, usually the program crashes because memory was overwritten */ - std::cout << *domain << std::endl; + std::cout << loki::StreamWriter(*domain) << std::endl; return 0; } diff --git a/exe/domain.cpp b/exe/domain.cpp index eac87aaa..d0bfa4ce 100644 --- a/exe/domain.cpp +++ b/exe/domain.cpp @@ -30,7 +30,7 @@ int main(int argc, char** argv) // 1. Parse the domain const auto domain_parser = loki::DomainParser(domain_file); const auto domain = domain_parser.get_domain(); - std::cout << *domain << std::endl; + std::cout << loki::StreamWriter(*domain) << std::endl; return 0; } diff --git a/exe/problem.cpp b/exe/problem.cpp index 8a47997e..eb867481 100644 --- a/exe/problem.cpp +++ b/exe/problem.cpp @@ -31,12 +31,12 @@ int main(int argc, char** argv) // 1. Parse the domain auto domain_parser = loki::DomainParser(domain_file); const auto domain = domain_parser.get_domain(); - std::cout << *domain << std::endl; + std::cout << loki::StreamWriter(*domain) << std::endl; // 2. Parse the problem const auto problem_parser = loki::ProblemParser(problem_file, domain_parser); const auto problem = problem_parser.get_problem(); - std::cout << *problem << std::endl; + std::cout << loki::StreamWriter(*problem) << std::endl; return 0; } diff --git a/include/loki/details/ast/printer.hpp b/include/loki/details/ast/printer.hpp index c7cb8763..3cae8dfd 100644 --- a/include/loki/details/ast/printer.hpp +++ b/include/loki/details/ast/printer.hpp @@ -19,7 +19,7 @@ #define LOKI_INCLUDE_LOKI_AST_PRINTER_HPP_ #include "loki/details/ast/ast.hpp" -#include "loki/details/utils/printer.hpp" +#include "loki/details/pddl/formatter.hpp" namespace loki { @@ -28,195 +28,195 @@ namespace loki * Domain */ // create string representations from ast nodes. -extern std::string parse_text(const ast::Name& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Variable& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Number& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::FunctionSymbol& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Term& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Predicate& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::RequirementStrips& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementTyping& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementNegativePreconditions& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementDisjunctivePreconditions& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementEquality& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementExistentialPreconditions& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementUniversalPreconditions& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementQuantifiedPreconditions& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementConditionalEffects& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementFluents& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementObjectFluents& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementNumericFluents& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementAdl& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementDurativeActions& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementDerivedPredicates& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementTimedInitialLiterals& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementPreferences& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementConstraints& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::RequirementActionCosts& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Requirement& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::Type& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::TypeObject& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::TypeNumber& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::TypeEither& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::TypedListOfNamesRecursively& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::TypedListOfNames& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::TypedListOfVariablesRecursively& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::TypedListOfVariables& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::AtomicFormulaSkeleton& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::AtomicFunctionSkeletonTotalCost& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AtomicFunctionSkeletonGeneral& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AtomicFunctionSkeleton& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecursively& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletons& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::AtomicFormulaOfTermsPredicate& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AtomicFormulaOfTermsEquality& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AtomicFormulaOfTerms& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Atom& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::NegatedAtom& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Literal& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::MultiOperatorMul& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MultiOperatorPlus& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MultiOperator& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::BinaryOperatorMinus& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::BinaryOperatorDiv& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::BinaryOperator& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::BinaryComparatorGreater& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::BinaryComparatorLess& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::BinaryComparatorEqual& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::BinaryComparatorGreaterEqual& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::BinaryComparatorLessEqual& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::BinaryComparator& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::FunctionHead& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::FunctionExpression& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::FunctionExpressionNumber& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::FunctionExpressionBinaryOp& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::FunctionExpressionMinus& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::FunctionExpressionHead& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::GoalDescriptor& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorAtom& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorLiteral& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorAnd& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorOr& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorNot& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorImply& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorExists& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorForall& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorFunctionComparison& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::ConstraintGoalDescriptor& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorAnd& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorForall& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorAtEnd& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorAlways& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorSometime& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorWithin& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorAtMostOnce& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorSometimeAfter& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorSometimeBefore& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorAlwaysWithin& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorHoldDuring& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ConstraintGoalDescriptorHoldAfter& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::PreferenceName& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::PreconditionGoalDescriptor& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::PreconditionGoalDescriptorSimple& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::PreconditionGoalDescriptorAnd& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::PreconditionGoalDescriptorPreference& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::PreconditionGoalDescriptorForall& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::AssignOperatorAssign& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AssignOperatorScaleUp& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AssignOperatorScaleDown& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AssignOperatorIncrease& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AssignOperatorDecrease& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AssignOperator& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::Effect& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::EffectProductionLiteral& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::EffectProductionNumericFluentTotalCost& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::EffectProductionNumericFluentGeneral& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::EffectProduction& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::EffectConditionalForall& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::EffectConditionalWhen& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::EffectConditional& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::EffectNumericFluentTotalCostOrEffect& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::EffectRoot& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::ActionSymbol& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ActionBody& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::Action& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Axiom& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::DomainName& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Requirements& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Types& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Constants& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Predicates& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Functions& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Constraints& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Structure& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Domain& node, const FormattingOptions& options = {}); +extern std::string parse_text(const ast::Name& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Variable& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Number& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::FunctionSymbol& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Term& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Predicate& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::RequirementStrips& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementTyping& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementNegativePreconditions& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementDisjunctivePreconditions& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementEquality& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementExistentialPreconditions& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementUniversalPreconditions& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementQuantifiedPreconditions& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementConditionalEffects& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementFluents& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementObjectFluents& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementNumericFluents& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementAdl& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementDurativeActions& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementDerivedPredicates& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementTimedInitialLiterals& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementPreferences& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementConstraints& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::RequirementActionCosts& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Requirement& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::Type& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::TypeObject& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::TypeNumber& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::TypeEither& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::TypedListOfNamesRecursively& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::TypedListOfNames& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::TypedListOfVariablesRecursively& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::TypedListOfVariables& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::AtomicFormulaSkeleton& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::AtomicFunctionSkeletonTotalCost& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AtomicFunctionSkeletonGeneral& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AtomicFunctionSkeleton& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecursively& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletons& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::AtomicFormulaOfTermsPredicate& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AtomicFormulaOfTermsEquality& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AtomicFormulaOfTerms& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Atom& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::NegatedAtom& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Literal& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::MultiOperatorMul& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MultiOperatorPlus& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MultiOperator& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::BinaryOperatorMinus& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::BinaryOperatorDiv& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::BinaryOperator& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::BinaryComparatorGreater& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::BinaryComparatorLess& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::BinaryComparatorEqual& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::BinaryComparatorGreaterEqual& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::BinaryComparatorLessEqual& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::BinaryComparator& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::FunctionHead& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::FunctionExpression& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::FunctionExpressionNumber& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::FunctionExpressionBinaryOp& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::FunctionExpressionMinus& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::FunctionExpressionHead& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::GoalDescriptor& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GoalDescriptorAtom& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GoalDescriptorLiteral& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GoalDescriptorAnd& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GoalDescriptorOr& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GoalDescriptorNot& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GoalDescriptorImply& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GoalDescriptorExists& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GoalDescriptorForall& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GoalDescriptorFunctionComparison& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::ConstraintGoalDescriptor& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorAnd& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorForall& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorAtEnd& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorAlways& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorSometime& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorWithin& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorAtMostOnce& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorSometimeAfter& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorSometimeBefore& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorAlwaysWithin& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorHoldDuring& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ConstraintGoalDescriptorHoldAfter& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::PreferenceName& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::PreconditionGoalDescriptor& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::PreconditionGoalDescriptorSimple& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::PreconditionGoalDescriptorAnd& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::PreconditionGoalDescriptorPreference& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::PreconditionGoalDescriptorForall& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::AssignOperatorAssign& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AssignOperatorScaleUp& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AssignOperatorScaleDown& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AssignOperatorIncrease& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AssignOperatorDecrease& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AssignOperator& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::Effect& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectProductionLiteral& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectProductionNumericFluentTotalCost& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectProductionNumericFluentGeneral& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectProduction& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectConditionalForall& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectConditionalWhen& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectConditional& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectNumericFluentTotalCostOrEffect& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectRoot& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::ActionSymbol& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ActionBody& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::Action& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Axiom& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::DomainName& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Requirements& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Types& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Constants& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Predicates& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Functions& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Constraints& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Structure& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Domain& node, const DefaultFormatterOptions& options = {}); /** * Problem */ // create string representations from ast nodes. -extern std::string parse_text(const ast::BasicFunctionTerm& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::AtomicFormulaOfNamesPredicate& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AtomicFormulaOfNamesEquality& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::AtomicFormulaOfNames& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GroundAtom& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::NegatedGroundAtom& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GroundLiteral& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::InitialElementLiteral& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::InitialElementTimedLiterals& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::InitialElementNumericFluentsTotalCost& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::InitialElementNumericFluentsGeneral& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::InitialElement& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::MetricFunctionExpression& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricFunctionExpressionNumber& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricFunctionExpressionBinaryOperator& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricFunctionExpressionMultiOperator& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricFunctionExpressionMinus& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricFunctionExpressionBasicFunctionTerm& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricFunctionExpressionTotalTime& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricFunctionExpressionPreferences& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::OptimizationMinimize& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::OptimizationMaximize& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Optimization& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricSpecificationTotalCost& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricSpecificationGeneral& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptor& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptorAnd& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptorForall& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptorPreference& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptorSimple& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::ProblemName& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ProblemDomainName& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Objects& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Initial& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::Goal& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::ProblemConstraints& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::MetricSpecification& node, const FormattingOptions& options = {}); - -extern std::string parse_text(const ast::Problem& node, const FormattingOptions& options = {}); +extern std::string parse_text(const ast::BasicFunctionTerm& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::AtomicFormulaOfNamesPredicate& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AtomicFormulaOfNamesEquality& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::AtomicFormulaOfNames& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GroundAtom& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::NegatedGroundAtom& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::GroundLiteral& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::InitialElementLiteral& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::InitialElementTimedLiterals& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::InitialElementNumericFluentsTotalCost& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::InitialElementNumericFluentsGeneral& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::InitialElement& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::MetricFunctionExpression& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricFunctionExpressionNumber& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricFunctionExpressionBinaryOperator& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricFunctionExpressionMultiOperator& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricFunctionExpressionMinus& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricFunctionExpressionBasicFunctionTerm& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricFunctionExpressionTotalTime& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricFunctionExpressionPreferences& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::OptimizationMinimize& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::OptimizationMaximize& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Optimization& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricSpecificationTotalCost& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricSpecificationGeneral& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptor& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptorAnd& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptorForall& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptorPreference& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::PreferenceConstraintGoalDescriptorSimple& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::ProblemName& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ProblemDomainName& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Objects& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Initial& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::Goal& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::ProblemConstraints& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::MetricSpecification& node, const DefaultFormatterOptions& options = {}); + +extern std::string parse_text(const ast::Problem& node, const DefaultFormatterOptions& options = {}); } #endif \ No newline at end of file diff --git a/include/loki/details/pddl/action.hpp b/include/loki/details/pddl/action.hpp index 4458fe55..d6fe7b25 100644 --- a/include/loki/details/pddl/action.hpp +++ b/include/loki/details/pddl/action.hpp @@ -47,11 +47,6 @@ class ActionImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const std::string& get_name() const; size_t get_original_arity() const; diff --git a/include/loki/details/pddl/atom.hpp b/include/loki/details/pddl/atom.hpp index 8aece8a8..675b3394 100644 --- a/include/loki/details/pddl/atom.hpp +++ b/include/loki/details/pddl/atom.hpp @@ -37,11 +37,6 @@ class AtomImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Predicate& get_predicate() const; const TermList& get_terms() const; diff --git a/include/loki/details/pddl/axiom.hpp b/include/loki/details/pddl/axiom.hpp index bc6c44be..4731d046 100644 --- a/include/loki/details/pddl/axiom.hpp +++ b/include/loki/details/pddl/axiom.hpp @@ -39,11 +39,6 @@ class AxiomImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const std::string& get_derived_predicate_name() const; const ParameterList& get_parameters() const; diff --git a/include/loki/details/pddl/base.hpp b/include/loki/details/pddl/base.hpp index 858ff70c..5008dded 100644 --- a/include/loki/details/pddl/base.hpp +++ b/include/loki/details/pddl/base.hpp @@ -18,8 +18,6 @@ #ifndef LOKI_INCLUDE_LOKI_PDDL_BASE_HPP_ #define LOKI_INCLUDE_LOKI_PDDL_BASE_HPP_ -#include "loki/details/utils/printer.hpp" - #include #include #include @@ -33,8 +31,6 @@ template class Base { private: - constexpr const auto& self() const { return static_cast(*this); } - size_t m_index; explicit Base(size_t index) : m_index(index) {} @@ -47,25 +43,6 @@ class Base Base(Base&& other) = default; Base& operator=(Base&& other) = default; - /// @brief Overload of the output stream insertion operator (operator<<). - friend std::ostream& operator<<(std::ostream& os, const Base& element) - { - os << element.str(); - return os; - } - - /// @brief Compute a string representation of this object. - void str(std::ostream& out, const FormattingOptions& options) const { self().str_impl(out, options); } - - /// @brief Compute a string representation of this object. - std::string str() const - { - std::ostringstream out; - FormattingOptions options { 0, 4 }; - str(out, options); - return out.str(); - } - /// @brief Get the index. size_t get_index() const { return m_index; } }; diff --git a/include/loki/details/pddl/conditions.hpp b/include/loki/details/pddl/conditions.hpp index 23eb012b..22bea8c8 100644 --- a/include/loki/details/pddl/conditions.hpp +++ b/include/loki/details/pddl/conditions.hpp @@ -38,11 +38,6 @@ class ConditionLiteralImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Literal& get_literal() const; }; @@ -59,11 +54,6 @@ class ConditionAndImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const ConditionList& get_conditions() const; }; @@ -80,13 +70,6 @@ class ConditionOrImpl : public Base template friend class UniqueFactory; - bool is_structurally_equivalent_to_impl(const ConditionOrImpl& other) const; - size_t hash_impl() const; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const ConditionList& get_conditions() const; }; @@ -103,11 +86,6 @@ class ConditionNotImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Condition& get_condition() const; }; @@ -125,11 +103,6 @@ class ConditionImplyImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Condition& get_condition_left() const; const Condition& get_condition_right() const; @@ -148,11 +121,6 @@ class ConditionExistsImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const ParameterList& get_parameters() const; const Condition& get_condition() const; @@ -171,11 +139,6 @@ class ConditionForallImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const ParameterList& get_parameters() const; const Condition& get_condition() const; diff --git a/include/loki/details/pddl/domain.hpp b/include/loki/details/pddl/domain.hpp index b031689d..e2a1d955 100644 --- a/include/loki/details/pddl/domain.hpp +++ b/include/loki/details/pddl/domain.hpp @@ -56,11 +56,6 @@ class DomainImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const std::optional& get_filepath() const; const std::string& get_name() const; diff --git a/include/loki/details/pddl/effects.hpp b/include/loki/details/pddl/effects.hpp index 6726195e..19e9dc0c 100644 --- a/include/loki/details/pddl/effects.hpp +++ b/include/loki/details/pddl/effects.hpp @@ -49,11 +49,6 @@ class EffectLiteralImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Literal& get_literal() const; }; @@ -70,11 +65,6 @@ class EffectAndImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const EffectList& get_effects() const; }; @@ -93,11 +83,6 @@ class EffectNumericImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: AssignOperatorEnum get_assign_operator() const; const Function& get_function() const; @@ -117,11 +102,6 @@ class EffectConditionalForallImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const ParameterList& get_parameters() const; const Effect& get_effect() const; @@ -140,11 +120,6 @@ class EffectConditionalWhenImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Condition& get_condition() const; const Effect& get_effect() const; diff --git a/include/loki/details/pddl/formatter.hpp b/include/loki/details/pddl/formatter.hpp index d3c08939..856e4f10 100644 --- a/include/loki/details/pddl/formatter.hpp +++ b/include/loki/details/pddl/formatter.hpp @@ -18,10 +18,35 @@ #ifndef LOKI_INCLUDE_LOKI_PDDL_FORMATTER_HPP_ #define LOKI_INCLUDE_LOKI_PDDL_FORMATTER_HPP_ +// StreamWriter needs complete definition +#include "loki/details/pddl/action.hpp" +#include "loki/details/pddl/atom.hpp" +#include "loki/details/pddl/axiom.hpp" +#include "loki/details/pddl/conditions.hpp" #include "loki/details/pddl/declarations.hpp" +#include "loki/details/pddl/domain.hpp" +#include "loki/details/pddl/effects.hpp" +#include "loki/details/pddl/function.hpp" +#include "loki/details/pddl/function_expressions.hpp" +#include "loki/details/pddl/function_skeleton.hpp" +#include "loki/details/pddl/literal.hpp" +#include "loki/details/pddl/metric.hpp" +#include "loki/details/pddl/numeric_fluent.hpp" +#include "loki/details/pddl/object.hpp" +#include "loki/details/pddl/parameter.hpp" +#include "loki/details/pddl/position.hpp" +#include "loki/details/pddl/predicate.hpp" +#include "loki/details/pddl/problem.hpp" +#include "loki/details/pddl/requirements.hpp" +#include "loki/details/pddl/term.hpp" +#include "loki/details/pddl/type.hpp" +#include "loki/details/pddl/variable.hpp" +#include #include #include +#include +#include namespace loki { @@ -79,24 +104,42 @@ class DefaultFormatter }; /// @brief `Writer` is a utility class to write to a stream using `operator<<` -template +template class StreamWriter { private: const T& m_element; const Formatter& m_formatter; + FormatterOptions m_options; public: - StreamWriter(const T& element, const Formatter& formatter) : m_element(element), m_formatter(formatter) {} + StreamWriter(const T& element, const Formatter& formatter = Formatter(), const FormatterOptions& options = FormatterOptions()) : + m_element(element), + m_formatter(formatter), + m_options(options) + { + } - template - friend std::ostream& operator<<(std::ostream& out, const StreamWriter& writer) + std::string str() const { - writer.m_formatter.write(writer.m_element, out); - return out; + std::stringstream ss; + m_formatter.write(m_element, m_options, ss); + return ss.str(); } + + const T& get_element() const { return m_element; } + const Formatter& get_formatter() const { return m_formatter; } + const FormatterOptions& get_options() const { return m_options; } }; +// Define the operator<< function outside of the class template +template +std::ostream& operator<<(std::ostream& out, const StreamWriter& writer) +{ + writer.get_formatter().write(writer.get_element(), writer.get_options(), out); + return out; +} + } #endif \ No newline at end of file diff --git a/include/loki/details/pddl/function.hpp b/include/loki/details/pddl/function.hpp index 47588e3a..956bfb88 100644 --- a/include/loki/details/pddl/function.hpp +++ b/include/loki/details/pddl/function.hpp @@ -37,11 +37,6 @@ class FunctionImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const FunctionSkeleton& get_function_skeleton() const; const TermList& get_terms() const; diff --git a/include/loki/details/pddl/function_expressions.hpp b/include/loki/details/pddl/function_expressions.hpp index c786fbed..6a42b467 100644 --- a/include/loki/details/pddl/function_expressions.hpp +++ b/include/loki/details/pddl/function_expressions.hpp @@ -58,11 +58,6 @@ class FunctionExpressionNumberImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: double get_number() const; }; @@ -84,11 +79,6 @@ class FunctionExpressionBinaryOperatorImpl : public Base friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: BinaryOperatorEnum get_binary_operator() const; const FunctionExpression& get_left_function_expression() const; @@ -108,11 +98,6 @@ class FunctionExpressionMultiOperatorImpl : public Base friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: MultiOperatorEnum get_multi_operator() const; const FunctionExpressionList& get_function_expressions() const; @@ -130,11 +115,6 @@ class FunctionExpressionMinusImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const FunctionExpression& get_function_expression() const; }; @@ -151,11 +131,6 @@ class FunctionExpressionFunctionImpl : public Base friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Function& get_function() const; }; diff --git a/include/loki/details/pddl/function_skeleton.hpp b/include/loki/details/pddl/function_skeleton.hpp index 1a1488b8..e76f98d7 100644 --- a/include/loki/details/pddl/function_skeleton.hpp +++ b/include/loki/details/pddl/function_skeleton.hpp @@ -38,11 +38,6 @@ class FunctionSkeletonImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const std::string& get_name() const; const ParameterList& get_parameters() const; diff --git a/include/loki/details/pddl/literal.hpp b/include/loki/details/pddl/literal.hpp index 9d3bb17b..dcac835f 100644 --- a/include/loki/details/pddl/literal.hpp +++ b/include/loki/details/pddl/literal.hpp @@ -37,11 +37,6 @@ class LiteralImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: bool is_negated() const; const Atom& get_atom() const; diff --git a/include/loki/details/pddl/metric.hpp b/include/loki/details/pddl/metric.hpp index dabad588..50b5e10d 100644 --- a/include/loki/details/pddl/metric.hpp +++ b/include/loki/details/pddl/metric.hpp @@ -46,11 +46,6 @@ class OptimizationMetricImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: OptimizationMetricEnum get_optimization_metric() const; const FunctionExpression& get_function_expression() const; diff --git a/include/loki/details/pddl/numeric_fluent.hpp b/include/loki/details/pddl/numeric_fluent.hpp index 0a705293..56b697f7 100644 --- a/include/loki/details/pddl/numeric_fluent.hpp +++ b/include/loki/details/pddl/numeric_fluent.hpp @@ -37,11 +37,6 @@ class NumericFluentImpl : public Base NumericFluentImpl(size_t index, Function function, double number); - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Function& get_function() const; double get_number() const; diff --git a/include/loki/details/pddl/object.hpp b/include/loki/details/pddl/object.hpp index 7897b67e..dc73bbe3 100644 --- a/include/loki/details/pddl/object.hpp +++ b/include/loki/details/pddl/object.hpp @@ -37,11 +37,6 @@ class ObjectImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const std::string& get_name() const; const TypeList& get_bases() const; diff --git a/include/loki/details/pddl/parameter.hpp b/include/loki/details/pddl/parameter.hpp index 46ae828c..f5dede67 100644 --- a/include/loki/details/pddl/parameter.hpp +++ b/include/loki/details/pddl/parameter.hpp @@ -38,11 +38,6 @@ class ParameterImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Variable& get_variable() const; const TypeList& get_bases() const; diff --git a/include/loki/details/pddl/predicate.hpp b/include/loki/details/pddl/predicate.hpp index 2d46ecc3..1385542c 100644 --- a/include/loki/details/pddl/predicate.hpp +++ b/include/loki/details/pddl/predicate.hpp @@ -39,11 +39,6 @@ class PredicateImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const std::string& get_name() const; const ParameterList& get_parameters() const; diff --git a/include/loki/details/pddl/problem.hpp b/include/loki/details/pddl/problem.hpp index c07e09ea..6d11c8c0 100644 --- a/include/loki/details/pddl/problem.hpp +++ b/include/loki/details/pddl/problem.hpp @@ -59,11 +59,6 @@ class ProblemImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const std::optional& get_filepath() const; const Domain& get_domain() const; diff --git a/include/loki/details/pddl/requirements.hpp b/include/loki/details/pddl/requirements.hpp index 011c4422..1ba9f897 100644 --- a/include/loki/details/pddl/requirements.hpp +++ b/include/loki/details/pddl/requirements.hpp @@ -67,11 +67,6 @@ class RequirementsImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: bool test(RequirementEnum requirement) const; diff --git a/include/loki/details/pddl/term.hpp b/include/loki/details/pddl/term.hpp index 88d3eb16..89941749 100644 --- a/include/loki/details/pddl/term.hpp +++ b/include/loki/details/pddl/term.hpp @@ -39,11 +39,6 @@ class TermObjectImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Object& get_object() const; }; @@ -61,11 +56,6 @@ class TermVariableImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const Variable& get_variable() const; }; diff --git a/include/loki/details/pddl/type.hpp b/include/loki/details/pddl/type.hpp index 876d479a..5ba04a3e 100644 --- a/include/loki/details/pddl/type.hpp +++ b/include/loki/details/pddl/type.hpp @@ -37,11 +37,6 @@ class TypeImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const std::string& get_name() const; const TypeList& get_bases() const; diff --git a/include/loki/details/pddl/variable.hpp b/include/loki/details/pddl/variable.hpp index 7ea0567f..f9a38012 100644 --- a/include/loki/details/pddl/variable.hpp +++ b/include/loki/details/pddl/variable.hpp @@ -36,11 +36,6 @@ class VariableImpl : public Base template friend class UniqueFactory; - void str_impl(std::ostream& out, const FormattingOptions& options) const; - - // Give access to the private interface implementations. - friend class Base; - public: const std::string& get_name() const; }; diff --git a/include/loki/details/pddl/visitors.hpp b/include/loki/details/pddl/visitors.hpp deleted file mode 100644 index 18fc5a9d..00000000 --- a/include/loki/details/pddl/visitors.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2023 Dominik Drexler - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LOKI_INCLUDE_LOKI_PDDL_VISITORS_HPP_ -#define LOKI_INCLUDE_LOKI_PDDL_VISITORS_HPP_ - -#include "loki/details/utils/printer.hpp" - -#include - -namespace loki -{ -struct StringifyVisitor -{ - std::ostream& out; - const FormattingOptions& options; - - StringifyVisitor(std::ostream& out_, const FormattingOptions& options_) : out(out_), options(options_) {} - - template - void operator()(const T& object) - { - object.str(out, options); - } -}; - -} - -#endif diff --git a/include/loki/details/utils/printer.hpp b/include/loki/details/utils/printer.hpp deleted file mode 100644 index beb46f00..00000000 --- a/include/loki/details/utils/printer.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2023 Dominik Drexler - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LOKI_INCLUDE_LOKI_PRINTER_HPP_ -#define LOKI_INCLUDE_LOKI_PRINTER_HPP_ - -namespace loki -{ - -struct FormattingOptions -{ - // The indentation in the current level. - int indent = 0; - // The amount of indentation added per nesting - int add_indent = 0; -}; - -} - -#endif \ No newline at end of file diff --git a/include/loki/loki.hpp b/include/loki/loki.hpp index 229b8a3e..945adc5d 100644 --- a/include/loki/loki.hpp +++ b/include/loki/loki.hpp @@ -35,6 +35,7 @@ #include "loki/details/pddl/error_reporting.hpp" #include "loki/details/pddl/exceptions.hpp" #include "loki/details/pddl/factories.hpp" +#include "loki/details/pddl/formatter.hpp" #include "loki/details/pddl/function.hpp" #include "loki/details/pddl/function_expressions.hpp" #include "loki/details/pddl/function_skeleton.hpp" @@ -52,7 +53,6 @@ #include "loki/details/pddl/term.hpp" #include "loki/details/pddl/type.hpp" #include "loki/details/pddl/variable.hpp" -#include "loki/details/pddl/visitors.hpp" /** * Utils @@ -63,7 +63,6 @@ #include "loki/details/utils/filesystem.hpp" #include "loki/details/utils/hash.hpp" #include "loki/details/utils/memory.hpp" -#include "loki/details/utils/printer.hpp" #include "loki/details/utils/segmented_vector.hpp" #include "loki/details/utils/unique_factory.hpp" diff --git a/src/ast/printer.cpp b/src/ast/printer.cpp index 33833b7d..5de7d636 100644 --- a/src/ast/printer.cpp +++ b/src/ast/printer.cpp @@ -26,16 +26,16 @@ namespace loki { // Printer for std::vector template -inline std::string parse_text(const std::vector& nodes, const FormattingOptions& options); +inline std::string parse_text(const std::vector& nodes, const DefaultFormatterOptions& options); // Printer for boost::variant class NodeVisitorPrinter : public boost::static_visitor { private: - const FormattingOptions* options; + const DefaultFormatterOptions* options; public: - NodeVisitorPrinter(const FormattingOptions& options) : options(&options) {} + NodeVisitorPrinter(const DefaultFormatterOptions& options) : options(&options) {} template std::string operator()(const Node& node) const @@ -44,52 +44,52 @@ class NodeVisitorPrinter : public boost::static_visitor } }; -string parse_text(const ast::Name& node, const FormattingOptions&) { return node.characters; } +string parse_text(const ast::Name& node, const DefaultFormatterOptions&) { return node.characters; } -string parse_text(const ast::Variable& node, const FormattingOptions&) { return node.characters; } +string parse_text(const ast::Variable& node, const DefaultFormatterOptions&) { return node.characters; } -std::string parse_text(const ast::FunctionSymbol& node, const FormattingOptions& options) { return parse_text(node.name, options); } +std::string parse_text(const ast::FunctionSymbol& node, const DefaultFormatterOptions& options) { return parse_text(node.name, options); } -string parse_text(const ast::Term& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +string parse_text(const ast::Term& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::Predicate& node, const FormattingOptions& options) { return parse_text(node.name, options); } +std::string parse_text(const ast::Predicate& node, const DefaultFormatterOptions& options) { return parse_text(node.name, options); } -string parse_text(const ast::Number& node, const FormattingOptions&) +string parse_text(const ast::Number& node, const DefaultFormatterOptions&) { stringstream ss; ss << node.value; return ss.str(); } -std::string parse_text(const ast::RequirementStrips&, const FormattingOptions&) { return ":strips"; } -std::string parse_text(const ast::RequirementTyping&, const FormattingOptions&) { return ":typing"; } -std::string parse_text(const ast::RequirementNegativePreconditions&, const FormattingOptions&) { return ":negative-preconditions"; } -std::string parse_text(const ast::RequirementDisjunctivePreconditions&, const FormattingOptions&) { return ":disjunctive-preconditions"; } -std::string parse_text(const ast::RequirementEquality&, const FormattingOptions&) { return ":equality"; } -std::string parse_text(const ast::RequirementExistentialPreconditions&, const FormattingOptions&) { return ":existential-preconditions"; } -std::string parse_text(const ast::RequirementUniversalPreconditions&, const FormattingOptions&) { return ":universal-preconditions"; } -std::string parse_text(const ast::RequirementQuantifiedPreconditions&, const FormattingOptions&) { return ":quantified-preconditions"; } -std::string parse_text(const ast::RequirementConditionalEffects&, const FormattingOptions&) { return ":conditional-effects"; } -std::string parse_text(const ast::RequirementFluents&, const FormattingOptions&) { return ":fluents"; } -std::string parse_text(const ast::RequirementObjectFluents&, const FormattingOptions&) { return ":object-fluents"; } -std::string parse_text(const ast::RequirementNumericFluents&, const FormattingOptions&) { return ":numeric-fluents"; } -std::string parse_text(const ast::RequirementAdl&, const FormattingOptions&) { return ":adl"; } -std::string parse_text(const ast::RequirementDurativeActions&, const FormattingOptions&) { return ":durative-actions"; } -std::string parse_text(const ast::RequirementDerivedPredicates&, const FormattingOptions&) { return ":derived-predicates"; } -std::string parse_text(const ast::RequirementTimedInitialLiterals&, const FormattingOptions&) { return ":timed-initial-literals"; } -std::string parse_text(const ast::RequirementPreferences&, const FormattingOptions&) { return ":preferences"; } -std::string parse_text(const ast::RequirementConstraints&, const FormattingOptions&) { return ":constraints"; } -std::string parse_text(const ast::RequirementActionCosts&, const FormattingOptions&) { return ":action-costs"; } +std::string parse_text(const ast::RequirementStrips&, const DefaultFormatterOptions&) { return ":strips"; } +std::string parse_text(const ast::RequirementTyping&, const DefaultFormatterOptions&) { return ":typing"; } +std::string parse_text(const ast::RequirementNegativePreconditions&, const DefaultFormatterOptions&) { return ":negative-preconditions"; } +std::string parse_text(const ast::RequirementDisjunctivePreconditions&, const DefaultFormatterOptions&) { return ":disjunctive-preconditions"; } +std::string parse_text(const ast::RequirementEquality&, const DefaultFormatterOptions&) { return ":equality"; } +std::string parse_text(const ast::RequirementExistentialPreconditions&, const DefaultFormatterOptions&) { return ":existential-preconditions"; } +std::string parse_text(const ast::RequirementUniversalPreconditions&, const DefaultFormatterOptions&) { return ":universal-preconditions"; } +std::string parse_text(const ast::RequirementQuantifiedPreconditions&, const DefaultFormatterOptions&) { return ":quantified-preconditions"; } +std::string parse_text(const ast::RequirementConditionalEffects&, const DefaultFormatterOptions&) { return ":conditional-effects"; } +std::string parse_text(const ast::RequirementFluents&, const DefaultFormatterOptions&) { return ":fluents"; } +std::string parse_text(const ast::RequirementObjectFluents&, const DefaultFormatterOptions&) { return ":object-fluents"; } +std::string parse_text(const ast::RequirementNumericFluents&, const DefaultFormatterOptions&) { return ":numeric-fluents"; } +std::string parse_text(const ast::RequirementAdl&, const DefaultFormatterOptions&) { return ":adl"; } +std::string parse_text(const ast::RequirementDurativeActions&, const DefaultFormatterOptions&) { return ":durative-actions"; } +std::string parse_text(const ast::RequirementDerivedPredicates&, const DefaultFormatterOptions&) { return ":derived-predicates"; } +std::string parse_text(const ast::RequirementTimedInitialLiterals&, const DefaultFormatterOptions&) { return ":timed-initial-literals"; } +std::string parse_text(const ast::RequirementPreferences&, const DefaultFormatterOptions&) { return ":preferences"; } +std::string parse_text(const ast::RequirementConstraints&, const DefaultFormatterOptions&) { return ":constraints"; } +std::string parse_text(const ast::RequirementActionCosts&, const DefaultFormatterOptions&) { return ":action-costs"; } -std::string parse_text(const ast::Requirement& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::Requirement& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -string parse_text(const ast::Type& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +string parse_text(const ast::Type& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -string parse_text(const ast::TypeObject& /*node*/, const FormattingOptions& /*options*/) { return "object"; } +string parse_text(const ast::TypeObject& /*node*/, const DefaultFormatterOptions& /*options*/) { return "object"; } -string parse_text(const ast::TypeNumber& /*node*/, const FormattingOptions& /*options*/) { return "number"; } +string parse_text(const ast::TypeNumber& /*node*/, const DefaultFormatterOptions& /*options*/) { return "number"; } -string parse_text(const ast::TypeEither& node, const FormattingOptions& options) +string parse_text(const ast::TypeEither& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(either "; @@ -103,7 +103,7 @@ string parse_text(const ast::TypeEither& node, const FormattingOptions& options) return ss.str(); } -string parse_text(const ast::TypedListOfNamesRecursively& node, const FormattingOptions& options) +string parse_text(const ast::TypedListOfNamesRecursively& node, const DefaultFormatterOptions& options) { stringstream ss; for (size_t i = 0; i < node.names.size(); ++i) @@ -115,7 +115,7 @@ string parse_text(const ast::TypedListOfNamesRecursively& node, const Formatting ss << " - " << parse_text(node.type, options); // lookahead - auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; + auto nested_options = DefaultFormatterOptions { options.indent + options.add_indent, options.add_indent }; auto nested_text = parse_text(node.typed_list_of_names, nested_options); if (nested_text.size() > 0) { @@ -125,9 +125,9 @@ string parse_text(const ast::TypedListOfNamesRecursively& node, const Formatting return ss.str(); } -string parse_text(const ast::TypedListOfNames& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +string parse_text(const ast::TypedListOfNames& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::TypedListOfVariablesRecursively& node, const FormattingOptions& options) +std::string parse_text(const ast::TypedListOfVariablesRecursively& node, const DefaultFormatterOptions& options) { stringstream ss; for (size_t i = 0; i < node.variables.size(); ++i) @@ -139,7 +139,7 @@ std::string parse_text(const ast::TypedListOfVariablesRecursively& node, const F ss << " - " << parse_text(node.type, options); // lookahead - auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; + auto nested_options = DefaultFormatterOptions { options.indent + options.add_indent, options.add_indent }; auto nested_text = parse_text(node.typed_list_of_variables, options); if (nested_text.size() > 0) { @@ -149,38 +149,38 @@ std::string parse_text(const ast::TypedListOfVariablesRecursively& node, const F return ss.str(); } -std::string parse_text(const ast::TypedListOfVariables& node, const FormattingOptions& options) +std::string parse_text(const ast::TypedListOfVariables& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::AtomicFormulaSkeleton& node, const FormattingOptions& options) +std::string parse_text(const ast::AtomicFormulaSkeleton& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" << parse_text(node.predicate, options) << " " << parse_text(node.typed_list_of_variables, options) << ")"; return ss.str(); } -std::string parse_text(const ast::AtomicFunctionSkeletonTotalCost& node, const FormattingOptions& /*options*/) +std::string parse_text(const ast::AtomicFunctionSkeletonTotalCost& node, const DefaultFormatterOptions& /*options*/) { std::stringstream ss; ss << "(" << parse_text(node.function_symbol) << ")"; return ss.str(); } -std::string parse_text(const ast::AtomicFunctionSkeletonGeneral& node, const FormattingOptions& options) +std::string parse_text(const ast::AtomicFunctionSkeletonGeneral& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" << parse_text(node.function_symbol, options) << " " << parse_text(node.arguments, options) << ")"; return ss.str(); } -std::string parse_text(const ast::AtomicFunctionSkeleton& node, const FormattingOptions& options) +std::string parse_text(const ast::AtomicFunctionSkeleton& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecursively& node, const FormattingOptions& options) +std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecursively& node, const DefaultFormatterOptions& options) { stringstream ss; for (size_t i = 0; i < node.atomic_function_skeletons.size(); ++i) @@ -192,7 +192,7 @@ std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecu ss << " - " << parse_text(node.function_type, options); // lookahead - auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; + auto nested_options = DefaultFormatterOptions { options.indent + options.add_indent, options.add_indent }; if (node.function_typed_list_of_atomic_function_skeletons.has_value()) { auto nested_text = parse_text(node.function_typed_list_of_atomic_function_skeletons.value(), options); @@ -205,19 +205,19 @@ std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecu return ss.str(); } -std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletons& node, const FormattingOptions& options) +std::string parse_text(const ast::FunctionTypedListOfAtomicFunctionSkeletons& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::AtomicFormulaOfTermsPredicate& node, const FormattingOptions& options) +std::string parse_text(const ast::AtomicFormulaOfTermsPredicate& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" << parse_text(node.predicate, options) << " " << parse_text(node.terms, options) << ")"; return ss.str(); } -std::string parse_text(const ast::AtomicFormulaOfTermsEquality& node, const FormattingOptions& options) +std::string parse_text(const ast::AtomicFormulaOfTermsEquality& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" @@ -225,38 +225,47 @@ std::string parse_text(const ast::AtomicFormulaOfTermsEquality& node, const Form return ss.str(); } -std::string parse_text(const ast::AtomicFormulaOfTerms& node, const FormattingOptions& options) +std::string parse_text(const ast::AtomicFormulaOfTerms& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::Atom& node, const FormattingOptions& options) { return parse_text(node.atomic_formula_of_terms, options); } +std::string parse_text(const ast::Atom& node, const DefaultFormatterOptions& options) { return parse_text(node.atomic_formula_of_terms, options); } -std::string parse_text(const ast::NegatedAtom& node, const FormattingOptions& options) +std::string parse_text(const ast::NegatedAtom& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(not " << parse_text(node.atomic_formula_of_terms, options) << ")"; return ss.str(); } -std::string parse_text(const ast::Literal& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::Literal& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::MultiOperatorMul&, const FormattingOptions&) { return "*"; } -std::string parse_text(const ast::MultiOperatorPlus&, const FormattingOptions&) { return "+"; } -std::string parse_text(const ast::MultiOperator& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::MultiOperatorMul&, const DefaultFormatterOptions&) { return "*"; } +std::string parse_text(const ast::MultiOperatorPlus&, const DefaultFormatterOptions&) { return "+"; } +std::string parse_text(const ast::MultiOperator& node, const DefaultFormatterOptions& options) +{ + return boost::apply_visitor(NodeVisitorPrinter(options), node); +} -std::string parse_text(const ast::BinaryOperatorMinus&, const FormattingOptions&) { return "-"; } -std::string parse_text(const ast::BinaryOperatorDiv&, const FormattingOptions&) { return "/"; } -std::string parse_text(const ast::BinaryOperator& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::BinaryOperatorMinus&, const DefaultFormatterOptions&) { return "-"; } +std::string parse_text(const ast::BinaryOperatorDiv&, const DefaultFormatterOptions&) { return "/"; } +std::string parse_text(const ast::BinaryOperator& node, const DefaultFormatterOptions& options) +{ + return boost::apply_visitor(NodeVisitorPrinter(options), node); +} -std::string parse_text(const ast::BinaryComparatorGreater&, const FormattingOptions&) { return ">"; } -std::string parse_text(const ast::BinaryComparatorLess&, const FormattingOptions&) { return "<"; } -std::string parse_text(const ast::BinaryComparatorEqual&, const FormattingOptions&) { return "="; } -std::string parse_text(const ast::BinaryComparatorGreaterEqual&, const FormattingOptions&) { return ">="; } -std::string parse_text(const ast::BinaryComparatorLessEqual&, const FormattingOptions&) { return "<="; } -std::string parse_text(const ast::BinaryComparator& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::BinaryComparatorGreater&, const DefaultFormatterOptions&) { return ">"; } +std::string parse_text(const ast::BinaryComparatorLess&, const DefaultFormatterOptions&) { return "<"; } +std::string parse_text(const ast::BinaryComparatorEqual&, const DefaultFormatterOptions&) { return "="; } +std::string parse_text(const ast::BinaryComparatorGreaterEqual&, const DefaultFormatterOptions&) { return ">="; } +std::string parse_text(const ast::BinaryComparatorLessEqual&, const DefaultFormatterOptions&) { return "<="; } +std::string parse_text(const ast::BinaryComparator& node, const DefaultFormatterOptions& options) +{ + return boost::apply_visitor(NodeVisitorPrinter(options), node); +} -std::string parse_text(const ast::FunctionHead& node, const FormattingOptions& options) +std::string parse_text(const ast::FunctionHead& node, const DefaultFormatterOptions& options) { std::stringstream ss; if (node.terms.size() > 0) @@ -270,14 +279,14 @@ std::string parse_text(const ast::FunctionHead& node, const FormattingOptions& o return ss.str(); } -std::string parse_text(const ast::FunctionExpression& node, const FormattingOptions& options) +std::string parse_text(const ast::FunctionExpression& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::FunctionExpressionNumber& node, const FormattingOptions& options) { return parse_text(node.number, options); } +std::string parse_text(const ast::FunctionExpressionNumber& node, const DefaultFormatterOptions& options) { return parse_text(node.number, options); } -std::string parse_text(const ast::FunctionExpressionBinaryOp& node, const FormattingOptions& options) +std::string parse_text(const ast::FunctionExpressionBinaryOp& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" << parse_text(node.binary_operator, options) << " " << parse_text(node.function_expression_left, options) << " " @@ -285,64 +294,67 @@ std::string parse_text(const ast::FunctionExpressionBinaryOp& node, const Format return ss.str(); } -std::string parse_text(const ast::FunctionExpressionMinus& node, const FormattingOptions& options) +std::string parse_text(const ast::FunctionExpressionMinus& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(- " << parse_text(node.function_expression, options) << ")"; return ss.str(); } -std::string parse_text(const ast::FunctionExpressionHead& node, const FormattingOptions& options) { return parse_text(node.function_head, options); } +std::string parse_text(const ast::FunctionExpressionHead& node, const DefaultFormatterOptions& options) { return parse_text(node.function_head, options); } -std::string parse_text(const ast::GoalDescriptor& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::GoalDescriptor& node, const DefaultFormatterOptions& options) +{ + return boost::apply_visitor(NodeVisitorPrinter(options), node); +} -std::string parse_text(const ast::GoalDescriptorAtom& node, const FormattingOptions& options) { return parse_text(node.atom, options); } +std::string parse_text(const ast::GoalDescriptorAtom& node, const DefaultFormatterOptions& options) { return parse_text(node.atom, options); } -std::string parse_text(const ast::GoalDescriptorLiteral& node, const FormattingOptions& options) { return parse_text(node.literal, options); } +std::string parse_text(const ast::GoalDescriptorLiteral& node, const DefaultFormatterOptions& options) { return parse_text(node.literal, options); } -std::string parse_text(const ast::GoalDescriptorAnd& node, const FormattingOptions& options) +std::string parse_text(const ast::GoalDescriptorAnd& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(and " << parse_text(node.goal_descriptors, options) << ")"; return ss.str(); } -std::string parse_text(const ast::GoalDescriptorOr& node, const FormattingOptions& options) +std::string parse_text(const ast::GoalDescriptorOr& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(or " << parse_text(node.goal_descriptors, options) << ")"; return ss.str(); } -std::string parse_text(const ast::GoalDescriptorNot& node, const FormattingOptions& options) +std::string parse_text(const ast::GoalDescriptorNot& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(not " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::GoalDescriptorImply& node, const FormattingOptions& options) +std::string parse_text(const ast::GoalDescriptorImply& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(imply " << parse_text(node.goal_descriptor_left, options) << " " << parse_text(node.goal_descriptor_right, options) << ")"; return ss.str(); } -std::string parse_text(const ast::GoalDescriptorExists& node, const FormattingOptions& options) +std::string parse_text(const ast::GoalDescriptorExists& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(exists " << parse_text(node.typed_list_of_variables, options) << " " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::GoalDescriptorForall& node, const FormattingOptions& options) +std::string parse_text(const ast::GoalDescriptorForall& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(forall " << parse_text(node.typed_list_of_variables, options) << " " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::GoalDescriptorFunctionComparison& node, const FormattingOptions& options) +std::string parse_text(const ast::GoalDescriptorFunctionComparison& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" << parse_text(node.binary_comparator, options) << " " << parse_text(node.function_expression_left, options) << " " @@ -350,75 +362,75 @@ std::string parse_text(const ast::GoalDescriptorFunctionComparison& node, const return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptor& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptor& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::ConstraintGoalDescriptorAnd& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorAnd& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(and " << parse_text(node.constraint_goal_descriptors, options) << ")"; return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorForall& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorForall& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(forall " << parse_text(node.typed_list_of_variables, options) << " " << parse_text(node.constraint_goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorAtEnd& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorAtEnd& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(at end " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorAlways& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorAlways& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(always " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorSometime& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorSometime& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(sometime " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorWithin& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorWithin& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(within " << parse_text(node.number, options) << " " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorAtMostOnce& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorAtMostOnce& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(at-most-once " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorSometimeAfter& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorSometimeAfter& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(sometime-after " << parse_text(node.goal_descriptor_left, options) << " " << parse_text(node.goal_descriptor_right, options) << ")"; return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorSometimeBefore& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorSometimeBefore& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(sometime-before " << parse_text(node.goal_descriptor_left, options) << " " << parse_text(node.goal_descriptor_right, options) << ")"; return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorAlwaysWithin& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorAlwaysWithin& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(always-within " << parse_text(node.number, options) << " " << parse_text(node.goal_descriptor_left, options) << " " @@ -426,7 +438,7 @@ std::string parse_text(const ast::ConstraintGoalDescriptorAlwaysWithin& node, co return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorHoldDuring& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorHoldDuring& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(hold-during " << parse_text(node.number_left, options) << " " << parse_text(node.number_right, options) << " " @@ -434,58 +446,61 @@ std::string parse_text(const ast::ConstraintGoalDescriptorHoldDuring& node, cons return ss.str(); } -std::string parse_text(const ast::ConstraintGoalDescriptorHoldAfter& node, const FormattingOptions& options) +std::string parse_text(const ast::ConstraintGoalDescriptorHoldAfter& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(hold-after " << parse_text(node.number, options) << " " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::PreferenceName& node, const FormattingOptions& options) { return parse_text(node.name, options); } +std::string parse_text(const ast::PreferenceName& node, const DefaultFormatterOptions& options) { return parse_text(node.name, options); } -std::string parse_text(const ast::PreconditionGoalDescriptor& node, const FormattingOptions& options) +std::string parse_text(const ast::PreconditionGoalDescriptor& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::PreconditionGoalDescriptorSimple& node, const FormattingOptions& options) +std::string parse_text(const ast::PreconditionGoalDescriptorSimple& node, const DefaultFormatterOptions& options) { return parse_text(node.goal_descriptor, options); } -std::string parse_text(const ast::PreconditionGoalDescriptorAnd& node, const FormattingOptions& options) +std::string parse_text(const ast::PreconditionGoalDescriptorAnd& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(and " << parse_text(node.precondition_goal_descriptors, options) << ")"; return ss.str(); } -std::string parse_text(const ast::PreconditionGoalDescriptorPreference& node, const FormattingOptions& options) +std::string parse_text(const ast::PreconditionGoalDescriptorPreference& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(preference " << parse_text(node.preference_name, options) << " " << parse_text(node.goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::PreconditionGoalDescriptorForall& node, const FormattingOptions& options) +std::string parse_text(const ast::PreconditionGoalDescriptorForall& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(forall " << parse_text(node.typed_list_of_variables, options) << " " << parse_text(node.precondition_goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::AssignOperatorAssign&, const FormattingOptions&) { return "assign"; } -std::string parse_text(const ast::AssignOperatorScaleUp&, const FormattingOptions&) { return "scale-up"; } -std::string parse_text(const ast::AssignOperatorScaleDown&, const FormattingOptions&) { return "scale-down"; } -std::string parse_text(const ast::AssignOperatorIncrease&, const FormattingOptions&) { return "increase"; } -std::string parse_text(const ast::AssignOperatorDecrease&, const FormattingOptions&) { return "decrease"; } -std::string parse_text(const ast::AssignOperator& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::AssignOperatorAssign&, const DefaultFormatterOptions&) { return "assign"; } +std::string parse_text(const ast::AssignOperatorScaleUp&, const DefaultFormatterOptions&) { return "scale-up"; } +std::string parse_text(const ast::AssignOperatorScaleDown&, const DefaultFormatterOptions&) { return "scale-down"; } +std::string parse_text(const ast::AssignOperatorIncrease&, const DefaultFormatterOptions&) { return "increase"; } +std::string parse_text(const ast::AssignOperatorDecrease&, const DefaultFormatterOptions&) { return "decrease"; } +std::string parse_text(const ast::AssignOperator& node, const DefaultFormatterOptions& options) +{ + return boost::apply_visitor(NodeVisitorPrinter(options), node); +} -std::string parse_text(const ast::Effect& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::Effect& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::EffectProductionLiteral& node, const FormattingOptions& options) { return parse_text(node.literal, options); } +std::string parse_text(const ast::EffectProductionLiteral& node, const DefaultFormatterOptions& options) { return parse_text(node.literal, options); } -std::string parse_text(const ast::EffectProductionNumericFluentTotalCost& node, const FormattingOptions& options) +std::string parse_text(const ast::EffectProductionNumericFluentTotalCost& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" << parse_text(node.assign_operator_increase, options) << " " << parse_text(node.function_symbol_total_cost, options) << " " @@ -493,7 +508,7 @@ std::string parse_text(const ast::EffectProductionNumericFluentTotalCost& node, return ss.str(); } -std::string parse_text(const ast::EffectProductionNumericFluentGeneral& node, const FormattingOptions& options) +std::string parse_text(const ast::EffectProductionNumericFluentGeneral& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" << parse_text(node.assign_operator, options) << " " << parse_text(node.function_head, options) << " " @@ -501,34 +516,40 @@ std::string parse_text(const ast::EffectProductionNumericFluentGeneral& node, co return ss.str(); } -std::string parse_text(const ast::EffectProduction& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::EffectProduction& node, const DefaultFormatterOptions& options) +{ + return boost::apply_visitor(NodeVisitorPrinter(options), node); +} -std::string parse_text(const ast::EffectConditionalForall& node, const FormattingOptions& options) +std::string parse_text(const ast::EffectConditionalForall& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(forall " << parse_text(node.typed_list_of_variables, options) << " " << parse_text(node.effect, options) << ")"; return ss.str(); } -std::string parse_text(const ast::EffectConditionalWhen& node, const FormattingOptions& options) +std::string parse_text(const ast::EffectConditionalWhen& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(when " << parse_text(node.goal_descriptor, options) << " " << parse_text(node.effect, options) << ")"; return ss.str(); } -std::string parse_text(const ast::EffectConditional& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::EffectConditional& node, const DefaultFormatterOptions& options) +{ + return boost::apply_visitor(NodeVisitorPrinter(options), node); +} -std::string parse_text(const ast::EffectNumericFluentTotalCostOrEffect& node, const FormattingOptions& options) +std::string parse_text(const ast::EffectNumericFluentTotalCostOrEffect& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::EffectRoot& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::EffectRoot& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::ActionSymbol& node, const FormattingOptions& options) { return parse_text(node.name, options); } +std::string parse_text(const ast::ActionSymbol& node, const DefaultFormatterOptions& options) { return parse_text(node.name, options); } -std::string parse_text(const ast::ActionBody& node, const FormattingOptions& options) +std::string parse_text(const ast::ActionBody& node, const DefaultFormatterOptions& options) { std::stringstream ss; if (node.precondition_goal_descriptor.has_value()) @@ -542,11 +563,11 @@ std::string parse_text(const ast::ActionBody& node, const FormattingOptions& opt return ss.str(); } -std::string parse_text(const ast::Action& node, const FormattingOptions& options) +std::string parse_text(const ast::Action& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << std::string(options.indent, ' ') << "(action " << parse_text(node.action_symbol, options) << "\n"; - FormattingOptions nested_options { options.indent + options.add_indent, options.add_indent }; + DefaultFormatterOptions nested_options { options.indent + options.add_indent, options.add_indent }; ss << std::string(nested_options.indent, ' ') << ":parameters (" << parse_text(node.typed_list_of_variables, nested_options) << ")\n" << parse_text(node.action_body, nested_options) << "\n"; ss << std::string(options.indent, ' ') << ")"; @@ -554,23 +575,23 @@ std::string parse_text(const ast::Action& node, const FormattingOptions& options return ss.str(); } -std::string parse_text(const ast::Axiom& node, const FormattingOptions& options) +std::string parse_text(const ast::Axiom& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << std::string(options.indent, ' ') << "(:derived " << parse_text(node.atomic_formula_skeleton, options) << "\n"; - FormattingOptions nested_options { options.indent + options.add_indent, options.add_indent }; + DefaultFormatterOptions nested_options { options.indent + options.add_indent, options.add_indent }; ss << std::string(nested_options.indent, ' ') << parse_text(node.goal_descriptor, options) << ")\n"; return ss.str(); } -std::string parse_text(const ast::DomainName& node, const FormattingOptions& options) +std::string parse_text(const ast::DomainName& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(domain " << parse_text(node.name, options) << ")"; return ss.str(); } -std::string parse_text(const ast::Requirements& node, const FormattingOptions& options) +std::string parse_text(const ast::Requirements& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(:requirements "; @@ -584,48 +605,48 @@ std::string parse_text(const ast::Requirements& node, const FormattingOptions& o return ss.str(); } -std::string parse_text(const ast::Types& node, const FormattingOptions& options) +std::string parse_text(const ast::Types& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(:types " << parse_text(node.typed_list_of_names, options) << ")"; return ss.str(); } -std::string parse_text(const ast::Constants& node, const FormattingOptions& options) +std::string parse_text(const ast::Constants& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(:constants " << parse_text(node.typed_list_of_names, options) << ")"; return ss.str(); } -std::string parse_text(const ast::Predicates& node, const FormattingOptions& options) +std::string parse_text(const ast::Predicates& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(:predicates " << parse_text(node.atomic_formula_skeletons, options) << ")"; return ss.str(); } -std::string parse_text(const ast::Functions& node, const FormattingOptions& options) +std::string parse_text(const ast::Functions& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(:functions " << parse_text(node.function_types_list_of_atomic_function_skeletons, options) << ")"; return ss.str(); } -std::string parse_text(const ast::Constraints& node, const FormattingOptions& options) +std::string parse_text(const ast::Constraints& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(:constraints " << parse_text(node.constraint_goal_descriptor, options) << ")"; return ss.str(); } -std::string parse_text(const ast::Structure& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +std::string parse_text(const ast::Structure& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::Domain& node, const FormattingOptions& options) +std::string parse_text(const ast::Domain& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << string(options.indent, ' ') << "(define " << parse_text(node.domain_name, options) << "\n"; - auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; + auto nested_options = DefaultFormatterOptions { options.indent + options.add_indent, options.add_indent }; if (node.requirements.has_value()) { ss << string(nested_options.indent, ' ') << parse_text(node.requirements.value(), nested_options) << "\n"; @@ -658,7 +679,7 @@ std::string parse_text(const ast::Domain& node, const FormattingOptions& options return ss.str(); } -string parse_text(const ast::BasicFunctionTerm& node, const FormattingOptions& options) +string parse_text(const ast::BasicFunctionTerm& node, const DefaultFormatterOptions& options) { std::stringstream ss; if (node.names.size() > 0) @@ -672,14 +693,14 @@ string parse_text(const ast::BasicFunctionTerm& node, const FormattingOptions& o return ss.str(); } -string parse_text(const ast::AtomicFormulaOfNamesPredicate& node, const FormattingOptions& options) +string parse_text(const ast::AtomicFormulaOfNamesPredicate& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" << parse_text(node.predicate, options) << " " << parse_text(node.names, options) << ")"; return ss.str(); } -string parse_text(const ast::AtomicFormulaOfNamesEquality& node, const FormattingOptions& options) +string parse_text(const ast::AtomicFormulaOfNamesEquality& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" @@ -687,52 +708,55 @@ string parse_text(const ast::AtomicFormulaOfNamesEquality& node, const Formattin return ss.str(); } -string parse_text(const ast::AtomicFormulaOfNames& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +string parse_text(const ast::AtomicFormulaOfNames& node, const DefaultFormatterOptions& options) +{ + return boost::apply_visitor(NodeVisitorPrinter(options), node); +} -string parse_text(const ast::GroundAtom& node, const FormattingOptions& options) { return parse_text(node.atomic_formula_of_names, options); } +string parse_text(const ast::GroundAtom& node, const DefaultFormatterOptions& options) { return parse_text(node.atomic_formula_of_names, options); } -string parse_text(const ast::NegatedGroundAtom& node, const FormattingOptions& options) +string parse_text(const ast::NegatedGroundAtom& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(not " << parse_text(node.atomic_formula_of_names, options) << ")"; return ss.str(); } -string parse_text(const ast::GroundLiteral& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +string parse_text(const ast::GroundLiteral& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -string parse_text(const ast::InitialElementLiteral& node, const FormattingOptions& options) { return parse_text(node.literal, options); } +string parse_text(const ast::InitialElementLiteral& node, const DefaultFormatterOptions& options) { return parse_text(node.literal, options); } -string parse_text(const ast::InitialElementTimedLiterals& node, const FormattingOptions& options) +string parse_text(const ast::InitialElementTimedLiterals& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(at " << parse_text(node.number, options) << " " << parse_text(node.literal, options) << ")"; return ss.str(); } -string parse_text(const ast::InitialElementNumericFluentsTotalCost& node, const FormattingOptions& options) +string parse_text(const ast::InitialElementNumericFluentsTotalCost& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(= " << parse_text(node.function_symbol_total_cost, options) << " " << parse_text(node.number, options) << ")"; return ss.str(); } -string parse_text(const ast::InitialElementNumericFluentsGeneral& node, const FormattingOptions& options) +string parse_text(const ast::InitialElementNumericFluentsGeneral& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(= " << parse_text(node.basic_function_term, options) << " " << parse_text(node.number, options) << ")"; return ss.str(); } -string parse_text(const ast::InitialElement& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +string parse_text(const ast::InitialElement& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -string parse_text(const ast::MetricFunctionExpression& node, const FormattingOptions& options) +string parse_text(const ast::MetricFunctionExpression& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -string parse_text(const ast::MetricFunctionExpressionNumber& node, const FormattingOptions& options) { return parse_text(node.number, options); } +string parse_text(const ast::MetricFunctionExpressionNumber& node, const DefaultFormatterOptions& options) { return parse_text(node.number, options); } -string parse_text(const ast::MetricFunctionExpressionBinaryOperator& node, const FormattingOptions& options) +string parse_text(const ast::MetricFunctionExpressionBinaryOperator& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(" << parse_text(node.binary_operator, options) << " " << parse_text(node.metric_function_expression_left, options) << " " @@ -740,7 +764,7 @@ string parse_text(const ast::MetricFunctionExpressionBinaryOperator& node, const return ss.str(); } -string parse_text(const ast::MetricFunctionExpressionMultiOperator& node, const FormattingOptions& options) +string parse_text(const ast::MetricFunctionExpressionMultiOperator& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(" << parse_text(node.multi_operator, options) << " " << parse_text(node.metric_function_expression_first, options) << " " @@ -748,21 +772,21 @@ string parse_text(const ast::MetricFunctionExpressionMultiOperator& node, const return ss.str(); } -string parse_text(const ast::MetricFunctionExpressionMinus& node, const FormattingOptions& options) +string parse_text(const ast::MetricFunctionExpressionMinus& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(-" << parse_text(node.metric_function_expression, options) << ")"; return ss.str(); } -string parse_text(const ast::MetricFunctionExpressionBasicFunctionTerm& node, const FormattingOptions& options) +string parse_text(const ast::MetricFunctionExpressionBasicFunctionTerm& node, const DefaultFormatterOptions& options) { return parse_text(node.basic_function_term, options); } -string parse_text(const ast::MetricFunctionExpressionTotalTime&, const FormattingOptions&) { return "total-time"; } +string parse_text(const ast::MetricFunctionExpressionTotalTime&, const DefaultFormatterOptions&) { return "total-time"; } -string parse_text(const ast::MetricFunctionExpressionPreferences& node, const FormattingOptions& options) +string parse_text(const ast::MetricFunctionExpressionPreferences& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(" @@ -770,44 +794,44 @@ string parse_text(const ast::MetricFunctionExpressionPreferences& node, const Fo return ss.str(); } -string parse_text(const ast::OptimizationMinimize&, const FormattingOptions&) { return "minimize"; } -string parse_text(const ast::OptimizationMaximize&, const FormattingOptions&) { return "maximize"; } -string parse_text(const ast::Optimization& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +string parse_text(const ast::OptimizationMinimize&, const DefaultFormatterOptions&) { return "minimize"; } +string parse_text(const ast::OptimizationMaximize&, const DefaultFormatterOptions&) { return "maximize"; } +string parse_text(const ast::Optimization& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::MetricSpecificationTotalCost& node, const FormattingOptions& options) +std::string parse_text(const ast::MetricSpecificationTotalCost& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(:metric " << parse_text(node.optimization_minimize, options) << " " << parse_text(node.function_symbol_total_cost, options) << ")"; return ss.str(); } -std::string parse_text(const ast::MetricSpecificationGeneral& node, const FormattingOptions& options) +std::string parse_text(const ast::MetricSpecificationGeneral& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(:metric " << parse_text(node.optimization, options) << " " << parse_text(node.metric_function_expression, options) << ")"; return ss.str(); } -string parse_text(const ast::PreferenceConstraintGoalDescriptor& node, const FormattingOptions& options) +string parse_text(const ast::PreferenceConstraintGoalDescriptor& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -string parse_text(const ast::PreferenceConstraintGoalDescriptorAnd& node, const FormattingOptions& options) +string parse_text(const ast::PreferenceConstraintGoalDescriptorAnd& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(and " << parse_text(node.preference_constraint_goal_descriptors, options) << ")"; return ss.str(); } -string parse_text(const ast::PreferenceConstraintGoalDescriptorForall& node, const FormattingOptions& options) +string parse_text(const ast::PreferenceConstraintGoalDescriptorForall& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(forall " << parse_text(node.typed_list_of_variables, options) << " " << parse_text(node.preference_constraint_goal_descriptor, options) << ")"; return ss.str(); } -string parse_text(const ast::PreferenceConstraintGoalDescriptorPreference& node, const FormattingOptions& options) +string parse_text(const ast::PreferenceConstraintGoalDescriptorPreference& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(preference "; @@ -819,60 +843,63 @@ string parse_text(const ast::PreferenceConstraintGoalDescriptorPreference& node, return ss.str(); } -string parse_text(const ast::PreferenceConstraintGoalDescriptorSimple& node, const FormattingOptions& options) +string parse_text(const ast::PreferenceConstraintGoalDescriptorSimple& node, const DefaultFormatterOptions& options) { return parse_text(node.constraint_goal_descriptor, options); } -string parse_text(const ast::ProblemName& node, const FormattingOptions& options) +string parse_text(const ast::ProblemName& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(problem " << parse_text(node.name, options) << ")"; return ss.str(); } -string parse_text(const ast::ProblemDomainName& node, const FormattingOptions& options) +string parse_text(const ast::ProblemDomainName& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(:domain " << parse_text(node.name, options) << ")"; return ss.str(); } -string parse_text(const ast::Objects& node, const FormattingOptions& options) +string parse_text(const ast::Objects& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(:objects " << parse_text(node.typed_list_of_names, options) << ")"; return ss.str(); } -string parse_text(const ast::Initial& node, const FormattingOptions& options) +string parse_text(const ast::Initial& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(:init " << parse_text(node.initial_elements, options) << ")"; return ss.str(); } -string parse_text(const ast::Goal& node, const FormattingOptions& options) +string parse_text(const ast::Goal& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(:goal " << parse_text(node.precondition_goal_descriptor, options) << ")"; return ss.str(); } -string parse_text(const ast::ProblemConstraints& node, const FormattingOptions& options) +string parse_text(const ast::ProblemConstraints& node, const DefaultFormatterOptions& options) { stringstream ss; ss << "(:constraints " << parse_text(node.preference_constraint_goal_descriptor, options) << ")"; return ss.str(); } -string parse_text(const ast::MetricSpecification& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } +string parse_text(const ast::MetricSpecification& node, const DefaultFormatterOptions& options) +{ + return boost::apply_visitor(NodeVisitorPrinter(options), node); +} -string parse_text(const ast::Problem& node, const FormattingOptions& options) +string parse_text(const ast::Problem& node, const DefaultFormatterOptions& options) { stringstream ss; ss << string(options.indent, ' ') << "(define " << parse_text(node.problem_name, options) << "\n"; - auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; + auto nested_options = DefaultFormatterOptions { options.indent + options.add_indent, options.add_indent }; ss << string(nested_options.indent, ' ') << parse_text(node.domain_name, nested_options) << "\n"; if (node.requirements.has_value()) { @@ -903,7 +930,7 @@ string parse_text(const ast::Problem& node, const FormattingOptions& options) } template -inline std::string parse_text(const std::vector& nodes, const FormattingOptions& options) +inline std::string parse_text(const std::vector& nodes, const DefaultFormatterOptions& options) { std::stringstream ss; for (size_t i = 0; i < nodes.size(); ++i) diff --git a/src/pddl/action.cpp b/src/pddl/action.cpp index 135bf613..e895eb0b 100644 --- a/src/pddl/action.cpp +++ b/src/pddl/action.cpp @@ -20,7 +20,6 @@ #include "loki/details/pddl/conditions.hpp" #include "loki/details/pddl/effects.hpp" #include "loki/details/pddl/parameter.hpp" -#include "loki/details/pddl/visitors.hpp" namespace loki { @@ -39,34 +38,6 @@ ActionImpl::ActionImpl(size_t index, { } -void ActionImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; - out << std::string(options.indent, ' ') << "(:action " << m_name << "\n" << std::string(nested_options.indent, ' ') << ":parameters ("; - for (size_t i = 0; i < m_parameters.size(); ++i) - { - if (i != 0) - out << " "; - m_parameters[i]->str(out, options); - } - out << ")"; - out << "\n"; - out << std::string(nested_options.indent, ' ') << ":conditions "; - if (m_condition.has_value()) - std::visit(StringifyVisitor(out, nested_options), *m_condition.value()); - else - out << "()"; - - out << "\n"; - out << std::string(nested_options.indent, ' ') << ":effects "; - if (m_effect.has_value()) - std::visit(StringifyVisitor(out, nested_options), *m_effect.value()); - else - out << "()"; - - out << ")\n"; -} - const std::string& ActionImpl::get_name() const { return m_name; } size_t ActionImpl::get_original_arity() const { return m_original_arity; } diff --git a/src/pddl/atom.cpp b/src/pddl/atom.cpp index a83b50e0..6249b2aa 100644 --- a/src/pddl/atom.cpp +++ b/src/pddl/atom.cpp @@ -19,23 +19,11 @@ #include "loki/details/pddl/predicate.hpp" #include "loki/details/pddl/term.hpp" -#include "loki/details/pddl/visitors.hpp" namespace loki { AtomImpl::AtomImpl(size_t index, Predicate predicate, TermList terms) : Base(index), m_predicate(std::move(predicate)), m_terms(std::move(terms)) {} -void AtomImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(" << m_predicate->get_name(); - for (size_t i = 0; i < m_terms.size(); ++i) - { - out << " "; - std::visit(StringifyVisitor(out, options), *m_terms[i]); - } - out << ")"; -} - const Predicate& AtomImpl::get_predicate() const { return m_predicate; } const TermList& AtomImpl::get_terms() const { return m_terms; } diff --git a/src/pddl/axiom.cpp b/src/pddl/axiom.cpp index d8ff477d..ce99f06f 100644 --- a/src/pddl/axiom.cpp +++ b/src/pddl/axiom.cpp @@ -22,7 +22,6 @@ #include "loki/details/pddl/literal.hpp" #include "loki/details/pddl/parameter.hpp" #include "loki/details/pddl/predicate.hpp" -#include "loki/details/pddl/visitors.hpp" namespace loki { @@ -35,21 +34,6 @@ AxiomImpl::AxiomImpl(size_t index, std::string derived_predicate_name, Parameter { } -void AxiomImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; - out << std::string(options.indent, ' ') << "(:derived " << m_derived_predicate_name; - for (size_t i = 0; i < m_parameters.size(); ++i) - { - out << " "; - m_parameters[i]->str(out, options); - } - out << "\n"; - out << std::string(nested_options.indent, ' '); - std::visit(StringifyVisitor(out, nested_options), *m_condition); - out << ")\n"; -} - const std::string& AxiomImpl::get_derived_predicate_name() const { return m_derived_predicate_name; } const Condition& AxiomImpl::get_condition() const { return m_condition; } diff --git a/src/pddl/conditions.cpp b/src/pddl/conditions.cpp index 855279ac..ddf9c904 100644 --- a/src/pddl/conditions.cpp +++ b/src/pddl/conditions.cpp @@ -19,7 +19,6 @@ #include "loki/details/pddl/literal.hpp" #include "loki/details/pddl/parameter.hpp" -#include "loki/details/pddl/visitors.hpp" namespace loki { @@ -27,54 +26,21 @@ namespace loki /* Literal */ ConditionLiteralImpl::ConditionLiteralImpl(size_t index, Literal literal) : Base(index), m_literal(std::move(literal)) {} -void ConditionLiteralImpl::str_impl(std::ostream& out, const FormattingOptions& options) const { m_literal->str(out, options); } - const Literal& ConditionLiteralImpl::get_literal() const { return m_literal; } /* And */ ConditionAndImpl::ConditionAndImpl(size_t index, ConditionList conditions) : Base(index), m_conditions(std::move(conditions)) {} -void ConditionAndImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(and "; - for (size_t i = 0; i < m_conditions.size(); ++i) - { - if (i != 0) - out << " "; - std::visit(StringifyVisitor(out, options), *m_conditions[i]); - } - out << ")"; -} - const ConditionList& ConditionAndImpl::get_conditions() const { return m_conditions; } /* Or */ ConditionOrImpl::ConditionOrImpl(size_t index, ConditionList conditions) : Base(index), m_conditions(std::move(conditions)) {} -void ConditionOrImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(or "; - for (size_t i = 0; i < m_conditions.size(); ++i) - { - if (i != 0) - out << " "; - std::visit(StringifyVisitor(out, options), *m_conditions[i]); - } - out << ")"; -} - const ConditionList& ConditionOrImpl::get_conditions() const { return m_conditions; } /* Not */ ConditionNotImpl::ConditionNotImpl(size_t index, Condition condition) : Base(index), m_condition(std::move(condition)) {} -void ConditionNotImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(not "; - std::visit(StringifyVisitor(out, options), *m_condition); - out << ")"; -} - const Condition& ConditionNotImpl::get_condition() const { return m_condition; } /* Imply */ @@ -85,15 +51,6 @@ ConditionImplyImpl::ConditionImplyImpl(size_t index, Condition condition_left, C { } -void ConditionImplyImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(imply "; - std::visit(StringifyVisitor(out, options), *m_condition_left); - out << " "; - std::visit(StringifyVisitor(out, options), *m_condition_right); - out << ")"; -} - const Condition& ConditionImplyImpl::get_condition_left() const { return m_condition_left; } const Condition& ConditionImplyImpl::get_condition_right() const { return m_condition_right; } @@ -106,20 +63,6 @@ ConditionExistsImpl::ConditionExistsImpl(size_t index, ParameterList parameters, { } -void ConditionExistsImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(exists ("; - for (size_t i = 0; i < m_parameters.size(); ++i) - { - if (i != 0) - out << " "; - m_parameters[i]->str(out, options); - } - out << ") "; - std::visit(StringifyVisitor(out, options), *m_condition); - out << ")"; -} - const ParameterList& ConditionExistsImpl::get_parameters() const { return m_parameters; } const Condition& ConditionExistsImpl::get_condition() const { return m_condition; } @@ -132,20 +75,6 @@ ConditionForallImpl::ConditionForallImpl(size_t index, ParameterList parameters, { } -void ConditionForallImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(forall ("; - for (size_t i = 0; i < m_parameters.size(); ++i) - { - if (i != 0) - out << " "; - m_parameters[i]->str(out, options); - } - out << ") "; - std::visit(StringifyVisitor(out, options), *m_condition); - out << ")"; -} - const ParameterList& ConditionForallImpl::get_parameters() const { return m_parameters; } const Condition& ConditionForallImpl::get_condition() const { return m_condition; } diff --git a/src/pddl/domain.cpp b/src/pddl/domain.cpp index 225577a8..9f6dfb82 100644 --- a/src/pddl/domain.cpp +++ b/src/pddl/domain.cpp @@ -56,135 +56,6 @@ DomainImpl::DomainImpl(size_t index, { } -void DomainImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << string(options.indent, ' ') << "(define (domain " << m_name << ")\n"; - auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; - if (!m_requirements->get_requirements().empty()) - { - out << string(nested_options.indent, ' '); - m_requirements->str(out, nested_options); - out << "\n"; - } - if (!m_types.empty()) - { - out << string(nested_options.indent, ' ') << "(:types "; - std::unordered_map> subtypes_by_parent_types; - for (const auto& type : m_types) - { - // We do not want to print root type "object" - if (!type->get_bases().empty()) - { - subtypes_by_parent_types[type->get_bases()].push_back(type); - } - } - size_t i = 0; - for (const auto& [types, sub_types] : subtypes_by_parent_types) - { - if (i != 0) - out << "\n" << string(nested_options.indent, ' '); - for (size_t i = 0; i < sub_types.size(); ++i) - { - if (i != 0) - out << " "; - out << sub_types[i]->get_name(); - } - out << " - "; - if (types.size() > 1) - { - out << "(either "; - for (size_t i = 0; i < types.size(); ++i) - { - if (i != 0) - out << " "; - types[i]->get_name(); - } - out << ")"; - } - else if (types.size() == 1) - { - out << types.front()->get_name(); - } - ++i; - } - out << ")\n"; - } - if (!m_constants.empty()) - { - out << string(nested_options.indent, ' ') << "(:constants "; - std::unordered_map> constants_by_types; - for (const auto& constant : m_constants) - { - constants_by_types[constant->get_bases()].push_back(constant); - } - size_t i = 0; - for (const auto& pair : constants_by_types) - { - if (i != 0) - out << "\n" << string(nested_options.indent, ' '); - const auto& constants = pair.second; - for (size_t i = 0; i < constants.size(); ++i) - { - if (i != 0) - out << " "; - constants[i]->str(out, nested_options); - } - if (m_requirements->test(RequirementEnum::TYPING)) - { - out << " - "; - const auto& types = pair.first; - for (size_t i = 0; i < types.size(); ++i) - { - if (i != 0) - out << " "; - types[i]->str(out, nested_options); - } - } - ++i; - } - out << ")\n"; - } - if (!m_predicates.empty()) - { - out << string(nested_options.indent, ' ') << "(:predicates "; - for (size_t i = 0; i < m_predicates.size(); ++i) - { - if (i != 0) - out << " "; - m_predicates[i]->str(out, nested_options); - } - out << ")\n"; - } - if (!m_functions.empty()) - { - out << string(nested_options.indent, ' ') << "(:functions "; - for (size_t i = 0; i < m_functions.size(); ++i) - { - if (i != 0) - out << " "; - m_functions[i]->str(out, nested_options); - } - } - - for (const auto& action : m_actions) - { - action->str(out, nested_options); - } - - for (const auto& axiom : m_axioms) - { - axiom->str(out, nested_options); - } - - out << std::string(options.indent, ' ') << ")"; -} - -std::ostream& operator<<(std::ostream& os, const DomainImpl& domain) -{ - domain.str(os, FormattingOptions { 0, 4 }); - return os; -} - const std::optional& DomainImpl::get_filepath() const { return m_filepath; } const std::string& DomainImpl::get_name() const { return m_name; } diff --git a/src/pddl/effects.cpp b/src/pddl/effects.cpp index 635f3ea1..bd9d76e4 100644 --- a/src/pddl/effects.cpp +++ b/src/pddl/effects.cpp @@ -22,7 +22,6 @@ #include "loki/details/pddl/function_expressions.hpp" #include "loki/details/pddl/literal.hpp" #include "loki/details/pddl/parameter.hpp" -#include "loki/details/pddl/visitors.hpp" #include @@ -43,25 +42,11 @@ const std::string& to_string(AssignOperatorEnum assign_operator) /* EffectLiteral */ EffectLiteralImpl::EffectLiteralImpl(size_t index, Literal literal) : Base(index), m_literal(std::move(literal)) {} -void EffectLiteralImpl::str_impl(std::ostream& out, const FormattingOptions& options) const { m_literal->str(out, options); } - const Literal& EffectLiteralImpl::get_literal() const { return m_literal; } /* EffectAnd */ EffectAndImpl::EffectAndImpl(size_t index, EffectList effects) : Base(index), m_effects(std::move(effects)) {} -void EffectAndImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(and "; - for (size_t i = 0; i < m_effects.size(); ++i) - { - if (i != 0) - out << " "; - std::visit(StringifyVisitor(out, options), *m_effects[i]); - } - out << ")"; -} - const EffectList& EffectAndImpl::get_effects() const { return m_effects; } /* EffectNumeric */ @@ -73,15 +58,6 @@ EffectNumericImpl::EffectNumericImpl(size_t index, AssignOperatorEnum assign_ope { } -void EffectNumericImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(" << to_string(m_assign_operator) << " "; - m_function->str(out, options); - out << " "; - std::visit(StringifyVisitor(out, options), *m_function_expression); - out << ")"; -} - AssignOperatorEnum EffectNumericImpl::get_assign_operator() const { return m_assign_operator; } const Function& EffectNumericImpl::get_function() const { return m_function; } @@ -96,20 +72,6 @@ EffectConditionalForallImpl::EffectConditionalForallImpl(size_t index, Parameter { } -void EffectConditionalForallImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(forall ("; - for (size_t i = 0; i < m_parameters.size(); ++i) - { - if (i != 0) - out << " "; - m_parameters[i]->str(out, options); - } - out << ") "; - std::visit(StringifyVisitor(out, options), *m_effect); - out << ")"; -} - const ParameterList& EffectConditionalForallImpl::get_parameters() const { return m_parameters; } const Effect& EffectConditionalForallImpl::get_effect() const { return m_effect; } @@ -122,15 +84,6 @@ EffectConditionalWhenImpl::EffectConditionalWhenImpl(size_t index, Condition con { } -void EffectConditionalWhenImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(when "; - std::visit(StringifyVisitor(out, options), *m_condition); - out << " "; - std::visit(StringifyVisitor(out, options), *m_effect); - out << ")"; -} - const Condition& EffectConditionalWhenImpl::get_condition() const { return m_condition; } const Effect& EffectConditionalWhenImpl::get_effect() const { return m_effect; } diff --git a/src/pddl/exceptions.cpp b/src/pddl/exceptions.cpp index ea14e25d..27a7982d 100644 --- a/src/pddl/exceptions.cpp +++ b/src/pddl/exceptions.cpp @@ -17,14 +17,7 @@ #include "loki/details/pddl/exceptions.hpp" -#include "loki/details/pddl/domain.hpp" -#include "loki/details/pddl/function.hpp" -#include "loki/details/pddl/function_skeleton.hpp" -#include "loki/details/pddl/object.hpp" -#include "loki/details/pddl/parameter.hpp" -#include "loki/details/pddl/predicate.hpp" -#include "loki/details/pddl/type.hpp" -#include "loki/details/pddl/variable.hpp" +#include "loki/details/pddl/formatter.hpp" #include @@ -173,8 +166,8 @@ MultiDefinitionObjectError::MultiDefinitionObjectError(const std::string& name, IllformedFunctionDefinitionMissingValue::IllformedFunctionDefinitionMissingValue(const FunctionSkeleton& function_skeleton, const Function& values, const std::string& error_handler_output) : - SemanticParserError("The function with name \"" + function_skeleton->str() + "\n misses a value definition in the initial state for arguments \"" - + values->str() + "\".", + SemanticParserError("The function with name \"" + StreamWriter(*function_skeleton).str() + + "\n misses a value definition in the initial state for arguments \"" + StreamWriter(*values).str() + "\".", error_handler_output) { } @@ -182,7 +175,8 @@ IllformedFunctionDefinitionMissingValue::IllformedFunctionDefinitionMissingValue IllformedFunctionDefinitionMultipleValues::IllformedFunctionDefinitionMultipleValues(const FunctionSkeleton& function_skeleton, const Function& ground_function, const std::string& error_handler_output) : - SemanticParserError("The function with name \"" + function_skeleton->str() + "\n has multiple values defined for \"" + ground_function->str() + "\".", + SemanticParserError("The function with name \"" + StreamWriter(*function_skeleton).str() + "\n has multiple values defined for \"" + + StreamWriter(*ground_function).str() + "\".", error_handler_output) { } @@ -191,8 +185,8 @@ IllformedFunctionDefinitionMultipleValues::IllformedFunctionDefinitionMultipleVa IncompatibleParameterTypesError::IncompatibleParameterTypesError(const Parameter& specialized_parameter, const Parameter& generalized_parameter, const std::string& error_handler_output) : - SemanticParserError("The types of the parameter \""s + specialized_parameter->str() + "\" are incompatible with the types of parameter \"" - + generalized_parameter->str() + "\"s", + SemanticParserError("The types of the parameter \""s + StreamWriter(*specialized_parameter).str() + "\" are incompatible with the types of parameter \"" + + StreamWriter(*generalized_parameter).str() + "\"s", error_handler_output) { } diff --git a/src/pddl/formatter.cpp b/src/pddl/formatter.cpp index c71720d2..3315183e 100644 --- a/src/pddl/formatter.cpp +++ b/src/pddl/formatter.cpp @@ -636,14 +636,14 @@ void DefaultFormatter::write(const RequirementsImpl& element, const DefaultForma out << ")"; } -void DefaultFormatter::write(const TermObjectImpl& element, const DefaultFormatterOptions& options, std::ostream& out) const +void DefaultFormatter::write(const TermObjectImpl& element, const DefaultFormatterOptions&, std::ostream& out) const { - write(*element.get_object(), options, out); + out << element.get_object()->get_name(); } -void DefaultFormatter::write(const TermVariableImpl& element, const DefaultFormatterOptions& options, std::ostream& out) const +void DefaultFormatter::write(const TermVariableImpl& element, const DefaultFormatterOptions&, std::ostream& out) const { - write(*element.get_variable(), options, out); + out << element.get_variable()->get_name(); } void DefaultFormatter::write(const TermImpl& element, const DefaultFormatterOptions& options, std::ostream& out) const diff --git a/src/pddl/function.cpp b/src/pddl/function.cpp index b4815efb..644f19c7 100644 --- a/src/pddl/function.cpp +++ b/src/pddl/function.cpp @@ -19,7 +19,6 @@ #include "loki/details/pddl/function_skeleton.hpp" #include "loki/details/pddl/term.hpp" -#include "loki/details/pddl/visitors.hpp" namespace loki { @@ -30,25 +29,6 @@ FunctionImpl::FunctionImpl(size_t index, FunctionSkeleton function_skeleton, Ter { } -void FunctionImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - if (m_terms.empty()) - { - out << "(" << m_function_skeleton->get_name() << ")"; - } - else - { - out << "(" << m_function_skeleton->get_name() << "("; - for (size_t i = 0; i < m_terms.size(); ++i) - { - if (i != 0) - out << " "; - std::visit(StringifyVisitor(out, options), *m_terms[i]); - } - out << "))"; - } -} - const FunctionSkeleton& FunctionImpl::get_function_skeleton() const { return m_function_skeleton; } const TermList& FunctionImpl::get_terms() const { return m_terms; } diff --git a/src/pddl/function_expressions.cpp b/src/pddl/function_expressions.cpp index 65d148c1..eacaf15a 100644 --- a/src/pddl/function_expressions.cpp +++ b/src/pddl/function_expressions.cpp @@ -18,7 +18,6 @@ #include "loki/details/pddl/function_expressions.hpp" #include "loki/details/pddl/function.hpp" -#include "loki/details/pddl/visitors.hpp" #include @@ -52,8 +51,6 @@ const std::string& to_string(MultiOperatorEnum multi_operator) /* FunctionExpressionNumber */ FunctionExpressionNumberImpl::FunctionExpressionNumberImpl(size_t index, double number) : Base(index), m_number(number) {} -void FunctionExpressionNumberImpl::str_impl(std::ostream& out, const FormattingOptions& /*options*/) const { out << m_number; } - double FunctionExpressionNumberImpl::get_number() const { return m_number; } /* FunctionExpressionBinaryOperator */ @@ -68,15 +65,6 @@ FunctionExpressionBinaryOperatorImpl::FunctionExpressionBinaryOperatorImpl(size_ { } -void FunctionExpressionBinaryOperatorImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(" << to_string(m_binary_operator) << " "; - std::visit(StringifyVisitor(out, options), *m_left_function_expression); - out << " "; - std::visit(StringifyVisitor(out, options), *m_right_function_expression); - out << ")"; -} - BinaryOperatorEnum FunctionExpressionBinaryOperatorImpl::get_binary_operator() const { return m_binary_operator; } const FunctionExpression& FunctionExpressionBinaryOperatorImpl::get_left_function_expression() const { return m_left_function_expression; } @@ -93,18 +81,6 @@ FunctionExpressionMultiOperatorImpl::FunctionExpressionMultiOperatorImpl(size_t { } -void FunctionExpressionMultiOperatorImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(" << to_string(m_multi_operator); - assert(!m_function_expressions.empty()); - for (const auto& function_expression : m_function_expressions) - { - out << " "; - std::visit(StringifyVisitor(out, options), *function_expression); - } - out << ")"; -} - MultiOperatorEnum FunctionExpressionMultiOperatorImpl::get_multi_operator() const { return m_multi_operator; } const FunctionExpressionList& FunctionExpressionMultiOperatorImpl::get_function_expressions() const { return m_function_expressions; } @@ -116,20 +92,11 @@ FunctionExpressionMinusImpl::FunctionExpressionMinusImpl(size_t index, FunctionE { } -void FunctionExpressionMinusImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(- "; - std::visit(StringifyVisitor(out, options), *m_function_expression); - out << ")"; -} - const FunctionExpression& FunctionExpressionMinusImpl::get_function_expression() const { return m_function_expression; } /* FunctionExpressionFunction */ FunctionExpressionFunctionImpl::FunctionExpressionFunctionImpl(size_t index, Function function) : Base(index), m_function(std::move(function)) {} -void FunctionExpressionFunctionImpl::str_impl(std::ostream& out, const FormattingOptions& options) const { m_function->str(out, options); } - const Function& FunctionExpressionFunctionImpl::get_function() const { return m_function; } } diff --git a/src/pddl/function_skeleton.cpp b/src/pddl/function_skeleton.cpp index bd723439..1e636658 100644 --- a/src/pddl/function_skeleton.cpp +++ b/src/pddl/function_skeleton.cpp @@ -29,17 +29,6 @@ FunctionSkeletonImpl::FunctionSkeletonImpl(size_t index, std::string name, Param { } -void FunctionSkeletonImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(" << m_name; - for (size_t i = 0; i < m_parameters.size(); ++i) - { - out << " "; - m_parameters[i]->str(out, options); - } - out << ")"; -} - const std::string& FunctionSkeletonImpl::get_name() const { return m_name; } const ParameterList& FunctionSkeletonImpl::get_parameters() const { return m_parameters; } diff --git a/src/pddl/literal.cpp b/src/pddl/literal.cpp index 72c5d752..2d7da26b 100644 --- a/src/pddl/literal.cpp +++ b/src/pddl/literal.cpp @@ -23,20 +23,6 @@ namespace loki { LiteralImpl::LiteralImpl(size_t index, bool is_negated, Atom atom) : Base(index), m_is_negated(is_negated), m_atom(std::move(atom)) {} -void LiteralImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - if (m_is_negated) - { - out << "(not "; - m_atom->str(out, options); - out << ")"; - } - else - { - m_atom->str(out, options); - } -} - bool LiteralImpl::is_negated() const { return m_is_negated; } const Atom& LiteralImpl::get_atom() const { return m_atom; } diff --git a/src/pddl/metric.cpp b/src/pddl/metric.cpp index ba6f1cce..6ae5874a 100644 --- a/src/pddl/metric.cpp +++ b/src/pddl/metric.cpp @@ -18,7 +18,6 @@ #include "loki/details/pddl/metric.hpp" #include "loki/details/pddl/function_expressions.hpp" -#include "loki/details/pddl/visitors.hpp" #include @@ -44,13 +43,6 @@ OptimizationMetricImpl::OptimizationMetricImpl(size_t index, OptimizationMetricE { } -void OptimizationMetricImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(" << to_string(m_optimization_metric) << " "; - std::visit(StringifyVisitor(out, options), *m_function_expression); - out << ")"; -} - OptimizationMetricEnum OptimizationMetricImpl::get_optimization_metric() const { return m_optimization_metric; } const FunctionExpression& OptimizationMetricImpl::get_function_expression() const { return m_function_expression; } diff --git a/src/pddl/numeric_fluent.cpp b/src/pddl/numeric_fluent.cpp index 3f2756cc..b8df552c 100644 --- a/src/pddl/numeric_fluent.cpp +++ b/src/pddl/numeric_fluent.cpp @@ -23,13 +23,6 @@ namespace loki { NumericFluentImpl::NumericFluentImpl(size_t index, Function function, double number) : Base(index), m_function(std::move(function)), m_number(number) {} -void NumericFluentImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(= "; - m_function->str(out, options); - out << " " << m_number << ")"; -} - const Function& NumericFluentImpl::get_function() const { return m_function; } double NumericFluentImpl::get_number() const { return m_number; } diff --git a/src/pddl/object.cpp b/src/pddl/object.cpp index 5d9f0dd7..2f8b6cc0 100644 --- a/src/pddl/object.cpp +++ b/src/pddl/object.cpp @@ -23,30 +23,6 @@ namespace loki { ObjectImpl::ObjectImpl(size_t index, std::string name, TypeList types) : Base(index), m_name(std::move(name)), m_types(std::move(types)) {} -void ObjectImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << m_name; - if (!m_types.empty()) - { - out << " - "; - if (m_types.size() > 1) - { - out << "(either "; - for (size_t i = 0; i < m_types.size(); ++i) - { - if (i != 0) - out << " "; - m_types[i]->str(out, options); - } - out << ")"; - } - else if (m_types.size() == 1) - { - m_types.front()->str(out, options); - } - } -} - const std::string& ObjectImpl::get_name() const { return m_name; } const TypeList& ObjectImpl::get_bases() const { return m_types; } diff --git a/src/pddl/parameter.cpp b/src/pddl/parameter.cpp index f79e1766..c6d58c25 100644 --- a/src/pddl/parameter.cpp +++ b/src/pddl/parameter.cpp @@ -26,30 +26,6 @@ namespace loki { ParameterImpl::ParameterImpl(size_t index, Variable variable, TypeList types) : Base(index), m_variable(std::move(variable)), m_types(std::move(types)) {} -void ParameterImpl::str_impl(std::ostream& out, const FormattingOptions& /*options*/) const -{ - out << m_variable->get_name(); - if (!m_types.empty()) - { - out << " - "; - if (m_types.size() > 1) - { - out << "(either "; - for (size_t i = 0; i < m_types.size(); ++i) - { - if (i != 0) - out << " "; - m_types[i]->get_name(); - } - out << ")"; - } - else if (m_types.size() == 1) - { - out << m_types.front()->get_name(); - } - } -} - const Variable& ParameterImpl::get_variable() const { return m_variable; } const TypeList& ParameterImpl::get_bases() const { return m_types; } diff --git a/src/pddl/parser/conditions.cpp b/src/pddl/parser/conditions.cpp index fe92384b..0204b865 100644 --- a/src/pddl/parser/conditions.cpp +++ b/src/pddl/parser/conditions.cpp @@ -22,7 +22,6 @@ #include "loki/details/ast/printer.hpp" #include "loki/details/pddl/conditions.hpp" #include "loki/details/pddl/exceptions.hpp" -#include "loki/details/pddl/visitors.hpp" #include "parameters.hpp" #include "reference_utils.hpp" diff --git a/src/pddl/parser/structure.cpp b/src/pddl/parser/structure.cpp index e374435a..09212a22 100644 --- a/src/pddl/parser/structure.cpp +++ b/src/pddl/parser/structure.cpp @@ -25,6 +25,7 @@ #include "literal.hpp" #include "loki/details/pddl/action.hpp" #include "loki/details/pddl/axiom.hpp" +#include "loki/details/pddl/formatter.hpp" #include "parameters.hpp" #include "predicates.hpp" #include "reference_utils.hpp" @@ -67,7 +68,7 @@ Action parse(const ast::Action& node, Context& context) { if (!context.quiet) { - std::cout << "Removed unused parameter " << *parameter << " from action " << name << std::endl; + std::cout << "Removed unused parameter " << StreamWriter(*parameter) << " from action " << name << std::endl; } } } diff --git a/src/pddl/predicate.cpp b/src/pddl/predicate.cpp index 2f77c45a..888f48f5 100644 --- a/src/pddl/predicate.cpp +++ b/src/pddl/predicate.cpp @@ -32,17 +32,6 @@ PredicateImpl::PredicateImpl(size_t index, std::string name, ParameterList param { } -void PredicateImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << "(" << m_name; - for (size_t i = 0; i < m_parameters.size(); ++i) - { - out << " "; - m_parameters[i]->str(out, options); - } - out << ")"; -} - const std::string& PredicateImpl::get_name() const { return m_name; } const ParameterList& PredicateImpl::get_parameters() const { return m_parameters; } diff --git a/src/pddl/problem.cpp b/src/pddl/problem.cpp index d971b1f1..0bc0424b 100644 --- a/src/pddl/problem.cpp +++ b/src/pddl/problem.cpp @@ -27,7 +27,6 @@ #include "loki/details/pddl/predicate.hpp" #include "loki/details/pddl/requirements.hpp" #include "loki/details/pddl/type.hpp" -#include "loki/details/pddl/visitors.hpp" #include "loki/details/utils/equal_to.hpp" #include "loki/details/utils/hash.hpp" @@ -64,120 +63,6 @@ ProblemImpl::ProblemImpl(size_t index, { } -void ProblemImpl::str_impl(std::ostream& out, const FormattingOptions& options) const -{ - out << string(options.indent, ' ') << "(define (problem " << m_name << ")\n"; - auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; - out << string(nested_options.indent, ' ') << "(:domain " << m_domain->get_name() << ")\n"; - if (!m_requirements->get_requirements().empty()) - { - out << string(nested_options.indent, ' '); - m_requirements->str(out, nested_options); - out << "\n"; - } - - if (!m_objects.empty()) - { - out << string(nested_options.indent, ' ') << "(:objects "; - std::unordered_map> objects_by_types; - for (const auto& object : m_objects) - { - objects_by_types[object->get_bases()].push_back(object); - } - size_t i = 0; - for (const auto& [types, objects] : objects_by_types) - { - if (i != 0) - out << "\n" << string(nested_options.indent, ' '); - for (size_t i = 0; i < objects.size(); ++i) - { - if (i != 0) - { - out << " "; - } - out << objects[i]->get_name(); - } - if (m_requirements->test(RequirementEnum::TYPING)) - { - out << " - "; - if (types.size() > 1) - { - out << "(either "; - for (size_t i = 0; i < types.size(); ++i) - { - if (i != 0) - out << " "; - types[i]->get_name(); - } - out << ")"; - } - else if (types.size() == 1) - { - out << types.front()->get_name(); - } - } - ++i; - } - out << ")\n"; - } - - if (!m_derived_predicates.empty()) - { - out << string(nested_options.indent, ' ') << "(:derived-predicates "; - for (size_t i = 0; i < m_derived_predicates.size(); ++i) - { - if (i != 0) - out << " "; - m_derived_predicates[i]->str(out, nested_options); - } - out << ")\n"; - } - - if (!(m_initial_literals.empty() && m_numeric_fluents.empty())) - { - out << string(nested_options.indent, ' ') << "(:init "; - for (size_t i = 0; i < m_initial_literals.size(); ++i) - { - if (i != 0) - out << " "; - m_initial_literals[i]->str(out, nested_options); - } - for (size_t i = 0; i < m_numeric_fluents.size(); ++i) - { - out << " "; - m_numeric_fluents[i]->str(out, nested_options); - } - } - out << ")\n"; - - if (m_goal_condition.has_value()) - { - out << string(nested_options.indent, ' ') << "(:goal "; - std::visit(StringifyVisitor(out, options), *m_goal_condition.value()); - out << ")\n"; - } - - if (m_optimization_metric.has_value()) - { - out << string(nested_options.indent, ' ') << "(:metric "; - m_optimization_metric.value()->str(out, nested_options); - out << ")\n"; - } - - for (const auto& axiom : m_axioms) - { - axiom->str(out, nested_options); - } - - out << string(options.indent, ' ') << ")"; -} - -std::ostream& operator<<(std::ostream& os, const ProblemImpl& problem) -{ - problem.str(os, FormattingOptions { 0, 4 }); - return os; -} - const std::optional& ProblemImpl::get_filepath() const { return m_filepath; } const Domain& ProblemImpl::get_domain() const { return m_domain; } diff --git a/src/pddl/requirements.cpp b/src/pddl/requirements.cpp index 1c3c82f7..650f1605 100644 --- a/src/pddl/requirements.cpp +++ b/src/pddl/requirements.cpp @@ -50,20 +50,6 @@ const std::string& to_string(RequirementEnum requirement) RequirementsImpl::RequirementsImpl(size_t index, RequirementEnumSet requirements) : Base(index), m_requirements(std::move(requirements)) {} -void RequirementsImpl::str_impl(std::ostream& out, const FormattingOptions& /*options*/) const -{ - out << "(:requirements "; - int i = 0; - for (const auto& requirement : m_requirements) - { - if (i != 0) - out << " "; - out << to_string(requirement); - ++i; - } - out << ")"; -} - bool RequirementsImpl::test(RequirementEnum requirement) const { return m_requirements.count(requirement); } const RequirementEnumSet& RequirementsImpl::get_requirements() const { return m_requirements; } diff --git a/src/pddl/term.cpp b/src/pddl/term.cpp index 9275f7c6..0c0a3e17 100644 --- a/src/pddl/term.cpp +++ b/src/pddl/term.cpp @@ -26,15 +26,11 @@ namespace loki /* TermObjectImpl */ TermObjectImpl::TermObjectImpl(size_t index, Object object) : Base(index), m_object(std::move(object)) {} -void TermObjectImpl::str_impl(std::ostream& out, const FormattingOptions& /*options*/) const { out << m_object->get_name(); } - const Object& TermObjectImpl::get_object() const { return m_object; } /* TermVariableImpl */ TermVariableImpl::TermVariableImpl(size_t index, Variable variable) : Base(index), m_variable(std::move(variable)) {} -void TermVariableImpl::str_impl(std::ostream& out, const FormattingOptions& /*options*/) const { out << m_variable->get_name(); } - const Variable& TermVariableImpl::get_variable() const { return m_variable; } } diff --git a/src/pddl/type.cpp b/src/pddl/type.cpp index dc5bc83a..d15f576c 100644 --- a/src/pddl/type.cpp +++ b/src/pddl/type.cpp @@ -21,30 +21,6 @@ namespace loki { TypeImpl::TypeImpl(size_t index, std::string name, TypeList bases) : Base(index), m_name(std::move(name)), m_bases(std::move(bases)) {} -void TypeImpl::str_impl(std::ostream& out, const FormattingOptions& /*options*/) const -{ - out << m_name; - if (!m_bases.empty()) - { - out << " - "; - if (m_bases.size() > 1) - { - out << "(either "; - for (size_t i = 0; i < m_bases.size(); ++i) - { - if (i != 0) - out << " "; - out << m_bases[i]->get_name(); - } - out << ")"; - } - else if (m_bases.size() == 1) - { - out << m_bases.front()->get_name(); - } - } -} - const std::string& TypeImpl::get_name() const { return m_name; } const TypeList& TypeImpl::get_bases() const { return m_bases; } diff --git a/src/pddl/variable.cpp b/src/pddl/variable.cpp index 4bd61a18..65699991 100644 --- a/src/pddl/variable.cpp +++ b/src/pddl/variable.cpp @@ -27,8 +27,6 @@ namespace loki { VariableImpl::VariableImpl(size_t index, std::string name) : Base(index), m_name(std::move(name)) {} -void VariableImpl::str_impl(std::ostream& out, const FormattingOptions& /*options*/) const { out << m_name; } - const std::string& VariableImpl::get_name() const { return m_name; } static void collect_free_variables_recursively(const loki::ConditionImpl& condition, VariableSet& ref_quantified_variables, VariableSet& ref_free_variables)