From 813fecbf1543981c2d9a8155c088c5abdeb18e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sat, 4 Jun 2016 16:24:10 +0200 Subject: [PATCH] Removed now unnecessary Parser function arguments. --- include/plasp/pddl/Action.h | 2 +- include/plasp/pddl/Expression.h | 8 +- include/plasp/pddl/Requirement.h | 4 +- include/plasp/pddl/expressions/And.h | 10 +-- include/plasp/pddl/expressions/Constant.h | 6 +- include/plasp/pddl/expressions/Either.h | 10 +-- include/plasp/pddl/expressions/NAry.h | 16 ++-- include/plasp/pddl/expressions/Not.h | 13 +-- include/plasp/pddl/expressions/Or.h | 9 +- include/plasp/pddl/expressions/Predicate.h | 4 +- .../pddl/expressions/PredicateDeclaration.h | 2 +- .../plasp/pddl/expressions/PrimitiveType.h | 9 +- include/plasp/pddl/expressions/Type.h | 3 +- include/plasp/pddl/expressions/Variable.h | 7 +- src/plasp/pddl/Action.cpp | 28 +++--- src/plasp/pddl/Domain.cpp | 10 +-- src/plasp/pddl/Expression.cpp | 86 +++++++++---------- src/plasp/pddl/Requirement.cpp | 6 +- src/plasp/pddl/expressions/Constant.cpp | 24 +++--- src/plasp/pddl/expressions/Predicate.cpp | 15 ++-- .../pddl/expressions/PredicateDeclaration.cpp | 16 ++-- src/plasp/pddl/expressions/PrimitiveType.cpp | 22 ++--- src/plasp/pddl/expressions/Type.cpp | 5 +- src/plasp/pddl/expressions/Variable.cpp | 40 ++++----- 24 files changed, 170 insertions(+), 185 deletions(-) diff --git a/include/plasp/pddl/Action.h b/include/plasp/pddl/Action.h index 6836227..2cb1225 100644 --- a/include/plasp/pddl/Action.h +++ b/include/plasp/pddl/Action.h @@ -21,7 +21,7 @@ namespace pddl class Action { public: - static Action &parseDeclaration(utils::Parser &parser, Context &context); + static Action &parseDeclaration(Context &context); public: const std::string &name() const; diff --git a/include/plasp/pddl/Expression.h b/include/plasp/pddl/Expression.h index 1e44afe..1b7a49e 100644 --- a/include/plasp/pddl/Expression.h +++ b/include/plasp/pddl/Expression.h @@ -75,13 +75,11 @@ class Expression //////////////////////////////////////////////////////////////////////////////////////////////////// -ExpressionPointer parsePreconditionExpression(utils::Parser &parser, Context &context, - const expressions::Variables ¶meters); -ExpressionPointer parseExpression(utils::Parser &parser, Context &context, +ExpressionPointer parsePreconditionExpression(Context &context, const expressions::Variables ¶meters); +ExpressionPointer parseExpression(Context &context, const expressions::Variables ¶meters); -ExpressionPointer parseEffectExpression(utils::Parser &parser, Context &context, - const expressions::Variables ¶meters); +ExpressionPointer parseEffectExpression(Context &context, const expressions::Variables ¶meters); //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/plasp/pddl/Requirement.h b/include/plasp/pddl/Requirement.h index 99ca03e..45106ab 100644 --- a/include/plasp/pddl/Requirement.h +++ b/include/plasp/pddl/Requirement.h @@ -3,7 +3,7 @@ #include -#include +#include namespace plasp { @@ -49,7 +49,7 @@ class Requirement ActionCosts }; - static Requirement parse(utils::Parser &parser); + static Requirement parse(Context &context); public: Requirement(Type type); diff --git a/include/plasp/pddl/expressions/And.h b/include/plasp/pddl/expressions/And.h index 8a55e18..e17298b 100644 --- a/include/plasp/pddl/expressions/And.h +++ b/include/plasp/pddl/expressions/And.h @@ -20,8 +20,8 @@ class And: public NAry { public: template - static AndPointer parse(utils::Parser &parser, Context &context, - const Variables ¶meters, ExpressionParser parseExpression); + static AndPointer parse(Context &context, const Variables ¶meters, + ExpressionParser parseExpression); public: void accept(ExpressionVisitor &expressionVisitor) const override; @@ -33,12 +33,12 @@ class And: public NAry //////////////////////////////////////////////////////////////////////////////////////////////////// template -AndPointer And::parse(utils::Parser &parser, Context &context, - const Variables ¶meters, ExpressionParser parseExpression) +AndPointer And::parse(Context &context, const Variables ¶meters, + ExpressionParser parseExpression) { auto expression = std::make_unique(And()); - expression->NAry::parse(parser, context, parameters, parseExpression); + expression->NAry::parse(context, parameters, parseExpression); if (expression->arguments().empty()) throw ConsistencyException("\"and\" expressions should not be empty"); diff --git a/include/plasp/pddl/expressions/Constant.h b/include/plasp/pddl/expressions/Constant.h index 60aa5d5..cd80e6e 100644 --- a/include/plasp/pddl/expressions/Constant.h +++ b/include/plasp/pddl/expressions/Constant.h @@ -22,10 +22,10 @@ namespace expressions class Constant: public Expression { public: - static ConstantPointer parseDeclaration(utils::Parser &parser, Context &context); - static void parseTypedDeclaration(utils::Parser &parser, Context &context); + static ConstantPointer parseDeclaration(Context &context); + static void parseTypedDeclaration(Context &context); - static Constant *parseExisting(utils::Parser &parser, Context &context); + static Constant *parseExisting(Context &context); // TODO: method for lazy creation if not existing diff --git a/include/plasp/pddl/expressions/Either.h b/include/plasp/pddl/expressions/Either.h index 7238ec7..6db4c8c 100644 --- a/include/plasp/pddl/expressions/Either.h +++ b/include/plasp/pddl/expressions/Either.h @@ -20,8 +20,8 @@ class Either: public NAry { public: template - static EitherPointer parse(utils::Parser &parser, Context &context, - const Variables ¶meters, ExpressionParser parseExpression); + static EitherPointer parse(Context &context, const Variables ¶meters, + ExpressionParser parseExpression); public: void accept(ExpressionVisitor &expressionVisitor) const override; @@ -33,12 +33,12 @@ class Either: public NAry //////////////////////////////////////////////////////////////////////////////////////////////////// template -EitherPointer Either::parse(utils::Parser &parser, Context &context, - const Variables ¶meters, ExpressionParser parseExpression) +EitherPointer Either::parse(Context &context, const Variables ¶meters, + ExpressionParser parseExpression) { auto expression = std::make_unique(Either()); - expression->NAry::parse(parser, context, parameters, parseExpression); + expression->NAry::parse(context, parameters, parseExpression); if (expression->arguments().empty()) throw ConsistencyException("\"and\" expressions should not be empty"); diff --git a/include/plasp/pddl/expressions/NAry.h b/include/plasp/pddl/expressions/NAry.h index be33193..cfb1a70 100644 --- a/include/plasp/pddl/expressions/NAry.h +++ b/include/plasp/pddl/expressions/NAry.h @@ -2,9 +2,9 @@ #define __PLASP__PDDL__EXPRESSION__N_ARY_H #include +#include #include #include -#include namespace plasp { @@ -26,8 +26,7 @@ class NAry: public Expression protected: template - void parse(utils::Parser &parser, Context &context, const Variables ¶meters, - ExpressionParser parseExpression); + void parse(Context &context, const Variables ¶meters, ExpressionParser parseExpression); private: Expressions m_arguments; @@ -36,18 +35,17 @@ class NAry: public Expression //////////////////////////////////////////////////////////////////////////////////////////////////// template -void NAry::parse(utils::Parser &parser, Context &context, - const Variables ¶meters, ExpressionParser parseExpression) +void NAry::parse(Context &context, const Variables ¶meters, ExpressionParser parseExpression) { - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); // Assume that expression identifier (and, or, etc.) is already parsed // Parse arguments of the expression - while (parser.currentCharacter() != ')') + while (context.parser.currentCharacter() != ')') { - m_arguments.emplace_back(parseExpression(parser, context, parameters)); + m_arguments.emplace_back(parseExpression(context, parameters)); - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); } } diff --git a/include/plasp/pddl/expressions/Not.h b/include/plasp/pddl/expressions/Not.h index 03f6594..e5121da 100644 --- a/include/plasp/pddl/expressions/Not.h +++ b/include/plasp/pddl/expressions/Not.h @@ -1,6 +1,7 @@ #ifndef __PLASP__PDDL__EXPRESSION__NOT_H #define __PLASP__PDDL__EXPRESSION__NOT_H +#include #include namespace plasp @@ -20,8 +21,8 @@ class Not: public Expression { public: template - static NotPointer parse(utils::Parser &parser, Context &context, - const Variables ¶meters, ExpressionParser parseExpression); + static NotPointer parse(Context &context, const Variables ¶meters, + ExpressionParser parseExpression); public: void accept(ExpressionVisitor &expressionVisitor) const override; @@ -37,15 +38,15 @@ class Not: public Expression //////////////////////////////////////////////////////////////////////////////////////////////////// template -NotPointer Not::parse(utils::Parser &parser, Context &context, - const Variables ¶meters, ExpressionParser parseExpression) +NotPointer Not::parse(Context &context, const Variables ¶meters, + ExpressionParser parseExpression) { auto expression = std::make_unique(Not()); - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); // Parse argument - expression->m_argument = parseExpression(parser, context, parameters); + expression->m_argument = parseExpression(context, parameters); return expression; } diff --git a/include/plasp/pddl/expressions/Or.h b/include/plasp/pddl/expressions/Or.h index 82cdf79..1d69bd1 100644 --- a/include/plasp/pddl/expressions/Or.h +++ b/include/plasp/pddl/expressions/Or.h @@ -20,8 +20,8 @@ class Or: public NAry { public: template - static OrPointer parse(utils::Parser &parser, Context &context, - const Variables ¶meters, ExpressionParser parseExpression); + static OrPointer parse(Context &context, const Variables ¶meters, + ExpressionParser parseExpression); public: void accept(ExpressionVisitor &expressionVisitor) const override; @@ -33,12 +33,11 @@ class Or: public NAry //////////////////////////////////////////////////////////////////////////////////////////////////// template -OrPointer Or::parse(utils::Parser &parser, Context &context, - const Variables ¶meters, ExpressionParser parseExpression) +OrPointer Or::parse(Context &context, const Variables ¶meters, ExpressionParser parseExpression) { auto expression = std::make_unique(Or()); - expression->NAry::parse(parser, context, parameters, parseExpression); + expression->NAry::parse(context, parameters, parseExpression); if (expression->arguments().empty()) throw ConsistencyException("\"or\" expressions should not be empty"); diff --git a/include/plasp/pddl/expressions/Predicate.h b/include/plasp/pddl/expressions/Predicate.h index 02436bb..5089ff3 100644 --- a/include/plasp/pddl/expressions/Predicate.h +++ b/include/plasp/pddl/expressions/Predicate.h @@ -19,8 +19,8 @@ namespace expressions class Predicate: public Expression { public: - static PredicatePointer parse(std::string name, utils::Parser &parser, - Context &context, const Variables ¶meters); + static PredicatePointer parse(std::string name, Context &context, + const Variables ¶meters); public: void accept(ExpressionVisitor &expressionVisitor) const override; diff --git a/include/plasp/pddl/expressions/PredicateDeclaration.h b/include/plasp/pddl/expressions/PredicateDeclaration.h index cf664f0..4ca023a 100644 --- a/include/plasp/pddl/expressions/PredicateDeclaration.h +++ b/include/plasp/pddl/expressions/PredicateDeclaration.h @@ -19,7 +19,7 @@ namespace expressions class PredicateDeclaration: public Expression { public: - static void parse(utils::Parser &parser, Context &context); + static void parse(Context &context); public: void accept(ExpressionVisitor &expressionVisitor) const override; diff --git a/include/plasp/pddl/expressions/PrimitiveType.h b/include/plasp/pddl/expressions/PrimitiveType.h index 1c1fdd7..87d54f9 100644 --- a/include/plasp/pddl/expressions/PrimitiveType.h +++ b/include/plasp/pddl/expressions/PrimitiveType.h @@ -4,7 +4,6 @@ #include #include #include -#include #include namespace plasp @@ -23,12 +22,10 @@ namespace expressions class PrimitiveType: public Expression { public: - static PrimitiveType *parseDeclaration(utils::Parser &parser, Context &context); - static void parseTypedDeclaration(utils::Parser &parser, Context &context); + static PrimitiveType *parseDeclaration(Context &context); + static void parseTypedDeclaration(Context &context); - static PrimitiveType *parseExisting(utils::Parser &parser, Context &context); - - // TODO: method for lazy creation if not existing + static PrimitiveType *parseExisting(Context &context); public: void accept(ExpressionVisitor &expressionVisitor) const override; diff --git a/include/plasp/pddl/expressions/Type.h b/include/plasp/pddl/expressions/Type.h index 4029760..fbd57f1 100644 --- a/include/plasp/pddl/expressions/Type.h +++ b/include/plasp/pddl/expressions/Type.h @@ -20,8 +20,7 @@ namespace expressions // //////////////////////////////////////////////////////////////////////////////////////////////////// -ExpressionPointer parseExistingPrimitiveType(utils::Parser &parser, Context &context, - const Variables ¶meters); +ExpressionPointer parseExistingPrimitiveType(Context &context, const Variables ¶meters); //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/plasp/pddl/expressions/Variable.h b/include/plasp/pddl/expressions/Variable.h index 931f86c..0f3900e 100644 --- a/include/plasp/pddl/expressions/Variable.h +++ b/include/plasp/pddl/expressions/Variable.h @@ -19,12 +19,11 @@ namespace expressions class Variable: public Expression { public: - static VariablePointer parseDeclaration(utils::Parser &parser); + static VariablePointer parseDeclaration(Context &context); - static void parseTypedDeclaration(utils::Parser &parser, Context &context, - Variables ¶meters); + static void parseTypedDeclaration(Context &context, Variables ¶meters); - static const Variable *parseExisting(utils::Parser &parser, const Variables &variables); + static const Variable *parseExisting(Context &context, const Variables &variables); public: void accept(ExpressionVisitor &expressionVisitor) const override; diff --git a/src/plasp/pddl/Action.cpp b/src/plasp/pddl/Action.cpp index d353234..f534606 100644 --- a/src/plasp/pddl/Action.cpp +++ b/src/plasp/pddl/Action.cpp @@ -25,39 +25,39 @@ Action::Action(std::string name) //////////////////////////////////////////////////////////////////////////////////////////////////// -Action &Action::parseDeclaration(utils::Parser &parser, Context &context) +Action &Action::parseDeclaration(Context &context) { - const auto actionName = parser.parseIdentifier(isIdentifier); + const auto actionName = context.parser.parseIdentifier(isIdentifier); auto action = std::make_unique(Action(actionName)); - parser.expect(":parameters"); + context.parser.expect(":parameters"); - parser.expect("("); + context.parser.expect("("); // Read parameters - while (parser.currentCharacter() != ')') + while (context.parser.currentCharacter() != ')') { - expressions::Variable::parseTypedDeclaration(parser, context, action->m_parameters); + expressions::Variable::parseTypedDeclaration(context, action->m_parameters); - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); } - parser.expect(")"); + context.parser.expect(")"); // Parse preconditions and effects - while (parser.currentCharacter() != ')') + while (context.parser.currentCharacter() != ')') { - parser.expect(":"); + context.parser.expect(":"); - const auto sectionIdentifier = parser.parseIdentifier(isIdentifier); + const auto sectionIdentifier = context.parser.parseIdentifier(isIdentifier); if (sectionIdentifier == "precondition") - action->m_precondition = parsePreconditionExpression(parser, context, action->m_parameters); + action->m_precondition = parsePreconditionExpression(context, action->m_parameters); else if (sectionIdentifier == "effect") - action->m_effect = parseEffectExpression(parser, context, action->m_parameters); + action->m_effect = parseEffectExpression(context, action->m_parameters); - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); } // Store new action diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index 73f2a31..fda1ad3 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -162,7 +162,7 @@ void Domain::parseRequirementSection() if (m_context.parser.currentCharacter() == ':') m_context.parser.advance(); - m_requirements.emplace_back(Requirement::parse(m_context.parser)); + m_requirements.emplace_back(Requirement::parse(m_context)); m_context.parser.skipWhiteSpace(); } @@ -242,7 +242,7 @@ void Domain::parseTypeSection() if (m_context.parser.currentCharacter() == '(') throw utils::ParserException(m_context.parser, "Only primitive types are allowed in type section"); - expressions::PrimitiveType::parseTypedDeclaration(m_context.parser, m_context); + expressions::PrimitiveType::parseTypedDeclaration(m_context); m_context.parser.skipWhiteSpace(); } @@ -259,7 +259,7 @@ void Domain::parseConstantSection() // Store constants while (m_context.parser.currentCharacter() != ')') { - expressions::Constant::parseTypedDeclaration(m_context.parser, m_context); + expressions::Constant::parseTypedDeclaration(m_context); m_context.parser.skipWhiteSpace(); } @@ -276,7 +276,7 @@ void Domain::parsePredicateSection() // Store predicates and their arguments while (m_context.parser.currentCharacter() != ')') { - expressions::PredicateDeclaration::parse(m_context.parser, m_context); + expressions::PredicateDeclaration::parse(m_context); m_context.parser.skipWhiteSpace(); } @@ -290,7 +290,7 @@ void Domain::parseActionSection() { m_context.parser.skipWhiteSpace(); - Action::parseDeclaration(m_context.parser, m_context); + Action::parseDeclaration(m_context); m_context.parser.expect(")"); } diff --git a/src/plasp/pddl/Expression.cpp b/src/plasp/pddl/Expression.cpp index 39df92a..1a8e90c 100644 --- a/src/plasp/pddl/Expression.cpp +++ b/src/plasp/pddl/Expression.cpp @@ -22,11 +22,10 @@ namespace pddl //////////////////////////////////////////////////////////////////////////////////////////////////// ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier, - utils::Parser &parser, Context &context, const expressions::Variables ¶meters); + Context &context, const expressions::Variables ¶meters); ExpressionPointer parseEffectBodyExpressionContent(const std::string &expressionIdentifier, - utils::Parser &parser, Context &context, const expressions::Variables ¶meters); -ExpressionPointer parsePredicate(utils::Parser &parser, Context &context, - const expressions::Variables ¶meters); + Context &context, const expressions::Variables ¶meters); +ExpressionPointer parsePredicate(Context &context, const expressions::Variables ¶meters); //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -37,45 +36,44 @@ void throwUnsupported(const utils::Parser &parser, const std::string &expression //////////////////////////////////////////////////////////////////////////////////////////////////// -ExpressionPointer parsePreconditionExpression(utils::Parser &parser, Context &context, +ExpressionPointer parsePreconditionExpression(Context &context, const expressions::Variables ¶meters) { - parser.expect("("); + context.parser.expect("("); - const auto expressionIdentifier = parser.parseIdentifier(isIdentifier); + const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier); ExpressionPointer expression; if (expressionIdentifier == "and") { - expression = expressions::And::parse(parser, context, parameters, + expression = expressions::And::parse(context, parameters, parsePreconditionExpression); } else if (expressionIdentifier == "forall" || expressionIdentifier == "preference") { - throwUnsupported(parser, expressionIdentifier); + throwUnsupported(context.parser, expressionIdentifier); } else - expression = parseExpressionContent(expressionIdentifier, parser, context, parameters); + expression = parseExpressionContent(expressionIdentifier, context, parameters); - parser.expect(")"); + context.parser.expect(")"); return expression; } //////////////////////////////////////////////////////////////////////////////////////////////////// -ExpressionPointer parseExpression(utils::Parser &parser, Context &context, - const expressions::Variables ¶meters) +ExpressionPointer parseExpression(Context &context, const expressions::Variables ¶meters) { - parser.expect("("); + context.parser.expect("("); - const auto expressionIdentifier = parser.parseIdentifier(isIdentifier); + const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier); - auto expression = parseExpressionContent(expressionIdentifier, parser, context, parameters); + auto expression = parseExpressionContent(expressionIdentifier, context, parameters); - parser.expect(")"); + context.parser.expect(")"); return expression; } @@ -83,18 +81,18 @@ ExpressionPointer parseExpression(utils::Parser &parser, Context &context, //////////////////////////////////////////////////////////////////////////////////////////////////// ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier, - utils::Parser &parser, Context &context, const expressions::Variables ¶meters) + Context &context, const expressions::Variables ¶meters) { - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); ExpressionPointer expression; if (expressionIdentifier == "and") - expression = expressions::And::parse(parser, context, parameters, parseExpression); + expression = expressions::And::parse(context, parameters, parseExpression); else if (expressionIdentifier == "or") - expression = expressions::Or::parse(parser, context, parameters, parseExpression); + expression = expressions::Or::parse(context, parameters, parseExpression); else if (expressionIdentifier == "not") - expression = expressions::Not::parse(parser, context, parameters, parseExpression); + expression = expressions::Not::parse(context, parameters, parseExpression); else if (expressionIdentifier == "imply" || expressionIdentifier == "exists" || expressionIdentifier == "forall" @@ -110,7 +108,7 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier || expressionIdentifier == ">=" || expressionIdentifier == "<=") { - throwUnsupported(parser, expressionIdentifier); + throwUnsupported(context.parser, expressionIdentifier); } else { @@ -123,9 +121,9 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier // If predicate exists, parse it if (match != context.predicateDeclarations.cend()) - expression = expressions::Predicate::parse(expressionIdentifier, parser, context, parameters); + expression = expressions::Predicate::parse(expressionIdentifier, context, parameters); else - throw utils::ParserException(parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context"); + throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context"); } return expression; @@ -133,26 +131,25 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier //////////////////////////////////////////////////////////////////////////////////////////////////// -ExpressionPointer parseEffectExpression(utils::Parser &parser, Context &context, - const expressions::Variables ¶meters) +ExpressionPointer parseEffectExpression(Context &context, const expressions::Variables ¶meters) { - parser.expect("("); + context.parser.expect("("); - const auto expressionIdentifier = parser.parseIdentifier(isIdentifier); + const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier); ExpressionPointer expression; if (expressionIdentifier == "and") - expression = expressions::And::parse(parser, context, parameters, parseEffectExpression); + expression = expressions::And::parse(context, parameters, parseEffectExpression); else if (expressionIdentifier == "forall" || expressionIdentifier == "when") { - throwUnsupported(parser, expressionIdentifier); + throwUnsupported(context.parser, expressionIdentifier); } else - expression = parseEffectBodyExpressionContent(expressionIdentifier, parser, context, parameters); + expression = parseEffectBodyExpressionContent(expressionIdentifier, context, parameters); - parser.expect(")"); + context.parser.expect(")"); return expression; } @@ -160,12 +157,12 @@ ExpressionPointer parseEffectExpression(utils::Parser &parser, Context &context, //////////////////////////////////////////////////////////////////////////////////////////////////// ExpressionPointer parseEffectBodyExpressionContent(const std::string &expressionIdentifier, - utils::Parser &parser, Context &context, const expressions::Variables ¶meters) + Context &context, const expressions::Variables ¶meters) { ExpressionPointer expression; if (expressionIdentifier == "not") - expression = expressions::Not::parse(parser, context, parameters, parsePredicate); + expression = expressions::Not::parse(context, parameters, parsePredicate); else if (expressionIdentifier == "=" || expressionIdentifier == "assign" || expressionIdentifier == "scale-up" @@ -173,7 +170,7 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression || expressionIdentifier == "increase" || expressionIdentifier == "decrease") { - throwUnsupported(parser, expressionIdentifier); + throwUnsupported(context.parser, expressionIdentifier); } else { @@ -186,9 +183,9 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression // If predicate exists, parse it if (match != context.predicateDeclarations.cend()) - expression = expressions::Predicate::parse(expressionIdentifier, parser, context, parameters); + expression = expressions::Predicate::parse(expressionIdentifier, context, parameters); else - throw utils::ParserException(parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context"); + throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context"); } return expression; @@ -196,12 +193,11 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression //////////////////////////////////////////////////////////////////////////////////////////////////// -ExpressionPointer parsePredicate(utils::Parser &parser, Context &context, - const expressions::Variables ¶meters) +ExpressionPointer parsePredicate(Context &context, const expressions::Variables ¶meters) { - parser.expect("("); + context.parser.expect("("); - const auto predicateName = parser.parseIdentifier(isIdentifier); + const auto predicateName = context.parser.parseIdentifier(isIdentifier); ExpressionPointer expression; @@ -214,11 +210,11 @@ ExpressionPointer parsePredicate(utils::Parser &parser, Context &context, // If predicate exists, parse it if (match == context.predicateDeclarations.cend()) - throw utils::ParserException(parser, "Unknown predicate \"" + predicateName + "\""); + throw utils::ParserException(context.parser, "Unknown predicate \"" + predicateName + "\""); - expression = expressions::Predicate::parse(predicateName, parser, context, parameters); + expression = expressions::Predicate::parse(predicateName, context, parameters); - parser.expect(")"); + context.parser.expect(")"); return expression; } diff --git a/src/plasp/pddl/Requirement.cpp b/src/plasp/pddl/Requirement.cpp index 686a2f3..e4f0ed0 100644 --- a/src/plasp/pddl/Requirement.cpp +++ b/src/plasp/pddl/Requirement.cpp @@ -79,14 +79,14 @@ Requirement::Requirement(Requirement::Type type) //////////////////////////////////////////////////////////////////////////////////////////////////// -Requirement Requirement::parse(utils::Parser &parser) +Requirement Requirement::parse(Context &context) { - const auto requirementName = parser.parseIdentifier(isIdentifier); + const auto requirementName = context.parser.parseIdentifier(isIdentifier); const auto match = requirementTypesToPDDL.right.find(requirementName); if (match == requirementTypesToPDDL.right.end()) - throw utils::ParserException(parser, "Unknown PDDL requirement \"" + requirementName + "\""); + throw utils::ParserException(context.parser, "Unknown PDDL requirement \"" + requirementName + "\""); return Requirement(match->second); } diff --git a/src/plasp/pddl/expressions/Constant.cpp b/src/plasp/pddl/expressions/Constant.cpp index 69506a8..0384eab 100644 --- a/src/plasp/pddl/expressions/Constant.cpp +++ b/src/plasp/pddl/expressions/Constant.cpp @@ -28,13 +28,13 @@ Constant::Constant() //////////////////////////////////////////////////////////////////////////////////////////////////// -ConstantPointer Constant::parseDeclaration(utils::Parser &parser, Context &context) +ConstantPointer Constant::parseDeclaration(Context &context) { - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); auto constant = std::make_unique(Constant()); - constant->m_name = parser.parseIdentifier(isIdentifier); + constant->m_name = context.parser.parseIdentifier(isIdentifier); BOOST_ASSERT(constant->m_name != "-"); @@ -48,24 +48,24 @@ ConstantPointer Constant::parseDeclaration(utils::Parser &parser, Context &conte //////////////////////////////////////////////////////////////////////////////////////////////////// -void Constant::parseTypedDeclaration(utils::Parser &parser, Context &context) +void Constant::parseTypedDeclaration(Context &context) { // Parse and store constant - context.constants.emplace_back(parseDeclaration(parser, context)); + context.constants.emplace_back(parseDeclaration(context)); const auto &constant = context.constants.back(); // Flag constant as correctly declared in the types section constant->setDeclared(); - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); // Check for typing information - if (!parser.advanceIf('-')) + if (!context.parser.advanceIf('-')) return; // If existing, parse and store parent type - auto *type = PrimitiveType::parseExisting(parser, context); + auto *type = PrimitiveType::parseExisting(context); // Assign parent type to all types that were previously flagged std::for_each(context.constants.begin(), context.constants.end(), @@ -81,11 +81,11 @@ void Constant::parseTypedDeclaration(utils::Parser &parser, Context &context) //////////////////////////////////////////////////////////////////////////////////////////////////// -Constant *Constant::parseExisting(utils::Parser &parser, Context &context) +Constant *Constant::parseExisting(Context &context) { - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); - const auto constantName = parser.parseIdentifier(isIdentifier); + const auto constantName = context.parser.parseIdentifier(isIdentifier); // TODO: use hash map const auto match = std::find_if(context.constants.cbegin(), context.constants.cend(), [&](const auto &constant) @@ -95,7 +95,7 @@ Constant *Constant::parseExisting(utils::Parser &parser, Context &context) const auto constantExists = (match != context.constants.cend()); if (!constantExists) - throw utils::ParserException(parser, "Constant \"" + constantName + "\" used but never declared"); + throw utils::ParserException(context.parser, "Constant \"" + constantName + "\" used but never declared"); return match->get(); } diff --git a/src/plasp/pddl/expressions/Predicate.cpp b/src/plasp/pddl/expressions/Predicate.cpp index 6103007..15c8526 100644 --- a/src/plasp/pddl/expressions/Predicate.cpp +++ b/src/plasp/pddl/expressions/Predicate.cpp @@ -27,34 +27,33 @@ Predicate::Predicate() //////////////////////////////////////////////////////////////////////////////////////////////////// -PredicatePointer Predicate::parse(std::string name, utils::Parser &parser, - Context &context, const Variables ¶meters) +PredicatePointer Predicate::parse(std::string name, Context &context, const Variables ¶meters) { auto predicate = std::make_unique(Predicate()); predicate->m_name = name; - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); // Parse arguments - while (parser.currentCharacter() != ')') + while (context.parser.currentCharacter() != ')') { // Parse variables - if (parser.currentCharacter() == '?') + if (context.parser.currentCharacter() == '?') { - const auto *variable = Variable::parseExisting(parser, parameters); + const auto *variable = Variable::parseExisting(context, parameters); auto variableReference = std::make_unique>(variable); predicate->m_arguments.emplace_back(std::move(variableReference)); } // Parse constants else { - const auto *constant = Constant::parseExisting(parser, context); + const auto *constant = Constant::parseExisting(context); auto constantReference = std::make_unique>(constant); predicate->m_arguments.emplace_back(std::move(constantReference)); } - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); } // TODO: check that signature matches one of the declared ones diff --git a/src/plasp/pddl/expressions/PredicateDeclaration.cpp b/src/plasp/pddl/expressions/PredicateDeclaration.cpp index 2beae85..a7ed7cd 100644 --- a/src/plasp/pddl/expressions/PredicateDeclaration.cpp +++ b/src/plasp/pddl/expressions/PredicateDeclaration.cpp @@ -27,28 +27,28 @@ PredicateDeclaration::PredicateDeclaration() //////////////////////////////////////////////////////////////////////////////////////////////////// -void PredicateDeclaration::parse(utils::Parser &parser, Context &context) +void PredicateDeclaration::parse(Context &context) { - parser.expect("("); + context.parser.expect("("); auto predicate = std::make_unique(PredicateDeclaration()); - predicate->m_name = parser.parseIdentifier(isIdentifier); + predicate->m_name = context.parser.parseIdentifier(isIdentifier); // Flag predicate as correctly declared in the types section predicate->setDeclared(); - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); // Parse arguments - while (parser.currentCharacter() != ')') + while (context.parser.currentCharacter() != ')') { - expressions::Variable::parseTypedDeclaration(parser, context, predicate->m_arguments); + expressions::Variable::parseTypedDeclaration(context, predicate->m_arguments); - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); } - parser.expect(")"); + context.parser.expect(")"); // Store new predicate context.predicateDeclarations.emplace_back(std::move(predicate)); diff --git a/src/plasp/pddl/expressions/PrimitiveType.cpp b/src/plasp/pddl/expressions/PrimitiveType.cpp index ad5f82f..de09e1b 100644 --- a/src/plasp/pddl/expressions/PrimitiveType.cpp +++ b/src/plasp/pddl/expressions/PrimitiveType.cpp @@ -46,11 +46,11 @@ PrimitiveType *PrimitiveType::create(std::string name, Context &context) //////////////////////////////////////////////////////////////////////////////////////////////////// -PrimitiveType *PrimitiveType::parseDeclaration(utils::Parser &parser, Context &context) +PrimitiveType *PrimitiveType::parseDeclaration(Context &context) { - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); - const auto typeName = parser.parseIdentifier(isIdentifier); + const auto typeName = context.parser.parseIdentifier(isIdentifier); // TODO: use hash map const auto match = std::find_if(context.primitiveTypes.cbegin(), context.primitiveTypes.cend(), @@ -74,22 +74,22 @@ PrimitiveType *PrimitiveType::parseDeclaration(utils::Parser &parser, Context &c //////////////////////////////////////////////////////////////////////////////////////////////////// -void PrimitiveType::parseTypedDeclaration(utils::Parser &parser, Context &context) +void PrimitiveType::parseTypedDeclaration(Context &context) { // Parse and store type - auto *type = parseDeclaration(parser, context); + auto *type = parseDeclaration(context); // Flag type as correctly declared in the types section type->setDeclared(); - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); // Check for type inheritance - if (!parser.advanceIf('-')) + if (!context.parser.advanceIf('-')) return; // If existing, parse and store parent type - auto *parentType = parseExisting(parser, context); + auto *parentType = parseExisting(context); parentType->setDirty(false); @@ -110,11 +110,11 @@ void PrimitiveType::parseTypedDeclaration(utils::Parser &parser, Context &contex //////////////////////////////////////////////////////////////////////////////////////////////////// -PrimitiveType *PrimitiveType::parseExisting(utils::Parser &parser, Context &context) +PrimitiveType *PrimitiveType::parseExisting(Context &context) { - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); - const auto typeName = parser.parseIdentifier(isIdentifier); + const auto typeName = context.parser.parseIdentifier(isIdentifier); BOOST_ASSERT(!typeName.empty()); diff --git a/src/plasp/pddl/expressions/Type.cpp b/src/plasp/pddl/expressions/Type.cpp index 6f7e3ee..a8c16b9 100644 --- a/src/plasp/pddl/expressions/Type.cpp +++ b/src/plasp/pddl/expressions/Type.cpp @@ -16,10 +16,9 @@ namespace expressions // //////////////////////////////////////////////////////////////////////////////////////////////////// -ExpressionPointer parseExistingPrimitiveType(utils::Parser &parser, Context &context, - const Variables ¶meters) +ExpressionPointer parseExistingPrimitiveType(Context &context, const Variables ¶meters) { - auto primitiveType = PrimitiveType::parseExisting(parser, context); + auto primitiveType = PrimitiveType::parseExisting(context); return std::make_unique>(primitiveType); } diff --git a/src/plasp/pddl/expressions/Variable.cpp b/src/plasp/pddl/expressions/Variable.cpp index 81add30..b758744 100644 --- a/src/plasp/pddl/expressions/Variable.cpp +++ b/src/plasp/pddl/expressions/Variable.cpp @@ -29,15 +29,15 @@ Variable::Variable() //////////////////////////////////////////////////////////////////////////////////////////////////// -VariablePointer Variable::parseDeclaration(utils::Parser &parser) +VariablePointer Variable::parseDeclaration(Context &context) { - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); - parser.expect("?"); + context.parser.expect("?"); auto variable = std::make_unique(Variable()); - variable->m_name = parser.parseIdentifier(isIdentifier); + variable->m_name = context.parser.parseIdentifier(isIdentifier); // Flag variable for potentially upcoming type declaration variable->setDirty(); @@ -47,17 +47,17 @@ VariablePointer Variable::parseDeclaration(utils::Parser &parser) //////////////////////////////////////////////////////////////////////////////////////////////////// -void Variable::parseTypedDeclaration(utils::Parser &parser, Context &context, Variables ¶meters) +void Variable::parseTypedDeclaration(Context &context, Variables ¶meters) { // Parse and store variable itself - parameters.emplace_back(parseDeclaration(parser)); + parameters.emplace_back(parseDeclaration(context)); auto ¶meter = parameters.back(); - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); // Check if the variable has a type declaration - if (!parser.advanceIf('-')) + if (!context.parser.advanceIf('-')) return; // TODO: do not allow nested either expressions @@ -77,37 +77,37 @@ void Variable::parseTypedDeclaration(utils::Parser &parser, Context &context, Va }); }; - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); // Parse argument of "either" type (always begins with opening parenthesis) - if (parser.currentCharacter() == '(') + if (context.parser.currentCharacter() == '(') { - parser.expect("("); - parser.expect("either"); + context.parser.expect("("); + context.parser.expect("either"); - parameter->m_eitherExpression = Either::parse(parser, context, parameters, parseExistingPrimitiveType); + parameter->m_eitherExpression = Either::parse(context, parameters, parseExistingPrimitiveType); - parser.expect(")"); + context.parser.expect(")"); setType(parameter->m_eitherExpression.get()); return; } // Parse primitive type - const auto *type = PrimitiveType::parseExisting(parser, context); + const auto *type = PrimitiveType::parseExisting(context); setType(type); } //////////////////////////////////////////////////////////////////////////////////////////////////// -const Variable *Variable::parseExisting(utils::Parser &parser, const Variables &variables) +const Variable *Variable::parseExisting(Context &context, const Variables &variables) { - parser.skipWhiteSpace(); + context.parser.skipWhiteSpace(); - parser.expect("?"); + context.parser.expect("?"); - const auto variableName = parser.parseIdentifier(isIdentifier); + const auto variableName = context.parser.parseIdentifier(isIdentifier); const auto match = std::find_if(variables.cbegin(), variables.cend(), [&](const auto &variable) @@ -116,7 +116,7 @@ const Variable *Variable::parseExisting(utils::Parser &parser, const Variables & }); if (match == variables.cend()) - throw utils::ParserException(parser, "Variable \"" + variableName + "\" used but never declared"); + throw utils::ParserException(context.parser, "Variable \"" + variableName + "\" used but never declared"); return match->get(); }