patrick
/
plasp
Archived
1
0
Fork 0

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,49 +25,50 @@ 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 match = context.types.find(typeName);
const auto typeExists = (match != context.types.cend());
const auto typeName = parser.parseIdentifier(isIdentifier);
const auto match = context.types.find(typeName);
const auto typeExists = (match != context.types.cend());
if (typeExists)
{
auto &type = match->second;
if (typeExists)
{
auto &type = match->second;
type.setDirty();
type.setDirty();
return type;
}
return type;
}
const auto insertionResult = context.types.emplace(std::make_pair(typeName, Type(typeName)));
auto &type = insertionResult.first->second;
const auto insertionResult = context.types.emplace(std::make_pair(typeName, Type(typeName)));
auto &type = insertionResult.first->second;
// Flag type for potentially upcoming parent type declaration
type.setDirty();
// Flag type for potentially upcoming parent type declaration
type.setDirty();
// Flag type as correctly declared in the types section
type.setDeclared();
// Flag type as correctly declared in the types section
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();
// 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;
}
////////////////////////////////////////////////////////////////////////////////////////////////////