From b249e1cbf8760f0eee7b753f5cfa36d7510250db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 1 Jun 2016 17:02:35 +0200 Subject: [PATCH] Put generic Type parsing in separate function. --- include/plasp/pddl/Type.h | 7 +++++++ src/plasp/pddl/Predicate.cpp | 13 +------------ src/plasp/pddl/Type.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 src/plasp/pddl/Type.cpp diff --git a/include/plasp/pddl/Type.h b/include/plasp/pddl/Type.h index ddda7b9..6f43499 100644 --- a/include/plasp/pddl/Type.h +++ b/include/plasp/pddl/Type.h @@ -5,6 +5,7 @@ #include #include +#include namespace plasp { @@ -17,8 +18,14 @@ namespace pddl // //////////////////////////////////////////////////////////////////////////////////////////////////// +class Context; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + using TypePtr = boost::variant; +TypePtr parseType(utils::Parser &parser, Context &context); + //////////////////////////////////////////////////////////////////////////////////////////////////// } diff --git a/src/plasp/pddl/Predicate.cpp b/src/plasp/pddl/Predicate.cpp index 507a10b..e44bac0 100644 --- a/src/plasp/pddl/Predicate.cpp +++ b/src/plasp/pddl/Predicate.cpp @@ -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(), diff --git a/src/plasp/pddl/Type.cpp b/src/plasp/pddl/Type.cpp new file mode 100644 index 0000000..fe1685c --- /dev/null +++ b/src/plasp/pddl/Type.cpp @@ -0,0 +1,29 @@ +#include + +#include + +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); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +}