Started implementing predicate parsing.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#ifndef __PLASP__PDDL__CONTEXT_H
|
||||
#define __PLASP__PDDL__CONTEXT_H
|
||||
|
||||
#include <plasp/pddl/Predicate.h>
|
||||
#include <plasp/pddl/Type.h>
|
||||
|
||||
namespace plasp
|
||||
@@ -14,9 +15,11 @@ namespace pddl
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Context
|
||||
class Context
|
||||
{
|
||||
TypeHashMap types;
|
||||
public:
|
||||
TypeHashMap types;
|
||||
PredicateHashMap predicates;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Predicate.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
#include <plasp/pddl/Type.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
@@ -28,6 +29,7 @@ class Domain
|
||||
const std::string &name() const;
|
||||
const Requirements &requirements() const;
|
||||
const TypeHashMap &types() const;
|
||||
const PredicateHashMap &predicates() const;
|
||||
|
||||
private:
|
||||
Domain(Context &context);
|
||||
@@ -40,6 +42,8 @@ class Domain
|
||||
|
||||
void parseTypingSection(utils::Parser &parser);
|
||||
|
||||
void parsePredicateSection(utils::Parser &parser);
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
Context &m_context;
|
||||
|
87
include/plasp/pddl/Predicate.h
Normal file
87
include/plasp/pddl/Predicate.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#ifndef __PLASP__PDDL__PREDICATE_H
|
||||
#define __PLASP__PDDL__PREDICATE_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include <plasp/pddl/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Predicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
|
||||
struct PredicateHashMapKey
|
||||
{
|
||||
std::string name;
|
||||
size_t arity;
|
||||
|
||||
bool operator==(const PredicateHashMapKey &other) const
|
||||
{
|
||||
return arity == other.arity && name == other.name;
|
||||
}
|
||||
};
|
||||
|
||||
class Predicate;
|
||||
using PredicateHashMap = std::unordered_map<PredicateHashMapKey, Predicate>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Predicate
|
||||
{
|
||||
public:
|
||||
static Predicate &parseDeclaration(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Variables &arguments() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
Predicate(std::string name);
|
||||
|
||||
void setDeclared();
|
||||
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
Variables m_arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<plasp::pddl::PredicateHashMapKey>
|
||||
{
|
||||
std::size_t operator()(const plasp::pddl::PredicateHashMapKey &key) const
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
|
||||
boost::hash_combine(seed, key.name);
|
||||
boost::hash_combine(seed, key.arity);
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@@ -30,7 +30,7 @@ class Type
|
||||
{
|
||||
public:
|
||||
static Type &parse(utils::Parser &parser, Context &context);
|
||||
static Type &parseWithInheritance(utils::Parser &parser, Context &context);
|
||||
static Type &parseDeclaration(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
|
56
include/plasp/pddl/Variable.h
Normal file
56
include/plasp/pddl/Variable.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef __PLASP__PDDL__VARIABLE_H
|
||||
#define __PLASP__PDDL__VARIABLE_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/Type.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Variable
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
|
||||
class Variable;
|
||||
using Variables = std::vector<Variable>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Variable
|
||||
{
|
||||
public:
|
||||
static Variable parse(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Type &type() const;
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setType(const Type &type);
|
||||
|
||||
private:
|
||||
Variable(std::string name);
|
||||
|
||||
bool m_isDirty;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
const Type *m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user