Fixed whitespace issue in typing sections and added test cases.
This commit is contained in:
parent
6ce4eecb18
commit
230844c3ae
@ -59,6 +59,7 @@ void parseAndAddPrimitiveTypeDeclarations(Context &context, ast::Domain &domain)
|
|||||||
|
|
||||||
// Skip parent type information for now
|
// Skip parent type information for now
|
||||||
tokenizer.getIdentifier();
|
tokenizer.getIdentifier();
|
||||||
|
tokenizer.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenizer.seek(position);
|
tokenizer.seek(position);
|
||||||
@ -83,6 +84,7 @@ void parseAndAddPrimitiveTypeDeclarations(Context &context, ast::Domain &domain)
|
|||||||
|
|
||||||
// If existing, parse and store parent type
|
// If existing, parse and store parent type
|
||||||
auto parentType = parsePrimitiveType(context, domain);
|
auto parentType = parsePrimitiveType(context, domain);
|
||||||
|
tokenizer.skipWhiteSpace();
|
||||||
|
|
||||||
auto &types = domain.types;
|
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
|
// All types up to now are labeled with their parent types
|
||||||
inheritanceIndex = i + 1;
|
inheritanceIndex = i + 1;
|
||||||
|
|
||||||
tokenizer.skipWhiteSpace();
|
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
lib/pddlparse/tests/TestIssues.cpp
Normal file
34
lib/pddlparse/tests/TestIssues.cpp
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
@ -214,7 +214,12 @@ std::string Tokenizer<TokenizerPolicy>::getIdentifier()
|
|||||||
const auto character = currentCharacter();
|
const auto character = currentCharacter();
|
||||||
|
|
||||||
if (!TokenizerPolicy::isIdentifierCharacter(character))
|
if (!TokenizerPolicy::isIdentifierCharacter(character))
|
||||||
|
{
|
||||||
|
if (value.empty())
|
||||||
|
throw TokenizerException(location(), "could not parse identifier");
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
value.push_back(character);
|
value.push_back(character);
|
||||||
advance();
|
advance();
|
||||||
|
@ -128,6 +128,7 @@ Location Stream::location() const
|
|||||||
|
|
||||||
char Stream::currentCharacter() const
|
char Stream::currentCharacter() const
|
||||||
{
|
{
|
||||||
|
// TODO: check if this should be secured by check()
|
||||||
return m_stream.peek();
|
return m_stream.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
tests/data/issues/issue-7.pddl
Normal file
8
tests/data/issues/issue-7.pddl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
(define
|
||||||
|
(domain mystery-typed)
|
||||||
|
(:requirements :typing)
|
||||||
|
(:types
|
||||||
|
foo - object
|
||||||
|
bar - (either foo foo)
|
||||||
|
)
|
||||||
|
)
|
9
tests/data/issues/issue-8.pddl
Normal file
9
tests/data/issues/issue-8.pddl
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
(define (domain miconic)
|
||||||
|
(:requirements :typing)
|
||||||
|
(:types
|
||||||
|
object
|
||||||
|
passenger - object
|
||||||
|
floor - object
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
Reference in New Issue
Block a user