patrick
/
plasp
Archived
1
0
Fork 0

Fixed whitespace issue in typing sections and added test cases.

This commit is contained in:
Patrick Lühne 2017-06-18 05:18:52 +02:00
parent 6ce4eecb18
commit 230844c3ae
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
6 changed files with 59 additions and 3 deletions

View File

@ -59,6 +59,7 @@ void parseAndAddPrimitiveTypeDeclarations(Context &context, ast::Domain &domain)
// Skip parent type information for now
tokenizer.getIdentifier();
tokenizer.skipWhiteSpace();
}
tokenizer.seek(position);
@ -83,6 +84,7 @@ void parseAndAddPrimitiveTypeDeclarations(Context &context, ast::Domain &domain)
// If existing, parse and store parent type
auto parentType = parsePrimitiveType(context, domain);
tokenizer.skipWhiteSpace();
auto &types = domain.types;
@ -91,9 +93,6 @@ void parseAndAddPrimitiveTypeDeclarations(Context &context, ast::Domain &domain)
// All types up to now are labeled with their parent types
inheritanceIndex = i + 1;
tokenizer.skipWhiteSpace();
i++;
}
}

View File

@ -0,0 +1,34 @@
#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 &warning){std::cout << warning << std::endl;};
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[PDDL parser issues] Check past issues", "[PDDL parser issues]")
{
pddl::Tokenizer tokenizer;
pddl::Context context(std::move(tokenizer), ignoreWarnings);
// Check that no infinite loop occurs
SECTION("“either” in typing section")
{
const auto domainFile = fs::path("data") / "issues" / "issue-7.pddl";
context.tokenizer.read(domainFile);
CHECK_THROWS(pddl::parseDescription(context));
}
// Check that whitespace is correctly ignored in type section
SECTION("whitespace in typing section")
{
const auto domainFile = fs::path("data") / "issues" / "issue-8.pddl";
context.tokenizer.read(domainFile);
CHECK_NOTHROW(pddl::parseDescription(context));
}
}

View File

@ -214,7 +214,12 @@ std::string Tokenizer<TokenizerPolicy>::getIdentifier()
const auto character = currentCharacter();
if (!TokenizerPolicy::isIdentifierCharacter(character))
{
if (value.empty())
throw TokenizerException(location(), "could not parse identifier");
return value;
}
value.push_back(character);
advance();

View File

@ -128,6 +128,7 @@ Location Stream::location() const
char Stream::currentCharacter() const
{
// TODO: check if this should be secured by check()
return m_stream.peek();
}

View File

@ -0,0 +1,8 @@
(define
(domain mystery-typed)
(:requirements :typing)
(:types
foo - object
bar - (either foo foo)
)
)

View File

@ -0,0 +1,9 @@
(define (domain miconic)
(:requirements :typing)
(:types
object
passenger - object
floor - object
)
)