Refactoring to use cleaner output implementation.
This commit is contained in:
@@ -12,8 +12,11 @@ file(GLOB pddl_expressions_headers "../include/plasp/pddl/expressions/*.h")
|
||||
file(GLOB sas_sources "plasp/sas/*.cpp")
|
||||
file(GLOB sas_headers "../include/plasp/sas/*.h")
|
||||
|
||||
file(GLOB utils_sources "plasp/utils/*.cpp")
|
||||
file(GLOB utils_headers "../include/plasp/utils/*.h")
|
||||
file(GLOB input_sources "plasp/input/*.cpp")
|
||||
file(GLOB input_headers "../include/plasp/input/*.h")
|
||||
|
||||
file(GLOB output_sources "plasp/output/*.cpp")
|
||||
file(GLOB output_headers "../include/plasp/output/*.h")
|
||||
|
||||
include_directories(
|
||||
${Boost_INCLUDE_DIRS}
|
||||
@@ -36,8 +39,11 @@ set(sources
|
||||
${sas_sources}
|
||||
${sas_headers}
|
||||
|
||||
${utils_sources}
|
||||
${utils_headers}
|
||||
${input_sources}
|
||||
${input_headers}
|
||||
|
||||
${output_sources}
|
||||
${output_headers}
|
||||
)
|
||||
|
||||
set(libraries
|
||||
|
@@ -1,10 +1,12 @@
|
||||
#include <plasp/utils/Stream.h>
|
||||
#include <plasp/input/Stream.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <plasp/input/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
namespace input
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -77,7 +79,7 @@ typename Stream::Position Stream::position() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
StreamCoordinate Stream::coordinate() const
|
||||
Location Stream::location() const
|
||||
{
|
||||
const auto currentPosition = position();
|
||||
|
||||
@@ -99,7 +101,7 @@ StreamCoordinate Stream::coordinate() const
|
||||
size_t row = 1;
|
||||
size_t column = 1;
|
||||
|
||||
// Compute the coordinate character by character
|
||||
// Compute the location character by character
|
||||
while (true)
|
||||
{
|
||||
if (currentPosition == -1 && atEnd())
|
||||
@@ -120,7 +122,7 @@ StreamCoordinate Stream::coordinate() const
|
||||
m_stream.ignore(1);
|
||||
}
|
||||
|
||||
return {currentFile->sectionName, row, column};
|
||||
return {currentFile->sectionName.c_str(), currentFile->sectionName.c_str(), row, row, column, column};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -142,10 +144,10 @@ bool Stream::atEnd() const
|
||||
void Stream::check() const
|
||||
{
|
||||
if (atEnd())
|
||||
throw ParserException(coordinate(), "reading past end of file");
|
||||
throw ParserException(location(), "reading past end of file");
|
||||
|
||||
if (m_stream.fail())
|
||||
throw ParserException(coordinate());
|
||||
throw ParserException(location());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
163
src/plasp/output/Logger.cpp
Normal file
163
src/plasp/output/Logger.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
#include <plasp/output/Logger.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Logger
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
constexpr Format priorityFormat(Priority priority)
|
||||
{
|
||||
switch (priority)
|
||||
{
|
||||
case Priority::Debug:
|
||||
return {Color::Green, FontWeight::Bold};
|
||||
case Priority::Info:
|
||||
return {Color::Blue, FontWeight::Bold};
|
||||
case Priority::Warning:
|
||||
return {Color::Magenta, FontWeight::Bold};
|
||||
case Priority::Error:
|
||||
return {Color::Red, FontWeight::Bold};
|
||||
}
|
||||
|
||||
return {Color::White, FontWeight::Bold};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
constexpr const Format MessageBodyFormat = {Color::White, FontWeight::Bold};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
constexpr const Format LocationFormat = {Color::White, FontWeight::Bold};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger()
|
||||
: Logger(std::cout, std::cerr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger(ColorStream &&outputStream)
|
||||
: Logger(std::forward<ColorStream &&>(outputStream), std::cerr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger(ColorStream &&outputStream, ColorStream &&errorStream)
|
||||
: m_outputStream{outputStream},
|
||||
m_errorStream{errorStream},
|
||||
m_logPriority{Priority::Warning}
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger(Logger &&other)
|
||||
: m_outputStream{std::move(other.m_outputStream)},
|
||||
m_errorStream{std::move(other.m_errorStream)},
|
||||
m_logPriority{other.m_logPriority}
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger &Logger::operator=(Logger &&other)
|
||||
{
|
||||
*this = std::move(other);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &Logger::outputStream()
|
||||
{
|
||||
return m_outputStream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &Logger::errorStream()
|
||||
{
|
||||
return m_errorStream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::setLogPriority(Priority logPriority)
|
||||
{
|
||||
m_logPriority = logPriority;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::setColorPolicy(ColorStream::ColorPolicy colorPolicy)
|
||||
{
|
||||
m_outputStream.setColorPolicy(colorPolicy);
|
||||
m_errorStream.setColorPolicy(colorPolicy);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const char *message)
|
||||
{
|
||||
const auto priorityID = static_cast<int>(priority);
|
||||
|
||||
if (priorityID < static_cast<int>(m_logPriority))
|
||||
return;
|
||||
|
||||
m_errorStream
|
||||
<< priorityFormat(priority) << priorityName(priority) << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< MessageBodyFormat << message
|
||||
<< ResetFormat() << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const std::string &message)
|
||||
{
|
||||
log(priority, message.c_str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const input::Location &location, const char *message)
|
||||
{
|
||||
const auto priorityID = static_cast<int>(priority);
|
||||
|
||||
if (priorityID < static_cast<int>(m_logPriority))
|
||||
return;
|
||||
|
||||
m_errorStream
|
||||
<< LocationFormat
|
||||
<< location.sectionStart << ":" << location.rowStart << ":" << location.columnStart << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< priorityFormat(priority) << priorityName(priority) << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< MessageBodyFormat << message
|
||||
<< ResetFormat() << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const input::Location &location, const std::string &message)
|
||||
{
|
||||
log(priority, location, message.c_str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
@@ -5,8 +5,8 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/pddl/IO.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -19,8 +19,9 @@ namespace pddl
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Description::Description()
|
||||
: m_domainPosition{-1},
|
||||
Description::Description(Context &context)
|
||||
: m_context(context),
|
||||
m_domainPosition{-1},
|
||||
m_domain{std::make_unique<Domain>(Domain(m_context))},
|
||||
m_problemPosition{-1}
|
||||
{
|
||||
@@ -28,11 +29,10 @@ Description::Description()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Description Description::fromContext(Context &&context)
|
||||
Description Description::fromContext(Context &context)
|
||||
{
|
||||
Description description;
|
||||
Description description(context);
|
||||
|
||||
description.m_context = std::move(context);
|
||||
description.parse();
|
||||
|
||||
return description;
|
||||
@@ -40,9 +40,9 @@ Description Description::fromContext(Context &&context)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Description Description::fromStream(std::istream &istream)
|
||||
Description Description::fromStream(std::istream &istream, Context &context)
|
||||
{
|
||||
Description description;
|
||||
Description description(context);
|
||||
|
||||
description.m_context.parser.read("std::cin", istream);
|
||||
description.parse();
|
||||
@@ -52,9 +52,9 @@ Description Description::fromStream(std::istream &istream)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Description Description::fromFile(const std::string &path)
|
||||
Description Description::fromFile(const std::string &path, Context &context)
|
||||
{
|
||||
Description description;
|
||||
Description description(context);
|
||||
|
||||
description.m_context.parser.read(path);
|
||||
description.parse();
|
||||
@@ -64,11 +64,13 @@ Description Description::fromFile(const std::string &path)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Description Description::fromFiles(const std::vector<std::string> &paths)
|
||||
Description Description::fromFiles(const std::vector<std::string> &paths, Context &context)
|
||||
{
|
||||
BOOST_ASSERT(!paths.empty());
|
||||
|
||||
Description description;
|
||||
// TODO: handle dirty context objects (for instance, reused context objects in unit tests)
|
||||
|
||||
Description description(context);
|
||||
|
||||
std::for_each(paths.cbegin(), paths.cend(),
|
||||
[&](const auto &path)
|
||||
@@ -165,7 +167,7 @@ void Description::findSections()
|
||||
if (parser.testAndSkip<std::string>("domain"))
|
||||
{
|
||||
if (m_domainPosition != -1)
|
||||
throw utils::ParserException(parser.coordinate(), "PDDL description may not contain two domains");
|
||||
throw input::ParserException(parser.location(), "PDDL description may not contain two domains");
|
||||
|
||||
m_domainPosition = position;
|
||||
|
||||
@@ -175,7 +177,7 @@ void Description::findSections()
|
||||
else if (m_context.parser.testAndSkip<std::string>("problem"))
|
||||
{
|
||||
if (m_problemPosition != -1)
|
||||
throw utils::ParserException(parser.coordinate(), "PDDL description may currently not contain two problems");
|
||||
throw input::ParserException(parser.location(), "PDDL description may currently not contain two problems");
|
||||
|
||||
m_problem = std::make_unique<Problem>(Problem(m_context, *m_domain));
|
||||
|
||||
@@ -187,7 +189,7 @@ void Description::findSections()
|
||||
else
|
||||
{
|
||||
const auto sectionIdentifier = parser.parse<std::string>();
|
||||
throw utils::ParserException(parser.coordinate(), "unknown PDDL section “" + sectionIdentifier + "”");
|
||||
throw input::ParserException(parser.location(), "unknown PDDL section “" + sectionIdentifier + "”");
|
||||
}
|
||||
|
||||
m_context.parser.skipWhiteSpace();
|
||||
|
@@ -2,13 +2,13 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/pddl/ConsistencyException.h>
|
||||
#include <plasp/pddl/IO.h>
|
||||
#include <plasp/pddl/expressions/Constant.h>
|
||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -51,7 +51,7 @@ void Domain::findSections()
|
||||
if (unique && sectionPosition != -1)
|
||||
{
|
||||
parser.seek(value);
|
||||
throw utils::ParserException(parser.coordinate(), "only one “:" + sectionName + "” section allowed");
|
||||
throw input::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
|
||||
}
|
||||
|
||||
sectionPosition = value;
|
||||
@@ -92,7 +92,7 @@ void Domain::findSections()
|
||||
|
||||
const auto sectionIdentifier = parser.parseIdentifier();
|
||||
|
||||
m_context.logger.logWarning(parser.coordinate(), "section type “" + sectionIdentifier + "” currently unsupported");
|
||||
m_context.logger.log(output::Priority::Warning, parser.location(), "section type “" + sectionIdentifier + "” currently unsupported");
|
||||
|
||||
parser.seek(sectionIdentifierPosition);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ void Domain::findSections()
|
||||
const auto sectionIdentifier = parser.parseIdentifier();
|
||||
|
||||
parser.seek(position);
|
||||
throw utils::ParserException(parser.coordinate(), "unknown domain section “" + sectionIdentifier + "”");
|
||||
throw input::ParserException(parser.location(), "unknown domain section “" + sectionIdentifier + "”");
|
||||
}
|
||||
|
||||
// Skip section for now and parse it later
|
||||
@@ -277,7 +277,7 @@ void Domain::checkRequirement(Requirement::Type requirementType)
|
||||
if (hasRequirement(requirementType))
|
||||
return;
|
||||
|
||||
m_context.logger.logWarning(m_context.parser.coordinate(), "requirement “" + Requirement(requirementType).toPDDL() + "” used but never declared");
|
||||
m_context.logger.log(output::Priority::Warning, m_context.parser.location(), "requirement “" + Requirement(requirementType).toPDDL() + "” used but never declared");
|
||||
|
||||
m_requirements.push_back(requirementType);
|
||||
}
|
||||
@@ -340,7 +340,7 @@ void Domain::parseTypeSection()
|
||||
while (parser.currentCharacter() != ')')
|
||||
{
|
||||
if (parser.currentCharacter() == '(')
|
||||
throw utils::ParserException(parser.coordinate(), "only primitive types are allowed in type section");
|
||||
throw input::ParserException(parser.location(), "only primitive types are allowed in type section");
|
||||
|
||||
expressions::PrimitiveType::parseTypedDeclaration(m_context, *this);
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Domain.h>
|
||||
#include <plasp/pddl/ExpressionContext.h>
|
||||
@@ -11,7 +12,6 @@
|
||||
#include <plasp/pddl/expressions/Predicate.h>
|
||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||
#include <plasp/pddl/expressions/Unsupported.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -157,7 +157,7 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio
|
||||
const auto expressionIdentifier = parser.parseIdentifier();
|
||||
|
||||
parser.seek(position);
|
||||
throw utils::ParserException(parser.coordinate(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||
throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -229,7 +229,7 @@ ExpressionPointer parseEffectBodyExpression(Context &context, ExpressionContext
|
||||
const auto expressionIdentifier = parser.parseIdentifier();
|
||||
|
||||
parser.seek(position);
|
||||
throw utils::ParserException(parser.coordinate(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||
throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -243,7 +243,7 @@ ExpressionPointer parsePredicate(Context &context, ExpressionContext &expression
|
||||
if ((expression = expressions::Predicate::parse(context, expressionContext)))
|
||||
return expression;
|
||||
|
||||
throw utils::ParserException(parser.coordinate(), "expected predicate");
|
||||
throw input::ParserException(parser.location(), "expected predicate");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#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>
|
||||
@@ -7,7 +8,6 @@
|
||||
#include <plasp/pddl/expressions/At.h>
|
||||
#include <plasp/pddl/expressions/Predicate.h>
|
||||
#include <plasp/pddl/expressions/Unsupported.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -58,7 +58,7 @@ std::unique_ptr<InitialState> InitialState::parseDeclaration(Context &context,
|
||||
const auto expressionIdentifier = parser.parseIdentifier();
|
||||
|
||||
parser.seek(position);
|
||||
throw utils::ParserException(parser.coordinate(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||
throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||
};
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
|
@@ -2,11 +2,11 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/pddl/Domain.h>
|
||||
#include <plasp/pddl/ExpressionContext.h>
|
||||
#include <plasp/pddl/IO.h>
|
||||
#include <plasp/pddl/expressions/Constant.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -51,7 +51,7 @@ void Problem::findSections()
|
||||
if (unique && sectionPosition != -1)
|
||||
{
|
||||
parser.seek(value);
|
||||
throw utils::ParserException(parser.coordinate(), "only one “:" + sectionName + "” section allowed");
|
||||
throw input::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
|
||||
}
|
||||
|
||||
sectionPosition = value;
|
||||
@@ -87,7 +87,7 @@ void Problem::findSections()
|
||||
|
||||
const auto sectionIdentifier = parser.parseIdentifier();
|
||||
|
||||
m_context.logger.logWarning(parser.coordinate(), "section type “" + sectionIdentifier + "” currently unsupported");
|
||||
m_context.logger.log(output::Priority::Warning, parser.location(), "section type “" + sectionIdentifier + "” currently unsupported");
|
||||
|
||||
parser.seek(sectionIdentifierPosition);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ void Problem::findSections()
|
||||
const auto sectionIdentifier = parser.parseIdentifier();
|
||||
|
||||
parser.seek(position);
|
||||
throw utils::ParserException(parser.coordinate(), "unknown problem section “" + sectionIdentifier + "”");
|
||||
throw input::ParserException(parser.location(), "unknown problem section “" + sectionIdentifier + "”");
|
||||
}
|
||||
|
||||
// Skip section for now and parse it later
|
||||
@@ -202,7 +202,7 @@ void Problem::parseDomainSection()
|
||||
const auto domainName = parser.parseIdentifier();
|
||||
|
||||
if (m_domain.name() != domainName)
|
||||
throw utils::ParserException(parser.coordinate(), "domains do not match (“" + m_domain.name() + "” and “" + domainName + "”)");
|
||||
throw input::ParserException(parser.location(), "domains do not match (“" + m_domain.name() + "” and “" + domainName + "”)");
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
}
|
||||
@@ -259,7 +259,7 @@ void Problem::checkRequirement(Requirement::Type requirementType)
|
||||
if (hasRequirement(requirementType))
|
||||
return;
|
||||
|
||||
m_context.logger.logWarning(m_context.parser.coordinate(), "requirement “" + Requirement(requirementType).toPDDL() + "” used but never declared");
|
||||
m_context.logger.log(output::Priority::Warning, m_context.parser.location(), "requirement “" + Requirement(requirementType).toPDDL() + "” used but never declared");
|
||||
|
||||
m_requirements.push_back(requirementType);
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bimap.hpp>
|
||||
|
||||
#include <plasp/utils/ParserException.h>
|
||||
#include <plasp/input/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -89,12 +89,12 @@ Requirement Requirement::parse(Context &context)
|
||||
const auto match = requirementTypesToPDDL.right.find(requirementName);
|
||||
|
||||
if (match == requirementTypesToPDDL.right.end())
|
||||
throw utils::ParserException(parser.coordinate(), "unknown PDDL requirement “" + requirementName + "”");
|
||||
throw input::ParserException(parser.location(), "unknown PDDL requirement “" + requirementName + "”");
|
||||
|
||||
const auto requirementType = match->second;
|
||||
|
||||
if (requirementType == Requirement::Type::GoalUtilities)
|
||||
context.logger.logWarning(parser.coordinate(), "requirement “goal-utilities” is not part of the PDDL 3.1 specification");
|
||||
context.logger.log(output::Priority::Warning, parser.location(), "requirement “goal-utilities” is not part of the PDDL 3.1 specification");
|
||||
|
||||
return Requirement(match->second);
|
||||
}
|
||||
|
@@ -2,11 +2,11 @@
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
#include <plasp/pddl/expressions/And.h>
|
||||
#include <plasp/pddl/expressions/Not.h>
|
||||
#include <plasp/pddl/expressions/Predicate.h>
|
||||
#include <plasp/utils/Formatting.h>
|
||||
#include <plasp/utils/TranslatorException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -19,7 +19,7 @@ namespace pddl
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TranslatorASP::TranslatorASP(Description &description, utils::LogStream &outputStream)
|
||||
TranslatorASP::TranslatorASP(Description &description, output::ColorStream &outputStream)
|
||||
: m_description(description),
|
||||
m_outputStream(outputStream)
|
||||
{
|
||||
@@ -43,7 +43,7 @@ void TranslatorASP::translate() const
|
||||
|
||||
void TranslatorASP::translateDomain() const
|
||||
{
|
||||
m_outputStream << utils::Heading1("domain");
|
||||
m_outputStream << output::Heading1("domain");
|
||||
|
||||
const auto &domain = m_description.domain();
|
||||
|
||||
@@ -77,7 +77,7 @@ void TranslatorASP::translateDomain() const
|
||||
|
||||
void TranslatorASP::translateTypes() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("types");
|
||||
m_outputStream << output::Heading2("types");
|
||||
|
||||
m_outputStream << std::endl;
|
||||
|
||||
@@ -86,8 +86,8 @@ void TranslatorASP::translateTypes() const
|
||||
if (types.empty())
|
||||
{
|
||||
m_outputStream
|
||||
<< utils::RuleName("type") << "("
|
||||
<< utils::Keyword("type") << "(" << utils::String("object") << "))." << std::endl;
|
||||
<< output::Function("type") << "("
|
||||
<< output::Keyword("type") << "(" << output::String("object") << "))." << std::endl;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -96,9 +96,9 @@ void TranslatorASP::translateTypes() const
|
||||
[&](const auto &type)
|
||||
{
|
||||
m_outputStream
|
||||
<< utils::RuleName("type") << "("
|
||||
<< utils::Keyword("type") << "("
|
||||
<< utils::String(type->name())
|
||||
<< output::Function("type") << "("
|
||||
<< output::Keyword("type") << "("
|
||||
<< output::String(type->name().c_str())
|
||||
<< "))." << std::endl;
|
||||
|
||||
const auto &parentTypes = type->parentTypes();
|
||||
@@ -107,23 +107,23 @@ void TranslatorASP::translateTypes() const
|
||||
[&](const auto &parentType)
|
||||
{
|
||||
m_outputStream
|
||||
<< utils::RuleName("inherits") << "(" << utils::Keyword("type")
|
||||
<< "(" << utils::String(type->name()) << "), " << utils::Keyword("type")
|
||||
<< "(" << utils::String(parentType->name()) << "))." << std::endl;
|
||||
<< output::Function("inherits") << "(" << output::Keyword("type")
|
||||
<< "(" << output::String(type->name().c_str()) << "), " << output::Keyword("type")
|
||||
<< "(" << output::String(parentType->name().c_str()) << "))." << std::endl;
|
||||
});
|
||||
});
|
||||
|
||||
m_outputStream
|
||||
<< std::endl
|
||||
<< utils::RuleName("has") << "("
|
||||
<< utils::Variable("X") << ", "
|
||||
<< utils::Keyword("type") << "(" << utils::Variable("T2") << ")) :- "
|
||||
<< utils::RuleName("has") << "("
|
||||
<< utils::Variable("X") << ", "
|
||||
<< utils::Keyword("type") << "(" << utils::Variable("T1") << ")), "
|
||||
<< utils::RuleName("inherits") << "("
|
||||
<< utils::Keyword("type") << "(" << utils::Variable("T1") << "), "
|
||||
<< utils::Keyword("type") << "(" << utils::Variable("T2") << "))."
|
||||
<< output::Function("has") << "("
|
||||
<< output::Variable("X") << ", "
|
||||
<< output::Keyword("type") << "(" << output::Variable("T2") << ")) :- "
|
||||
<< output::Function("has") << "("
|
||||
<< output::Variable("X") << ", "
|
||||
<< output::Keyword("type") << "(" << output::Variable("T1") << ")), "
|
||||
<< output::Function("inherits") << "("
|
||||
<< output::Keyword("type") << "(" << output::Variable("T1") << "), "
|
||||
<< output::Keyword("type") << "(" << output::Variable("T2") << "))."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ void TranslatorASP::translateTypes() const
|
||||
|
||||
void TranslatorASP::translatePredicates() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("variables");
|
||||
m_outputStream << output::Heading2("variables");
|
||||
|
||||
const auto &predicates = m_description.domain().predicates();
|
||||
|
||||
@@ -140,12 +140,12 @@ void TranslatorASP::translatePredicates() const
|
||||
{
|
||||
if (predicate->arguments().empty())
|
||||
{
|
||||
m_outputStream << utils::String(predicate->name());
|
||||
m_outputStream << output::String(predicate->name().c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_outputStream << "(" << utils::String(predicate->name());
|
||||
m_outputStream << "(" << output::String(predicate->name().c_str());
|
||||
this->translateVariablesHead(predicate->arguments());
|
||||
m_outputStream << ")";
|
||||
};
|
||||
@@ -155,8 +155,8 @@ void TranslatorASP::translatePredicates() const
|
||||
{
|
||||
m_outputStream
|
||||
<< std::endl
|
||||
<< utils::RuleName("variable") << "("
|
||||
<< utils::Keyword("variable") << "(";
|
||||
<< output::Function("variable") << "("
|
||||
<< output::Keyword("variable") << "(";
|
||||
|
||||
printPredicateName(predicate);
|
||||
|
||||
@@ -169,14 +169,14 @@ void TranslatorASP::translatePredicates() const
|
||||
|
||||
m_outputStream
|
||||
<< std::endl << std::endl
|
||||
<< utils::RuleName("boolean") << "(" << utils::Boolean("true") << ")." << std::endl
|
||||
<< utils::RuleName("boolean") << "(" << utils::Boolean("false") << ")." << std::endl
|
||||
<< output::Function("boolean") << "(" << output::Boolean("true") << ")." << std::endl
|
||||
<< output::Function("boolean") << "(" << output::Boolean("false") << ")." << std::endl
|
||||
<< std::endl
|
||||
<< utils::RuleName("contains") << "("
|
||||
<< utils::Keyword("variable") << "(" << utils::Variable("X") << "), "
|
||||
<< utils::Keyword("value") << "(" << utils::Variable("X") << ", " << utils::Variable("B") << ")) :- "
|
||||
<< utils::RuleName("variable") << "(" << utils::Keyword("variable") << "(" << utils::Variable("X") << ")), "
|
||||
<< utils::RuleName("boolean") << "(" << utils::Variable("B") << ")."
|
||||
<< output::Function("contains") << "("
|
||||
<< output::Keyword("variable") << "(" << output::Variable("X") << "), "
|
||||
<< output::Keyword("value") << "(" << output::Variable("X") << ", " << output::Variable("B") << ")) :- "
|
||||
<< output::Function("variable") << "(" << output::Keyword("variable") << "(" << output::Variable("X") << ")), "
|
||||
<< output::Function("boolean") << "(" << output::Variable("B") << ")."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
@@ -184,23 +184,23 @@ void TranslatorASP::translatePredicates() const
|
||||
|
||||
void TranslatorASP::translateActions() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("actions");
|
||||
m_outputStream << output::Heading2("actions");
|
||||
|
||||
const auto &actions = m_description.domain().actions();
|
||||
|
||||
const auto printActionName =
|
||||
[&](const auto &action)
|
||||
{
|
||||
m_outputStream << utils::Keyword("action") << "(";
|
||||
m_outputStream << output::Keyword("action") << "(";
|
||||
|
||||
if (action.parameters().empty())
|
||||
{
|
||||
m_outputStream << utils::String(action.name()) << ")";
|
||||
m_outputStream << output::String(action.name().c_str()) << ")";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_outputStream << "(" << utils::String(action.name());
|
||||
m_outputStream << "(" << output::String(action.name().c_str());
|
||||
this->translateVariablesHead(action.parameters());
|
||||
m_outputStream << "))";
|
||||
};
|
||||
@@ -212,19 +212,19 @@ void TranslatorASP::translateActions() const
|
||||
const auto translateLiteral =
|
||||
[&](const auto &ruleHead, const auto &literal, bool enumerateEffects = false)
|
||||
{
|
||||
m_outputStream << std::endl << utils::RuleName(ruleHead) << "(";
|
||||
m_outputStream << std::endl << output::Function(ruleHead) << "(";
|
||||
|
||||
printActionName(*action);
|
||||
|
||||
// TODO: implement conditional effects
|
||||
if (enumerateEffects)
|
||||
m_outputStream << ", " << utils::Keyword("effect") << "(" << utils::Reserved("unconditional") << ")";
|
||||
m_outputStream << ", " << output::Keyword("effect") << "(" << output::Reserved("unconditional") << ")";
|
||||
|
||||
m_outputStream << ", ";
|
||||
|
||||
this->translateLiteral(literal);
|
||||
|
||||
m_outputStream << ") :- " << utils::RuleName("action") << "(";
|
||||
m_outputStream << ") :- " << output::Function("action") << "(";
|
||||
|
||||
printActionName(*action);
|
||||
|
||||
@@ -234,7 +234,7 @@ void TranslatorASP::translateActions() const
|
||||
m_outputStream << std::endl;
|
||||
|
||||
// Name
|
||||
m_outputStream << utils::RuleName("action") << "(";
|
||||
m_outputStream << output::Function("action") << "(";
|
||||
printActionName(*action);
|
||||
m_outputStream << ")";
|
||||
|
||||
@@ -256,7 +256,7 @@ void TranslatorASP::translateActions() const
|
||||
else
|
||||
{
|
||||
if (precondition.expressionType() != Expression::Type::And)
|
||||
throw utils::TranslatorException("only “and” expressions and (negated) predicates supported as action preconditions currently");
|
||||
throw output::TranslatorException("only “and” expressions and (negated) predicates supported as action preconditions currently");
|
||||
|
||||
const auto &andExpression = dynamic_cast<const expressions::And &>(precondition);
|
||||
|
||||
@@ -282,7 +282,7 @@ void TranslatorASP::translateActions() const
|
||||
else
|
||||
{
|
||||
if (effect.expressionType() != Expression::Type::And)
|
||||
throw utils::TranslatorException("only “and” expressions and (negated) predicates supported as action effects currently");
|
||||
throw output::TranslatorException("only “and” expressions and (negated) predicates supported as action effects currently");
|
||||
|
||||
const auto &andExpression = dynamic_cast<const expressions::And &>(effect);
|
||||
|
||||
@@ -302,30 +302,30 @@ void TranslatorASP::translateActions() const
|
||||
|
||||
void TranslatorASP::translateConstants(const std::string &heading, const expressions::Constants &constants) const
|
||||
{
|
||||
m_outputStream << utils::Heading2(heading);
|
||||
m_outputStream << output::Heading2(heading.c_str());
|
||||
|
||||
std::for_each(constants.cbegin(), constants.cend(),
|
||||
[&](const auto &constant)
|
||||
{
|
||||
m_outputStream << std::endl
|
||||
<< utils::RuleName("constant") << "("
|
||||
<< utils::Keyword("constant") << "("
|
||||
<< utils::String(constant->name())
|
||||
<< output::Function("constant") << "("
|
||||
<< output::Keyword("constant") << "("
|
||||
<< output::String(constant->name().c_str())
|
||||
<< "))." << std::endl;
|
||||
|
||||
const auto type = constant->type();
|
||||
|
||||
if (type != nullptr)
|
||||
{
|
||||
m_outputStream << utils::RuleName("has") << "("
|
||||
<< utils::Keyword("constant") << "(" << utils::String(constant->name()) << "), "
|
||||
<< utils::Keyword("type") << "(" << utils::String(type->name()) << "))." << std::endl;
|
||||
m_outputStream << output::Function("has") << "("
|
||||
<< output::Keyword("constant") << "(" << output::String(constant->name().c_str()) << "), "
|
||||
<< output::Keyword("type") << "(" << output::String(type->name().c_str()) << "))." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_outputStream << utils::RuleName("has") << "("
|
||||
<< utils::Keyword("constant") << "(" << utils::String(constant->name()) << "), "
|
||||
<< utils::Keyword("type") << "(" << utils::String("object") << "))." << std::endl;
|
||||
m_outputStream << output::Function("has") << "("
|
||||
<< output::Keyword("constant") << "(" << output::String(constant->name().c_str()) << "), "
|
||||
<< output::Keyword("type") << "(" << output::String("object") << "))." << std::endl;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -341,7 +341,7 @@ void TranslatorASP::translateVariablesHead(const expressions::Variables &variabl
|
||||
{
|
||||
const auto &variable = **i;
|
||||
|
||||
m_outputStream << ", " << utils::Variable(variable.name());
|
||||
m_outputStream << ", " << output::Variable(variable.name().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,19 +364,19 @@ void TranslatorASP::translateVariablesBody(const expressions::Variables &variabl
|
||||
if (variable.type() != nullptr)
|
||||
{
|
||||
if (variable.type()->expressionType() != Expression::Type::PrimitiveType)
|
||||
throw utils::TranslatorException("only primitive types supported currently");
|
||||
throw output::TranslatorException("only primitive types supported currently");
|
||||
|
||||
const auto &type = dynamic_cast<const expressions::PrimitiveType &>(*variable.type());
|
||||
|
||||
m_outputStream << utils::RuleName("has") << "("
|
||||
<< utils::Variable(variable.name()) << ", "
|
||||
<< utils::Keyword("type") << "(" << utils::String(type.name()) << "))";
|
||||
m_outputStream << output::Function("has") << "("
|
||||
<< output::Variable(variable.name().c_str()) << ", "
|
||||
<< output::Keyword("type") << "(" << output::String(type.name().c_str()) << "))";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_outputStream << utils::RuleName("has") << "("
|
||||
<< utils::Variable(variable.name()) << ", "
|
||||
<< utils::Keyword("type") << "(" << utils::String("object") << "))";
|
||||
m_outputStream << output::Function("has") << "("
|
||||
<< output::Variable(variable.name().c_str()) << ", "
|
||||
<< output::Keyword("type") << "(" << output::String("object") << "))";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -390,11 +390,11 @@ void TranslatorASP::translateLiteral(const Expression &literal) const
|
||||
{
|
||||
const auto &predicate = dynamic_cast<const expressions::Predicate &>(literal);
|
||||
|
||||
m_outputStream << utils::Keyword("variable") << "(";
|
||||
m_outputStream << output::Keyword("variable") << "(";
|
||||
this->translatePredicate(predicate);
|
||||
m_outputStream << "), " << utils::Keyword("value") << "(";
|
||||
m_outputStream << "), " << output::Keyword("value") << "(";
|
||||
this->translatePredicate(predicate);
|
||||
m_outputStream << ", " << utils::Boolean("true") << ")";
|
||||
m_outputStream << ", " << output::Boolean("true") << ")";
|
||||
}
|
||||
// Assuming that "not" expression may only contain a predicate
|
||||
else if (literal.expressionType() == Expression::Type::Not)
|
||||
@@ -402,18 +402,18 @@ void TranslatorASP::translateLiteral(const Expression &literal) const
|
||||
const auto ¬Expression = dynamic_cast<const expressions::Not &>(literal);
|
||||
|
||||
if (notExpression.argument()->expressionType() != Expression::Type::Predicate)
|
||||
throw utils::TranslatorException("only negations of primitive predicates supported as literals currently");
|
||||
throw output::TranslatorException("only negations of primitive predicates supported as literals currently");
|
||||
|
||||
const auto &predicate = dynamic_cast<const expressions::Predicate &>(*notExpression.argument());
|
||||
|
||||
m_outputStream << utils::Keyword("variable") << "(";
|
||||
m_outputStream << output::Keyword("variable") << "(";
|
||||
this->translatePredicate(predicate);
|
||||
m_outputStream << "), " << utils::Keyword("value") << "(";
|
||||
m_outputStream << "), " << output::Keyword("value") << "(";
|
||||
this->translatePredicate(predicate);
|
||||
m_outputStream << ", " << utils::Boolean("false") << ")";
|
||||
m_outputStream << ", " << output::Boolean("false") << ")";
|
||||
}
|
||||
else
|
||||
throw utils::TranslatorException("only primitive predicates and their negations supported as literals currently");
|
||||
throw output::TranslatorException("only primitive predicates and their negations supported as literals currently");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -424,12 +424,12 @@ void TranslatorASP::translatePredicate(const expressions::Predicate &predicate)
|
||||
|
||||
if (arguments.empty())
|
||||
{
|
||||
m_outputStream << utils::String(predicate.name());
|
||||
m_outputStream << output::String(predicate.name().c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_outputStream << "(" << utils::String(predicate.name());
|
||||
m_outputStream << "(" << output::String(predicate.name().c_str());
|
||||
|
||||
for (auto i = arguments.cbegin(); i != arguments.cend(); i++)
|
||||
{
|
||||
@@ -439,16 +439,16 @@ void TranslatorASP::translatePredicate(const expressions::Predicate &predicate)
|
||||
{
|
||||
const auto &constant = dynamic_cast<const expressions::Constant &>(**i);
|
||||
|
||||
m_outputStream << utils::Keyword("constant") << "(" << utils::String(constant.name()) << ")";
|
||||
m_outputStream << output::Keyword("constant") << "(" << output::String(constant.name().c_str()) << ")";
|
||||
}
|
||||
else if ((*i)->expressionType() == Expression::Type::Variable)
|
||||
{
|
||||
const auto &variable = dynamic_cast<const expressions::Variable &>(**i);
|
||||
|
||||
m_outputStream << utils::Variable(variable.name());
|
||||
m_outputStream << output::Variable(variable.name().c_str());
|
||||
}
|
||||
else
|
||||
throw utils::TranslatorException("only variables and constants supported in predicates currently");
|
||||
throw output::TranslatorException("only variables and constants supported in predicates currently");
|
||||
}
|
||||
|
||||
m_outputStream << ")";
|
||||
@@ -460,7 +460,7 @@ void TranslatorASP::translateProblem() const
|
||||
{
|
||||
BOOST_ASSERT(m_description.containsProblem());
|
||||
|
||||
m_outputStream << utils::Heading1("problem");
|
||||
m_outputStream << output::Heading1("problem");
|
||||
|
||||
const auto &problem = m_description.problem();
|
||||
|
||||
@@ -486,25 +486,25 @@ void TranslatorASP::translateInitialState() const
|
||||
{
|
||||
BOOST_ASSERT(m_description.containsProblem());
|
||||
|
||||
m_outputStream << utils::Heading2("initial state");
|
||||
m_outputStream << output::Heading2("initial state");
|
||||
|
||||
const auto &initialStateFacts = m_description.problem().initialState().facts();
|
||||
|
||||
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
||||
[&](const auto &fact)
|
||||
{
|
||||
m_outputStream << std::endl << utils::RuleName("initialState") << "(";
|
||||
m_outputStream << std::endl << output::Function("initialState") << "(";
|
||||
|
||||
// Translate single predicate
|
||||
if (fact->expressionType() == Expression::Type::Predicate)
|
||||
{
|
||||
const auto &predicate = dynamic_cast<const expressions::Predicate &>(*fact);
|
||||
|
||||
m_outputStream << utils::Keyword("variable") << "(";
|
||||
m_outputStream << output::Keyword("variable") << "(";
|
||||
this->translatePredicate(predicate);
|
||||
m_outputStream << "), " << utils::Keyword("value") << "(";
|
||||
m_outputStream << "), " << output::Keyword("value") << "(";
|
||||
this->translatePredicate(predicate);
|
||||
m_outputStream << ", " << utils::Boolean("true") << ")";
|
||||
m_outputStream << ", " << output::Boolean("true") << ")";
|
||||
}
|
||||
// Assuming that "not" expression may only contain a predicate
|
||||
else if (fact->expressionType() == Expression::Type::Not)
|
||||
@@ -512,24 +512,24 @@ void TranslatorASP::translateInitialState() const
|
||||
const auto ¬Expression = dynamic_cast<const expressions::Not &>(*fact);
|
||||
|
||||
if (notExpression.argument()->expressionType() != Expression::Type::Predicate)
|
||||
throw utils::TranslatorException("only negations of simple predicates supported in initial state currently");
|
||||
throw output::TranslatorException("only negations of simple predicates supported in initial state currently");
|
||||
}
|
||||
else
|
||||
throw utils::TranslatorException("only predicates and their negations supported in initial state currently");
|
||||
throw output::TranslatorException("only predicates and their negations supported in initial state currently");
|
||||
|
||||
m_outputStream << ").";
|
||||
});
|
||||
|
||||
m_outputStream
|
||||
<< std::endl << std::endl
|
||||
<< utils::RuleName("initialState") << "("
|
||||
<< utils::Keyword("variable") << "(" << utils::Variable("X") << "), "
|
||||
<< utils::Keyword("value") << "(" << utils::Variable("X") << ", " << utils::Boolean("false") << ")) :- "
|
||||
<< utils::RuleName("variable") << "(" << utils::Keyword("variable") << "(" << utils::Variable("X") << ")), "
|
||||
<< utils::Keyword("not") << " "
|
||||
<< utils::RuleName("initialState") << "("
|
||||
<< utils::Keyword("variable") << "(" << utils::Variable("X") << "), "
|
||||
<< utils::Keyword("value") << "(" << utils::Variable("X") << ", " << utils::Boolean("true") << "))."
|
||||
<< output::Function("initialState") << "("
|
||||
<< output::Keyword("variable") << "(" << output::Variable("X") << "), "
|
||||
<< output::Keyword("value") << "(" << output::Variable("X") << ", " << output::Boolean("false") << ")) :- "
|
||||
<< output::Function("variable") << "(" << output::Keyword("variable") << "(" << output::Variable("X") << ")), "
|
||||
<< output::Keyword("not") << " "
|
||||
<< output::Function("initialState") << "("
|
||||
<< output::Keyword("variable") << "(" << output::Variable("X") << "), "
|
||||
<< output::Keyword("value") << "(" << output::Variable("X") << ", " << output::Boolean("true") << "))."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
@@ -539,14 +539,14 @@ void TranslatorASP::translateGoal() const
|
||||
{
|
||||
BOOST_ASSERT(m_description.containsProblem());
|
||||
|
||||
m_outputStream << utils::Heading2("goal");
|
||||
m_outputStream << output::Heading2("goal");
|
||||
|
||||
const auto &goal = m_description.problem().goal();
|
||||
|
||||
if (goal.expressionType() == Expression::Type::Predicate
|
||||
|| goal.expressionType() == Expression::Type::Not)
|
||||
{
|
||||
m_outputStream << std::endl << utils::RuleName("goal") << "(";
|
||||
m_outputStream << std::endl << output::Function("goal") << "(";
|
||||
|
||||
translateLiteral(goal);
|
||||
|
||||
@@ -559,7 +559,7 @@ void TranslatorASP::translateGoal() const
|
||||
std::for_each(andExpression.arguments().cbegin(), andExpression.arguments().cend(),
|
||||
[&](const auto argument)
|
||||
{
|
||||
m_outputStream << std::endl << utils::RuleName("goal") << "(";
|
||||
m_outputStream << std::endl << output::Function("goal") << "(";
|
||||
|
||||
this->translateLiteral(*argument);
|
||||
|
||||
@@ -567,7 +567,7 @@ void TranslatorASP::translateGoal() const
|
||||
});
|
||||
}
|
||||
else
|
||||
throw utils::TranslatorException("only single predicates, their negations, and conjunctions are currently supported in the goal");
|
||||
throw output::TranslatorException("only single predicates, their negations, and conjunctions are currently supported in the goal");
|
||||
|
||||
m_outputStream << std::endl;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <plasp/pddl/expressions/At.h>
|
||||
|
||||
#include <plasp/utils/TranslatorException.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -38,7 +38,7 @@ ExpressionPointer At::argument() const
|
||||
|
||||
ExpressionPointer At::reduced()
|
||||
{
|
||||
throw utils::TranslatorException("reducing “at” predicates currently not supported");
|
||||
throw output::TranslatorException("reducing “at” predicates currently not supported");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Domain.h>
|
||||
#include <plasp/pddl/ExpressionContext.h>
|
||||
@@ -113,7 +114,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 utils::ParserException(parser.coordinate(), "constant has undeclared type");
|
||||
throw input::ParserException(parser.location(), "constant has undeclared type");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -140,7 +141,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 utils::ParserException(parser.coordinate(), "constant has undeclared type");
|
||||
throw input::ParserException(parser.location(), "constant has undeclared type");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -158,7 +159,7 @@ ConstantPointer Constant::parseAndFind(Context &context, const Domain &domain)
|
||||
if (constant != nullptr)
|
||||
return constant;
|
||||
|
||||
throw utils::ParserException(parser.coordinate(), "constant “" + constantName + "” used but never declared");
|
||||
throw input::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -181,7 +182,7 @@ ConstantPointer Constant::parseAndFind(Context &context, const Problem &problem)
|
||||
if (constant)
|
||||
return constant;
|
||||
|
||||
throw utils::ParserException(parser.coordinate(), "constant “" + constantName + "” used but never declared");
|
||||
throw input::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -126,7 +126,7 @@ PredicatePointer Predicate::parse(Context &context, const Problem &problem)
|
||||
while (parser.currentCharacter() != ')')
|
||||
{
|
||||
if (parser.currentCharacter() == '?')
|
||||
throw utils::ParserException(parser.coordinate(), "variables not allowed in this context");
|
||||
throw input::ParserException(parser.location(), "variables not allowed in this context");
|
||||
|
||||
// Parse objects and constants
|
||||
const auto constant = Constant::parseAndFind(context, problem);
|
||||
|
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Domain.h>
|
||||
#include <plasp/pddl/ExpressionContext.h>
|
||||
@@ -111,7 +112,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
|
||||
const auto typeName = parser.parseIdentifier();
|
||||
|
||||
if (typeName.empty())
|
||||
throw utils::ParserException(parser.coordinate(), "no type supplied");
|
||||
throw input::ParserException(parser.location(), "no type supplied");
|
||||
|
||||
const auto match = std::find_if(types.cbegin(), types.cend(),
|
||||
[&](const auto &primitiveType)
|
||||
@@ -124,11 +125,11 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
|
||||
// Only "object" is allowed as an implicit type
|
||||
if (typeName == "object" || typeName == "objects")
|
||||
{
|
||||
context.logger.logWarning(parser.coordinate(), "primitive type “" + typeName + "” should be declared");
|
||||
context.logger.log(output::Priority::Warning, parser.location(), "primitive type “" + typeName + "” should be declared");
|
||||
types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
|
||||
}
|
||||
else
|
||||
throw utils::ParserException(parser.coordinate(), "type “" + typeName + "” used but never declared");
|
||||
throw input::ParserException(parser.location(), "type “" + typeName + "” used but never declared");
|
||||
|
||||
return types.back().get();
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ UnsupportedPointer Unsupported::parse(Context &context)
|
||||
|
||||
expression->m_type = parser.parseIdentifier();
|
||||
|
||||
context.logger.logWarning(parser.coordinate(), "expression type “" + expression->m_type + "” currently unsupported in this context");
|
||||
context.logger.log(output::Priority::Warning, parser.location(), "expression type “" + expression->m_type + "” currently unsupported in this context");
|
||||
|
||||
skipSection(parser);
|
||||
|
||||
|
@@ -4,13 +4,13 @@
|
||||
|
||||
#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/expressions/Either.h>
|
||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||
#include <plasp/pddl/expressions/Type.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -53,7 +53,7 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters)
|
||||
});
|
||||
|
||||
if (match != parameters.cend())
|
||||
throw utils::ParserException(parser.coordinate(), "variable “" + variable->m_name + "” already declared in this scope");
|
||||
throw input::ParserException(parser.location(), "variable “" + variable->m_name + "” already declared in this scope");
|
||||
|
||||
// Flag variable for potentially upcoming type declaration
|
||||
variable->setDirty();
|
||||
@@ -130,7 +130,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 utils::ParserException(parser.coordinate(), "variable has undeclared type");
|
||||
throw input::ParserException(parser.location(), "variable has undeclared type");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -154,7 +154,7 @@ VariablePointer Variable::parseAndFind(Context &context, const ExpressionContext
|
||||
});
|
||||
|
||||
if (match == variables.cend())
|
||||
throw utils::ParserException(parser.coordinate(), "parameter “" + variableName + "” used but never declared");
|
||||
throw input::ParserException(parser.location(), "parameter “" + variableName + "” used but never declared");
|
||||
|
||||
return match->get();
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ AssignedVariable::AssignedVariable(const Variable &variable, const Value &value)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AssignedVariable AssignedVariable::fromSAS(utils::Parser<> &parser, const Variables &variables)
|
||||
AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variables &variables)
|
||||
{
|
||||
AssignedVariable assignedVariable;
|
||||
|
||||
@@ -43,7 +43,7 @@ AssignedVariable AssignedVariable::fromSAS(utils::Parser<> &parser, const Variab
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AssignedVariable AssignedVariable::fromSAS(utils::Parser<> &parser, const Variable &variable)
|
||||
AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variable &variable)
|
||||
{
|
||||
AssignedVariable assignedVariable;
|
||||
|
||||
|
@@ -23,7 +23,7 @@ AxiomRule::AxiomRule(AxiomRule::Conditions conditions, AxiomRule::Condition post
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AxiomRule AxiomRule::fromSAS(utils::Parser<> &parser, const Variables &variables)
|
||||
AxiomRule AxiomRule::fromSAS(input::Parser<> &parser, const Variables &variables)
|
||||
{
|
||||
parser.expect<std::string>("begin_rule");
|
||||
|
||||
|
@@ -13,163 +13,163 @@ namespace sas
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
utils::LogStream &operator<<(utils::LogStream &ostream, const Description &description)
|
||||
output::ColorStream &operator<<(output::ColorStream &stream, const Description &description)
|
||||
{
|
||||
// Metric section
|
||||
ostream << "uses action costs: " << (description.usesActionCosts() ? "yes" : "no") << std::endl;
|
||||
stream << "uses action costs: " << (description.usesActionCosts() ? "yes" : "no") << std::endl;
|
||||
|
||||
// Variable section
|
||||
const auto &variables = description.variables();
|
||||
|
||||
ostream << "variables: " << variables.size() << std::endl;
|
||||
stream << "variables: " << variables.size() << std::endl;
|
||||
|
||||
std::for_each(variables.cbegin(), variables.cend(),
|
||||
[&](const auto &variable)
|
||||
{
|
||||
const auto &values = variable.values();
|
||||
|
||||
ostream << "\t" << variable.name() << ":" << std::endl;
|
||||
ostream << "\t\tvalues: " << values.size() << std::endl;
|
||||
stream << "\t" << variable.name() << ":" << std::endl;
|
||||
stream << "\t\tvalues: " << values.size() << std::endl;
|
||||
|
||||
std::for_each(values.cbegin(), values.cend(),
|
||||
[&](const auto &value)
|
||||
{
|
||||
ostream << "\t\t\t";
|
||||
value.printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
stream << "\t\t\t";
|
||||
value.printAsSAS(stream);
|
||||
stream << std::endl;
|
||||
});
|
||||
|
||||
ostream << "\t\taxiom layer: " << variable.axiomLayer() << std::endl;
|
||||
stream << "\t\taxiom layer: " << variable.axiomLayer() << std::endl;
|
||||
});
|
||||
|
||||
// Mutex section
|
||||
const auto &mutexGroups = description.mutexGroups();
|
||||
|
||||
ostream << "mutex groups: " << mutexGroups.size() << std::endl;
|
||||
stream << "mutex groups: " << mutexGroups.size() << std::endl;
|
||||
|
||||
std::for_each(mutexGroups.cbegin(), mutexGroups.cend(),
|
||||
[&](const auto &mutexGroup)
|
||||
{
|
||||
ostream << "\tmutex group:" << std::endl;
|
||||
stream << "\tmutex group:" << std::endl;
|
||||
|
||||
std::for_each(mutexGroup.facts().cbegin(), mutexGroup.facts().cend(),
|
||||
[&](const auto &fact)
|
||||
{
|
||||
ostream << "\t\t" << fact.variable().name() << " = ";
|
||||
fact.value().printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
stream << "\t\t" << fact.variable().name() << " = ";
|
||||
fact.value().printAsSAS(stream);
|
||||
stream << std::endl;
|
||||
});
|
||||
});
|
||||
|
||||
// Initial state section
|
||||
const auto &initialState = description.initialState();
|
||||
|
||||
ostream << "initial state:" << std::endl;
|
||||
stream << "initial state:" << std::endl;
|
||||
|
||||
std::for_each(initialState.facts().cbegin(), initialState.facts().cend(),
|
||||
[&](const auto &fact)
|
||||
{
|
||||
ostream << "\t" << fact.variable().name() << " = ";
|
||||
fact.value().printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
stream << "\t" << fact.variable().name() << " = ";
|
||||
fact.value().printAsSAS(stream);
|
||||
stream << std::endl;
|
||||
});
|
||||
|
||||
// Goal section
|
||||
const auto &goal = description.goal();
|
||||
|
||||
ostream << "goal:" << std::endl;
|
||||
stream << "goal:" << std::endl;
|
||||
|
||||
std::for_each(goal.facts().cbegin(), goal.facts().cend(),
|
||||
[&](const auto &fact)
|
||||
{
|
||||
ostream << "\t" << fact.variable().name() << " = ";
|
||||
fact.value().printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
stream << "\t" << fact.variable().name() << " = ";
|
||||
fact.value().printAsSAS(stream);
|
||||
stream << std::endl;
|
||||
});
|
||||
|
||||
// Operator section
|
||||
const auto &operators = description.operators();
|
||||
|
||||
ostream << "operators: " << operators.size() << std::endl;
|
||||
stream << "operators: " << operators.size() << std::endl;
|
||||
|
||||
std::for_each(operators.cbegin(), operators.cend(),
|
||||
[&](const auto &operator_)
|
||||
{
|
||||
ostream << "\t";
|
||||
operator_.predicate().printAsSAS(ostream);
|
||||
ostream << ":" << std::endl;
|
||||
stream << "\t";
|
||||
operator_.predicate().printAsSAS(stream);
|
||||
stream << ":" << std::endl;
|
||||
|
||||
const auto &preconditions = operator_.preconditions();
|
||||
|
||||
ostream << "\t\tpreconditions: " << preconditions.size() << std::endl;
|
||||
stream << "\t\tpreconditions: " << preconditions.size() << std::endl;
|
||||
|
||||
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
||||
[&](const auto &precondition)
|
||||
{
|
||||
std::cout << "\t\t\t" << precondition.variable().name() << " = ";
|
||||
precondition.value().printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
precondition.value().printAsSAS(stream);
|
||||
stream << std::endl;
|
||||
});
|
||||
|
||||
const auto &effects = operator_.effects();
|
||||
|
||||
ostream << "\t\teffects: " << effects.size() << std::endl;
|
||||
stream << "\t\teffects: " << effects.size() << std::endl;
|
||||
|
||||
std::for_each(effects.cbegin(), effects.cend(),
|
||||
[&](const auto &effect)
|
||||
{
|
||||
ostream << "\t\t\teffect:" << std::endl;
|
||||
stream << "\t\t\teffect:" << std::endl;
|
||||
|
||||
const auto &conditions = effect.conditions();
|
||||
|
||||
ostream << "\t\t\t\tconditions: " << conditions.size() << std::endl;
|
||||
stream << "\t\t\t\tconditions: " << conditions.size() << std::endl;
|
||||
|
||||
std::for_each(conditions.cbegin(), conditions.cend(),
|
||||
[&](const auto &condition)
|
||||
{
|
||||
ostream << "\t\t\t\t\t" << condition.variable().name() << " = ";
|
||||
condition.value().printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
stream << "\t\t\t\t\t" << condition.variable().name() << " = ";
|
||||
condition.value().printAsSAS(stream);
|
||||
stream << std::endl;
|
||||
});
|
||||
|
||||
ostream << "\t\t\t\tpostcondition:" << std::endl;
|
||||
ostream << "\t\t\t\t\t" << effect.postcondition().variable().name() << " = ";
|
||||
effect.postcondition().value().printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
stream << "\t\t\t\tpostcondition:" << std::endl;
|
||||
stream << "\t\t\t\t\t" << effect.postcondition().variable().name() << " = ";
|
||||
effect.postcondition().value().printAsSAS(stream);
|
||||
stream << std::endl;
|
||||
});
|
||||
|
||||
ostream << "\t\tcosts: " << operator_.costs() << std::endl;
|
||||
stream << "\t\tcosts: " << operator_.costs() << std::endl;
|
||||
});
|
||||
|
||||
// Axiom section
|
||||
const auto &axiomRules = description.axiomRules();
|
||||
|
||||
ostream << "axiom rules: " << axiomRules.size() << std::endl;
|
||||
stream << "axiom rules: " << axiomRules.size() << std::endl;
|
||||
|
||||
std::for_each(axiomRules.cbegin(), axiomRules.cend(),
|
||||
[&](const auto &axiomRule)
|
||||
{
|
||||
ostream << "\taxiom rule:" << std::endl;
|
||||
stream << "\taxiom rule:" << std::endl;
|
||||
|
||||
const auto conditions = axiomRule.conditions();
|
||||
|
||||
ostream << "\t\tconditions: " << conditions.size() << std::endl;
|
||||
stream << "\t\tconditions: " << conditions.size() << std::endl;
|
||||
|
||||
std::for_each(conditions.cbegin(), conditions.cend(),
|
||||
[&](const auto &condition)
|
||||
{
|
||||
ostream << "\t\t\t" << condition.variable().name() << " = ";
|
||||
condition.value().printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
stream << "\t\t\t" << condition.variable().name() << " = ";
|
||||
condition.value().printAsSAS(stream);
|
||||
stream << std::endl;
|
||||
});
|
||||
|
||||
ostream << "\t\tpostcondition:" << std::endl;
|
||||
ostream << "\t\t\t" << axiomRule.postcondition().variable().name() << " = ";
|
||||
axiomRule.postcondition().value().printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
stream << "\t\tpostcondition:" << std::endl;
|
||||
stream << "\t\t\t" << axiomRule.postcondition().variable().name() << " = ";
|
||||
axiomRule.postcondition().value().printAsSAS(stream);
|
||||
stream << std::endl;
|
||||
});
|
||||
|
||||
return ostream;
|
||||
return stream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <plasp/utils/ParserException.h>
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/sas/VariableTransition.h>
|
||||
|
||||
namespace plasp
|
||||
@@ -28,7 +28,7 @@ Description::Description()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Description Description::fromParser(utils::Parser<> &&parser)
|
||||
Description Description::fromParser(input::Parser<> &&parser)
|
||||
{
|
||||
Description description;
|
||||
description.parseContent(parser);
|
||||
@@ -40,7 +40,7 @@ Description Description::fromParser(utils::Parser<> &&parser)
|
||||
|
||||
Description Description::fromStream(std::istream &istream)
|
||||
{
|
||||
utils::Parser<> parser;
|
||||
input::Parser<> parser;
|
||||
parser.read("std::cin", istream);
|
||||
|
||||
Description description;
|
||||
@@ -56,7 +56,7 @@ Description Description::fromFile(const boost::filesystem::path &path)
|
||||
if (!boost::filesystem::is_regular_file(path))
|
||||
throw std::runtime_error("File does not exist: “" + path.string() + "”");
|
||||
|
||||
utils::Parser<> parser;
|
||||
input::Parser<> parser;
|
||||
parser.read(path);
|
||||
|
||||
Description description;
|
||||
@@ -160,7 +160,7 @@ bool Description::hasRequirements() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseContent(utils::Parser<> &parser)
|
||||
void Description::parseContent(input::Parser<> &parser)
|
||||
{
|
||||
parseVersionSection(parser);
|
||||
parseMetricSection(parser);
|
||||
@@ -174,26 +174,26 @@ void Description::parseContent(utils::Parser<> &parser)
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
if (!parser.atEnd())
|
||||
throw utils::ParserException(parser.coordinate(), "expected end of SAS description (perhaps, input contains two SAS descriptions?)");
|
||||
throw input::ParserException(parser.location(), "expected end of SAS description (perhaps, input contains two SAS descriptions?)");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseVersionSection(utils::Parser<> &parser) const
|
||||
void Description::parseVersionSection(input::Parser<> &parser) const
|
||||
{
|
||||
parser.expect<std::string>("begin_version");
|
||||
|
||||
const auto formatVersion = parser.parse<size_t>();
|
||||
|
||||
if (formatVersion != 3)
|
||||
throw utils::ParserException(parser.coordinate(), "unsupported SAS format version (" + std::to_string(formatVersion) + ")");
|
||||
throw input::ParserException(parser.location(), "unsupported SAS format version (" + std::to_string(formatVersion) + ")");
|
||||
|
||||
parser.expect<std::string>("end_version");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseMetricSection(utils::Parser<> &parser)
|
||||
void Description::parseMetricSection(input::Parser<> &parser)
|
||||
{
|
||||
parser.expect<std::string>("begin_metric");
|
||||
|
||||
@@ -204,7 +204,7 @@ void Description::parseMetricSection(utils::Parser<> &parser)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseVariablesSection(utils::Parser<> &parser)
|
||||
void Description::parseVariablesSection(input::Parser<> &parser)
|
||||
{
|
||||
const auto numberOfVariables = parser.parse<size_t>();
|
||||
m_variables.reserve(numberOfVariables);
|
||||
@@ -215,7 +215,7 @@ void Description::parseVariablesSection(utils::Parser<> &parser)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseMutexSection(utils::Parser<> &parser)
|
||||
void Description::parseMutexSection(input::Parser<> &parser)
|
||||
{
|
||||
const auto numberOfMutexGroups = parser.parse<size_t>();
|
||||
m_mutexGroups.reserve(numberOfMutexGroups);
|
||||
@@ -226,21 +226,21 @@ void Description::parseMutexSection(utils::Parser<> &parser)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseInitialStateSection(utils::Parser<> &parser)
|
||||
void Description::parseInitialStateSection(input::Parser<> &parser)
|
||||
{
|
||||
m_initialState = std::make_unique<InitialState>(InitialState::fromSAS(parser, m_variables));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseGoalSection(utils::Parser<> &parser)
|
||||
void Description::parseGoalSection(input::Parser<> &parser)
|
||||
{
|
||||
m_goal = std::make_unique<Goal>(Goal::fromSAS(parser, m_variables));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseOperatorSection(utils::Parser<> &parser)
|
||||
void Description::parseOperatorSection(input::Parser<> &parser)
|
||||
{
|
||||
const auto numberOfOperators = parser.parse<size_t>();
|
||||
m_operators.reserve(numberOfOperators);
|
||||
@@ -251,7 +251,7 @@ void Description::parseOperatorSection(utils::Parser<> &parser)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseAxiomSection(utils::Parser<> &parser)
|
||||
void Description::parseAxiomSection(input::Parser<> &parser)
|
||||
{
|
||||
const auto numberOfAxiomRules = parser.parse<size_t>();
|
||||
m_axiomRules.reserve(numberOfAxiomRules);
|
||||
|
@@ -23,7 +23,7 @@ Effect::Effect(Conditions conditions, Condition postcondition)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Effect Effect::fromSAS(utils::Parser<> &parser, const Variables &variables, Conditions &preconditions)
|
||||
Effect Effect::fromSAS(input::Parser<> &parser, const Variables &variables, Conditions &preconditions)
|
||||
{
|
||||
Effect::Conditions conditions;
|
||||
|
||||
|
@@ -13,7 +13,7 @@ namespace sas
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Goal Goal::fromSAS(utils::Parser<> &parser, const Variables &variables)
|
||||
Goal Goal::fromSAS(input::Parser<> &parser, const Variables &variables)
|
||||
{
|
||||
Goal goal;
|
||||
|
||||
|
@@ -11,7 +11,7 @@ namespace sas
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
InitialState InitialState::fromSAS(utils::Parser<> &parser, const Variables &variables)
|
||||
InitialState InitialState::fromSAS(input::Parser<> &parser, const Variables &variables)
|
||||
{
|
||||
InitialState initialState;
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/utils/ParserException.h>
|
||||
#include <plasp/input/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -15,7 +15,7 @@ namespace sas
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MutexGroup MutexGroup::fromSAS(utils::Parser<> &parser, const Variables &variables)
|
||||
MutexGroup MutexGroup::fromSAS(input::Parser<> &parser, const Variables &variables)
|
||||
{
|
||||
MutexGroup mutexGroup;
|
||||
|
||||
@@ -29,7 +29,7 @@ MutexGroup MutexGroup::fromSAS(utils::Parser<> &parser, const Variables &variabl
|
||||
mutexGroup.m_facts.emplace_back(Fact::fromSAS(parser, variables));
|
||||
|
||||
if (mutexGroup.m_facts[j].value() == Value::None)
|
||||
throw utils::ParserException(parser.coordinate(), "mutex groups must not contain <none of those> values");
|
||||
throw input::ParserException(parser.location(), "mutex groups must not contain <none of those> values");
|
||||
}
|
||||
|
||||
parser.expect<std::string>("end_mutex_group");
|
||||
|
@@ -3,8 +3,8 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/sas/VariableTransition.h>
|
||||
#include <plasp/utils/Formatting.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -17,7 +17,7 @@ namespace sas
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Operator Operator::fromSAS(utils::Parser<> &parser, const Variables &variables)
|
||||
Operator Operator::fromSAS(input::Parser<> &parser, const Variables &variables)
|
||||
{
|
||||
Operator operator_;
|
||||
|
||||
@@ -46,11 +46,11 @@ Operator Operator::fromSAS(utils::Parser<> &parser, const Variables &variables)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Operator::printPredicateAsASP(utils::LogStream &outputStream) const
|
||||
void Operator::printPredicateAsASP(output::ColorStream &stream) const
|
||||
{
|
||||
outputStream << utils::Keyword("action") << "(";
|
||||
m_predicate.printAsASP(outputStream);
|
||||
outputStream << ")";
|
||||
stream << output::Keyword("action") << "(";
|
||||
m_predicate.printAsASP(stream);
|
||||
stream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -4,8 +4,8 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
#include <plasp/utils/Formatting.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/output/Formatting.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace sas
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Predicate Predicate::fromSAS(utils::Parser<> &parser)
|
||||
Predicate Predicate::fromSAS(input::Parser<> &parser)
|
||||
{
|
||||
Predicate predicate;
|
||||
|
||||
@@ -43,7 +43,7 @@ Predicate Predicate::fromSAS(utils::Parser<> &parser)
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
throw utils::ParserException(parser.coordinate(), "could not parse operator predicate");
|
||||
throw input::ParserException(parser.location(), "could not parse operator predicate");
|
||||
}
|
||||
|
||||
return predicate;
|
||||
@@ -65,38 +65,38 @@ const Predicate::Arguments &Predicate::arguments() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Predicate::printAsSAS(utils::LogStream &outputStream) const
|
||||
void Predicate::printAsSAS(output::ColorStream &stream) const
|
||||
{
|
||||
if (m_arguments.empty())
|
||||
{
|
||||
outputStream << m_name;
|
||||
stream << m_name;
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_arguments.size(); i++)
|
||||
{
|
||||
if (i > 0)
|
||||
outputStream << " ";
|
||||
stream << " ";
|
||||
|
||||
outputStream << m_arguments[i];
|
||||
stream << m_arguments[i];
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Predicate::printAsASP(utils::LogStream &outputStream) const
|
||||
void Predicate::printAsASP(output::ColorStream &stream) const
|
||||
{
|
||||
if (m_arguments.empty())
|
||||
{
|
||||
outputStream << utils::String(m_name);
|
||||
stream << output::String(m_name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << "(" << utils::String(m_name);
|
||||
stream << "(" << output::String(m_name.c_str());
|
||||
|
||||
for (size_t i = 0; i < m_arguments.size(); i++)
|
||||
outputStream << ", " << utils::String(m_arguments[i]);
|
||||
stream << ", " << output::String(m_arguments[i].c_str());
|
||||
|
||||
outputStream << ")";
|
||||
stream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <plasp/sas/TranslatorASP.h>
|
||||
|
||||
#include <plasp/utils/Formatting.h>
|
||||
#include <plasp/output/Formatting.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -13,9 +13,9 @@ namespace sas
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TranslatorASP::TranslatorASP(const Description &description, utils::LogStream &ostream)
|
||||
TranslatorASP::TranslatorASP(const Description &description, output::ColorStream &outputStream)
|
||||
: m_description(description),
|
||||
m_outputStream(ostream)
|
||||
m_outputStream(outputStream)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,30 +56,30 @@ void TranslatorASP::translate() const
|
||||
|
||||
void TranslatorASP::translateRequirements() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("feature requirements") << std::endl;
|
||||
m_outputStream << output::Heading2("feature requirements") << std::endl;
|
||||
|
||||
if (m_description.usesActionCosts())
|
||||
m_outputStream << utils::RuleName("requires") << "(" << utils::Keyword("feature") << "(" << utils::Reserved("actionCosts") << "))." << std::endl;
|
||||
m_outputStream << output::Function("requires") << "(" << output::Keyword("feature") << "(" << output::Reserved("actionCosts") << "))." << std::endl;
|
||||
|
||||
if (m_description.usesAxiomRules())
|
||||
m_outputStream << utils::RuleName("requires") << "(" << utils::Keyword("feature") << "(" << utils::Reserved("axiomRules") << "))." << std::endl;
|
||||
m_outputStream << output::Function("requires") << "(" << output::Keyword("feature") << "(" << output::Reserved("axiomRules") << "))." << std::endl;
|
||||
|
||||
if (m_description.usesConditionalEffects())
|
||||
m_outputStream << utils::RuleName("requires") << "(" << utils::Keyword("feature") << "(" << utils::Reserved("conditionalEffects") << "))." << std::endl;
|
||||
m_outputStream << output::Function("requires") << "(" << output::Keyword("feature") << "(" << output::Reserved("conditionalEffects") << "))." << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TranslatorASP::translateInitialState() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("initial state") << std::endl;
|
||||
m_outputStream << output::Heading2("initial state") << std::endl;
|
||||
|
||||
const auto &initialStateFacts = m_description.initialState().facts();
|
||||
|
||||
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
||||
[&](const auto &fact)
|
||||
{
|
||||
m_outputStream << utils::RuleName("initialState") << "(";
|
||||
m_outputStream << output::Function("initialState") << "(";
|
||||
fact.variable().printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
fact.value().printAsASPPredicate(m_outputStream);
|
||||
@@ -91,14 +91,14 @@ void TranslatorASP::translateInitialState() const
|
||||
|
||||
void TranslatorASP::translateGoal() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("goal") << std::endl;
|
||||
m_outputStream << output::Heading2("goal") << std::endl;
|
||||
|
||||
const auto &goalFacts = m_description.goal().facts();
|
||||
|
||||
std::for_each(goalFacts.cbegin(), goalFacts.cend(),
|
||||
[&](const auto &fact)
|
||||
{
|
||||
m_outputStream << utils::RuleName("goal") << "(";
|
||||
m_outputStream << output::Function("goal") << "(";
|
||||
fact.variable().printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
fact.value().printAsASPPredicate(m_outputStream);
|
||||
@@ -110,7 +110,7 @@ void TranslatorASP::translateGoal() const
|
||||
|
||||
void TranslatorASP::translateVariables() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("variables");
|
||||
m_outputStream << output::Heading2("variables");
|
||||
|
||||
const auto &variables = m_description.variables();
|
||||
|
||||
@@ -121,14 +121,14 @@ void TranslatorASP::translateVariables() const
|
||||
|
||||
BOOST_ASSERT(!values.empty());
|
||||
|
||||
m_outputStream << std::endl << utils::RuleName("variable") << "(";
|
||||
m_outputStream << std::endl << output::Function("variable") << "(";
|
||||
variable.printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ")." << std::endl;
|
||||
|
||||
std::for_each(values.cbegin(), values.cend(),
|
||||
[&](const auto &value)
|
||||
{
|
||||
m_outputStream << utils::RuleName("contains") << "(";
|
||||
m_outputStream << output::Function("contains") << "(";
|
||||
variable.printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
value.printAsASPPredicate(m_outputStream);
|
||||
@@ -141,7 +141,7 @@ void TranslatorASP::translateVariables() const
|
||||
|
||||
void TranslatorASP::translateActions() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("actions");
|
||||
m_outputStream << output::Heading2("actions");
|
||||
|
||||
const auto &operators = m_description.operators();
|
||||
|
||||
@@ -150,7 +150,7 @@ void TranslatorASP::translateActions() const
|
||||
std::for_each(operators.cbegin(), operators.cend(),
|
||||
[&](const auto &operator_)
|
||||
{
|
||||
m_outputStream << std::endl << utils::RuleName("action") << "(";
|
||||
m_outputStream << std::endl << output::Function("action") << "(";
|
||||
operator_.printPredicateAsASP(m_outputStream);
|
||||
m_outputStream << ")." << std::endl;
|
||||
|
||||
@@ -159,7 +159,7 @@ void TranslatorASP::translateActions() const
|
||||
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
||||
[&](const auto &precondition)
|
||||
{
|
||||
m_outputStream << utils::RuleName("precondition") << "(";
|
||||
m_outputStream << output::Function("precondition") << "(";
|
||||
operator_.printPredicateAsASP(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
precondition.variable().printNameAsASPPredicate(m_outputStream);
|
||||
@@ -175,13 +175,13 @@ void TranslatorASP::translateActions() const
|
||||
{
|
||||
const auto &conditions = effect.conditions();
|
||||
|
||||
m_outputStream << utils::RuleName("postcondition") << "(";
|
||||
m_outputStream << output::Function("postcondition") << "(";
|
||||
operator_.printPredicateAsASP(m_outputStream);
|
||||
|
||||
if (conditions.empty())
|
||||
m_outputStream << ", " << utils::Keyword("effect") << "(" << utils::Reserved("unconditional") << "), ";
|
||||
m_outputStream << ", " << output::Keyword("effect") << "(" << output::Reserved("unconditional") << "), ";
|
||||
else
|
||||
m_outputStream << ", " << utils::Keyword("effect") << "(" << utils::Number(std::to_string(currentEffectID)) << "), ";
|
||||
m_outputStream << ", " << output::Keyword("effect") << "(" << output::Number<decltype(currentEffectID)>(currentEffectID) << "), ";
|
||||
|
||||
effect.postcondition().variable().printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
@@ -193,8 +193,8 @@ void TranslatorASP::translateActions() const
|
||||
{
|
||||
// Conditions of conditional effects
|
||||
m_outputStream
|
||||
<< utils::RuleName("precondition") << "("
|
||||
<< utils::Keyword("effect") << "(" << utils::Number(std::to_string(currentEffectID)) << "), ";
|
||||
<< output::Function("precondition") << "("
|
||||
<< output::Keyword("effect") << "(" << output::Number<decltype(currentEffectID)>(currentEffectID) << "), ";
|
||||
condition.variable().printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
condition.value().printAsASPPredicate(m_outputStream);
|
||||
@@ -205,9 +205,9 @@ void TranslatorASP::translateActions() const
|
||||
currentEffectID++;
|
||||
});
|
||||
|
||||
m_outputStream << utils::RuleName("costs") << "(";
|
||||
m_outputStream << output::Function("costs") << "(";
|
||||
operator_.printPredicateAsASP(m_outputStream);
|
||||
m_outputStream << ", " << utils::Number(std::to_string(operator_.costs())) << ")." << std::endl;
|
||||
m_outputStream << ", " << output::Number<decltype(operator_.costs())>(operator_.costs()) << ")." << std::endl;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ void TranslatorASP::translateActions() const
|
||||
|
||||
void TranslatorASP::translateMutexes() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("mutex groups");
|
||||
m_outputStream << output::Heading2("mutex groups");
|
||||
|
||||
const auto &mutexGroups = m_description.mutexGroups();
|
||||
|
||||
@@ -229,9 +229,9 @@ void TranslatorASP::translateMutexes() const
|
||||
|
||||
m_outputStream
|
||||
<< std::endl
|
||||
<< utils::RuleName("mutexGroup") << "("
|
||||
<< utils::Keyword("mutexGroup") << "("
|
||||
<< utils::Number(mutexGroupID)
|
||||
<< output::Function("mutexGroup") << "("
|
||||
<< output::Keyword("mutexGroup") << "("
|
||||
<< output::Number<decltype(mutexGroupID)>(mutexGroupID)
|
||||
<< "))." << std::endl;
|
||||
|
||||
const auto &facts = mutexGroup.facts();
|
||||
@@ -239,7 +239,7 @@ void TranslatorASP::translateMutexes() const
|
||||
std::for_each(facts.cbegin(), facts.cend(),
|
||||
[&](const auto &fact)
|
||||
{
|
||||
m_outputStream << utils::RuleName("contains") << "(" << utils::Keyword("mutexGroup") << "(" << utils::Number(mutexGroupID) << "), ";
|
||||
m_outputStream << output::Function("contains") << "(" << output::Keyword("mutexGroup") << "(" << output::Number<decltype(mutexGroupID)>(mutexGroupID) << "), ";
|
||||
fact.variable().printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
fact.value().printAsASPPredicate(m_outputStream);
|
||||
@@ -252,7 +252,7 @@ void TranslatorASP::translateMutexes() const
|
||||
|
||||
void TranslatorASP::translateAxiomRules() const
|
||||
{
|
||||
m_outputStream << utils::Heading2("axiom rules");
|
||||
m_outputStream << output::Heading2("axiom rules");
|
||||
|
||||
const auto &axiomRules = m_description.axiomRules();
|
||||
|
||||
@@ -266,9 +266,9 @@ void TranslatorASP::translateAxiomRules() const
|
||||
|
||||
m_outputStream
|
||||
<< std::endl
|
||||
<< utils::RuleName("axiomRule") << "("
|
||||
<< utils::Keyword("axiomRule") << "("
|
||||
<< utils::Number(axiomRuleID)
|
||||
<< output::Function("axiomRule") << "("
|
||||
<< output::Keyword("axiomRule") << "("
|
||||
<< output::Number<decltype(axiomRuleID)>(axiomRuleID)
|
||||
<< "))." << std::endl;
|
||||
|
||||
const auto &conditions = axiomRule.conditions();
|
||||
@@ -277,8 +277,8 @@ void TranslatorASP::translateAxiomRules() const
|
||||
[&](const auto &condition)
|
||||
{
|
||||
m_outputStream
|
||||
<< utils::RuleName("precondition") << "("
|
||||
<< utils::Keyword("axiomRule") << "(" << utils::Number(axiomRuleID) << "), ";
|
||||
<< output::Function("precondition") << "("
|
||||
<< output::Keyword("axiomRule") << "(" << output::Number<decltype(axiomRuleID)>(axiomRuleID) << "), ";
|
||||
condition.variable().printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
condition.value().printAsASPPredicate(m_outputStream);
|
||||
@@ -288,9 +288,9 @@ void TranslatorASP::translateAxiomRules() const
|
||||
const auto &postcondition = axiomRule.postcondition();
|
||||
|
||||
m_outputStream
|
||||
<< utils::RuleName("postcondition") << "("
|
||||
<< utils::Keyword("axiomRule") << "(" << utils::Number(axiomRuleID) << "), "
|
||||
<< utils::Keyword("effect") << "(" << utils::Reserved("unconditional") << "), ";
|
||||
<< output::Function("postcondition") << "("
|
||||
<< output::Keyword("axiomRule") << "(" << output::Number<decltype(axiomRuleID)>(axiomRuleID) << "), "
|
||||
<< output::Keyword("effect") << "(" << output::Reserved("unconditional") << "), ";
|
||||
postcondition.variable().printNameAsASPPredicate(m_outputStream);
|
||||
m_outputStream << ", ";
|
||||
postcondition.value().printAsASPPredicate(m_outputStream);
|
||||
|
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Formatting.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -54,7 +54,7 @@ Value Value::negated() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Value Value::fromSAS(utils::Parser<> &parser)
|
||||
Value Value::fromSAS(input::Parser<> &parser)
|
||||
{
|
||||
const auto sasSign = parser.parse<std::string>();
|
||||
|
||||
@@ -74,7 +74,7 @@ Value Value::fromSAS(utils::Parser<> &parser)
|
||||
else if (sasSign == "NegatedAtom")
|
||||
value.m_sign = Value::Sign::Negative;
|
||||
else
|
||||
throw utils::ParserException(parser.coordinate(), "invalid value sign “" + sasSign + "”");
|
||||
throw input::ParserException(parser.location(), "invalid value sign “" + sasSign + "”");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -90,7 +90,7 @@ Value Value::fromSAS(utils::Parser<> &parser)
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
throw utils::ParserException(parser.coordinate(), std::string("could not parse variable value (") + e.what() + ")");
|
||||
throw input::ParserException(parser.location(), std::string("could not parse variable value (") + e.what() + ")");
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -98,7 +98,7 @@ Value Value::fromSAS(utils::Parser<> &parser)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const Value &Value::referenceFromSAS(utils::Parser<> &parser, const Variable &variable)
|
||||
const Value &Value::referenceFromSAS(input::Parser<> &parser, const Variable &variable)
|
||||
{
|
||||
const auto valueID = parser.parse<int>();
|
||||
|
||||
@@ -106,7 +106,7 @@ const Value &Value::referenceFromSAS(utils::Parser<> &parser, const Variable &va
|
||||
return Value::Any;
|
||||
|
||||
if (valueID < 0 || static_cast<size_t>(valueID) >= variable.values().size())
|
||||
throw utils::ParserException(parser.coordinate(), "value index out of range (variable " + variable.name() + ", index " + std::to_string(valueID) + ")");
|
||||
throw input::ParserException(parser.location(), "value index out of range (variable " + variable.name() + ", index " + std::to_string(valueID) + ")");
|
||||
|
||||
return variable.values()[valueID];
|
||||
}
|
||||
@@ -127,32 +127,32 @@ const std::string &Value::name() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Value::printAsASPPredicate(utils::LogStream &outputStream) const
|
||||
void Value::printAsASPPredicate(output::ColorStream &stream) const
|
||||
{
|
||||
// TODO: do not compare by value
|
||||
if (*this == Value::None)
|
||||
{
|
||||
outputStream << utils::Keyword("value") << "(" << utils::Reserved("none") << ")";
|
||||
stream << output::Keyword("value") << "(" << output::Reserved("none") << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << utils::Keyword("value") << "(" << utils::String(m_name) << ", "
|
||||
<< (m_sign == Sign::Positive ? utils::Boolean("true") : utils::Boolean("false")) << ")";
|
||||
stream << output::Keyword("value") << "(" << output::String(m_name.c_str()) << ", "
|
||||
<< (m_sign == Sign::Positive ? output::Boolean("true") : output::Boolean("false")) << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Value::printAsSAS(utils::LogStream &outputStream) const
|
||||
void Value::printAsSAS(output::ColorStream &stream) const
|
||||
{
|
||||
if (m_sign == Value::Sign::Positive)
|
||||
outputStream << "Atom ";
|
||||
stream << "Atom ";
|
||||
else
|
||||
outputStream << "NegatedAtom ";
|
||||
stream << "NegatedAtom ";
|
||||
|
||||
outputStream << m_name;
|
||||
stream << m_name;
|
||||
|
||||
if (!m_hasArguments)
|
||||
outputStream << "()";
|
||||
stream << "()";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/utils/Formatting.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/output/Formatting.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -23,7 +23,7 @@ Variable::Variable()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Variable Variable::fromSAS(utils::Parser<> &parser)
|
||||
Variable Variable::fromSAS(input::Parser<> &parser)
|
||||
{
|
||||
Variable variable;
|
||||
|
||||
@@ -42,7 +42,7 @@ Variable Variable::fromSAS(utils::Parser<> &parser)
|
||||
|
||||
// <none of those> values are only allowed at the end
|
||||
if (j < numberOfValues - 1 && variable.m_values[j] == Value::None)
|
||||
throw utils::ParserException(parser.coordinate(), "<none of those> value must be the last value of a variable");
|
||||
throw input::ParserException(parser.location(), "<none of those> value must be the last value of a variable");
|
||||
}
|
||||
|
||||
parser.expect<std::string>("end_variable");
|
||||
@@ -52,20 +52,20 @@ Variable Variable::fromSAS(utils::Parser<> &parser)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Variable::printNameAsASPPredicate(utils::LogStream &outputStream) const
|
||||
void Variable::printNameAsASPPredicate(output::ColorStream &stream) const
|
||||
{
|
||||
// TODO: assert that name is a number indeed
|
||||
outputStream << utils::Keyword("variable") << "(" << utils::Number(m_name) << ")";
|
||||
stream << output::Keyword("variable") << "(" << output::Number<std::string>(m_name) << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const Variable &Variable::referenceFromSAS(utils::Parser<> &parser, const Variables &variables)
|
||||
const Variable &Variable::referenceFromSAS(input::Parser<> &parser, const Variables &variables)
|
||||
{
|
||||
const auto variableID = parser.parse<size_t>();
|
||||
|
||||
if (variableID >= variables.size())
|
||||
throw utils::ParserException(parser.coordinate(), "variable index out of range (index " + std::to_string(variableID) + ")");
|
||||
throw input::ParserException(parser.location(), "variable index out of range (index " + std::to_string(variableID) + ")");
|
||||
|
||||
return variables[variableID];
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ VariableTransition::VariableTransition()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
VariableTransition VariableTransition::fromSAS(utils::Parser<> &parser, const Variables &variables)
|
||||
VariableTransition VariableTransition::fromSAS(input::Parser<> &parser, const Variables &variables)
|
||||
{
|
||||
VariableTransition variableTransition;
|
||||
|
||||
|
@@ -1,143 +0,0 @@
|
||||
#include <plasp/utils/Logger.h>
|
||||
|
||||
#include <plasp/utils/Formatting.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Logger
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger()
|
||||
: m_outputStream(StandardStream::Out),
|
||||
m_errorStream(StandardStream::Err),
|
||||
m_warningLevel{Logger::WarningLevel::Show}
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger(const Logger &other)
|
||||
: m_outputStream{other.m_outputStream},
|
||||
m_errorStream{other.m_errorStream},
|
||||
m_warningLevel{other.m_warningLevel}
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger &Logger::operator=(const Logger &other)
|
||||
{
|
||||
m_outputStream = other.m_outputStream;
|
||||
m_errorStream = other.m_errorStream;
|
||||
m_warningLevel = other.m_warningLevel;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger::Logger(Logger &&other)
|
||||
: m_outputStream{std::move(other.m_outputStream)},
|
||||
m_errorStream{std::move(other.m_errorStream)},
|
||||
m_warningLevel{other.m_warningLevel}
|
||||
{
|
||||
other.m_warningLevel = WarningLevel::Show;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Logger &Logger::operator=(Logger &&other)
|
||||
{
|
||||
m_outputStream = std::move(other.m_outputStream);
|
||||
m_errorStream = std::move(other.m_errorStream);
|
||||
m_warningLevel = other.m_warningLevel;
|
||||
|
||||
other.m_warningLevel = WarningLevel::Show;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &Logger::outputStream()
|
||||
{
|
||||
return m_outputStream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &Logger::errorStream()
|
||||
{
|
||||
return m_errorStream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::setWarningLevel(WarningLevel warningLevel)
|
||||
{
|
||||
m_warningLevel = warningLevel;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::setColorPolicy(LogStream::ColorPolicy colorPolicy)
|
||||
{
|
||||
m_outputStream.setColorPolicy(colorPolicy);
|
||||
m_errorStream.setColorPolicy(colorPolicy);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::logError(const std::string &message)
|
||||
{
|
||||
m_errorStream
|
||||
<< Format(Color::Red, FontWeight::Bold) << "error:"
|
||||
<< ResetFormat() << " "
|
||||
<< Format(Color::White, FontWeight::Bold) << message
|
||||
<< ResetFormat() << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::logError(const StreamCoordinate &coordinate, const std::string &message)
|
||||
{
|
||||
m_errorStream
|
||||
<< Format(Color::White, FontWeight::Bold) << coordinate.sectionName << ":"
|
||||
<< std::to_string(coordinate.row) + ":" + std::to_string(coordinate.column) << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< Format(Color::Red, FontWeight::Bold) << "error:"
|
||||
<< ResetFormat() << " "
|
||||
<< Format(Color::White, FontWeight::Bold) << message
|
||||
<< ResetFormat() << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::logWarning(const StreamCoordinate &coordinate, const std::string &message)
|
||||
{
|
||||
if (m_warningLevel == WarningLevel::Ignore)
|
||||
return;
|
||||
|
||||
if (m_warningLevel == WarningLevel::Error)
|
||||
throw ParserException(coordinate, message);
|
||||
|
||||
m_errorStream
|
||||
<< Format(Color::White, FontWeight::Bold) << coordinate.sectionName << ":"
|
||||
<< std::to_string(coordinate.row) + ":" + std::to_string(coordinate.column) << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< Format(Color::Magenta, FontWeight::Bold) << "warning:"
|
||||
<< ResetFormat() << " "
|
||||
<< Format(Color::White, FontWeight::Bold) << message
|
||||
<< ResetFormat() << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user