Fixed issue in parsing typed objects in multiple iterations and added test case.

This commit is contained in:
Patrick Lühne 2017-06-18 04:15:05 +02:00
parent 04ded5e8b8
commit e364d01cf4
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
4 changed files with 23 additions and 5 deletions

View File

@ -34,7 +34,7 @@ void parseAndAddConstantDeclarations(Context &context, ast::Domain &domain, ast:
tokenizer.skipWhiteSpace();
// Index on the first element of the current inheritance list
size_t inheritanceIndex = 0;
size_t inheritanceIndex = constantDeclarations.size();
while (tokenizer.currentCharacter() != ')')
{

View File

@ -45,6 +45,7 @@ void parseAndAddPrimitiveTypeDeclarations(Context &context, ast::Domain &domain)
tokenizer.skipWhiteSpace();
const auto position = tokenizer.position();
const auto typeStartIndex = domain.types.size();
// First pass: collect all primitive types
while (tokenizer.currentCharacter() != ')')
@ -64,8 +65,9 @@ void parseAndAddPrimitiveTypeDeclarations(Context &context, ast::Domain &domain)
// Second pass: link parent types correctly
// Index on the first element of the current inheritance list
size_t inheritanceIndex = 0;
size_t i = 0;
// TODO: test correct implementation of offset if this function is called multiple times
size_t inheritanceIndex = typeStartIndex;
size_t i = typeStartIndex;
while (tokenizer.currentCharacter() != ')')
{

View File

@ -35,7 +35,7 @@ void parseAndAddVariableDeclarations(Context &context, ast::Domain &domain, ast:
tokenizer.skipWhiteSpace();
// Index on the first element of the current inheritance list
size_t inheritanceIndex = 0;
size_t inheritanceIndex = variableDeclarations.size();
while (tokenizer.currentCharacter() != ')')
{

View File

@ -279,7 +279,7 @@ TEST_CASE("[PDDL parser] The official PDDL instances are parsed correctly", "[PD
REQUIRE(types[9]->parentTypes.empty());
}
SECTION("typed objects in mystery domain")
SECTION("typing in mystery domain")
{
context.mode = pddl::Mode::Compatibility;
@ -289,6 +289,22 @@ TEST_CASE("[PDDL parser] The official PDDL instances are parsed correctly", "[PD
context.tokenizer.read(instanceFile);
auto description = pddl::parseDescription(context);
const auto &actions = description.domain->actions;
REQUIRE(actions.size() == 3);
// TODO: adjust if there are changes to handling :vars section
REQUIRE(actions[0]->parameters.size() == 5);
CHECK(actions[0]->parameters[0]->name == "c");
CHECK(actions[0]->parameters[0]->type.value().get<pddl::ast::PrimitiveTypePointer>()->declaration->name == "pain");
CHECK(actions[0]->parameters[1]->name == "v");
CHECK(actions[0]->parameters[1]->type.value().get<pddl::ast::PrimitiveTypePointer>()->declaration->name == "pleasure");
CHECK(actions[0]->parameters[2]->name == "n");
CHECK(actions[0]->parameters[2]->type.value().get<pddl::ast::PrimitiveTypePointer>()->declaration->name == "food");
CHECK(actions[0]->parameters[3]->name == "s1");
CHECK(actions[0]->parameters[3]->type.value().get<pddl::ast::PrimitiveTypePointer>()->declaration->name == "planet");
CHECK(actions[0]->parameters[4]->name == "s2");
CHECK(actions[0]->parameters[4]->type.value().get<pddl::ast::PrimitiveTypePointer>()->declaration->name == "planet");
REQUIRE(description.problem);
const auto &problem = description.problem.value();