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 class Type
{ {
public: 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: public:
const std::string &name() const; const std::string &name() const;

View File

@ -200,10 +200,10 @@ void Domain::computeDerivedRequirements()
void Domain::parseTypingSection(utils::Parser &parser) void Domain::parseTypingSection(utils::Parser &parser)
{ {
// Parses a type and potentially its parent type // Store types and their parent types
while (parser.currentCharacter() != ')') while (parser.currentCharacter() != ')')
{ {
Type::parsePDDL(parser, m_context); Type::parseWithInheritance(parser, m_context);
parser.skipWhiteSpace(); 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(); parser.skipWhiteSpace();
const auto typeName = parser.parseIdentifier(isIdentifier); const auto typeName = parser.parseIdentifier(isIdentifier);
@ -56,18 +52,23 @@ void Type::parsePDDL(utils::Parser &parser, Context &context)
type.setDeclared(); type.setDeclared();
return type; return type;
}; }
parseType(); ////////////////////////////////////////////////////////////////////////////////////////////////////
Type &Type::parseWithInheritance(utils::Parser &parser, Context &context)
{
// Parse and store type
auto &type = parse(parser, context);
parser.skipWhiteSpace(); parser.skipWhiteSpace();
// Check for type inheritance // Check for type inheritance
if (!parser.advanceIf('-')) if (!parser.advanceIf('-'))
return; return type;
// If existing, parse parent type // If existing, parse and store parent type
auto &parentType = parseType(); auto &parentType = parse(parser, context);
parentType.setDirty(false); parentType.setDirty(false);
@ -81,6 +82,8 @@ void Type::parsePDDL(utils::Parser &parser, Context &context)
childType.second.addParentType(parentType); childType.second.addParentType(parentType);
childType.second.setDirty(false); childType.second.setDirty(false);
}); });
return type;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////