Started implementing PDDL type parsing.

This commit is contained in:
2016-05-30 20:43:36 +02:00
parent 1c4c035acc
commit a989f5f86e
8 changed files with 362 additions and 13 deletions

View File

@@ -0,0 +1,57 @@
#ifndef __PLASP__PDDL__CONSISTENCY_EXCEPTION_H
#define __PLASP__PDDL__CONSISTENCY_EXCEPTION_H
#include <exception>
#include <string>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ConsistencyException
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class ConsistencyException: public std::exception
{
public:
explicit ConsistencyException()
: ConsistencyException("Unspecified consistency error")
{
}
explicit ConsistencyException(const char *message)
: ConsistencyException(static_cast<std::string>(message))
{
}
explicit ConsistencyException(const std::string &message)
: m_message{message}
{
}
~ConsistencyException() throw()
{
}
const char *what() const throw()
{
if (m_message.empty())
return "Unspecified consistency error";
return m_message.c_str();
}
private:
std::string m_message;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -1,7 +1,10 @@
#ifndef __PLASP__PDDL__DOMAIN_H
#define __PLASP__PDDL__DOMAIN_H
#include <unordered_map>
#include <plasp/pddl/Requirement.h>
#include <plasp/pddl/Type.h>
#include <plasp/utils/Parser.h>
namespace plasp
@@ -20,9 +23,12 @@ class Domain
public:
static Domain fromPDDL(utils::Parser &parser);
using TypesHashMap = std::unordered_map<std::string, Type>;
public:
const std::string &name() const;
const Requirement::Types &requirements() const;
const TypesHashMap &types() const;
private:
Domain() = default;
@@ -30,10 +36,16 @@ class Domain
void parseSection(utils::Parser &parser);
void parseRequirementsSection(utils::Parser &parser);
bool hasRequirement(Requirement::Type requirement) const;
void computeDerivedRequirements();
void parseTypingSection(utils::Parser &parser);
void checkConsistency();
std::string m_name;
Requirement::Types m_requirements;
TypesHashMap m_types;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

48
include/plasp/pddl/Type.h Normal file
View File

@@ -0,0 +1,48 @@
#ifndef __PLASP__PDDL__TYPE_H
#define __PLASP__PDDL__TYPE_H
#include <functional>
#include <string>
#include <vector>
#include <plasp/utils/Parser.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Type
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Type
{
public:
Type(std::string name);
public:
void setDirty(bool isDirty = true);
bool isDirty() const;
const std::string &name() const;
void addParentType(const Type &parentType);
const std::vector<const Type *> &parentTypes() const;
private:
bool m_isDirty;
std::string m_name;
std::vector<const Type *> m_parentTypes;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -26,6 +26,7 @@ class Parser
char currentCharacter() const;
void advance();
bool advanceIf(char expectedCharacter);
bool atEndOfFile() const;
template<typename Type>
@@ -54,8 +55,6 @@ class Parser
private:
void checkStream() const;
bool advanceIf(char expectedCharacter);
uint64_t parseIntegerBody();
std::istream &m_istream;