Put Parser into Context.
This commit is contained in:
@@ -25,6 +25,13 @@ namespace pddl
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
Context(utils::Parser &parser)
|
||||
: parser(parser)
|
||||
{
|
||||
}
|
||||
|
||||
utils::Parser &parser;
|
||||
|
||||
expressions::PrimitiveTypes primitiveTypes;
|
||||
//std::unordered_map<std::string, expressions::PrimitiveType *> primitiveTypesHashMap;
|
||||
|
||||
|
@@ -27,12 +27,14 @@ class Description
|
||||
const Domain &domain() const;
|
||||
|
||||
private:
|
||||
Description() = default;
|
||||
Description(std::istream &istream);
|
||||
|
||||
void parseContent(utils::Parser &parser);
|
||||
void parseSection(utils::Parser &parser);
|
||||
void parseContent();
|
||||
void parseSection();
|
||||
|
||||
utils::Parser m_parser;
|
||||
Context m_context;
|
||||
|
||||
std::unique_ptr<Domain> m_domain;
|
||||
//std::unique_ptr<Problem> m_problem;
|
||||
};
|
||||
|
@@ -6,7 +6,6 @@
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -22,7 +21,7 @@ namespace pddl
|
||||
class Domain
|
||||
{
|
||||
public:
|
||||
static Domain fromPDDL(utils::Parser &parser, Context &context);
|
||||
static Domain fromPDDL(Context &context);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
@@ -35,19 +34,19 @@ class Domain
|
||||
private:
|
||||
Domain(Context &context);
|
||||
|
||||
void parseSection(utils::Parser &parser);
|
||||
void parseSection();
|
||||
|
||||
void parseRequirementSection(utils::Parser &parser);
|
||||
void parseRequirementSection();
|
||||
bool hasRequirement(Requirement::Type requirementType) const;
|
||||
void computeDerivedRequirements();
|
||||
|
||||
void parseTypeSection(utils::Parser &parser);
|
||||
void parseTypeSection();
|
||||
|
||||
void parseConstantSection(utils::Parser &parser);
|
||||
void parseConstantSection();
|
||||
|
||||
void parsePredicateSection(utils::Parser &parser);
|
||||
void parsePredicateSection();
|
||||
|
||||
void parseActionSection(utils::Parser &parser);
|
||||
void parseActionSection();
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
|
@@ -25,8 +25,7 @@ class Constant: public Expression
|
||||
static ConstantPointer parseDeclaration(utils::Parser &parser, Context &context);
|
||||
static void parseTypedDeclaration(utils::Parser &parser, Context &context);
|
||||
|
||||
template<class Container>
|
||||
static Constant *parseExisting(utils::Parser &parser, const Container &constants);
|
||||
static Constant *parseExisting(utils::Parser &parser, Context &context);
|
||||
|
||||
// TODO: method for lazy creation if not existing
|
||||
|
||||
@@ -58,28 +57,6 @@ class Constant: public Expression
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Container>
|
||||
Constant *Constant::parseExisting(utils::Parser &parser, const Container &constants)
|
||||
{
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
const auto constantName = parser.parseIdentifier(isIdentifier);
|
||||
// TODO: use hash map
|
||||
const auto match = std::find_if(constants.cbegin(), constants.cend(),
|
||||
[&](const auto &constant)
|
||||
{
|
||||
return constant->name() == constantName;
|
||||
});
|
||||
const auto constantExists = (match != constants.cend());
|
||||
|
||||
if (!constantExists)
|
||||
throw utils::ParserException(parser.row(), parser.column(), "Constant \"" + constantName + "\" used but never declared");
|
||||
|
||||
return match->get();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
@@ -18,18 +20,18 @@ namespace utils
|
||||
class ParserException: public std::exception
|
||||
{
|
||||
public:
|
||||
explicit ParserException(size_t row, size_t column)
|
||||
: ParserException(row, column, "Unspecified parser error")
|
||||
explicit ParserException(const utils::Parser &parser)
|
||||
: ParserException(parser, "Unspecified parser error")
|
||||
{
|
||||
}
|
||||
|
||||
explicit ParserException(size_t row, size_t column, const char *message)
|
||||
: ParserException(row, column, static_cast<std::string>(message))
|
||||
explicit ParserException(const utils::Parser &parser, const char *message)
|
||||
: ParserException(parser, static_cast<std::string>(message))
|
||||
{
|
||||
}
|
||||
|
||||
explicit ParserException(size_t row, size_t column, const std::string &message)
|
||||
: m_message{std::to_string(row) + ":" + std::to_string(column) + "\t" + message}
|
||||
explicit ParserException(const utils::Parser &parser, const std::string &message)
|
||||
: m_message{std::to_string(parser.row()) + ":" + std::to_string(parser.column()) + "\t" + message}
|
||||
{
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user