Moved basic parsing to a separate module.

This commit is contained in:
2017-05-09 15:05:59 +02:00
parent 386e5356af
commit 27c6b69874
64 changed files with 322 additions and 234 deletions

View File

@@ -27,6 +27,7 @@ file(GLOB utils_headers "../include/plasp/utils/*.h")
set(includes
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/lib/parsebase/include
)
set(sources
@@ -57,6 +58,7 @@ set(sources
set(libraries
${Boost_LIBRARIES}
parsebase
pthread
)

View File

@@ -1,164 +0,0 @@
#include <plasp/input/Stream.h>
#include <fstream>
#include <plasp/input/ParserException.h>
namespace plasp
{
namespace input
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Stream
//
////////////////////////////////////////////////////////////////////////////////////////////////////
Stream::Stream()
{
std::setlocale(LC_NUMERIC, "C");
// Dont skip whitespace
m_stream.exceptions(std::istream::badbit);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
Stream::Stream(std::string streamName, std::istream &istream)
{
read(streamName, istream);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Stream::read(std::string streamName, std::istream &istream)
{
// Store position of new section
const auto position = m_stream.tellp();
m_delimiters.push_back({position, streamName});
m_stream << istream.rdbuf();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Stream::read(const boost::filesystem::path &path)
{
if (!boost::filesystem::is_regular_file(path))
throw std::runtime_error("File does not exist: “" + path.string() + "");
std::ifstream fileStream(path.string(), std::ios::in);
read(path.string(), fileStream);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Stream::reset()
{
m_stream.clear();
seek(0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Stream::seek(Position position)
{
m_stream.clear();
m_stream.seekg(position);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
typename Stream::Position Stream::position() const
{
return m_stream.tellg();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
Location Stream::location() const
{
const auto currentPosition = position();
// Find current section
auto currentFile = std::find_if(m_delimiters.crbegin(), m_delimiters.crend(),
[&](const auto &fileDelimiter)
{
return currentPosition >= fileDelimiter.position;
});
// If the parser is at the end of the stream, still count from the beginning of the last section
if (currentFile == m_delimiters.crend())
currentFile = m_delimiters.crbegin();
// Go back to beginning of section
m_stream.clear();
m_stream.seekg(currentFile->position);
size_t row = 1;
size_t column = 1;
// Compute the location character by character
while (true)
{
if (currentPosition == -1 && atEnd())
break;
else if (currentPosition >= 0 && position() >= currentPosition)
break;
const auto character = currentCharacter();
if (character == '\n')
{
row++;
column = 1;
}
else if (std::isblank(character) || std::isprint(character))
column++;
m_stream.ignore(1);
}
return {currentFile->sectionName.c_str(), currentFile->sectionName.c_str(), row, row, column, column};
}
////////////////////////////////////////////////////////////////////////////////////////////////////
char Stream::currentCharacter() const
{
return m_stream.peek();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
bool Stream::atEnd() const
{
return position() == -1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Stream::check() const
{
if (atEnd())
throw ParserException(location(), "reading past end of file");
if (m_stream.fail())
throw ParserException(location());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Stream::advance()
{
check();
m_stream.ignore(1);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@@ -123,7 +123,7 @@ void Logger::log(Priority priority, const std::string &message)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Logger::log(Priority priority, const input::Location &location, const char *message)
void Logger::log(Priority priority, const parsebase::Location &location, const char *message)
{
const auto priorityID = static_cast<int>(priority);
@@ -150,7 +150,7 @@ void Logger::log(Priority priority, const input::Location &location, const char
////////////////////////////////////////////////////////////////////////////////////////////////////
void Logger::log(Priority priority, const input::Location &location, const std::string &message)
void Logger::log(Priority priority, const parsebase::Location &location, const std::string &message)
{
log(priority, location, message.c_str());
}

View File

@@ -5,10 +5,11 @@
#include <boost/filesystem.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/IO.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@@ -168,7 +169,7 @@ void Description::findSections()
if (parser.testAndSkip<std::string>("domain"))
{
if (m_domainPosition != -1)
throw input::ParserException(parser.location(), "PDDL description may not contain two domains");
throw parsebase::ParserException(parser.location(), "PDDL description may not contain two domains");
m_domainPosition = position;
@@ -178,7 +179,7 @@ void Description::findSections()
else if (m_context.parser.testAndSkip<std::string>("problem"))
{
if (m_problemPosition != -1)
throw input::ParserException(parser.location(), "PDDL description may currently not contain two problems");
throw parsebase::ParserException(parser.location(), "PDDL description may currently not contain two problems");
m_problem = std::make_unique<Problem>(Problem(m_context, *m_domain));
@@ -190,7 +191,7 @@ void Description::findSections()
else
{
const auto sectionIdentifier = parser.parse<std::string>();
throw input::ParserException(parser.location(), "unknown PDDL section “" + sectionIdentifier + "");
throw parsebase::ParserException(parser.location(), "unknown PDDL section “" + sectionIdentifier + "");
}
m_context.parser.skipWhiteSpace();

View File

@@ -2,7 +2,6 @@
#include <algorithm>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/IO.h>
#include <plasp/pddl/expressions/Constant.h>
@@ -10,6 +9,8 @@
#include <plasp/pddl/expressions/PrimitiveType.h>
#include <plasp/pddl/expressions/Variable.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@@ -51,7 +52,7 @@ void Domain::findSections()
if (unique && sectionPosition != -1)
{
parser.seek(value);
throw input::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
throw parsebase::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
}
sectionPosition = value;
@@ -101,7 +102,7 @@ void Domain::findSections()
const auto sectionIdentifier = parser.parseIdentifier();
parser.seek(position);
throw input::ParserException(parser.location(), "unknown domain section “" + sectionIdentifier + "");
throw parsebase::ParserException(parser.location(), "unknown domain section “" + sectionIdentifier + "");
}
// Skip section for now and parse it later
@@ -354,7 +355,7 @@ void Domain::parseTypeSection()
while (parser.currentCharacter() != ')')
{
if (parser.currentCharacter() == '(')
throw input::ParserException(parser.location(), "only primitive types are allowed in type section");
throw parsebase::ParserException(parser.location(), "only primitive types are allowed in type section");
expressions::PrimitiveType::parseTypedDeclaration(m_context, *this);

View File

@@ -1,6 +1,5 @@
#include <plasp/pddl/Expression.h>
#include <plasp/input/ParserException.h>
#include <plasp/output/TranslatorException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Domain.h>
@@ -17,6 +16,8 @@
#include <plasp/pddl/expressions/Unsupported.h>
#include <plasp/pddl/expressions/When.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@@ -181,7 +182,7 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio
const auto expressionIdentifier = parser.parseIdentifier();
parser.seek(position);
throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
throw parsebase::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -256,7 +257,7 @@ ExpressionPointer parseEffectBodyExpression(Context &context, ExpressionContext
const auto expressionIdentifier = parser.parseIdentifier();
parser.seek(position);
throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
throw parsebase::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -282,7 +283,7 @@ ExpressionPointer parsePredicate(Context &context, ExpressionContext &expression
if ((expression = expressions::Predicate::parse(context, expressionContext)))
return expression;
throw input::ParserException(parser.location(), "expected predicate");
throw parsebase::ParserException(parser.location(), "expected predicate");
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -1,6 +1,5 @@
#include <plasp/pddl/InitialState.h>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/ExpressionContext.h>
#include <plasp/pddl/IO.h>
@@ -9,6 +8,8 @@
#include <plasp/pddl/expressions/Predicate.h>
#include <plasp/pddl/expressions/Unsupported.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@@ -58,7 +59,7 @@ std::unique_ptr<InitialState> InitialState::parseDeclaration(Context &context,
const auto expressionIdentifier = parser.parseIdentifier();
parser.seek(position);
throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
throw parsebase::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
};
parser.skipWhiteSpace();

View File

@@ -2,13 +2,14 @@
#include <algorithm>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/ExpressionContext.h>
#include <plasp/pddl/IO.h>
#include <plasp/pddl/expressions/Constant.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@@ -52,7 +53,7 @@ void Problem::findSections()
if (unique && sectionPosition != -1)
{
parser.seek(value);
throw input::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
throw parsebase::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
}
sectionPosition = value;
@@ -97,7 +98,7 @@ void Problem::findSections()
const auto sectionIdentifier = parser.parseIdentifier();
parser.seek(position);
throw input::ParserException(parser.location(), "unknown problem section “" + sectionIdentifier + "");
throw parsebase::ParserException(parser.location(), "unknown problem section “" + sectionIdentifier + "");
}
// Skip section for now and parse it later
@@ -203,7 +204,7 @@ void Problem::parseDomainSection()
const auto domainName = parser.parseIdentifier();
if (m_domain.name() != domainName)
throw input::ParserException(parser.location(), "domains do not match (“" + m_domain.name() + "” and “" + domainName + "”)");
throw parsebase::ParserException(parser.location(), "domains do not match (“" + m_domain.name() + "” and “" + domainName + "”)");
parser.expect<std::string>(")");
}

View File

@@ -4,7 +4,7 @@
#include <boost/assign.hpp>
#include <boost/bimap.hpp>
#include <plasp/input/ParserException.h>
#include <parsebase/ParserException.h>
namespace plasp
{
@@ -89,7 +89,7 @@ Requirement Requirement::parse(Context &context)
const auto match = requirementTypesToPDDL.right.find(requirementName);
if (match == requirementTypesToPDDL.right.end())
throw input::ParserException(parser.location(), "unknown PDDL requirement “" + requirementName + "");
throw parsebase::ParserException(parser.location(), "unknown PDDL requirement “" + requirementName + "");
const auto requirementType = match->second;

View File

@@ -53,7 +53,7 @@ expressions::VariablePointer VariableStack::parseAndFind(plasp::pddl::Context &c
return match->get();
}
throw input::ParserException(parser.location(), "variable “" + variableName + "” used but never declared");
throw parsebase::ParserException(parser.location(), "variable “" + variableName + "” used but never declared");
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -4,13 +4,14 @@
#include <boost/assert.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/ExpressionContext.h>
#include <plasp/pddl/Problem.h>
#include <plasp/pddl/expressions/PrimitiveType.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@@ -114,7 +115,7 @@ void Constant::parseTypedDeclarations(Context &context, Domain &domain)
domain.checkRequirement(Requirement::Type::Typing);
// If no types are given, check that typing is not a requirement
else if (domain.hasRequirement(Requirement::Type::Typing))
throw input::ParserException(parser.location(), "constant has undeclared type");
throw parsebase::ParserException(parser.location(), "constant has undeclared type");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -141,7 +142,7 @@ void Constant::parseTypedDeclarations(Context &context, Problem &problem)
problem.checkRequirement(Requirement::Type::Typing);
// If no types are given, check that typing is not a requirement
else if (problem.hasRequirement(Requirement::Type::Typing))
throw input::ParserException(parser.location(), "constant has undeclared type");
throw parsebase::ParserException(parser.location(), "constant has undeclared type");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -159,7 +160,7 @@ ConstantPointer Constant::parseAndFind(Context &context, const Domain &domain)
if (constant != nullptr)
return constant;
throw input::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
throw parsebase::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -182,7 +183,7 @@ ConstantPointer Constant::parseAndFind(Context &context, const Problem &problem)
if (constant)
return constant;
throw input::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
throw parsebase::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -126,7 +126,7 @@ PredicatePointer Predicate::parse(Context &context, const Problem &problem)
while (parser.currentCharacter() != ')')
{
if (parser.currentCharacter() == '?')
throw input::ParserException(parser.location(), "variables not allowed in this context");
throw parsebase::ParserException(parser.location(), "variables not allowed in this context");
// Parse objects and constants
const auto constant = Constant::parseAndFind(context, problem);

View File

@@ -4,11 +4,12 @@
#include <boost/assert.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/ExpressionContext.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@@ -112,7 +113,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
const auto typeName = parser.parseIdentifier();
if (typeName.empty())
throw input::ParserException(parser.location(), "no type supplied");
throw parsebase::ParserException(parser.location(), "no type supplied");
const auto match = std::find_if(types.cbegin(), types.cend(),
[&](const auto &primitiveType)
@@ -129,7 +130,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
}
else
throw input::ParserException(parser.location(), "type “" + typeName + "” used but never declared");
throw parsebase::ParserException(parser.location(), "type “" + typeName + "” used but never declared");
return types.back().get();
}

View File

@@ -4,7 +4,6 @@
#include <boost/assert.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/ExpressionContext.h>
@@ -12,6 +11,8 @@
#include <plasp/pddl/expressions/PrimitiveType.h>
#include <plasp/pddl/expressions/Type.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@@ -60,7 +61,7 @@ void Variable::parseDeclaration(Context &context, Variables &parameters)
});
if (match != parameters.cend())
throw input::ParserException(parser.location(), "variable “" + variable->m_name + "” already declared in this scope");
throw parsebase::ParserException(parser.location(), "variable “" + variable->m_name + "” already declared in this scope");
// Flag variable for potentially upcoming type declaration
variable->setDirty();
@@ -137,7 +138,7 @@ void Variable::parseTypedDeclarations(Context &context, ExpressionContext &expre
expressionContext.checkRequirement(Requirement::Type::Typing);
// If no types are given, check that typing is not a requirement
else if (expressionContext.hasRequirement(Requirement::Type::Typing))
throw input::ParserException(parser.location(), "variable has undeclared type");
throw parsebase::ParserException(parser.location(), "variable has undeclared type");
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -31,7 +31,7 @@ AssignedVariable::AssignedVariable(const Variable &variable, const Value &value)
////////////////////////////////////////////////////////////////////////////////////////////////////
AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variables &variables)
AssignedVariable AssignedVariable::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
{
AssignedVariable assignedVariable;
@@ -43,7 +43,7 @@ AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variab
////////////////////////////////////////////////////////////////////////////////////////////////////
AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variable &variable)
AssignedVariable AssignedVariable::fromSAS(parsebase::Parser<> &parser, const Variable &variable)
{
AssignedVariable assignedVariable;

View File

@@ -23,7 +23,7 @@ AxiomRule::AxiomRule(AxiomRule::Conditions conditions, AxiomRule::Condition post
////////////////////////////////////////////////////////////////////////////////////////////////////
AxiomRule AxiomRule::fromSAS(input::Parser<> &parser, const Variables &variables)
AxiomRule AxiomRule::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
{
parser.expect<std::string>("begin_rule");

View File

@@ -5,11 +5,10 @@
#include <fstream>
#include <sstream>
#include <boost/filesystem.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/sas/VariableTransition.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace sas
@@ -28,7 +27,7 @@ Description::Description()
////////////////////////////////////////////////////////////////////////////////////////////////////
Description Description::fromParser(input::Parser<> &&parser)
Description Description::fromParser(parsebase::Parser<> &&parser)
{
Description description;
description.parseContent(parser);
@@ -40,7 +39,7 @@ Description Description::fromParser(input::Parser<> &&parser)
Description Description::fromStream(std::istream &istream)
{
input::Parser<> parser;
parsebase::Parser<> parser;
parser.read("std::cin", istream);
Description description;
@@ -51,12 +50,12 @@ Description Description::fromStream(std::istream &istream)
////////////////////////////////////////////////////////////////////////////////////////////////////
Description Description::fromFile(const boost::filesystem::path &path)
Description Description::fromFile(const std::experimental::filesystem::path &path)
{
if (!boost::filesystem::is_regular_file(path))
if (!std::experimental::filesystem::is_regular_file(path))
throw std::runtime_error("File does not exist: “" + path.string() + "");
input::Parser<> parser;
parsebase::Parser<> parser;
parser.read(path);
Description description;
@@ -160,7 +159,7 @@ bool Description::hasRequirements() const
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseContent(input::Parser<> &parser)
void Description::parseContent(parsebase::Parser<> &parser)
{
parseVersionSection(parser);
parseMetricSection(parser);
@@ -174,26 +173,26 @@ void Description::parseContent(input::Parser<> &parser)
parser.skipWhiteSpace();
if (!parser.atEnd())
throw input::ParserException(parser.location(), "expected end of SAS description (perhaps, input contains two SAS descriptions?)");
throw parsebase::ParserException(parser.location(), "expected end of SAS description (perhaps, input contains two SAS descriptions?)");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseVersionSection(input::Parser<> &parser) const
void Description::parseVersionSection(parsebase::Parser<> &parser) const
{
parser.expect<std::string>("begin_version");
const auto formatVersion = parser.parse<size_t>();
if (formatVersion != 3)
throw input::ParserException(parser.location(), "unsupported SAS format version (" + std::to_string(formatVersion) + ")");
throw parsebase::ParserException(parser.location(), "unsupported SAS format version (" + std::to_string(formatVersion) + ")");
parser.expect<std::string>("end_version");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseMetricSection(input::Parser<> &parser)
void Description::parseMetricSection(parsebase::Parser<> &parser)
{
parser.expect<std::string>("begin_metric");
@@ -204,7 +203,7 @@ void Description::parseMetricSection(input::Parser<> &parser)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseVariablesSection(input::Parser<> &parser)
void Description::parseVariablesSection(parsebase::Parser<> &parser)
{
const auto numberOfVariables = parser.parse<size_t>();
m_variables.reserve(numberOfVariables);
@@ -215,7 +214,7 @@ void Description::parseVariablesSection(input::Parser<> &parser)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseMutexSection(input::Parser<> &parser)
void Description::parseMutexSection(parsebase::Parser<> &parser)
{
const auto numberOfMutexGroups = parser.parse<size_t>();
m_mutexGroups.reserve(numberOfMutexGroups);
@@ -226,21 +225,21 @@ void Description::parseMutexSection(input::Parser<> &parser)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseInitialStateSection(input::Parser<> &parser)
void Description::parseInitialStateSection(parsebase::Parser<> &parser)
{
m_initialState = std::make_unique<InitialState>(InitialState::fromSAS(parser, m_variables));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseGoalSection(input::Parser<> &parser)
void Description::parseGoalSection(parsebase::Parser<> &parser)
{
m_goal = std::make_unique<Goal>(Goal::fromSAS(parser, m_variables));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseOperatorSection(input::Parser<> &parser)
void Description::parseOperatorSection(parsebase::Parser<> &parser)
{
const auto numberOfOperators = parser.parse<size_t>();
m_operators.reserve(numberOfOperators);
@@ -251,7 +250,7 @@ void Description::parseOperatorSection(input::Parser<> &parser)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseAxiomSection(input::Parser<> &parser)
void Description::parseAxiomSection(parsebase::Parser<> &parser)
{
const auto numberOfAxiomRules = parser.parse<size_t>();
m_axiomRules.reserve(numberOfAxiomRules);

View File

@@ -23,7 +23,7 @@ Effect::Effect(Conditions conditions, Condition postcondition)
////////////////////////////////////////////////////////////////////////////////////////////////////
Effect Effect::fromSAS(input::Parser<> &parser, const Variables &variables, Conditions &preconditions)
Effect Effect::fromSAS(parsebase::Parser<> &parser, const Variables &variables, Conditions &preconditions)
{
Effect::Conditions conditions;

View File

@@ -13,7 +13,7 @@ namespace sas
//
////////////////////////////////////////////////////////////////////////////////////////////////////
Goal Goal::fromSAS(input::Parser<> &parser, const Variables &variables)
Goal Goal::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
{
Goal goal;

View File

@@ -11,7 +11,7 @@ namespace sas
//
////////////////////////////////////////////////////////////////////////////////////////////////////
InitialState InitialState::fromSAS(input::Parser<> &parser, const Variables &variables)
InitialState InitialState::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
{
InitialState initialState;

View File

@@ -2,7 +2,7 @@
#include <iostream>
#include <plasp/input/ParserException.h>
#include <parsebase/ParserException.h>
namespace plasp
{
@@ -15,7 +15,7 @@ namespace sas
//
////////////////////////////////////////////////////////////////////////////////////////////////////
MutexGroup MutexGroup::fromSAS(input::Parser<> &parser, const Variables &variables)
MutexGroup MutexGroup::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
{
MutexGroup mutexGroup;
@@ -29,7 +29,7 @@ MutexGroup MutexGroup::fromSAS(input::Parser<> &parser, const Variables &variabl
mutexGroup.m_facts.emplace_back(Fact::fromSAS(parser, variables));
if (mutexGroup.m_facts[j].value() == Value::None)
throw input::ParserException(parser.location(), "mutex groups must not contain <none of those> values");
throw parsebase::ParserException(parser.location(), "mutex groups must not contain <none of those> values");
}
parser.expect<std::string>("end_mutex_group");

View File

@@ -17,7 +17,7 @@ namespace sas
//
////////////////////////////////////////////////////////////////////////////////////////////////////
Operator Operator::fromSAS(input::Parser<> &parser, const Variables &variables)
Operator Operator::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
{
Operator operator_;

View File

@@ -4,9 +4,10 @@
#include <limits>
#include <sstream>
#include <plasp/input/ParserException.h>
#include <plasp/output/Formatting.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace sas
@@ -18,7 +19,7 @@ namespace sas
//
////////////////////////////////////////////////////////////////////////////////////////////////////
Predicate Predicate::fromSAS(input::Parser<> &parser)
Predicate Predicate::fromSAS(parsebase::Parser<> &parser)
{
Predicate predicate;
@@ -43,7 +44,7 @@ Predicate Predicate::fromSAS(input::Parser<> &parser)
}
catch (const std::exception &e)
{
throw input::ParserException(parser.location(), "could not parse operator predicate");
throw parsebase::ParserException(parser.location(), "could not parse operator predicate");
}
return predicate;

View File

@@ -1,5 +1,7 @@
#include <plasp/sas/TranslatorASP.h>
#include <boost/assert.hpp>
#include <plasp/output/Formatting.h>
namespace plasp

View File

@@ -2,10 +2,11 @@
#include <iostream>
#include <plasp/input/ParserException.h>
#include <plasp/output/Formatting.h>
#include <plasp/sas/Variable.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace sas
@@ -54,7 +55,7 @@ Value Value::negated() const
////////////////////////////////////////////////////////////////////////////////////////////////////
Value Value::fromSAS(input::Parser<> &parser)
Value Value::fromSAS(parsebase::Parser<> &parser)
{
const auto sasSign = parser.parse<std::string>();
@@ -74,7 +75,7 @@ Value Value::fromSAS(input::Parser<> &parser)
else if (sasSign == "NegatedAtom")
value.m_sign = Value::Sign::Negative;
else
throw input::ParserException(parser.location(), "invalid value sign “" + sasSign + "");
throw parsebase::ParserException(parser.location(), "invalid value sign “" + sasSign + "");
try
{
@@ -90,7 +91,7 @@ Value Value::fromSAS(input::Parser<> &parser)
}
catch (const std::exception &e)
{
throw input::ParserException(parser.location(), std::string("could not parse variable value (") + e.what() + ")");
throw parsebase::ParserException(parser.location(), std::string("could not parse variable value (") + e.what() + ")");
}
return value;
@@ -98,7 +99,7 @@ Value Value::fromSAS(input::Parser<> &parser)
////////////////////////////////////////////////////////////////////////////////////////////////////
const Value &Value::referenceFromSAS(input::Parser<> &parser, const Variable &variable)
const Value &Value::referenceFromSAS(parsebase::Parser<> &parser, const Variable &variable)
{
const auto valueID = parser.parse<int>();
@@ -106,7 +107,7 @@ const Value &Value::referenceFromSAS(input::Parser<> &parser, const Variable &va
return Value::Any;
if (valueID < 0 || static_cast<size_t>(valueID) >= variable.values().size())
throw input::ParserException(parser.location(), "value index out of range (variable " + variable.name() + ", index " + std::to_string(valueID) + ")");
throw parsebase::ParserException(parser.location(), "value index out of range (variable " + variable.name() + ", index " + std::to_string(valueID) + ")");
return variable.values()[valueID];
}

View File

@@ -2,9 +2,10 @@
#include <iostream>
#include <plasp/input/ParserException.h>
#include <plasp/output/Formatting.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace sas
@@ -23,7 +24,7 @@ Variable::Variable()
////////////////////////////////////////////////////////////////////////////////////////////////////
Variable Variable::fromSAS(input::Parser<> &parser)
Variable Variable::fromSAS(parsebase::Parser<> &parser)
{
Variable variable;
@@ -42,7 +43,7 @@ Variable Variable::fromSAS(input::Parser<> &parser)
// <none of those> values are only allowed at the end
if (j < numberOfValues - 1 && variable.m_values[j] == Value::None)
throw input::ParserException(parser.location(), "<none of those> value must be the last value of a variable");
throw parsebase::ParserException(parser.location(), "<none of those> value must be the last value of a variable");
}
parser.expect<std::string>("end_variable");
@@ -60,12 +61,12 @@ void Variable::printNameAsASPPredicate(output::ColorStream &stream) const
////////////////////////////////////////////////////////////////////////////////////////////////////
const Variable &Variable::referenceFromSAS(input::Parser<> &parser, const Variables &variables)
const Variable &Variable::referenceFromSAS(parsebase::Parser<> &parser, const Variables &variables)
{
const auto variableID = parser.parse<size_t>();
if (variableID >= variables.size())
throw input::ParserException(parser.location(), "variable index out of range (index " + std::to_string(variableID) + ")");
throw parsebase::ParserException(parser.location(), "variable index out of range (index " + std::to_string(variableID) + ")");
return variables[variableID];
}

View File

@@ -24,7 +24,7 @@ VariableTransition::VariableTransition()
////////////////////////////////////////////////////////////////////////////////////////////////////
VariableTransition VariableTransition::fromSAS(input::Parser<> &parser, const Variables &variables)
VariableTransition VariableTransition::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
{
VariableTransition variableTransition;