From 75fbb5fb4897a0d69bcfe64eb7ea5d0cff8015a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 8 Jun 2016 00:48:33 +0200 Subject: [PATCH] Checking type requirement. --- src/plasp/pddl/Domain.cpp | 35 +++++++++++--------- src/plasp/pddl/expressions/PrimitiveType.cpp | 3 ++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index d52b905..fb45689 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -137,32 +137,36 @@ const std::vector> &Domain::actions() const void Domain::parseSection() { - m_context.parser.expect("("); - m_context.parser.expect(":"); + auto &parser = m_context.parser; - const auto sectionIdentifier = m_context.parser.parseIdentifier(isIdentifier); + parser.expect("("); + parser.expect(":"); // TODO: check order of the sections - if (sectionIdentifier == "requirements") + if (parser.probe("requirements")) parseRequirementSection(); - else if (sectionIdentifier == "types") + else if (parser.probe("types")) parseTypeSection(); - else if (sectionIdentifier == "constants") + else if (parser.probe("constants")) parseConstantSection(); - else if (sectionIdentifier == "predicates") + else if (parser.probe("predicates")) parsePredicateSection(); - else if (sectionIdentifier == "action") + else if (parser.probe("action")) parseActionSection(); - else if (sectionIdentifier == "functions" - || sectionIdentifier == "constraints" - || sectionIdentifier == "durative-action" - || sectionIdentifier == "derived") + else if (parser.probe("functions") + || parser.probe("constraints") + || parser.probe("durative-action") + || parser.probe("derived")) { + const auto sectionIdentifier = parser.parseIdentifier(isIdentifier); std::cout << "Skipping section " << sectionIdentifier << std::endl; skipSection(m_context.parser); } else + { + const auto sectionIdentifier = parser.parseIdentifier(isIdentifier); throw utils::ParserException(m_context.parser, "Unknown domain section \"" + sectionIdentifier + "\""); + } } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -245,10 +249,13 @@ void Domain::computeDerivedRequirements() void Domain::parseTypeSection() { + if (!hasRequirement(Requirement::Type::Typing)) + throw utils::ParserException(m_context.parser, "Typing used but not declared as a requirement"); + m_context.parser.skipWhiteSpace(); // Store types and their parent types - while (m_context.parser.currentCharacter() != ')') + while (!m_context.parser.probe(')')) { if (m_context.parser.currentCharacter() == '(') throw utils::ParserException(m_context.parser, "Only primitive types are allowed in type section"); @@ -257,8 +264,6 @@ void Domain::parseTypeSection() m_context.parser.skipWhiteSpace(); } - - m_context.parser.expect(")"); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plasp/pddl/expressions/PrimitiveType.cpp b/src/plasp/pddl/expressions/PrimitiveType.cpp index a73b7e0..8834b56 100644 --- a/src/plasp/pddl/expressions/PrimitiveType.cpp +++ b/src/plasp/pddl/expressions/PrimitiveType.cpp @@ -85,6 +85,9 @@ void PrimitiveType::parseTypedDeclaration(Context &context, Domain &domain) if (!context.parser.probe('-')) return; + if (!domain.hasRequirement(Requirement::Type::Typing)) + throw utils::ParserException(context.parser, "Typing used but not declared as a requirement"); + // If existing, parse and store parent type auto *parentType = parseAndFindOrCreate(context, domain);