From 993d14d409a8e6c704fe5d3de7c1ecfdf51e2c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 8 Jun 2016 01:51:45 +0200 Subject: [PATCH] Implemented type requirement checking for problem objects. --- include/plasp/pddl/expressions/Constant.h | 1 + src/plasp/pddl/Problem.cpp | 7 +------ src/plasp/pddl/expressions/Constant.cpp | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/plasp/pddl/expressions/Constant.h b/include/plasp/pddl/expressions/Constant.h index 9864af0..4051a03 100644 --- a/include/plasp/pddl/expressions/Constant.h +++ b/include/plasp/pddl/expressions/Constant.h @@ -25,6 +25,7 @@ class Constant: public Expression static void parseTypedDeclaration(Context &context, Domain &domain); static void parseTypedDeclarations(Context &context, Domain &domain); static void parseTypedDeclaration(Context &context, Problem &problem); + static void parseTypedDeclarations(Context &context, Problem &problem); static Constant *parseAndFind(Context &context, const ExpressionContext &expressionContext); diff --git a/src/plasp/pddl/Problem.cpp b/src/plasp/pddl/Problem.cpp index 476b744..c0b0d65 100644 --- a/src/plasp/pddl/Problem.cpp +++ b/src/plasp/pddl/Problem.cpp @@ -235,12 +235,7 @@ void Problem::parseObjectSection() m_context.parser.skipWhiteSpace(); // Store constants - while (m_context.parser.currentCharacter() != ')') - { - expressions::Constant::parseTypedDeclaration(m_context, *this); - - m_context.parser.skipWhiteSpace(); - } + expressions::Constant::parseTypedDeclarations(m_context, *this); m_context.parser.expect(")"); } diff --git a/src/plasp/pddl/expressions/Constant.cpp b/src/plasp/pddl/expressions/Constant.cpp index 12a88e1..055b6a5 100644 --- a/src/plasp/pddl/expressions/Constant.cpp +++ b/src/plasp/pddl/expressions/Constant.cpp @@ -113,6 +113,28 @@ void Constant::parseTypedDeclarations(Context &context, Domain &domain) //////////////////////////////////////////////////////////////////////////////////////////////////// +void Constant::parseTypedDeclarations(Context &context, Problem &problem) +{ + while (context.parser.currentCharacter() != ')') + parseTypedDeclaration(context, problem); + + if (problem.objects().empty()) + return; + + // Check correct use of typing requirement + const auto typingUsed = (problem.objects().back()->type() != nullptr); + const auto typingDeclared = problem.domain().hasRequirement(Requirement::Type::Typing) + || problem.hasRequirement(Requirement::Type::Typing); + + if (!typingUsed && typingDeclared) + throw utils::ParserException(context.parser, "Constant has undeclared type"); + + if (typingUsed && !typingDeclared) + throw utils::ParserException(context.parser, "Typing used but not declared as a requirement"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + Constant *Constant::parseAndFind(Context &context, const ExpressionContext &expressionContext) { context.parser.skipWhiteSpace();