Fixed parsing of types.
This commit is contained in:
parent
30a092b365
commit
1876d1fe0b
@ -128,16 +128,6 @@ At<Argument> deepCopy(At<Argument> &other)
|
||||
return At<Argument>(other.timePoint, std::move(argument));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
template<class Argument>
|
||||
Either<Argument> deepCopy(Either<Argument> &other)
|
||||
{
|
||||
auto argument{deepCopy(other.argument)};
|
||||
|
||||
return Not<Argument>(std::move(argument));
|
||||
}*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
@ -152,20 +142,9 @@ Not<Argument> deepCopy(Not<Argument> &other)
|
||||
// Variants
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct DeepCopyVisitor
|
||||
{
|
||||
template<class Argument>
|
||||
Argument visit(Argument &other)
|
||||
{
|
||||
return deepCopy(other);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::Type deepCopy(ast::Type &other)
|
||||
{
|
||||
return other.match([](auto &x){deepCopy(x); return std::make_unique<ast::PrimitiveType>(nullptr);});
|
||||
return other.match([](auto &x) -> ast::Type {return deepCopy(x);});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -23,9 +23,8 @@ ast::Type parseType(Context &context, ast::Domain &domain)
|
||||
|
||||
if (tokenizer.testAndReturn<char>('('))
|
||||
{
|
||||
// TODO: put into Type parsing unit
|
||||
// TODO: refactor
|
||||
auto p =
|
||||
auto parsePrimitiveTypeWrapper =
|
||||
[](auto &context, auto &astContext, auto &) -> std::experimental::optional<ast::PrimitiveTypePointer>
|
||||
{
|
||||
return parsePrimitiveType(context, *astContext.domain);
|
||||
@ -35,7 +34,7 @@ ast::Type parseType(Context &context, ast::Domain &domain)
|
||||
ASTContext astContext(domain);
|
||||
VariableStack variableStack;
|
||||
|
||||
auto eitherType = parseEither<ast::PrimitiveTypePointer>(context, astContext, variableStack, p);
|
||||
auto eitherType = parseEither<ast::PrimitiveTypePointer>(context, astContext, variableStack, parsePrimitiveTypeWrapper);
|
||||
|
||||
if (!eitherType)
|
||||
throw ParserException(tokenizer.location(), "expected primitive type or “either” expression");
|
||||
|
@ -49,13 +49,12 @@ ast::VariableDeclarations parseVariableDeclarations(Context &context, ast::Domai
|
||||
continue;
|
||||
|
||||
auto parentType = parseType(context, domain);
|
||||
parentType = ast::deepCopy(parentType);
|
||||
|
||||
for (size_t i = inheritanceIndex; i < variableDeclarations.size(); i++)
|
||||
variableDeclarations[i]->type = ast::deepCopy(parentType);
|
||||
|
||||
// All types up to now are labeled with their parent types
|
||||
inheritanceIndex = variableDeclarations.size() + 1;
|
||||
inheritanceIndex = variableDeclarations.size();
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
}
|
||||
|
@ -7,13 +7,14 @@
|
||||
|
||||
namespace fs = std::experimental::filesystem;
|
||||
|
||||
const pddl::Context::WarningCallback ignoreWarnings = [](const auto &, const auto &){};
|
||||
const auto pddlInstanceBasePath = fs::path("data") / "pddl-instances";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_CASE("[PDDL parser acceptance] All the IPC domains are parsed without errors", "[PDDL parser acceptance]")
|
||||
TEST_CASE("[PDDL parser acceptance] All official PDDL domains are parsed without errors", "[PDDL parser acceptance]")
|
||||
{
|
||||
const pddl::Context::WarningCallback ignoreWarnings = [](const auto &, const auto &){};
|
||||
|
||||
for (const auto &competitionDirectory : fs::directory_iterator("data/pddl-instances"))
|
||||
for (const auto &competitionDirectory : fs::directory_iterator(pddlInstanceBasePath))
|
||||
{
|
||||
if (!fs::is_directory(competitionDirectory))
|
||||
continue;
|
||||
@ -36,11 +37,9 @@ TEST_CASE("[PDDL parser acceptance] All the IPC domains are parsed without error
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_CASE("[PDDL parser acceptance] The first instance of every IPC domain is parsed without errors", "[PDDL parser acceptance]")
|
||||
TEST_CASE("[PDDL parser acceptance] The first instance for all official PDDL domains is parsed without errors", "[PDDL parser acceptance]")
|
||||
{
|
||||
const pddl::Context::WarningCallback ignoreWarnings = [](const auto &, const auto &){};
|
||||
|
||||
for (const auto &competitionDirectory : fs::directory_iterator("data/pddl-instances"))
|
||||
for (const auto &competitionDirectory : fs::directory_iterator(pddlInstanceBasePath))
|
||||
{
|
||||
if (!fs::is_directory(competitionDirectory))
|
||||
continue;
|
||||
|
40
lib/pddlparse/tests/TestOfficialPDDLInstances.cpp
Normal file
40
lib/pddlparse/tests/TestOfficialPDDLInstances.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <experimental/filesystem>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/Parse.h>
|
||||
|
||||
namespace fs = std::experimental::filesystem;
|
||||
|
||||
const pddl::Context::WarningCallback ignoreWarnings = [](const auto &, const auto &){};
|
||||
const auto pddlInstanceBasePath = fs::path("data") / "pddl-instances";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_CASE("[PDDL parser] The official PDDL instances are parsed correctly", "[PDDL parser]")
|
||||
{
|
||||
std::cout << std::endl;
|
||||
|
||||
pddl::Tokenizer tokenizer;
|
||||
pddl::Context context(std::move(tokenizer), ignoreWarnings);
|
||||
|
||||
SECTION("“either” type in zenotravel domain")
|
||||
{
|
||||
const auto domainFile = pddlInstanceBasePath / "ipc-2002" / "domains" / "zenotravel-numeric-hand-coded" / "domain.pddl";
|
||||
context.tokenizer.read(domainFile);
|
||||
auto description = pddl::parseDescription(context);
|
||||
|
||||
const auto &predicates = description.domain->predicates;
|
||||
|
||||
REQUIRE(predicates.size() == 2);
|
||||
REQUIRE(predicates[0]->name == "at");
|
||||
REQUIRE(predicates[0]->parameters.size() == 2);
|
||||
REQUIRE(predicates[0]->parameters[0]->name == "x");
|
||||
REQUIRE(predicates[0]->parameters[0]->type);
|
||||
CHECK(predicates[0]->parameters[0]->type.value().is<pddl::ast::EitherPointer<pddl::ast::PrimitiveTypePointer>>());
|
||||
REQUIRE(predicates[0]->parameters[1]->name == "c");
|
||||
REQUIRE(predicates[0]->parameters[1]->type);
|
||||
CHECK(predicates[0]->parameters[1]->type.value().is<pddl::ast::PrimitiveTypePointer>());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user