Started implementing PDDL domain parser.

This commit is contained in:
2016-05-29 16:27:11 +02:00
parent 42fda5925d
commit 67c9e2148d
9 changed files with 360 additions and 12 deletions

View File

@@ -0,0 +1,43 @@
#ifndef __PLASP__PDDL__DESCRIPTION_H
#define __PLASP__PDDL__DESCRIPTION_H
#include <boost/filesystem/path.hpp>
#include <plasp/pddl/Domain.h>
#include <plasp/utils/Parser.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Description
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Description
{
public:
static Description fromStream(std::istream &istream);
static Description fromFile(const boost::filesystem::path &path);
public:
private:
Description() = default;
void parseContent(utils::Parser &parser);
void parseSection(utils::Parser &parser);
std::unique_ptr<Domain> m_domain;
//std::unique_ptr<Problem> m_problem;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,35 @@
#ifndef __PLASP__PDDL__DOMAIN_H
#define __PLASP__PDDL__DOMAIN_H
#include <plasp/utils/Parser.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Domain
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Domain
{
public:
static Domain fromPDDL(utils::Parser &parser);
private:
Domain() = default;
void parseSection(utils::Parser &parser);
std::string m_name;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,32 @@
#ifndef __PLASP__PDDL__IDENTIFIER_H
#define __PLASP__PDDL__IDENTIFIER_H
#include <cctype>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Identifier
//
////////////////////////////////////////////////////////////////////////////////////////////////////
const auto isIdentifier =
[](const auto character)
{
return character != '?'
&& character != '('
&& character != ')'
&& character != ';'
&& std::isgraph(character);
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -28,12 +28,17 @@ class Parser
size_t column() const;
CharacterType currentCharacter() const;
void advance();
bool atEndOfFile() const;
template<typename Type>
Type parse();
template<class WhiteSpacePredicate, class CharacterPredicate>
std::string parseIdentifier(WhiteSpacePredicate whiteSpacePredicate, CharacterPredicate characterPredicate);
template<class CharacterPredicate, class WhiteSpacePredicate>
std::string parseIdentifier(CharacterPredicate characterPredicate, WhiteSpacePredicate whiteSpacePredicate);
template<class CharacterPredicate>
std::string parseIdentifier(CharacterPredicate characterPredicate);
template<typename Type>
void expect(const Type &expectedValue);
@@ -51,7 +56,6 @@ class Parser
private:
void checkStream() const;
void advance();
bool advanceIf(CharacterType expectedCharacter);
@@ -68,8 +72,8 @@ class Parser
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class WhiteSpacePredicate, class CharacterPredicate>
std::string Parser::parseIdentifier(WhiteSpacePredicate whiteSpacePredicate, CharacterPredicate characterPredicate)
template<class CharacterPredicate, class WhiteSpacePredicate>
std::string Parser::parseIdentifier(CharacterPredicate characterPredicate, WhiteSpacePredicate whiteSpacePredicate)
{
skipWhiteSpace(whiteSpacePredicate);
@@ -89,12 +93,24 @@ std::string Parser::parseIdentifier(WhiteSpacePredicate whiteSpacePredicate, Cha
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class CharacterPredicate>
std::string Parser::parseIdentifier(CharacterPredicate characterPredicate)
{
return parseIdentifier(characterPredicate,
[&](const auto character)
{
return std::isspace(character);
});
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class WhiteSpacePredicate>
void Parser::skipWhiteSpace(WhiteSpacePredicate whiteSpacePredicate)
{
checkStream();
while (whiteSpacePredicate(*m_position))
while (m_position != EndOfFile && whiteSpacePredicate(*m_position))
advance();
}