Parsing PDDL requirements.

This commit is contained in:
Patrick Lühne 2016-05-30 15:06:04 +02:00
parent 8aa419b5c2
commit 5c37026ec7
4 changed files with 49 additions and 4 deletions

View File

@ -1,6 +1,7 @@
#ifndef __PLASP__PDDL__DOMAIN_H
#define __PLASP__PDDL__DOMAIN_H
#include <plasp/pddl/Requirement.h>
#include <plasp/utils/Parser.h>
namespace plasp
@ -19,12 +20,19 @@ class Domain
public:
static Domain fromPDDL(utils::Parser &parser);
public:
const std::string &name() const;
const Requirement::Types &requirements() const;
private:
Domain() = default;
void parseSection(utils::Parser &parser);
void parseRequirementsSection(utils::Parser &parser);
std::string m_name;
Requirement::Types m_requirements;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -2,6 +2,7 @@
#define __PLASP__PDDL__REQUIREMENT_H
#include <plasp/utils/Parser.h>
#include <vector>
namespace plasp
{
@ -40,6 +41,8 @@ struct Requirement
ActionCosts
};
using Types = std::vector<Type>;
static Requirement::Type fromPDDL(utils::Parser &parser);
static void toPDDL(std::ostream &ostream, Requirement::Type requirementType);

View File

@ -38,6 +38,20 @@ Domain Domain::fromPDDL(utils::Parser &parser)
////////////////////////////////////////////////////////////////////////////////////////////////////
const std::string &Domain::name() const
{
return m_name;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
const Requirement::Types &Domain::requirements() const
{
return m_requirements;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Domain::parseSection(utils::Parser &parser)
{
parser.expect<std::string>("(:");
@ -69,7 +83,7 @@ void Domain::parseSection(utils::Parser &parser)
};
if (sectionIdentifier == "requirements")
skipSection();
parseRequirementsSection(parser);
else if (sectionIdentifier == "types")
skipSection();
else if (sectionIdentifier == "constants")
@ -86,5 +100,25 @@ void Domain::parseSection(utils::Parser &parser)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Domain::parseRequirementsSection(utils::Parser &parser)
{
while (true)
{
parser.skipWhiteSpace();
if (parser.currentCharacter() == ')')
break;
if (parser.currentCharacter() == ':')
parser.advance();
m_requirements.emplace_back(Requirement::fromPDDL(parser));
}
parser.expect<std::string>(")");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -18,7 +18,7 @@ namespace pddl
//
////////////////////////////////////////////////////////////////////////////////////////////////////
using RequirementTypeNames = boost::bimap<Requirement::Type, const char *>;
using RequirementTypeNames = boost::bimap<Requirement::Type, std::string>;
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -74,10 +74,10 @@ Requirement::Type Requirement::fromPDDL(utils::Parser &parser)
{
const auto requirementName = parser.parseIdentifier(isIdentifier);
const auto match = requirementTypesToPDDL.right.find(requirementName.c_str());
const auto match = requirementTypesToPDDL.right.find(requirementName);
if (match == requirementTypesToPDDL.right.end())
throw utils::ParserException(parser.row(), parser.column(), "Could not parse requirement");
throw utils::ParserException(parser.row(), parser.column(), "Unknown PDDL requirement \"" + requirementName + "\"");
return match->second;
}