patrick
/
plasp
Archived
1
0
Fork 0

Put generic Type parsing in separate function.

This commit is contained in:
Patrick Lühne 2016-06-01 17:02:35 +02:00
parent 25cf7c8ae8
commit b249e1cbf8
3 changed files with 37 additions and 12 deletions

View File

@ -5,6 +5,7 @@
#include <plasp/pddl/EitherType.h>
#include <plasp/pddl/PrimitiveType.h>
#include <plasp/utils/Parser.h>
namespace plasp
{
@ -17,8 +18,14 @@ namespace pddl
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Context;
////////////////////////////////////////////////////////////////////////////////////////////////////
using TypePtr = boost::variant<const PrimitiveType *, const EitherType *>;
TypePtr parseType(utils::Parser &parser, Context &context);
////////////////////////////////////////////////////////////////////////////////////////////////////
}

View File

@ -48,19 +48,8 @@ Predicate &Predicate::parseDeclaration(utils::Parser &parser, Context &context)
if (!parser.advanceIf('-'))
continue;
auto parseType =
[&]() -> TypePtr
{
parser.skipWhiteSpace();
if (parser.currentCharacter() == '(')
return TypePtr(&EitherType::parse(parser, context));
return TypePtr(&PrimitiveType::parse(parser, context));
};
// Parse argument type
const auto type = parseType();
const auto type = parseType(parser, context);
// Set the argument type for all previously flagged arguments
std::for_each(predicate->m_arguments.begin(), predicate->m_arguments.end(),

29
src/plasp/pddl/Type.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <plasp/pddl/Type.h>
#include <plasp/pddl/Context.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Type
//
////////////////////////////////////////////////////////////////////////////////////////////////////
TypePtr parseType(utils::Parser &parser, Context &context)
{
parser.skipWhiteSpace();
if (parser.currentCharacter() == '(')
return &EitherType::parse(parser, context);
return &PrimitiveType::parse(parser, context);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}