Refactored interface for parsing Types.

This commit is contained in:
Patrick Lühne 2016-05-31 14:01:18 +02:00
parent 1395b62e60
commit cf1c66a085
3 changed files with 34 additions and 30 deletions

View File

@ -29,7 +29,8 @@ using TypeHashMap = std::unordered_map<std::string, Type>;
class Type
{
public:
static void parsePDDL(utils::Parser &parser, Context &context);
static Type &parse(utils::Parser &parser, Context &context);
static Type &parseWithInheritance(utils::Parser &parser, Context &context);
public:
const std::string &name() const;

View File

@ -200,10 +200,10 @@ void Domain::computeDerivedRequirements()
void Domain::parseTypingSection(utils::Parser &parser)
{
// Parses a type and potentially its parent type
// Store types and their parent types
while (parser.currentCharacter() != ')')
{
Type::parsePDDL(parser, m_context);
Type::parseWithInheritance(parser, m_context);
parser.skipWhiteSpace();
}

View File

@ -25,12 +25,8 @@ Type::Type(std::string name)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Type::parsePDDL(utils::Parser &parser, Context &context)
Type &Type::parse(utils::Parser &parser, Context &context)
{
// Parses a single type identifier
const auto parseType =
[&]() -> auto &
{
parser.skipWhiteSpace();
const auto typeName = parser.parseIdentifier(isIdentifier);
@ -56,18 +52,23 @@ void Type::parsePDDL(utils::Parser &parser, Context &context)
type.setDeclared();
return type;
};
}
parseType();
////////////////////////////////////////////////////////////////////////////////////////////////////
Type &Type::parseWithInheritance(utils::Parser &parser, Context &context)
{
// Parse and store type
auto &type = parse(parser, context);
parser.skipWhiteSpace();
// Check for type inheritance
if (!parser.advanceIf('-'))
return;
return type;
// If existing, parse parent type
auto &parentType = parseType();
// If existing, parse and store parent type
auto &parentType = parse(parser, context);
parentType.setDirty(false);
@ -81,6 +82,8 @@ void Type::parsePDDL(utils::Parser &parser, Context &context)
childType.second.addParentType(parentType);
childType.second.setDirty(false);
});
return type;
}
////////////////////////////////////////////////////////////////////////////////////////////////////