Refactoring to use cleaner output implementation.
This commit is contained in:
parent
9b49b8ebe7
commit
c4e19dddae
50
app/main.cpp
50
app/main.cpp
@ -5,12 +5,12 @@
|
|||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
#include <plasp/LanguageDetection.h>
|
#include <plasp/LanguageDetection.h>
|
||||||
|
#include <plasp/output/ColorStream.h>
|
||||||
|
#include <plasp/output/TranslatorException.h>
|
||||||
#include <plasp/pddl/Description.h>
|
#include <plasp/pddl/Description.h>
|
||||||
#include <plasp/pddl/TranslatorASP.h>
|
#include <plasp/pddl/TranslatorASP.h>
|
||||||
#include <plasp/sas/Description.h>
|
#include <plasp/sas/Description.h>
|
||||||
#include <plasp/sas/TranslatorASP.h>
|
#include <plasp/sas/TranslatorASP.h>
|
||||||
#include <plasp/utils/LogStream.h>
|
|
||||||
#include <plasp/utils/TranslatorException.h>
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -39,7 +39,7 @@ int main(int argc, char **argv)
|
|||||||
std::cout << description;
|
std::cout << description;
|
||||||
};
|
};
|
||||||
|
|
||||||
plasp::utils::Logger logger;
|
plasp::output::Logger logger;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -52,7 +52,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
catch (const po::error &e)
|
catch (const po::error &e)
|
||||||
{
|
{
|
||||||
logger.logError(e.what());
|
logger.log(plasp::output::Priority::Error, e.what());
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
printHelp();
|
printHelp();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -72,31 +72,32 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
const auto warningLevel = variablesMap["warning-level"].as<std::string>();
|
const auto warningLevel = variablesMap["warning-level"].as<std::string>();
|
||||||
|
|
||||||
if (warningLevel == "error")
|
// TODO: reimplement
|
||||||
logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Error);
|
/*if (warningLevel == "error")
|
||||||
|
logger.setWarningLevel(plasp::output::Logger::WarningLevel::Error);
|
||||||
else if (warningLevel == "ignore")
|
else if (warningLevel == "ignore")
|
||||||
logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Ignore);
|
logger.setWarningLevel(plasp::output::Logger::WarningLevel::Ignore);
|
||||||
else if (warningLevel == "show")
|
else if (warningLevel == "show")
|
||||||
logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Show);
|
logger.setWarningLevel(plasp::output::Logger::WarningLevel::Show);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.logError("unknown warning level “" + warningLevel + "”");
|
logger.log(plasp::output::Priority::Error, "unknown warning level “" + warningLevel + "”");
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
printHelp();
|
printHelp();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
const auto colorPolicy = variablesMap["color"].as<std::string>();
|
const auto colorPolicy = variablesMap["color"].as<std::string>();
|
||||||
|
|
||||||
if (colorPolicy == "auto")
|
if (colorPolicy == "auto")
|
||||||
logger.setColorPolicy(plasp::utils::LogStream::ColorPolicy::Auto);
|
logger.setColorPolicy(plasp::output::ColorStream::ColorPolicy::Auto);
|
||||||
else if (colorPolicy == "never")
|
else if (colorPolicy == "never")
|
||||||
logger.setColorPolicy(plasp::utils::LogStream::ColorPolicy::Never);
|
logger.setColorPolicy(plasp::output::ColorStream::ColorPolicy::Never);
|
||||||
else if (colorPolicy == "always")
|
else if (colorPolicy == "always")
|
||||||
logger.setColorPolicy(plasp::utils::LogStream::ColorPolicy::Always);
|
logger.setColorPolicy(plasp::output::ColorStream::ColorPolicy::Always);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.logError("unknown color policy “" + colorPolicy + "”");
|
logger.log(plasp::output::Priority::Error, "unknown color policy “" + colorPolicy + "”");
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
printHelp();
|
printHelp();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -104,7 +105,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plasp::utils::Parser<plasp::utils::CaseInsensitiveParserPolicy> parser;
|
plasp::input::Parser<plasp::input::CaseInsensitiveParserPolicy> parser;
|
||||||
|
|
||||||
if (variablesMap.count("input"))
|
if (variablesMap.count("input"))
|
||||||
{
|
{
|
||||||
@ -135,7 +136,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (language == plasp::Language::Type::Unknown)
|
if (language == plasp::Language::Type::Unknown)
|
||||||
{
|
{
|
||||||
logger.logError("unknown input language");
|
logger.log(plasp::output::Priority::Error, "unknown input language");
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
printHelp();
|
printHelp();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -143,10 +144,9 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (language == plasp::Language::Type::PDDL)
|
if (language == plasp::Language::Type::PDDL)
|
||||||
{
|
{
|
||||||
auto pddlLogger = logger;
|
auto context = plasp::pddl::Context(std::move(parser), logger);
|
||||||
auto context = plasp::pddl::Context(std::move(parser), std::move(pddlLogger));
|
auto description = plasp::pddl::Description::fromContext(context);
|
||||||
auto description = plasp::pddl::Description::fromContext(std::move(context));
|
const auto translator = plasp::pddl::TranslatorASP(description, logger.outputStream());
|
||||||
const auto translator = plasp::pddl::TranslatorASP(description, description.context().logger.outputStream());
|
|
||||||
translator.translate();
|
translator.translate();
|
||||||
}
|
}
|
||||||
else if (language == plasp::Language::Type::SAS)
|
else if (language == plasp::Language::Type::SAS)
|
||||||
@ -156,19 +156,19 @@ int main(int argc, char **argv)
|
|||||||
translator.translate();
|
translator.translate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const plasp::utils::ParserException &e)
|
catch (const plasp::input::ParserException &e)
|
||||||
{
|
{
|
||||||
logger.logError(e.coordinate(), e.message());
|
logger.log(plasp::output::Priority::Error, e.location(), e.message().c_str());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
catch (const plasp::utils::TranslatorException &e)
|
catch (const plasp::output::TranslatorException &e)
|
||||||
{
|
{
|
||||||
logger.logError(e.what());
|
logger.log(plasp::output::Priority::Error, e.what());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
logger.logError(e.what());
|
logger.log(plasp::output::Priority::Error, e.what());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef __PLASP__LANGUAGE_H
|
#ifndef __PLASP__LANGUAGE_H
|
||||||
#define __PLASP__LANGUAGE_H
|
#define __PLASP__LANGUAGE_H
|
||||||
|
|
||||||
#include <plasp/utils/Parser.h>
|
#include <string>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define __PLASP__LANGUAGE_DETECTION_H
|
#define __PLASP__LANGUAGE_DETECTION_H
|
||||||
|
|
||||||
#include <plasp/Language.h>
|
#include <plasp/Language.h>
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/input/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -13,7 +13,7 @@ namespace plasp
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Language::Type detectLanguage(utils::Parser<utils::CaseInsensitiveParserPolicy> &parser)
|
Language::Type detectLanguage(input::Parser<input::CaseInsensitiveParserPolicy> &parser)
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
parser.skipWhiteSpace();
|
||||||
|
|
||||||
|
@ -1,24 +1,29 @@
|
|||||||
#ifndef __PLASP__UTILS__STREAM_COORDINATE_H
|
#ifndef __PLASP__INPUT__LOCATION_H
|
||||||
#define __PLASP__UTILS__STREAM_COORDINATE_H
|
#define __PLASP__INPUT__LOCATION_H
|
||||||
|
|
||||||
#include <string>
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace utils
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// StreamCoordinate
|
// Location
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct StreamCoordinate
|
struct Location
|
||||||
{
|
{
|
||||||
std::string sectionName;
|
const char *sectionStart = nullptr;
|
||||||
size_t row;
|
const char *sectionEnd = nullptr;
|
||||||
size_t column;
|
|
||||||
|
std::size_t rowStart = -1;
|
||||||
|
std::size_t rowEnd = -1;
|
||||||
|
|
||||||
|
std::size_t columnStart = -1;
|
||||||
|
std::size_t columnEnd = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef __PLASP__UTILS__PARSER_H
|
#ifndef __PLASP__INPUT__PARSER_H
|
||||||
#define __PLASP__UTILS__PARSER_H
|
#define __PLASP__INPUT__PARSER_H
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
@ -8,14 +8,13 @@
|
|||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/utils/ParserPolicy.h>
|
#include <plasp/input/ParserPolicy.h>
|
||||||
#include <plasp/utils/Stream.h>
|
#include <plasp/input/Stream.h>
|
||||||
#include <plasp/utils/StreamCoordinate.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace utils
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
@ -30,7 +29,7 @@ struct Tag
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<class ParserPolicy = CaseSensitiveParserPolicy>
|
template<class ParserPolicy = CaseSensitiveParserPolicy>
|
||||||
class Parser: public Stream, public ParserPolicy
|
class Parser: public input::Stream, public ParserPolicy
|
||||||
{
|
{
|
||||||
template<class OtherParserPolicy>
|
template<class OtherParserPolicy>
|
||||||
friend class Parser;
|
friend class Parser;
|
||||||
@ -199,7 +198,7 @@ void Parser<ParserPolicy>::expect(const Type &expectedValue)
|
|||||||
std::stringstream message;
|
std::stringstream message;
|
||||||
message << "unexpected value, expected “" << expectedValue << "”";
|
message << "unexpected value, expected “" << expectedValue << "”";
|
||||||
|
|
||||||
throw ParserException(coordinate(), message.str());
|
throw ParserException(location(), message.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -402,7 +401,7 @@ uint64_t Parser<ParserPolicy>::parseIntegerBody()
|
|||||||
check();
|
check();
|
||||||
|
|
||||||
if (!std::isdigit(currentCharacter()))
|
if (!std::isdigit(currentCharacter()))
|
||||||
throw ParserException(coordinate(), "could not parse integer value");
|
throw ParserException(location(), "could not parse integer value");
|
||||||
|
|
||||||
uint64_t value = 0;
|
uint64_t value = 0;
|
||||||
|
|
||||||
@ -444,7 +443,7 @@ uint64_t Parser<ParserPolicy>::parseImpl(Tag<uint64_t>)
|
|||||||
skipWhiteSpace();
|
skipWhiteSpace();
|
||||||
|
|
||||||
if (currentCharacter() == '-')
|
if (currentCharacter() == '-')
|
||||||
throw ParserException(coordinate(), "expected unsigned integer, got signed one");
|
throw ParserException(location(), "expected unsigned integer, got signed one");
|
||||||
|
|
||||||
return parseIntegerBody();
|
return parseIntegerBody();
|
||||||
}
|
}
|
||||||
@ -478,7 +477,7 @@ bool Parser<ParserPolicy>::parseImpl(Tag<bool>)
|
|||||||
if (testAndSkip<char>('1'))
|
if (testAndSkip<char>('1'))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
throw ParserException(coordinate(), "could not parse Boolean value");
|
throw ParserException(location(), "could not parse Boolean value");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
72
include/plasp/input/ParserException.h
Normal file
72
include/plasp/input/ParserException.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#ifndef __PLASP__INPUT__PARSER_EXCEPTION_H
|
||||||
|
#define __PLASP__INPUT__PARSER_EXCEPTION_H
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <plasp/input/Location.h>
|
||||||
|
|
||||||
|
namespace plasp
|
||||||
|
{
|
||||||
|
namespace input
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// ParserException
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class ParserException: public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ParserException(const input::Location &location)
|
||||||
|
: ParserException(location, "unspecified parser error")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit ParserException(const input::Location &location, const char *message)
|
||||||
|
: ParserException(location, static_cast<std::string>(message))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit ParserException(const input::Location &location, const std::string &message)
|
||||||
|
: m_location{location},
|
||||||
|
m_message{message},
|
||||||
|
// TODO: refactor
|
||||||
|
m_plainMessage{std::string(m_location.sectionStart) + ":" + std::to_string(m_location.rowStart)
|
||||||
|
+ ":" + std::to_string(m_location.columnStart) + " " + m_message}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~ParserException() throw()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *what() const throw()
|
||||||
|
{
|
||||||
|
return m_plainMessage.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
const input::Location &location() const
|
||||||
|
{
|
||||||
|
return m_location;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &message() const
|
||||||
|
{
|
||||||
|
return m_message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
input::Location m_location;
|
||||||
|
std::string m_message;
|
||||||
|
std::string m_plainMessage;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,11 +1,11 @@
|
|||||||
#ifndef __PLASP__UTILS__PARSER_POLICY_H
|
#ifndef __PLASP__INPUT__PARSER_POLICY_H
|
||||||
#define __PLASP__UTILS__PARSER_POLICY_H
|
#define __PLASP__INPUT__PARSER_POLICY_H
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace utils
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef __PLASP__UTILS__STREAM_H
|
#ifndef __PLASP__INPUT__STREAM_H
|
||||||
#define __PLASP__UTILS__STREAM_H
|
#define __PLASP__INPUT__STREAM_H
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
@ -8,12 +8,11 @@
|
|||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/input/Location.h>
|
||||||
#include <plasp/utils/StreamCoordinate.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace utils
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -62,7 +61,7 @@ class Stream
|
|||||||
void reset();
|
void reset();
|
||||||
void seek(Position position);
|
void seek(Position position);
|
||||||
Position position() const;
|
Position position() const;
|
||||||
StreamCoordinate coordinate() const;
|
Location location() const;
|
||||||
|
|
||||||
char currentCharacter() const;
|
char currentCharacter() const;
|
||||||
void advance();
|
void advance();
|
294
include/plasp/output/ColorStream.h
Normal file
294
include/plasp/output/ColorStream.h
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
#ifndef __PLASP__OUTPUT__COLOR_STREAM_H
|
||||||
|
#define __PLASP__OUTPUT__COLOR_STREAM_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
namespace plasp
|
||||||
|
{
|
||||||
|
namespace output
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// ColorStream
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class ColorStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum class ColorPolicy
|
||||||
|
{
|
||||||
|
Never,
|
||||||
|
Auto,
|
||||||
|
Always
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
using CharacterType = std::ostream::char_type;
|
||||||
|
using TraitsType = std::ostream::traits_type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ColorStream(std::ostream &stream)
|
||||||
|
: m_stream{stream},
|
||||||
|
m_colorPolicy{ColorPolicy::Auto}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void setColorPolicy(ColorPolicy colorPolicy)
|
||||||
|
{
|
||||||
|
m_colorPolicy = colorPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool supportsColor() const
|
||||||
|
{
|
||||||
|
if (m_colorPolicy == ColorPolicy::Never)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (m_colorPolicy == ColorPolicy::Always)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (&m_stream == &std::cout)
|
||||||
|
return isatty(fileno(stdout));
|
||||||
|
|
||||||
|
if (&m_stream == &std::cerr)
|
||||||
|
return isatty(fileno(stderr));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &stream()
|
||||||
|
{
|
||||||
|
return m_stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ColorStream &operator<<(short value);
|
||||||
|
inline ColorStream &operator<<(unsigned short value);
|
||||||
|
inline ColorStream &operator<<(int value);
|
||||||
|
inline ColorStream &operator<<(unsigned int value);
|
||||||
|
inline ColorStream &operator<<(long value);
|
||||||
|
inline ColorStream &operator<<(unsigned long value);
|
||||||
|
inline ColorStream &operator<<(long long value);
|
||||||
|
inline ColorStream &operator<<(unsigned long long value);
|
||||||
|
inline ColorStream &operator<<(float value);
|
||||||
|
inline ColorStream &operator<<(double value);
|
||||||
|
inline ColorStream &operator<<(long double value);
|
||||||
|
inline ColorStream &operator<<(bool value);
|
||||||
|
inline ColorStream &operator<<(const void *value);
|
||||||
|
inline ColorStream &operator<<(const char *value);
|
||||||
|
inline ColorStream &operator<<(const signed char *value);
|
||||||
|
inline ColorStream &operator<<(const unsigned char *value);
|
||||||
|
inline ColorStream &operator<<(std::basic_streambuf<CharacterType, TraitsType> *sb);
|
||||||
|
inline ColorStream &operator<<(std::ios_base &(*func)(std::ios_base &));
|
||||||
|
inline ColorStream &operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &));
|
||||||
|
inline ColorStream &operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &));
|
||||||
|
|
||||||
|
inline ColorStream &operator<<(char value);
|
||||||
|
inline ColorStream &operator<<(signed char value);
|
||||||
|
inline ColorStream &operator<<(unsigned char value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::ostream &m_stream;
|
||||||
|
ColorPolicy m_colorPolicy;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(short value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(unsigned short value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(int value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(unsigned int value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(long value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(unsigned long value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(long long value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(unsigned long long value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(float value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(double value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(long double value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(bool value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(const void *value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(const char *value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(const signed char *value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(const unsigned char *value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(std::basic_streambuf<CharacterType, TraitsType>* sb)
|
||||||
|
{
|
||||||
|
m_stream << sb;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(std::ios_base &(*func)(std::ios_base &))
|
||||||
|
{
|
||||||
|
m_stream << func;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &))
|
||||||
|
{
|
||||||
|
m_stream << func;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &))
|
||||||
|
{
|
||||||
|
m_stream << func;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<class CharacterType, class Traits, class Allocator>
|
||||||
|
inline ColorStream &operator<<(ColorStream &colorStream, const std::basic_string<CharacterType, Traits, Allocator> &string)
|
||||||
|
{
|
||||||
|
colorStream.stream() << string;
|
||||||
|
return colorStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(char value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(signed char value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ColorStream &ColorStream::operator<<(unsigned char value)
|
||||||
|
{
|
||||||
|
m_stream << value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,13 +1,13 @@
|
|||||||
#ifndef __PLASP__UTILS__FORMATTING_H
|
#ifndef __PLASP__OUTPUT__FORMATTING_H
|
||||||
#define __PLASP__UTILS__FORMATTING_H
|
#define __PLASP__OUTPUT__FORMATTING_H
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <plasp/utils/LogStream.h>
|
#include <plasp/output/ColorStream.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace utils
|
namespace output
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -18,21 +18,30 @@ namespace utils
|
|||||||
|
|
||||||
enum class Color
|
enum class Color
|
||||||
{
|
{
|
||||||
Black = 0,
|
Default = 39,
|
||||||
Red = 1,
|
Black = 30,
|
||||||
Green = 2,
|
Red = 31,
|
||||||
Yellow = 3,
|
Green = 32,
|
||||||
Blue = 4,
|
Yellow = 33,
|
||||||
Magenta = 5,
|
Blue = 34,
|
||||||
Cyan = 6,
|
Magenta = 35,
|
||||||
White = 7
|
Cyan = 36,
|
||||||
|
LightGray = 37,
|
||||||
|
DarkGray = 90,
|
||||||
|
LightRed = 91,
|
||||||
|
LightGreen = 92,
|
||||||
|
LightYellow = 93,
|
||||||
|
LightBlue = 94,
|
||||||
|
LightMagenta = 95,
|
||||||
|
LightCyan = 96,
|
||||||
|
White = 97
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
enum class FontWeight
|
enum class FontWeight
|
||||||
{
|
{
|
||||||
Normal = 0,
|
Normal = 21,
|
||||||
Bold = 1
|
Bold = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -40,25 +49,19 @@ enum class FontWeight
|
|||||||
|
|
||||||
struct Format
|
struct Format
|
||||||
{
|
{
|
||||||
Format(Color color, FontWeight fontWeight = FontWeight::Normal)
|
Color color = Color::Default;
|
||||||
: m_color{color},
|
FontWeight fontWeight = FontWeight::Normal;
|
||||||
m_fontWeight{fontWeight}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Color m_color;
|
|
||||||
FontWeight m_fontWeight;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const Format &format)
|
inline ColorStream &operator<<(ColorStream &stream, const Format &format)
|
||||||
{
|
{
|
||||||
if (!stream.supportsColor())
|
if (!stream.supportsColor())
|
||||||
return stream;
|
return stream;
|
||||||
|
|
||||||
const auto fontWeightCode = static_cast<size_t>(format.m_fontWeight);
|
const auto fontWeightCode = static_cast<int>(format.fontWeight);
|
||||||
const auto colorCode = 30 + static_cast<size_t>(format.m_color);
|
const auto colorCode = static_cast<int>(format.color);
|
||||||
|
|
||||||
return (stream << "\033[" << fontWeightCode << ";" << colorCode << "m");
|
return (stream << "\033[" << fontWeightCode << ";" << colorCode << "m");
|
||||||
}
|
}
|
||||||
@ -71,7 +74,7 @@ struct ResetFormat
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const ResetFormat &)
|
inline ColorStream &operator<<(ColorStream &stream, const ResetFormat &)
|
||||||
{
|
{
|
||||||
if (!stream.supportsColor())
|
if (!stream.supportsColor())
|
||||||
return stream;
|
return stream;
|
||||||
@ -81,196 +84,224 @@ inline LogStream &operator<<(LogStream &stream, const ResetFormat &)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct Token
|
struct Function
|
||||||
{
|
{
|
||||||
Token(const std::string &name)
|
Function(const char *name)
|
||||||
: name(name)
|
: name{name}
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
const std::string &name;
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct RuleName: public Token
|
inline ColorStream &operator<<(ColorStream &stream, const Function &function)
|
||||||
{
|
|
||||||
RuleName(const std::string &name)
|
|
||||||
: Token(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const RuleName &keyword)
|
|
||||||
{
|
{
|
||||||
return (stream
|
return (stream
|
||||||
<< utils::Format(utils::Color::White, utils::FontWeight::Bold)
|
<< Format({Color::White, FontWeight::Normal})
|
||||||
|
<< function.name
|
||||||
|
<< ResetFormat());
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct Keyword
|
||||||
|
{
|
||||||
|
Keyword(const char *name)
|
||||||
|
: name{name}
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *name;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
inline ColorStream &operator<<(ColorStream &stream, const Keyword &keyword)
|
||||||
|
{
|
||||||
|
return (stream
|
||||||
|
<< Format({Color::Blue, FontWeight::Normal})
|
||||||
<< keyword.name
|
<< keyword.name
|
||||||
<< utils::ResetFormat());
|
<< ResetFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct Keyword: public Token
|
struct Operator
|
||||||
{
|
{
|
||||||
Keyword(const std::string &name)
|
Operator(const char *name)
|
||||||
: Token(name)
|
: name{name}
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const Keyword &keyword)
|
inline ColorStream &operator<<(ColorStream &stream, const Operator &operator_)
|
||||||
{
|
{
|
||||||
return (stream
|
return (stream << operator_.name);
|
||||||
<< utils::Format(utils::Color::Blue, utils::FontWeight::Normal)
|
|
||||||
<< keyword.name
|
|
||||||
<< utils::ResetFormat());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct Number: public Token
|
template<typename T>
|
||||||
|
struct Number
|
||||||
{
|
{
|
||||||
Number(const std::string &name)
|
Number(T value)
|
||||||
: Token(name)
|
: value{value}
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
|
T value;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const Number &number)
|
template<typename T>
|
||||||
|
inline ColorStream &operator<<(ColorStream &stream, const Number<T> &number)
|
||||||
{
|
{
|
||||||
return (stream
|
return (stream
|
||||||
<< utils::Format(utils::Color::Yellow, utils::FontWeight::Normal)
|
<< Format({Color::Yellow, FontWeight::Normal})
|
||||||
<< number.name
|
<< number.value
|
||||||
<< utils::ResetFormat());
|
<< ResetFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct Variable: public Token
|
struct Variable
|
||||||
{
|
{
|
||||||
Variable(const std::string &name)
|
Variable(const char *name)
|
||||||
: Token(name)
|
: name{name}
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const Variable &variable)
|
inline ColorStream &operator<<(ColorStream &stream, const Variable &variable)
|
||||||
{
|
{
|
||||||
return (stream
|
return (stream
|
||||||
<< utils::Format(utils::Color::Green, utils::FontWeight::Bold)
|
<< Format({Color::Green, FontWeight::Bold})
|
||||||
<< variable.name
|
<< variable.name
|
||||||
<< utils::ResetFormat());
|
<< ResetFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct String: public Token
|
struct String
|
||||||
{
|
{
|
||||||
String(const std::string &name)
|
String(const char *content)
|
||||||
: Token(name)
|
: content{content}
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const char *content;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const String &string)
|
inline ColorStream &operator<<(ColorStream &stream, const String &string)
|
||||||
{
|
{
|
||||||
return (stream
|
return (stream
|
||||||
<< utils::Format(utils::Color::Green, utils::FontWeight::Normal)
|
<< Format({Color::Green, FontWeight::Normal})
|
||||||
<< "\"" << string.name << "\""
|
<< "\"" << string.content << "\""
|
||||||
<< utils::ResetFormat());
|
<< ResetFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct Boolean: public Token
|
struct Boolean
|
||||||
{
|
{
|
||||||
Boolean(const std::string &name)
|
Boolean(const char *value)
|
||||||
: Token(name)
|
: value{value}
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const char *value;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const Boolean &string)
|
inline ColorStream &operator<<(ColorStream &stream, const Boolean &boolean)
|
||||||
{
|
{
|
||||||
return (stream
|
return (stream
|
||||||
<< utils::Format(utils::Color::Red, utils::FontWeight::Normal)
|
<< Format({Color::Red, FontWeight::Normal})
|
||||||
<< string.name
|
<< boolean.value
|
||||||
<< utils::ResetFormat());
|
<< ResetFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct Reserved: public Token
|
struct Reserved
|
||||||
{
|
{
|
||||||
Reserved(const std::string &name)
|
Reserved(const char *name)
|
||||||
: Token(name)
|
: name{name}
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const Reserved &string)
|
inline ColorStream &operator<<(ColorStream &stream, const Reserved &reserved)
|
||||||
{
|
{
|
||||||
return (stream
|
return (stream
|
||||||
<< utils::Format(utils::Color::White, utils::FontWeight::Normal)
|
<< Format({Color::White, FontWeight::Normal})
|
||||||
<< string.name
|
<< reserved.name
|
||||||
<< utils::ResetFormat());
|
<< ResetFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct Heading1: public Token
|
struct Heading1
|
||||||
{
|
{
|
||||||
Heading1(const std::string &name)
|
Heading1(const char *content)
|
||||||
: Token(name)
|
: content{content}
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const char *content;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const Heading1 &heading1)
|
inline ColorStream &operator<<(ColorStream &stream, const Heading1 &heading1)
|
||||||
{
|
{
|
||||||
return (stream
|
return (stream
|
||||||
<< utils::Format(utils::Color::Blue, utils::FontWeight::Bold)
|
<< Format({Color::Blue, FontWeight::Bold})
|
||||||
<< "%---------------------------------------" << std::endl
|
<< "%---------------------------------------" << std::endl
|
||||||
<< "% " << heading1.name << std::endl
|
<< "% " << heading1.content << std::endl
|
||||||
<< "%---------------------------------------"
|
<< "%---------------------------------------"
|
||||||
<< utils::ResetFormat()
|
<< ResetFormat()
|
||||||
<< std::endl);
|
<< std::endl);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct Heading2: public Token
|
struct Heading2
|
||||||
{
|
{
|
||||||
Heading2(const std::string &name)
|
Heading2(const char *content)
|
||||||
: Token(name)
|
: content{content}
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const char *content;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const Heading2 &heading2)
|
inline ColorStream &operator<<(ColorStream &stream, const Heading2 &heading2)
|
||||||
{
|
{
|
||||||
return (stream
|
return (stream
|
||||||
<< utils::Format(utils::Color::Blue, utils::FontWeight::Bold)
|
<< Format({Color::Blue, FontWeight::Bold})
|
||||||
<< "% " << heading2.name
|
<< "% " << heading2.content
|
||||||
<< utils::ResetFormat());
|
<< ResetFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
include/plasp/output/Logger.h
Normal file
54
include/plasp/output/Logger.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#ifndef __PLASP__OUTPUT__LOGGER_H
|
||||||
|
#define __PLASP__OUTPUT__LOGGER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <plasp/input/Location.h>
|
||||||
|
#include <plasp/output/ColorStream.h>
|
||||||
|
#include <plasp/output/Priority.h>
|
||||||
|
|
||||||
|
namespace plasp
|
||||||
|
{
|
||||||
|
namespace output
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Logger
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class Logger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit Logger();
|
||||||
|
explicit Logger(ColorStream &&outputStream);
|
||||||
|
explicit Logger(ColorStream &&outputStream, ColorStream &&errorStream);
|
||||||
|
Logger(Logger &&other);
|
||||||
|
Logger &operator=(Logger &&other);
|
||||||
|
|
||||||
|
ColorStream &outputStream();
|
||||||
|
ColorStream &errorStream();
|
||||||
|
|
||||||
|
// The level from which on messages should be printed
|
||||||
|
void setLogPriority(Priority logPriority);
|
||||||
|
void setColorPolicy(ColorStream::ColorPolicy colorPolicy);
|
||||||
|
|
||||||
|
void log(Priority priority, const char *message);
|
||||||
|
void log(Priority priority, const std::string &message);
|
||||||
|
void log(Priority priority, const input::Location &location, const char *message);
|
||||||
|
void log(Priority priority, const input::Location &location, const std::string &message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ColorStream m_outputStream;
|
||||||
|
ColorStream m_errorStream;
|
||||||
|
|
||||||
|
Priority m_logPriority;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
66
include/plasp/output/Priority.h
Normal file
66
include/plasp/output/Priority.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#ifndef __PLASP__OUTPUT__PRIORITY_H
|
||||||
|
#define __PLASP__OUTPUT__PRIORITY_H
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
|
namespace plasp
|
||||||
|
{
|
||||||
|
namespace output
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Priority
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
enum class Priority
|
||||||
|
{
|
||||||
|
Debug,
|
||||||
|
Info,
|
||||||
|
Warning,
|
||||||
|
Error
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
inline constexpr const char *priorityName(Priority priority)
|
||||||
|
{
|
||||||
|
switch (priority)
|
||||||
|
{
|
||||||
|
case Priority::Debug:
|
||||||
|
return "debug";
|
||||||
|
case Priority::Info:
|
||||||
|
return "info";
|
||||||
|
case Priority::Warning:
|
||||||
|
return "warning";
|
||||||
|
case Priority::Error:
|
||||||
|
return "error";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
inline Priority priorityFromName(const char *priorityName)
|
||||||
|
{
|
||||||
|
if (std::strcmp(priorityName, "debug") == 0)
|
||||||
|
return Priority::Debug;
|
||||||
|
if (std::strcmp(priorityName, "info") == 0)
|
||||||
|
return Priority::Info;
|
||||||
|
if (std::strcmp(priorityName, "warning") == 0)
|
||||||
|
return Priority::Warning;
|
||||||
|
if (std::strcmp(priorityName, "error") == 0)
|
||||||
|
return Priority::Error;
|
||||||
|
|
||||||
|
throw std::runtime_error("unknown log priority");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef __PLASP__UTILS__TRANSLATOR_EXCEPTION_H
|
#ifndef __PLASP__OUTPUT__TRANSLATOR_EXCEPTION_H
|
||||||
#define __PLASP__UTILS__TRANSLATOR_EXCEPTION_H
|
#define __PLASP__OUTPUT__TRANSLATOR_EXCEPTION_H
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace utils
|
namespace output
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/pddl/Expression.h>
|
#include <plasp/pddl/Expression.h>
|
||||||
#include <plasp/pddl/expressions/Variable.h>
|
#include <plasp/pddl/expressions/Variable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/output/Logger.h>
|
||||||
#include <plasp/pddl/Parser.h>
|
#include <plasp/pddl/Parser.h>
|
||||||
#include <plasp/utils/Logger.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -25,19 +25,9 @@ class Context
|
|||||||
Context() = default;
|
Context() = default;
|
||||||
~Context() = default;
|
~Context() = default;
|
||||||
|
|
||||||
explicit Context(Parser &&otherParser)
|
explicit Context(Parser &&otherParser, output::Logger &otherLogger)
|
||||||
: parser{std::move(otherParser)}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit Context(utils::Logger &&otherLogger)
|
|
||||||
: logger{std::move(otherLogger)}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit Context(Parser &&otherParser, utils::Logger &&otherLogger)
|
|
||||||
: parser{std::move(otherParser)},
|
: parser{std::move(otherParser)},
|
||||||
logger{std::move(otherLogger)}
|
logger(otherLogger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,17 +36,11 @@ class Context
|
|||||||
|
|
||||||
Context(Context &&other)
|
Context(Context &&other)
|
||||||
: parser(std::move(other.parser)),
|
: parser(std::move(other.parser)),
|
||||||
logger(std::move(other.logger))
|
logger(other.logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Context &operator=(Context &&other)
|
Context &operator=(Context &&other) = delete;
|
||||||
{
|
|
||||||
parser = std::move(other.parser);
|
|
||||||
logger = std::move(other.logger);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr static const char *auxiliaryPrefix()
|
constexpr static const char *auxiliaryPrefix()
|
||||||
{
|
{
|
||||||
@ -64,7 +48,7 @@ class Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
Parser parser;
|
Parser parser;
|
||||||
utils::Logger logger;
|
output::Logger &logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/Problem.h>
|
#include <plasp/pddl/Problem.h>
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/input/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -21,10 +21,10 @@ namespace pddl
|
|||||||
class Description
|
class Description
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Description fromContext(Context &&context);
|
static Description fromContext(Context &context);
|
||||||
static Description fromStream(std::istream &istream);
|
static Description fromStream(std::istream &istream, Context &context);
|
||||||
static Description fromFile(const std::string &path);
|
static Description fromFile(const std::string &path, Context &context);
|
||||||
static Description fromFiles(const std::vector<std::string> &paths);
|
static Description fromFiles(const std::vector<std::string> &paths, Context &context);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Context &context();
|
Context &context();
|
||||||
@ -38,18 +38,18 @@ class Description
|
|||||||
void normalize();
|
void normalize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Description();
|
Description(Context &context);
|
||||||
|
|
||||||
void parse();
|
void parse();
|
||||||
void findSections();
|
void findSections();
|
||||||
|
|
||||||
void checkConsistency();
|
void checkConsistency();
|
||||||
|
|
||||||
Context m_context;
|
Context &m_context;
|
||||||
|
|
||||||
utils::Stream::Position m_domainPosition;
|
input::Stream::Position m_domainPosition;
|
||||||
std::unique_ptr<Domain> m_domain;
|
std::unique_ptr<Domain> m_domain;
|
||||||
utils::Stream::Position m_problemPosition;
|
input::Stream::Position m_problemPosition;
|
||||||
std::unique_ptr<Problem> m_problem;
|
std::unique_ptr<Problem> m_problem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,19 +71,19 @@ class Domain
|
|||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
utils::Stream::Position m_requirementsPosition;
|
input::Stream::Position m_requirementsPosition;
|
||||||
Requirements m_requirements;
|
Requirements m_requirements;
|
||||||
|
|
||||||
utils::Stream::Position m_typesPosition;
|
input::Stream::Position m_typesPosition;
|
||||||
expressions::PrimitiveTypes m_types;
|
expressions::PrimitiveTypes m_types;
|
||||||
|
|
||||||
utils::Stream::Position m_constantsPosition;
|
input::Stream::Position m_constantsPosition;
|
||||||
expressions::Constants m_constants;
|
expressions::Constants m_constants;
|
||||||
|
|
||||||
utils::Stream::Position m_predicatesPosition;
|
input::Stream::Position m_predicatesPosition;
|
||||||
expressions::PredicateDeclarations m_predicates;
|
expressions::PredicateDeclarations m_predicates;
|
||||||
|
|
||||||
std::vector<utils::Stream::Position> m_actionPositions;
|
std::vector<input::Stream::Position> m_actionPositions;
|
||||||
std::vector<std::unique_ptr<Action>> m_actions;
|
std::vector<std::unique_ptr<Action>> m_actions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include <boost/intrusive_ptr.hpp>
|
#include <boost/intrusive_ptr.hpp>
|
||||||
|
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/input/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef __PLASP__PDDL__PARSER_H
|
#ifndef __PLASP__PDDL__PARSER_H
|
||||||
#define __PLASP__PDDL__PARSER_H
|
#define __PLASP__PDDL__PARSER_H
|
||||||
|
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/input/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ class PDDLParserPolicy
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
using Parser = utils::Parser<PDDLParserPolicy>;
|
using Parser = input::Parser<PDDLParserPolicy>;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -64,18 +64,18 @@ class Problem
|
|||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
utils::Stream::Position m_domainPosition;
|
input::Stream::Position m_domainPosition;
|
||||||
|
|
||||||
utils::Stream::Position m_requirementsPosition;
|
input::Stream::Position m_requirementsPosition;
|
||||||
Requirements m_requirements;
|
Requirements m_requirements;
|
||||||
|
|
||||||
utils::Stream::Position m_objectsPosition;
|
input::Stream::Position m_objectsPosition;
|
||||||
expressions::Constants m_objects;
|
expressions::Constants m_objects;
|
||||||
|
|
||||||
utils::Stream::Position m_initialStatePosition;
|
input::Stream::Position m_initialStatePosition;
|
||||||
std::unique_ptr<InitialState> m_initialState;
|
std::unique_ptr<InitialState> m_initialState;
|
||||||
|
|
||||||
utils::Stream::Position m_goalPosition;
|
input::Stream::Position m_goalPosition;
|
||||||
ExpressionPointer m_goal;
|
ExpressionPointer m_goal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ namespace pddl
|
|||||||
class TranslatorASP
|
class TranslatorASP
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TranslatorASP(Description &description, utils::LogStream &outputStream);
|
explicit TranslatorASP(Description &description, output::ColorStream &outputStream);
|
||||||
|
|
||||||
void translate() const;
|
void translate() const;
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ class TranslatorASP
|
|||||||
void translatePredicate(const expressions::Predicate &predicate) const;
|
void translatePredicate(const expressions::Predicate &predicate) const;
|
||||||
|
|
||||||
Description &m_description;
|
Description &m_description;
|
||||||
utils::LogStream &m_outputStream;
|
output::ColorStream &m_outputStream;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
#define __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
|
#define __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
|
||||||
|
|
||||||
#include <plasp/pddl/Expression.h>
|
#include <plasp/pddl/Expression.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ boost::intrusive_ptr<Derived> NAry<Derived>::parse(Context &context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (expression->m_arguments.empty())
|
if (expression->m_arguments.empty())
|
||||||
context.logger.logWarning(parser.coordinate(), "“" + Derived::Identifier + "” expressions should not be empty");
|
context.logger.log(output::Priority::Warning, parser.location(), "“" + Derived::Identifier + "” expressions should not be empty");
|
||||||
|
|
||||||
parser.expect<std::string>(")");
|
parser.expect<std::string>(")");
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <plasp/pddl/ConsistencyException.h>
|
#include <plasp/pddl/ConsistencyException.h>
|
||||||
#include <plasp/pddl/Expression.h>
|
#include <plasp/pddl/Expression.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/sas/Value.h>
|
#include <plasp/sas/Value.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -27,8 +27,8 @@ using AssignedVariables = std::vector<AssignedVariable>;
|
|||||||
class AssignedVariable
|
class AssignedVariable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static AssignedVariable fromSAS(utils::Parser<> &parser, const Variables &variables);
|
static AssignedVariable fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||||
static AssignedVariable fromSAS(utils::Parser<> &parser, const Variable &variable);
|
static AssignedVariable fromSAS(input::Parser<> &parser, const Variable &variable);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AssignedVariable(const Variable &variable, const Value &value);
|
explicit AssignedVariable(const Variable &variable, const Value &value);
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -29,7 +29,7 @@ class AxiomRule
|
|||||||
using Condition = AssignedVariable;
|
using Condition = AssignedVariable;
|
||||||
using Conditions = AssignedVariables;
|
using Conditions = AssignedVariables;
|
||||||
|
|
||||||
static AxiomRule fromSAS(utils::Parser<> &parser, const Variables &variables);
|
static AxiomRule fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Conditions &conditions() const;
|
const Conditions &conditions() const;
|
||||||
|
@ -16,7 +16,7 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
utils::LogStream &operator<<(utils::LogStream &ostream, const Description &description);
|
output::ColorStream &operator<<(output::ColorStream &ostream, const Description &description);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/sas/AxiomRule.h>
|
#include <plasp/sas/AxiomRule.h>
|
||||||
#include <plasp/sas/Goal.h>
|
#include <plasp/sas/Goal.h>
|
||||||
#include <plasp/sas/InitialState.h>
|
#include <plasp/sas/InitialState.h>
|
||||||
#include <plasp/sas/MutexGroup.h>
|
#include <plasp/sas/MutexGroup.h>
|
||||||
#include <plasp/sas/Operator.h>
|
#include <plasp/sas/Operator.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -29,7 +29,7 @@ namespace sas
|
|||||||
class Description
|
class Description
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Description fromParser(utils::Parser<> &&parser);
|
static Description fromParser(input::Parser<> &&parser);
|
||||||
static Description fromStream(std::istream &istream);
|
static Description fromStream(std::istream &istream);
|
||||||
static Description fromFile(const boost::filesystem::path &path);
|
static Description fromFile(const boost::filesystem::path &path);
|
||||||
|
|
||||||
@ -50,16 +50,16 @@ class Description
|
|||||||
private:
|
private:
|
||||||
Description();
|
Description();
|
||||||
|
|
||||||
void parseContent(utils::Parser<> &parser);
|
void parseContent(input::Parser<> &parser);
|
||||||
|
|
||||||
void parseVersionSection(utils::Parser<> &parser) const;
|
void parseVersionSection(input::Parser<> &parser) const;
|
||||||
void parseMetricSection(utils::Parser<> &parser);
|
void parseMetricSection(input::Parser<> &parser);
|
||||||
void parseVariablesSection(utils::Parser<> &parser);
|
void parseVariablesSection(input::Parser<> &parser);
|
||||||
void parseMutexSection(utils::Parser<> &parser);
|
void parseMutexSection(input::Parser<> &parser);
|
||||||
void parseInitialStateSection(utils::Parser<> &parser);
|
void parseInitialStateSection(input::Parser<> &parser);
|
||||||
void parseGoalSection(utils::Parser<> &parser);
|
void parseGoalSection(input::Parser<> &parser);
|
||||||
void parseOperatorSection(utils::Parser<> &parser);
|
void parseOperatorSection(input::Parser<> &parser);
|
||||||
void parseAxiomSection(utils::Parser<> &parser);
|
void parseAxiomSection(input::Parser<> &parser);
|
||||||
|
|
||||||
bool m_usesActionCosts;
|
bool m_usesActionCosts;
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -29,7 +29,7 @@ class Effect
|
|||||||
using Condition = AssignedVariable;
|
using Condition = AssignedVariable;
|
||||||
using Conditions = AssignedVariables;
|
using Conditions = AssignedVariables;
|
||||||
|
|
||||||
static Effect fromSAS(utils::Parser<> &parser, const Variables &variables, Conditions &preconditions);
|
static Effect fromSAS(input::Parser<> &parser, const Variables &variables, Conditions &preconditions);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Conditions &conditions() const;
|
const Conditions &conditions() const;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef __PLASP__SAS__GOAL_H
|
#ifndef __PLASP__SAS__GOAL_H
|
||||||
#define __PLASP__SAS__GOAL_H
|
#define __PLASP__SAS__GOAL_H
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ class Goal
|
|||||||
using Fact = AssignedVariable;
|
using Fact = AssignedVariable;
|
||||||
using Facts = AssignedVariables;
|
using Facts = AssignedVariables;
|
||||||
|
|
||||||
static Goal fromSAS(utils::Parser<> &parser, const Variables &variables);
|
static Goal fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Facts &facts() const;
|
const Facts &facts() const;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef __PLASP__SAS__INITIAL_STATE_H
|
#ifndef __PLASP__SAS__INITIAL_STATE_H
|
||||||
#define __PLASP__SAS__INITIAL_STATE_H
|
#define __PLASP__SAS__INITIAL_STATE_H
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ class InitialState
|
|||||||
using Fact = AssignedVariable;
|
using Fact = AssignedVariable;
|
||||||
using Facts = AssignedVariables;
|
using Facts = AssignedVariables;
|
||||||
|
|
||||||
static InitialState fromSAS(utils::Parser<> &parser, const Variables &variables);
|
static InitialState fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Facts &facts() const;
|
const Facts &facts() const;
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -28,7 +28,7 @@ class MutexGroup
|
|||||||
using Fact = AssignedVariable;
|
using Fact = AssignedVariable;
|
||||||
using Facts = AssignedVariables;
|
using Facts = AssignedVariables;
|
||||||
|
|
||||||
static MutexGroup fromSAS(utils::Parser<> &parser, const Variables &variables);
|
static MutexGroup fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Facts &facts() const;
|
const Facts &facts() const;
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
|
#include <plasp/output/ColorStream.h>
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
#include <plasp/sas/Effect.h>
|
#include <plasp/sas/Effect.h>
|
||||||
#include <plasp/sas/Predicate.h>
|
#include <plasp/sas/Predicate.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
#include <plasp/utils/LogStream.h>
|
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -33,10 +33,10 @@ class Operator
|
|||||||
using Condition = AssignedVariable;
|
using Condition = AssignedVariable;
|
||||||
using Conditions = AssignedVariables;
|
using Conditions = AssignedVariables;
|
||||||
|
|
||||||
static Operator fromSAS(utils::Parser<> &parser, const Variables &variables);
|
static Operator fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void printPredicateAsASP(utils::LogStream &ostream) const;
|
void printPredicateAsASP(output::ColorStream &stream) const;
|
||||||
|
|
||||||
const Predicate &predicate() const;
|
const Predicate &predicate() const;
|
||||||
const Conditions &preconditions() const;
|
const Conditions &preconditions() const;
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/utils/LogStream.h>
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/output/ColorStream.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -22,13 +22,13 @@ namespace sas
|
|||||||
class Predicate
|
class Predicate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Predicate fromSAS(utils::Parser<> &parser);
|
static Predicate fromSAS(input::Parser<> &parser);
|
||||||
|
|
||||||
using Arguments = std::vector<std::string>;
|
using Arguments = std::vector<std::string>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void printAsSAS(utils::LogStream &outputStream) const;
|
void printAsSAS(output::ColorStream &stream) const;
|
||||||
void printAsASP(utils::LogStream &outputStream) const;
|
void printAsASP(output::ColorStream &stream) const;
|
||||||
|
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
const Arguments &arguments() const;
|
const Arguments &arguments() const;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef __PLASP__SAS__TRANSLATOR_ASP_H
|
#ifndef __PLASP__SAS__TRANSLATOR_ASP_H
|
||||||
#define __PLASP__SAS__TRANSLATOR_ASP_H
|
#define __PLASP__SAS__TRANSLATOR_ASP_H
|
||||||
|
|
||||||
|
#include <plasp/output/ColorStream.h>
|
||||||
#include <plasp/sas/Description.h>
|
#include <plasp/sas/Description.h>
|
||||||
#include <plasp/utils/LogStream.h>
|
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ namespace sas
|
|||||||
class TranslatorASP
|
class TranslatorASP
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TranslatorASP(const Description &description, utils::LogStream &outputStream);
|
explicit TranslatorASP(const Description &description, output::ColorStream &outputStream);
|
||||||
|
|
||||||
void translate() const;
|
void translate() const;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ class TranslatorASP
|
|||||||
void translateAxiomRules() const;
|
void translateAxiomRules() const;
|
||||||
|
|
||||||
const Description &m_description;
|
const Description &m_description;
|
||||||
utils::LogStream &m_outputStream;
|
output::ColorStream &m_outputStream;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/utils/LogStream.h>
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/output/ColorStream.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -39,14 +39,14 @@ struct Value
|
|||||||
static const Value Any;
|
static const Value Any;
|
||||||
static const Value None;
|
static const Value None;
|
||||||
|
|
||||||
static Value fromSAS(utils::Parser<> &parser);
|
static Value fromSAS(input::Parser<> &parser);
|
||||||
static const Value &referenceFromSAS(utils::Parser<> &parser, const Variable &variable);
|
static const Value &referenceFromSAS(input::Parser<> &parser, const Variable &variable);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Value negated() const;
|
Value negated() const;
|
||||||
|
|
||||||
void printAsSAS(utils::LogStream &outputStream) const;
|
void printAsSAS(output::ColorStream &stream) const;
|
||||||
void printAsASPPredicate(utils::LogStream &outputStream) const;
|
void printAsASPPredicate(output::ColorStream &stream) const;
|
||||||
|
|
||||||
Sign sign() const;
|
Sign sign() const;
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
|
#include <plasp/output/ColorStream.h>
|
||||||
#include <plasp/sas/Value.h>
|
#include <plasp/sas/Value.h>
|
||||||
#include <plasp/utils/LogStream.h>
|
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -28,11 +28,11 @@ using Variables = std::vector<Variable>;
|
|||||||
class Variable
|
class Variable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Variable fromSAS(utils::Parser<> &parser);
|
static Variable fromSAS(input::Parser<> &parser);
|
||||||
static const Variable &referenceFromSAS(utils::Parser<> &parser, const Variables &variables);
|
static const Variable &referenceFromSAS(input::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void printNameAsASPPredicate(utils::LogStream &outputStream) const;
|
void printNameAsASPPredicate(output::ColorStream &outputStream) const;
|
||||||
|
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
int axiomLayer() const;
|
int axiomLayer() const;
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/sas/Value.h>
|
#include <plasp/sas/Value.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -26,7 +26,7 @@ using VariableTransitions = std::vector<VariableTransition>;
|
|||||||
class VariableTransition
|
class VariableTransition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static VariableTransition fromSAS(utils::Parser<> &parser, const Variables &variables);
|
static VariableTransition fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Variable &variable() const;
|
const Variable &variable() const;
|
||||||
|
@ -1,335 +0,0 @@
|
|||||||
#ifndef __PLASP__UTILS__LOG_STREAM_H
|
|
||||||
#define __PLASP__UTILS__LOG_STREAM_H
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
namespace plasp
|
|
||||||
{
|
|
||||||
namespace utils
|
|
||||||
{
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// LogStream
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
enum class StandardStream
|
|
||||||
{
|
|
||||||
Out,
|
|
||||||
Err
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class LogStream
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum class ColorPolicy
|
|
||||||
{
|
|
||||||
Never,
|
|
||||||
Auto,
|
|
||||||
Always
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
using CharacterType = std::ostream::char_type;
|
|
||||||
using TraitsType = std::ostream::traits_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
LogStream(StandardStream standardStream)
|
|
||||||
: m_standardStream{standardStream},
|
|
||||||
m_colorPolicy{ColorPolicy::Auto}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
LogStream(const LogStream &other)
|
|
||||||
: m_standardStream{other.m_standardStream},
|
|
||||||
m_colorPolicy{other.m_colorPolicy}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
LogStream &operator=(const LogStream &other)
|
|
||||||
{
|
|
||||||
m_standardStream = other.m_standardStream;
|
|
||||||
m_colorPolicy = other.m_colorPolicy;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogStream(LogStream &&other)
|
|
||||||
: m_standardStream{other.m_standardStream},
|
|
||||||
m_colorPolicy{other.m_colorPolicy}
|
|
||||||
{
|
|
||||||
other.m_colorPolicy = ColorPolicy::Auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogStream &operator=(LogStream &&other)
|
|
||||||
{
|
|
||||||
m_standardStream = other.m_standardStream;
|
|
||||||
m_colorPolicy = other.m_colorPolicy;
|
|
||||||
|
|
||||||
other.m_colorPolicy = ColorPolicy::Auto;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setColorPolicy(ColorPolicy colorPolicy)
|
|
||||||
{
|
|
||||||
m_colorPolicy = colorPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool supportsColor() const
|
|
||||||
{
|
|
||||||
if (m_colorPolicy == ColorPolicy::Never)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (m_colorPolicy == ColorPolicy::Always)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Autodetect by checking whether output goes to a terminal
|
|
||||||
const auto fileDescriptor =
|
|
||||||
(m_standardStream == utils::StandardStream::Out)
|
|
||||||
? STDOUT_FILENO
|
|
||||||
: STDERR_FILENO;
|
|
||||||
|
|
||||||
return isatty(fileDescriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream &ostream()
|
|
||||||
{
|
|
||||||
return (m_standardStream == utils::StandardStream::Out)
|
|
||||||
? std::cout
|
|
||||||
: std::cerr;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline LogStream &operator<<(short value);
|
|
||||||
inline LogStream &operator<<(unsigned short value);
|
|
||||||
inline LogStream &operator<<(int value);
|
|
||||||
inline LogStream &operator<<(unsigned int value);
|
|
||||||
inline LogStream &operator<<(long value);
|
|
||||||
inline LogStream &operator<<(unsigned long value);
|
|
||||||
inline LogStream &operator<<(long long value);
|
|
||||||
inline LogStream &operator<<(unsigned long long value);
|
|
||||||
inline LogStream &operator<<(float value);
|
|
||||||
inline LogStream &operator<<(double value);
|
|
||||||
inline LogStream &operator<<(long double value);
|
|
||||||
inline LogStream &operator<<(bool value);
|
|
||||||
inline LogStream &operator<<(const void *value);
|
|
||||||
inline LogStream &operator<<(const char *value);
|
|
||||||
inline LogStream &operator<<(const signed char *value);
|
|
||||||
inline LogStream &operator<<(const unsigned char *value);
|
|
||||||
inline LogStream &operator<<(std::basic_streambuf<CharacterType, TraitsType> *sb);
|
|
||||||
inline LogStream &operator<<(std::ios_base &(*func)(std::ios_base &));
|
|
||||||
inline LogStream &operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &));
|
|
||||||
inline LogStream &operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &));
|
|
||||||
|
|
||||||
inline LogStream &operator<<(char value);
|
|
||||||
inline LogStream &operator<<(signed char value);
|
|
||||||
inline LogStream &operator<<(unsigned char value);
|
|
||||||
|
|
||||||
private:
|
|
||||||
StandardStream m_standardStream;
|
|
||||||
ColorPolicy m_colorPolicy;
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(short value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(unsigned short value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(int value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(unsigned int value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(long value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(unsigned long value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(long long value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(unsigned long long value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(float value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(double value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(long double value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(bool value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(const void *value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(const char *value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(const signed char *value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(const unsigned char *value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(std::basic_streambuf<CharacterType, TraitsType>* sb)
|
|
||||||
{
|
|
||||||
ostream() << sb;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(std::ios_base &(*func)(std::ios_base &))
|
|
||||||
{
|
|
||||||
ostream() << func;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &))
|
|
||||||
{
|
|
||||||
ostream() << func;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &))
|
|
||||||
{
|
|
||||||
ostream() << func;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
template<class CharacterType, class Traits, class Allocator>
|
|
||||||
inline LogStream &operator<<(LogStream &stream, const std::basic_string<CharacterType, Traits, Allocator> &string)
|
|
||||||
{
|
|
||||||
stream.ostream() << string;
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(char value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(signed char value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LogStream &LogStream::operator<<(unsigned char value)
|
|
||||||
{
|
|
||||||
ostream() << value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,62 +0,0 @@
|
|||||||
#ifndef __PLASP__UTILS__LOGGER_H
|
|
||||||
#define __PLASP__UTILS__LOGGER_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <plasp/utils/LogStream.h>
|
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
#include <plasp/utils/StreamCoordinate.h>
|
|
||||||
|
|
||||||
namespace plasp
|
|
||||||
{
|
|
||||||
namespace utils
|
|
||||||
{
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Logger
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class Logger
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum class WarningLevel
|
|
||||||
{
|
|
||||||
Show,
|
|
||||||
Error,
|
|
||||||
Ignore
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
Logger();
|
|
||||||
|
|
||||||
Logger(const Logger &other);
|
|
||||||
Logger &operator=(const Logger &other);
|
|
||||||
|
|
||||||
Logger(Logger &&other);
|
|
||||||
Logger &operator=(Logger &&other);
|
|
||||||
|
|
||||||
LogStream &outputStream();
|
|
||||||
LogStream &errorStream();
|
|
||||||
|
|
||||||
void setWarningLevel(WarningLevel warningLevel);
|
|
||||||
void setColorPolicy(LogStream::ColorPolicy colorPolicy);
|
|
||||||
|
|
||||||
void logError(const std::string &message);
|
|
||||||
void logError(const StreamCoordinate &coordinate, const std::string &message);
|
|
||||||
void logWarning(const StreamCoordinate &parserCoordinate, const std::string &message);
|
|
||||||
|
|
||||||
private:
|
|
||||||
LogStream m_outputStream;
|
|
||||||
LogStream m_errorStream;
|
|
||||||
|
|
||||||
WarningLevel m_warningLevel;
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,71 +0,0 @@
|
|||||||
#ifndef __PLASP__UTILS__PARSER_EXCEPTION_H
|
|
||||||
#define __PLASP__UTILS__PARSER_EXCEPTION_H
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <plasp/utils/StreamCoordinate.h>
|
|
||||||
|
|
||||||
namespace plasp
|
|
||||||
{
|
|
||||||
namespace utils
|
|
||||||
{
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// ParserException
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class ParserException: public std::exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit ParserException(const StreamCoordinate &coordinate)
|
|
||||||
: ParserException(coordinate, "unspecified parser error")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit ParserException(const StreamCoordinate &coordinate, const char *message)
|
|
||||||
: ParserException(coordinate, static_cast<std::string>(message))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit ParserException(const StreamCoordinate &coordinate, const std::string &message)
|
|
||||||
: m_coordinate{coordinate},
|
|
||||||
m_message{message},
|
|
||||||
m_plainMessage{m_coordinate.sectionName + ":" + std::to_string(m_coordinate.row)
|
|
||||||
+ ":" + std::to_string(m_coordinate.column) + " " + m_message}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~ParserException() throw()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *what() const throw()
|
|
||||||
{
|
|
||||||
return m_plainMessage.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
const StreamCoordinate &coordinate() const
|
|
||||||
{
|
|
||||||
return m_coordinate;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string &message() const
|
|
||||||
{
|
|
||||||
return m_message;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
StreamCoordinate m_coordinate;
|
|
||||||
std::string m_message;
|
|
||||||
std::string m_plainMessage;
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -12,8 +12,11 @@ file(GLOB pddl_expressions_headers "../include/plasp/pddl/expressions/*.h")
|
|||||||
file(GLOB sas_sources "plasp/sas/*.cpp")
|
file(GLOB sas_sources "plasp/sas/*.cpp")
|
||||||
file(GLOB sas_headers "../include/plasp/sas/*.h")
|
file(GLOB sas_headers "../include/plasp/sas/*.h")
|
||||||
|
|
||||||
file(GLOB utils_sources "plasp/utils/*.cpp")
|
file(GLOB input_sources "plasp/input/*.cpp")
|
||||||
file(GLOB utils_headers "../include/plasp/utils/*.h")
|
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(
|
include_directories(
|
||||||
${Boost_INCLUDE_DIRS}
|
${Boost_INCLUDE_DIRS}
|
||||||
@ -36,8 +39,11 @@ set(sources
|
|||||||
${sas_sources}
|
${sas_sources}
|
||||||
${sas_headers}
|
${sas_headers}
|
||||||
|
|
||||||
${utils_sources}
|
${input_sources}
|
||||||
${utils_headers}
|
${input_headers}
|
||||||
|
|
||||||
|
${output_sources}
|
||||||
|
${output_headers}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(libraries
|
set(libraries
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#include <plasp/utils/Stream.h>
|
#include <plasp/input/Stream.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
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();
|
const auto currentPosition = position();
|
||||||
|
|
||||||
@ -99,7 +101,7 @@ StreamCoordinate Stream::coordinate() const
|
|||||||
size_t row = 1;
|
size_t row = 1;
|
||||||
size_t column = 1;
|
size_t column = 1;
|
||||||
|
|
||||||
// Compute the coordinate character by character
|
// Compute the location character by character
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (currentPosition == -1 && atEnd())
|
if (currentPosition == -1 && atEnd())
|
||||||
@ -120,7 +122,7 @@ StreamCoordinate Stream::coordinate() const
|
|||||||
m_stream.ignore(1);
|
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
|
void Stream::check() const
|
||||||
{
|
{
|
||||||
if (atEnd())
|
if (atEnd())
|
||||||
throw ParserException(coordinate(), "reading past end of file");
|
throw ParserException(location(), "reading past end of file");
|
||||||
|
|
||||||
if (m_stream.fail())
|
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 <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/pddl/IO.h>
|
#include <plasp/pddl/IO.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -19,8 +19,9 @@ namespace pddl
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Description::Description()
|
Description::Description(Context &context)
|
||||||
: m_domainPosition{-1},
|
: m_context(context),
|
||||||
|
m_domainPosition{-1},
|
||||||
m_domain{std::make_unique<Domain>(Domain(m_context))},
|
m_domain{std::make_unique<Domain>(Domain(m_context))},
|
||||||
m_problemPosition{-1}
|
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();
|
description.parse();
|
||||||
|
|
||||||
return description;
|
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.m_context.parser.read("std::cin", istream);
|
||||||
description.parse();
|
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.m_context.parser.read(path);
|
||||||
description.parse();
|
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());
|
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(),
|
std::for_each(paths.cbegin(), paths.cend(),
|
||||||
[&](const auto &path)
|
[&](const auto &path)
|
||||||
@ -165,7 +167,7 @@ void Description::findSections()
|
|||||||
if (parser.testAndSkip<std::string>("domain"))
|
if (parser.testAndSkip<std::string>("domain"))
|
||||||
{
|
{
|
||||||
if (m_domainPosition != -1)
|
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;
|
m_domainPosition = position;
|
||||||
|
|
||||||
@ -175,7 +177,7 @@ void Description::findSections()
|
|||||||
else if (m_context.parser.testAndSkip<std::string>("problem"))
|
else if (m_context.parser.testAndSkip<std::string>("problem"))
|
||||||
{
|
{
|
||||||
if (m_problemPosition != -1)
|
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));
|
m_problem = std::make_unique<Problem>(Problem(m_context, *m_domain));
|
||||||
|
|
||||||
@ -187,7 +189,7 @@ void Description::findSections()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto sectionIdentifier = parser.parse<std::string>();
|
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();
|
m_context.parser.skipWhiteSpace();
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/pddl/ConsistencyException.h>
|
#include <plasp/pddl/ConsistencyException.h>
|
||||||
#include <plasp/pddl/IO.h>
|
#include <plasp/pddl/IO.h>
|
||||||
#include <plasp/pddl/expressions/Constant.h>
|
#include <plasp/pddl/expressions/Constant.h>
|
||||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||||
#include <plasp/pddl/expressions/Variable.h>
|
#include <plasp/pddl/expressions/Variable.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -51,7 +51,7 @@ void Domain::findSections()
|
|||||||
if (unique && sectionPosition != -1)
|
if (unique && sectionPosition != -1)
|
||||||
{
|
{
|
||||||
parser.seek(value);
|
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;
|
sectionPosition = value;
|
||||||
@ -92,7 +92,7 @@ void Domain::findSections()
|
|||||||
|
|
||||||
const auto sectionIdentifier = parser.parseIdentifier();
|
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);
|
parser.seek(sectionIdentifierPosition);
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ void Domain::findSections()
|
|||||||
const auto sectionIdentifier = parser.parseIdentifier();
|
const auto sectionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
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
|
// Skip section for now and parse it later
|
||||||
@ -277,7 +277,7 @@ void Domain::checkRequirement(Requirement::Type requirementType)
|
|||||||
if (hasRequirement(requirementType))
|
if (hasRequirement(requirementType))
|
||||||
return;
|
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);
|
m_requirements.push_back(requirementType);
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ void Domain::parseTypeSection()
|
|||||||
while (parser.currentCharacter() != ')')
|
while (parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
if (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);
|
expressions::PrimitiveType::parseTypedDeclaration(m_context, *this);
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <plasp/pddl/Expression.h>
|
#include <plasp/pddl/Expression.h>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
@ -11,7 +12,6 @@
|
|||||||
#include <plasp/pddl/expressions/Predicate.h>
|
#include <plasp/pddl/expressions/Predicate.h>
|
||||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||||
#include <plasp/pddl/expressions/Unsupported.h>
|
#include <plasp/pddl/expressions/Unsupported.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -157,7 +157,7 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio
|
|||||||
const auto expressionIdentifier = parser.parseIdentifier();
|
const auto expressionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
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();
|
const auto expressionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
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)))
|
if ((expression = expressions::Predicate::parse(context, expressionContext)))
|
||||||
return expression;
|
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/pddl/InitialState.h>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
#include <plasp/pddl/IO.h>
|
#include <plasp/pddl/IO.h>
|
||||||
@ -7,7 +8,6 @@
|
|||||||
#include <plasp/pddl/expressions/At.h>
|
#include <plasp/pddl/expressions/At.h>
|
||||||
#include <plasp/pddl/expressions/Predicate.h>
|
#include <plasp/pddl/expressions/Predicate.h>
|
||||||
#include <plasp/pddl/expressions/Unsupported.h>
|
#include <plasp/pddl/expressions/Unsupported.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -58,7 +58,7 @@ std::unique_ptr<InitialState> InitialState::parseDeclaration(Context &context,
|
|||||||
const auto expressionIdentifier = parser.parseIdentifier();
|
const auto expressionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
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();
|
parser.skipWhiteSpace();
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
#include <plasp/pddl/IO.h>
|
#include <plasp/pddl/IO.h>
|
||||||
#include <plasp/pddl/expressions/Constant.h>
|
#include <plasp/pddl/expressions/Constant.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -51,7 +51,7 @@ void Problem::findSections()
|
|||||||
if (unique && sectionPosition != -1)
|
if (unique && sectionPosition != -1)
|
||||||
{
|
{
|
||||||
parser.seek(value);
|
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;
|
sectionPosition = value;
|
||||||
@ -87,7 +87,7 @@ void Problem::findSections()
|
|||||||
|
|
||||||
const auto sectionIdentifier = parser.parseIdentifier();
|
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);
|
parser.seek(sectionIdentifierPosition);
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ void Problem::findSections()
|
|||||||
const auto sectionIdentifier = parser.parseIdentifier();
|
const auto sectionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
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
|
// Skip section for now and parse it later
|
||||||
@ -202,7 +202,7 @@ void Problem::parseDomainSection()
|
|||||||
const auto domainName = parser.parseIdentifier();
|
const auto domainName = parser.parseIdentifier();
|
||||||
|
|
||||||
if (m_domain.name() != domainName)
|
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>(")");
|
parser.expect<std::string>(")");
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ void Problem::checkRequirement(Requirement::Type requirementType)
|
|||||||
if (hasRequirement(requirementType))
|
if (hasRequirement(requirementType))
|
||||||
return;
|
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);
|
m_requirements.push_back(requirementType);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <boost/assign.hpp>
|
#include <boost/assign.hpp>
|
||||||
#include <boost/bimap.hpp>
|
#include <boost/bimap.hpp>
|
||||||
|
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/input/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -89,12 +89,12 @@ Requirement Requirement::parse(Context &context)
|
|||||||
const auto match = requirementTypesToPDDL.right.find(requirementName);
|
const auto match = requirementTypesToPDDL.right.find(requirementName);
|
||||||
|
|
||||||
if (match == requirementTypesToPDDL.right.end())
|
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;
|
const auto requirementType = match->second;
|
||||||
|
|
||||||
if (requirementType == Requirement::Type::GoalUtilities)
|
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);
|
return Requirement(match->second);
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
|
#include <plasp/output/Formatting.h>
|
||||||
|
#include <plasp/output/TranslatorException.h>
|
||||||
#include <plasp/pddl/expressions/And.h>
|
#include <plasp/pddl/expressions/And.h>
|
||||||
#include <plasp/pddl/expressions/Not.h>
|
#include <plasp/pddl/expressions/Not.h>
|
||||||
#include <plasp/pddl/expressions/Predicate.h>
|
#include <plasp/pddl/expressions/Predicate.h>
|
||||||
#include <plasp/utils/Formatting.h>
|
|
||||||
#include <plasp/utils/TranslatorException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
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_description(description),
|
||||||
m_outputStream(outputStream)
|
m_outputStream(outputStream)
|
||||||
{
|
{
|
||||||
@ -43,7 +43,7 @@ void TranslatorASP::translate() const
|
|||||||
|
|
||||||
void TranslatorASP::translateDomain() const
|
void TranslatorASP::translateDomain() const
|
||||||
{
|
{
|
||||||
m_outputStream << utils::Heading1("domain");
|
m_outputStream << output::Heading1("domain");
|
||||||
|
|
||||||
const auto &domain = m_description.domain();
|
const auto &domain = m_description.domain();
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ void TranslatorASP::translateDomain() const
|
|||||||
|
|
||||||
void TranslatorASP::translateTypes() const
|
void TranslatorASP::translateTypes() const
|
||||||
{
|
{
|
||||||
m_outputStream << utils::Heading2("types");
|
m_outputStream << output::Heading2("types");
|
||||||
|
|
||||||
m_outputStream << std::endl;
|
m_outputStream << std::endl;
|
||||||
|
|
||||||
@ -86,8 +86,8 @@ void TranslatorASP::translateTypes() const
|
|||||||
if (types.empty())
|
if (types.empty())
|
||||||
{
|
{
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< utils::RuleName("type") << "("
|
<< output::Function("type") << "("
|
||||||
<< utils::Keyword("type") << "(" << utils::String("object") << "))." << std::endl;
|
<< output::Keyword("type") << "(" << output::String("object") << "))." << std::endl;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -96,9 +96,9 @@ void TranslatorASP::translateTypes() const
|
|||||||
[&](const auto &type)
|
[&](const auto &type)
|
||||||
{
|
{
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< utils::RuleName("type") << "("
|
<< output::Function("type") << "("
|
||||||
<< utils::Keyword("type") << "("
|
<< output::Keyword("type") << "("
|
||||||
<< utils::String(type->name())
|
<< output::String(type->name().c_str())
|
||||||
<< "))." << std::endl;
|
<< "))." << std::endl;
|
||||||
|
|
||||||
const auto &parentTypes = type->parentTypes();
|
const auto &parentTypes = type->parentTypes();
|
||||||
@ -107,23 +107,23 @@ void TranslatorASP::translateTypes() const
|
|||||||
[&](const auto &parentType)
|
[&](const auto &parentType)
|
||||||
{
|
{
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< utils::RuleName("inherits") << "(" << utils::Keyword("type")
|
<< output::Function("inherits") << "(" << output::Keyword("type")
|
||||||
<< "(" << utils::String(type->name()) << "), " << utils::Keyword("type")
|
<< "(" << output::String(type->name().c_str()) << "), " << output::Keyword("type")
|
||||||
<< "(" << utils::String(parentType->name()) << "))." << std::endl;
|
<< "(" << output::String(parentType->name().c_str()) << "))." << std::endl;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< utils::RuleName("has") << "("
|
<< output::Function("has") << "("
|
||||||
<< utils::Variable("X") << ", "
|
<< output::Variable("X") << ", "
|
||||||
<< utils::Keyword("type") << "(" << utils::Variable("T2") << ")) :- "
|
<< output::Keyword("type") << "(" << output::Variable("T2") << ")) :- "
|
||||||
<< utils::RuleName("has") << "("
|
<< output::Function("has") << "("
|
||||||
<< utils::Variable("X") << ", "
|
<< output::Variable("X") << ", "
|
||||||
<< utils::Keyword("type") << "(" << utils::Variable("T1") << ")), "
|
<< output::Keyword("type") << "(" << output::Variable("T1") << ")), "
|
||||||
<< utils::RuleName("inherits") << "("
|
<< output::Function("inherits") << "("
|
||||||
<< utils::Keyword("type") << "(" << utils::Variable("T1") << "), "
|
<< output::Keyword("type") << "(" << output::Variable("T1") << "), "
|
||||||
<< utils::Keyword("type") << "(" << utils::Variable("T2") << "))."
|
<< output::Keyword("type") << "(" << output::Variable("T2") << "))."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ void TranslatorASP::translateTypes() const
|
|||||||
|
|
||||||
void TranslatorASP::translatePredicates() const
|
void TranslatorASP::translatePredicates() const
|
||||||
{
|
{
|
||||||
m_outputStream << utils::Heading2("variables");
|
m_outputStream << output::Heading2("variables");
|
||||||
|
|
||||||
const auto &predicates = m_description.domain().predicates();
|
const auto &predicates = m_description.domain().predicates();
|
||||||
|
|
||||||
@ -140,12 +140,12 @@ void TranslatorASP::translatePredicates() const
|
|||||||
{
|
{
|
||||||
if (predicate->arguments().empty())
|
if (predicate->arguments().empty())
|
||||||
{
|
{
|
||||||
m_outputStream << utils::String(predicate->name());
|
m_outputStream << output::String(predicate->name().c_str());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_outputStream << "(" << utils::String(predicate->name());
|
m_outputStream << "(" << output::String(predicate->name().c_str());
|
||||||
this->translateVariablesHead(predicate->arguments());
|
this->translateVariablesHead(predicate->arguments());
|
||||||
m_outputStream << ")";
|
m_outputStream << ")";
|
||||||
};
|
};
|
||||||
@ -155,8 +155,8 @@ void TranslatorASP::translatePredicates() const
|
|||||||
{
|
{
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< utils::RuleName("variable") << "("
|
<< output::Function("variable") << "("
|
||||||
<< utils::Keyword("variable") << "(";
|
<< output::Keyword("variable") << "(";
|
||||||
|
|
||||||
printPredicateName(predicate);
|
printPredicateName(predicate);
|
||||||
|
|
||||||
@ -169,14 +169,14 @@ void TranslatorASP::translatePredicates() const
|
|||||||
|
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< std::endl << std::endl
|
<< std::endl << std::endl
|
||||||
<< utils::RuleName("boolean") << "(" << utils::Boolean("true") << ")." << std::endl
|
<< output::Function("boolean") << "(" << output::Boolean("true") << ")." << std::endl
|
||||||
<< utils::RuleName("boolean") << "(" << utils::Boolean("false") << ")." << std::endl
|
<< output::Function("boolean") << "(" << output::Boolean("false") << ")." << std::endl
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< utils::RuleName("contains") << "("
|
<< output::Function("contains") << "("
|
||||||
<< utils::Keyword("variable") << "(" << utils::Variable("X") << "), "
|
<< output::Keyword("variable") << "(" << output::Variable("X") << "), "
|
||||||
<< utils::Keyword("value") << "(" << utils::Variable("X") << ", " << utils::Variable("B") << ")) :- "
|
<< output::Keyword("value") << "(" << output::Variable("X") << ", " << output::Variable("B") << ")) :- "
|
||||||
<< utils::RuleName("variable") << "(" << utils::Keyword("variable") << "(" << utils::Variable("X") << ")), "
|
<< output::Function("variable") << "(" << output::Keyword("variable") << "(" << output::Variable("X") << ")), "
|
||||||
<< utils::RuleName("boolean") << "(" << utils::Variable("B") << ")."
|
<< output::Function("boolean") << "(" << output::Variable("B") << ")."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,23 +184,23 @@ void TranslatorASP::translatePredicates() const
|
|||||||
|
|
||||||
void TranslatorASP::translateActions() const
|
void TranslatorASP::translateActions() const
|
||||||
{
|
{
|
||||||
m_outputStream << utils::Heading2("actions");
|
m_outputStream << output::Heading2("actions");
|
||||||
|
|
||||||
const auto &actions = m_description.domain().actions();
|
const auto &actions = m_description.domain().actions();
|
||||||
|
|
||||||
const auto printActionName =
|
const auto printActionName =
|
||||||
[&](const auto &action)
|
[&](const auto &action)
|
||||||
{
|
{
|
||||||
m_outputStream << utils::Keyword("action") << "(";
|
m_outputStream << output::Keyword("action") << "(";
|
||||||
|
|
||||||
if (action.parameters().empty())
|
if (action.parameters().empty())
|
||||||
{
|
{
|
||||||
m_outputStream << utils::String(action.name()) << ")";
|
m_outputStream << output::String(action.name().c_str()) << ")";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_outputStream << "(" << utils::String(action.name());
|
m_outputStream << "(" << output::String(action.name().c_str());
|
||||||
this->translateVariablesHead(action.parameters());
|
this->translateVariablesHead(action.parameters());
|
||||||
m_outputStream << "))";
|
m_outputStream << "))";
|
||||||
};
|
};
|
||||||
@ -212,19 +212,19 @@ void TranslatorASP::translateActions() const
|
|||||||
const auto translateLiteral =
|
const auto translateLiteral =
|
||||||
[&](const auto &ruleHead, const auto &literal, bool enumerateEffects = false)
|
[&](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);
|
printActionName(*action);
|
||||||
|
|
||||||
// TODO: implement conditional effects
|
// TODO: implement conditional effects
|
||||||
if (enumerateEffects)
|
if (enumerateEffects)
|
||||||
m_outputStream << ", " << utils::Keyword("effect") << "(" << utils::Reserved("unconditional") << ")";
|
m_outputStream << ", " << output::Keyword("effect") << "(" << output::Reserved("unconditional") << ")";
|
||||||
|
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
|
|
||||||
this->translateLiteral(literal);
|
this->translateLiteral(literal);
|
||||||
|
|
||||||
m_outputStream << ") :- " << utils::RuleName("action") << "(";
|
m_outputStream << ") :- " << output::Function("action") << "(";
|
||||||
|
|
||||||
printActionName(*action);
|
printActionName(*action);
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ void TranslatorASP::translateActions() const
|
|||||||
m_outputStream << std::endl;
|
m_outputStream << std::endl;
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
m_outputStream << utils::RuleName("action") << "(";
|
m_outputStream << output::Function("action") << "(";
|
||||||
printActionName(*action);
|
printActionName(*action);
|
||||||
m_outputStream << ")";
|
m_outputStream << ")";
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ void TranslatorASP::translateActions() const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (precondition.expressionType() != Expression::Type::And)
|
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);
|
const auto &andExpression = dynamic_cast<const expressions::And &>(precondition);
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ void TranslatorASP::translateActions() const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (effect.expressionType() != Expression::Type::And)
|
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);
|
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
|
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(),
|
std::for_each(constants.cbegin(), constants.cend(),
|
||||||
[&](const auto &constant)
|
[&](const auto &constant)
|
||||||
{
|
{
|
||||||
m_outputStream << std::endl
|
m_outputStream << std::endl
|
||||||
<< utils::RuleName("constant") << "("
|
<< output::Function("constant") << "("
|
||||||
<< utils::Keyword("constant") << "("
|
<< output::Keyword("constant") << "("
|
||||||
<< utils::String(constant->name())
|
<< output::String(constant->name().c_str())
|
||||||
<< "))." << std::endl;
|
<< "))." << std::endl;
|
||||||
|
|
||||||
const auto type = constant->type();
|
const auto type = constant->type();
|
||||||
|
|
||||||
if (type != nullptr)
|
if (type != nullptr)
|
||||||
{
|
{
|
||||||
m_outputStream << utils::RuleName("has") << "("
|
m_outputStream << output::Function("has") << "("
|
||||||
<< utils::Keyword("constant") << "(" << utils::String(constant->name()) << "), "
|
<< output::Keyword("constant") << "(" << output::String(constant->name().c_str()) << "), "
|
||||||
<< utils::Keyword("type") << "(" << utils::String(type->name()) << "))." << std::endl;
|
<< output::Keyword("type") << "(" << output::String(type->name().c_str()) << "))." << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_outputStream << utils::RuleName("has") << "("
|
m_outputStream << output::Function("has") << "("
|
||||||
<< utils::Keyword("constant") << "(" << utils::String(constant->name()) << "), "
|
<< output::Keyword("constant") << "(" << output::String(constant->name().c_str()) << "), "
|
||||||
<< utils::Keyword("type") << "(" << utils::String("object") << "))." << std::endl;
|
<< output::Keyword("type") << "(" << output::String("object") << "))." << std::endl;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -341,7 +341,7 @@ void TranslatorASP::translateVariablesHead(const expressions::Variables &variabl
|
|||||||
{
|
{
|
||||||
const auto &variable = **i;
|
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() != nullptr)
|
||||||
{
|
{
|
||||||
if (variable.type()->expressionType() != Expression::Type::PrimitiveType)
|
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());
|
const auto &type = dynamic_cast<const expressions::PrimitiveType &>(*variable.type());
|
||||||
|
|
||||||
m_outputStream << utils::RuleName("has") << "("
|
m_outputStream << output::Function("has") << "("
|
||||||
<< utils::Variable(variable.name()) << ", "
|
<< output::Variable(variable.name().c_str()) << ", "
|
||||||
<< utils::Keyword("type") << "(" << utils::String(type.name()) << "))";
|
<< output::Keyword("type") << "(" << output::String(type.name().c_str()) << "))";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_outputStream << utils::RuleName("has") << "("
|
m_outputStream << output::Function("has") << "("
|
||||||
<< utils::Variable(variable.name()) << ", "
|
<< output::Variable(variable.name().c_str()) << ", "
|
||||||
<< utils::Keyword("type") << "(" << utils::String("object") << "))";
|
<< 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);
|
const auto &predicate = dynamic_cast<const expressions::Predicate &>(literal);
|
||||||
|
|
||||||
m_outputStream << utils::Keyword("variable") << "(";
|
m_outputStream << output::Keyword("variable") << "(";
|
||||||
this->translatePredicate(predicate);
|
this->translatePredicate(predicate);
|
||||||
m_outputStream << "), " << utils::Keyword("value") << "(";
|
m_outputStream << "), " << output::Keyword("value") << "(";
|
||||||
this->translatePredicate(predicate);
|
this->translatePredicate(predicate);
|
||||||
m_outputStream << ", " << utils::Boolean("true") << ")";
|
m_outputStream << ", " << output::Boolean("true") << ")";
|
||||||
}
|
}
|
||||||
// Assuming that "not" expression may only contain a predicate
|
// Assuming that "not" expression may only contain a predicate
|
||||||
else if (literal.expressionType() == Expression::Type::Not)
|
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);
|
const auto ¬Expression = dynamic_cast<const expressions::Not &>(literal);
|
||||||
|
|
||||||
if (notExpression.argument()->expressionType() != Expression::Type::Predicate)
|
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());
|
const auto &predicate = dynamic_cast<const expressions::Predicate &>(*notExpression.argument());
|
||||||
|
|
||||||
m_outputStream << utils::Keyword("variable") << "(";
|
m_outputStream << output::Keyword("variable") << "(";
|
||||||
this->translatePredicate(predicate);
|
this->translatePredicate(predicate);
|
||||||
m_outputStream << "), " << utils::Keyword("value") << "(";
|
m_outputStream << "), " << output::Keyword("value") << "(";
|
||||||
this->translatePredicate(predicate);
|
this->translatePredicate(predicate);
|
||||||
m_outputStream << ", " << utils::Boolean("false") << ")";
|
m_outputStream << ", " << output::Boolean("false") << ")";
|
||||||
}
|
}
|
||||||
else
|
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())
|
if (arguments.empty())
|
||||||
{
|
{
|
||||||
m_outputStream << utils::String(predicate.name());
|
m_outputStream << output::String(predicate.name().c_str());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_outputStream << "(" << utils::String(predicate.name());
|
m_outputStream << "(" << output::String(predicate.name().c_str());
|
||||||
|
|
||||||
for (auto i = arguments.cbegin(); i != arguments.cend(); i++)
|
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);
|
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)
|
else if ((*i)->expressionType() == Expression::Type::Variable)
|
||||||
{
|
{
|
||||||
const auto &variable = dynamic_cast<const expressions::Variable &>(**i);
|
const auto &variable = dynamic_cast<const expressions::Variable &>(**i);
|
||||||
|
|
||||||
m_outputStream << utils::Variable(variable.name());
|
m_outputStream << output::Variable(variable.name().c_str());
|
||||||
}
|
}
|
||||||
else
|
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 << ")";
|
m_outputStream << ")";
|
||||||
@ -460,7 +460,7 @@ void TranslatorASP::translateProblem() const
|
|||||||
{
|
{
|
||||||
BOOST_ASSERT(m_description.containsProblem());
|
BOOST_ASSERT(m_description.containsProblem());
|
||||||
|
|
||||||
m_outputStream << utils::Heading1("problem");
|
m_outputStream << output::Heading1("problem");
|
||||||
|
|
||||||
const auto &problem = m_description.problem();
|
const auto &problem = m_description.problem();
|
||||||
|
|
||||||
@ -486,25 +486,25 @@ void TranslatorASP::translateInitialState() const
|
|||||||
{
|
{
|
||||||
BOOST_ASSERT(m_description.containsProblem());
|
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();
|
const auto &initialStateFacts = m_description.problem().initialState().facts();
|
||||||
|
|
||||||
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
m_outputStream << std::endl << utils::RuleName("initialState") << "(";
|
m_outputStream << std::endl << output::Function("initialState") << "(";
|
||||||
|
|
||||||
// Translate single predicate
|
// Translate single predicate
|
||||||
if (fact->expressionType() == Expression::Type::Predicate)
|
if (fact->expressionType() == Expression::Type::Predicate)
|
||||||
{
|
{
|
||||||
const auto &predicate = dynamic_cast<const expressions::Predicate &>(*fact);
|
const auto &predicate = dynamic_cast<const expressions::Predicate &>(*fact);
|
||||||
|
|
||||||
m_outputStream << utils::Keyword("variable") << "(";
|
m_outputStream << output::Keyword("variable") << "(";
|
||||||
this->translatePredicate(predicate);
|
this->translatePredicate(predicate);
|
||||||
m_outputStream << "), " << utils::Keyword("value") << "(";
|
m_outputStream << "), " << output::Keyword("value") << "(";
|
||||||
this->translatePredicate(predicate);
|
this->translatePredicate(predicate);
|
||||||
m_outputStream << ", " << utils::Boolean("true") << ")";
|
m_outputStream << ", " << output::Boolean("true") << ")";
|
||||||
}
|
}
|
||||||
// Assuming that "not" expression may only contain a predicate
|
// Assuming that "not" expression may only contain a predicate
|
||||||
else if (fact->expressionType() == Expression::Type::Not)
|
else if (fact->expressionType() == Expression::Type::Not)
|
||||||
@ -512,24 +512,24 @@ void TranslatorASP::translateInitialState() const
|
|||||||
const auto ¬Expression = dynamic_cast<const expressions::Not &>(*fact);
|
const auto ¬Expression = dynamic_cast<const expressions::Not &>(*fact);
|
||||||
|
|
||||||
if (notExpression.argument()->expressionType() != Expression::Type::Predicate)
|
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
|
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 << ").";
|
||||||
});
|
});
|
||||||
|
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< std::endl << std::endl
|
<< std::endl << std::endl
|
||||||
<< utils::RuleName("initialState") << "("
|
<< output::Function("initialState") << "("
|
||||||
<< utils::Keyword("variable") << "(" << utils::Variable("X") << "), "
|
<< output::Keyword("variable") << "(" << output::Variable("X") << "), "
|
||||||
<< utils::Keyword("value") << "(" << utils::Variable("X") << ", " << utils::Boolean("false") << ")) :- "
|
<< output::Keyword("value") << "(" << output::Variable("X") << ", " << output::Boolean("false") << ")) :- "
|
||||||
<< utils::RuleName("variable") << "(" << utils::Keyword("variable") << "(" << utils::Variable("X") << ")), "
|
<< output::Function("variable") << "(" << output::Keyword("variable") << "(" << output::Variable("X") << ")), "
|
||||||
<< utils::Keyword("not") << " "
|
<< output::Keyword("not") << " "
|
||||||
<< utils::RuleName("initialState") << "("
|
<< output::Function("initialState") << "("
|
||||||
<< utils::Keyword("variable") << "(" << utils::Variable("X") << "), "
|
<< output::Keyword("variable") << "(" << output::Variable("X") << "), "
|
||||||
<< utils::Keyword("value") << "(" << utils::Variable("X") << ", " << utils::Boolean("true") << "))."
|
<< output::Keyword("value") << "(" << output::Variable("X") << ", " << output::Boolean("true") << "))."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,14 +539,14 @@ void TranslatorASP::translateGoal() const
|
|||||||
{
|
{
|
||||||
BOOST_ASSERT(m_description.containsProblem());
|
BOOST_ASSERT(m_description.containsProblem());
|
||||||
|
|
||||||
m_outputStream << utils::Heading2("goal");
|
m_outputStream << output::Heading2("goal");
|
||||||
|
|
||||||
const auto &goal = m_description.problem().goal();
|
const auto &goal = m_description.problem().goal();
|
||||||
|
|
||||||
if (goal.expressionType() == Expression::Type::Predicate
|
if (goal.expressionType() == Expression::Type::Predicate
|
||||||
|| goal.expressionType() == Expression::Type::Not)
|
|| goal.expressionType() == Expression::Type::Not)
|
||||||
{
|
{
|
||||||
m_outputStream << std::endl << utils::RuleName("goal") << "(";
|
m_outputStream << std::endl << output::Function("goal") << "(";
|
||||||
|
|
||||||
translateLiteral(goal);
|
translateLiteral(goal);
|
||||||
|
|
||||||
@ -559,7 +559,7 @@ void TranslatorASP::translateGoal() const
|
|||||||
std::for_each(andExpression.arguments().cbegin(), andExpression.arguments().cend(),
|
std::for_each(andExpression.arguments().cbegin(), andExpression.arguments().cend(),
|
||||||
[&](const auto argument)
|
[&](const auto argument)
|
||||||
{
|
{
|
||||||
m_outputStream << std::endl << utils::RuleName("goal") << "(";
|
m_outputStream << std::endl << output::Function("goal") << "(";
|
||||||
|
|
||||||
this->translateLiteral(*argument);
|
this->translateLiteral(*argument);
|
||||||
|
|
||||||
@ -567,7 +567,7 @@ void TranslatorASP::translateGoal() const
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
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;
|
m_outputStream << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include <plasp/pddl/expressions/At.h>
|
#include <plasp/pddl/expressions/At.h>
|
||||||
|
|
||||||
#include <plasp/utils/TranslatorException.h>
|
#include <plasp/output/TranslatorException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -38,7 +38,7 @@ ExpressionPointer At::argument() const
|
|||||||
|
|
||||||
ExpressionPointer At::reduced()
|
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 <boost/assert.hpp>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
@ -113,7 +114,7 @@ void Constant::parseTypedDeclarations(Context &context, Domain &domain)
|
|||||||
domain.checkRequirement(Requirement::Type::Typing);
|
domain.checkRequirement(Requirement::Type::Typing);
|
||||||
// If no types are given, check that typing is not a requirement
|
// If no types are given, check that typing is not a requirement
|
||||||
else if (domain.hasRequirement(Requirement::Type::Typing))
|
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);
|
problem.checkRequirement(Requirement::Type::Typing);
|
||||||
// If no types are given, check that typing is not a requirement
|
// If no types are given, check that typing is not a requirement
|
||||||
else if (problem.hasRequirement(Requirement::Type::Typing))
|
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)
|
if (constant != nullptr)
|
||||||
return 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -181,7 +182,7 @@ ConstantPointer Constant::parseAndFind(Context &context, const Problem &problem)
|
|||||||
if (constant)
|
if (constant)
|
||||||
return 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() != ')')
|
while (parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
if (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
|
// Parse objects and constants
|
||||||
const auto constant = Constant::parseAndFind(context, problem);
|
const auto constant = Constant::parseAndFind(context, problem);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
@ -111,7 +112,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
|
|||||||
const auto typeName = parser.parseIdentifier();
|
const auto typeName = parser.parseIdentifier();
|
||||||
|
|
||||||
if (typeName.empty())
|
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 match = std::find_if(types.cbegin(), types.cend(),
|
||||||
[&](const auto &primitiveType)
|
[&](const auto &primitiveType)
|
||||||
@ -124,11 +125,11 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
|
|||||||
// Only "object" is allowed as an implicit type
|
// Only "object" is allowed as an implicit type
|
||||||
if (typeName == "object" || typeName == "objects")
|
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)));
|
types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
|
||||||
}
|
}
|
||||||
else
|
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();
|
return types.back().get();
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ UnsupportedPointer Unsupported::parse(Context &context)
|
|||||||
|
|
||||||
expression->m_type = parser.parseIdentifier();
|
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);
|
skipSection(parser);
|
||||||
|
|
||||||
|
@ -4,13 +4,13 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
#include <plasp/pddl/expressions/Either.h>
|
#include <plasp/pddl/expressions/Either.h>
|
||||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||||
#include <plasp/pddl/expressions/Type.h>
|
#include <plasp/pddl/expressions/Type.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -53,7 +53,7 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters)
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (match != parameters.cend())
|
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
|
// Flag variable for potentially upcoming type declaration
|
||||||
variable->setDirty();
|
variable->setDirty();
|
||||||
@ -130,7 +130,7 @@ void Variable::parseTypedDeclarations(Context &context, ExpressionContext &expre
|
|||||||
expressionContext.checkRequirement(Requirement::Type::Typing);
|
expressionContext.checkRequirement(Requirement::Type::Typing);
|
||||||
// If no types are given, check that typing is not a requirement
|
// If no types are given, check that typing is not a requirement
|
||||||
else if (expressionContext.hasRequirement(Requirement::Type::Typing))
|
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())
|
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();
|
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;
|
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;
|
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");
|
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
|
// Metric section
|
||||||
ostream << "uses action costs: " << (description.usesActionCosts() ? "yes" : "no") << std::endl;
|
stream << "uses action costs: " << (description.usesActionCosts() ? "yes" : "no") << std::endl;
|
||||||
|
|
||||||
// Variable section
|
// Variable section
|
||||||
const auto &variables = description.variables();
|
const auto &variables = description.variables();
|
||||||
|
|
||||||
ostream << "variables: " << variables.size() << std::endl;
|
stream << "variables: " << variables.size() << std::endl;
|
||||||
|
|
||||||
std::for_each(variables.cbegin(), variables.cend(),
|
std::for_each(variables.cbegin(), variables.cend(),
|
||||||
[&](const auto &variable)
|
[&](const auto &variable)
|
||||||
{
|
{
|
||||||
const auto &values = variable.values();
|
const auto &values = variable.values();
|
||||||
|
|
||||||
ostream << "\t" << variable.name() << ":" << std::endl;
|
stream << "\t" << variable.name() << ":" << std::endl;
|
||||||
ostream << "\t\tvalues: " << values.size() << std::endl;
|
stream << "\t\tvalues: " << values.size() << std::endl;
|
||||||
|
|
||||||
std::for_each(values.cbegin(), values.cend(),
|
std::for_each(values.cbegin(), values.cend(),
|
||||||
[&](const auto &value)
|
[&](const auto &value)
|
||||||
{
|
{
|
||||||
ostream << "\t\t\t";
|
stream << "\t\t\t";
|
||||||
value.printAsSAS(ostream);
|
value.printAsSAS(stream);
|
||||||
ostream << std::endl;
|
stream << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
ostream << "\t\taxiom layer: " << variable.axiomLayer() << std::endl;
|
stream << "\t\taxiom layer: " << variable.axiomLayer() << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mutex section
|
// Mutex section
|
||||||
const auto &mutexGroups = description.mutexGroups();
|
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(),
|
std::for_each(mutexGroups.cbegin(), mutexGroups.cend(),
|
||||||
[&](const auto &mutexGroup)
|
[&](const auto &mutexGroup)
|
||||||
{
|
{
|
||||||
ostream << "\tmutex group:" << std::endl;
|
stream << "\tmutex group:" << std::endl;
|
||||||
|
|
||||||
std::for_each(mutexGroup.facts().cbegin(), mutexGroup.facts().cend(),
|
std::for_each(mutexGroup.facts().cbegin(), mutexGroup.facts().cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
ostream << "\t\t" << fact.variable().name() << " = ";
|
stream << "\t\t" << fact.variable().name() << " = ";
|
||||||
fact.value().printAsSAS(ostream);
|
fact.value().printAsSAS(stream);
|
||||||
ostream << std::endl;
|
stream << std::endl;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initial state section
|
// Initial state section
|
||||||
const auto &initialState = description.initialState();
|
const auto &initialState = description.initialState();
|
||||||
|
|
||||||
ostream << "initial state:" << std::endl;
|
stream << "initial state:" << std::endl;
|
||||||
|
|
||||||
std::for_each(initialState.facts().cbegin(), initialState.facts().cend(),
|
std::for_each(initialState.facts().cbegin(), initialState.facts().cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
ostream << "\t" << fact.variable().name() << " = ";
|
stream << "\t" << fact.variable().name() << " = ";
|
||||||
fact.value().printAsSAS(ostream);
|
fact.value().printAsSAS(stream);
|
||||||
ostream << std::endl;
|
stream << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Goal section
|
// Goal section
|
||||||
const auto &goal = description.goal();
|
const auto &goal = description.goal();
|
||||||
|
|
||||||
ostream << "goal:" << std::endl;
|
stream << "goal:" << std::endl;
|
||||||
|
|
||||||
std::for_each(goal.facts().cbegin(), goal.facts().cend(),
|
std::for_each(goal.facts().cbegin(), goal.facts().cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
ostream << "\t" << fact.variable().name() << " = ";
|
stream << "\t" << fact.variable().name() << " = ";
|
||||||
fact.value().printAsSAS(ostream);
|
fact.value().printAsSAS(stream);
|
||||||
ostream << std::endl;
|
stream << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Operator section
|
// Operator section
|
||||||
const auto &operators = description.operators();
|
const auto &operators = description.operators();
|
||||||
|
|
||||||
ostream << "operators: " << operators.size() << std::endl;
|
stream << "operators: " << operators.size() << std::endl;
|
||||||
|
|
||||||
std::for_each(operators.cbegin(), operators.cend(),
|
std::for_each(operators.cbegin(), operators.cend(),
|
||||||
[&](const auto &operator_)
|
[&](const auto &operator_)
|
||||||
{
|
{
|
||||||
ostream << "\t";
|
stream << "\t";
|
||||||
operator_.predicate().printAsSAS(ostream);
|
operator_.predicate().printAsSAS(stream);
|
||||||
ostream << ":" << std::endl;
|
stream << ":" << std::endl;
|
||||||
|
|
||||||
const auto &preconditions = operator_.preconditions();
|
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(),
|
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
||||||
[&](const auto &precondition)
|
[&](const auto &precondition)
|
||||||
{
|
{
|
||||||
std::cout << "\t\t\t" << precondition.variable().name() << " = ";
|
std::cout << "\t\t\t" << precondition.variable().name() << " = ";
|
||||||
precondition.value().printAsSAS(ostream);
|
precondition.value().printAsSAS(stream);
|
||||||
ostream << std::endl;
|
stream << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto &effects = operator_.effects();
|
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(),
|
std::for_each(effects.cbegin(), effects.cend(),
|
||||||
[&](const auto &effect)
|
[&](const auto &effect)
|
||||||
{
|
{
|
||||||
ostream << "\t\t\teffect:" << std::endl;
|
stream << "\t\t\teffect:" << std::endl;
|
||||||
|
|
||||||
const auto &conditions = effect.conditions();
|
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(),
|
std::for_each(conditions.cbegin(), conditions.cend(),
|
||||||
[&](const auto &condition)
|
[&](const auto &condition)
|
||||||
{
|
{
|
||||||
ostream << "\t\t\t\t\t" << condition.variable().name() << " = ";
|
stream << "\t\t\t\t\t" << condition.variable().name() << " = ";
|
||||||
condition.value().printAsSAS(ostream);
|
condition.value().printAsSAS(stream);
|
||||||
ostream << std::endl;
|
stream << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
ostream << "\t\t\t\tpostcondition:" << std::endl;
|
stream << "\t\t\t\tpostcondition:" << std::endl;
|
||||||
ostream << "\t\t\t\t\t" << effect.postcondition().variable().name() << " = ";
|
stream << "\t\t\t\t\t" << effect.postcondition().variable().name() << " = ";
|
||||||
effect.postcondition().value().printAsSAS(ostream);
|
effect.postcondition().value().printAsSAS(stream);
|
||||||
ostream << std::endl;
|
stream << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
ostream << "\t\tcosts: " << operator_.costs() << std::endl;
|
stream << "\t\tcosts: " << operator_.costs() << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Axiom section
|
// Axiom section
|
||||||
const auto &axiomRules = description.axiomRules();
|
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(),
|
std::for_each(axiomRules.cbegin(), axiomRules.cend(),
|
||||||
[&](const auto &axiomRule)
|
[&](const auto &axiomRule)
|
||||||
{
|
{
|
||||||
ostream << "\taxiom rule:" << std::endl;
|
stream << "\taxiom rule:" << std::endl;
|
||||||
|
|
||||||
const auto conditions = axiomRule.conditions();
|
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(),
|
std::for_each(conditions.cbegin(), conditions.cend(),
|
||||||
[&](const auto &condition)
|
[&](const auto &condition)
|
||||||
{
|
{
|
||||||
ostream << "\t\t\t" << condition.variable().name() << " = ";
|
stream << "\t\t\t" << condition.variable().name() << " = ";
|
||||||
condition.value().printAsSAS(ostream);
|
condition.value().printAsSAS(stream);
|
||||||
ostream << std::endl;
|
stream << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
ostream << "\t\tpostcondition:" << std::endl;
|
stream << "\t\tpostcondition:" << std::endl;
|
||||||
ostream << "\t\t\t" << axiomRule.postcondition().variable().name() << " = ";
|
stream << "\t\t\t" << axiomRule.postcondition().variable().name() << " = ";
|
||||||
axiomRule.postcondition().value().printAsSAS(ostream);
|
axiomRule.postcondition().value().printAsSAS(stream);
|
||||||
ostream << std::endl;
|
stream << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
return ostream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/sas/VariableTransition.h>
|
#include <plasp/sas/VariableTransition.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
@ -28,7 +28,7 @@ Description::Description()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Description Description::fromParser(utils::Parser<> &&parser)
|
Description Description::fromParser(input::Parser<> &&parser)
|
||||||
{
|
{
|
||||||
Description description;
|
Description description;
|
||||||
description.parseContent(parser);
|
description.parseContent(parser);
|
||||||
@ -40,7 +40,7 @@ Description Description::fromParser(utils::Parser<> &&parser)
|
|||||||
|
|
||||||
Description Description::fromStream(std::istream &istream)
|
Description Description::fromStream(std::istream &istream)
|
||||||
{
|
{
|
||||||
utils::Parser<> parser;
|
input::Parser<> parser;
|
||||||
parser.read("std::cin", istream);
|
parser.read("std::cin", istream);
|
||||||
|
|
||||||
Description description;
|
Description description;
|
||||||
@ -56,7 +56,7 @@ Description Description::fromFile(const boost::filesystem::path &path)
|
|||||||
if (!boost::filesystem::is_regular_file(path))
|
if (!boost::filesystem::is_regular_file(path))
|
||||||
throw std::runtime_error("File does not exist: “" + path.string() + "”");
|
throw std::runtime_error("File does not exist: “" + path.string() + "”");
|
||||||
|
|
||||||
utils::Parser<> parser;
|
input::Parser<> parser;
|
||||||
parser.read(path);
|
parser.read(path);
|
||||||
|
|
||||||
Description description;
|
Description description;
|
||||||
@ -160,7 +160,7 @@ bool Description::hasRequirements() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseContent(utils::Parser<> &parser)
|
void Description::parseContent(input::Parser<> &parser)
|
||||||
{
|
{
|
||||||
parseVersionSection(parser);
|
parseVersionSection(parser);
|
||||||
parseMetricSection(parser);
|
parseMetricSection(parser);
|
||||||
@ -174,26 +174,26 @@ void Description::parseContent(utils::Parser<> &parser)
|
|||||||
parser.skipWhiteSpace();
|
parser.skipWhiteSpace();
|
||||||
|
|
||||||
if (!parser.atEnd())
|
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");
|
parser.expect<std::string>("begin_version");
|
||||||
|
|
||||||
const auto formatVersion = parser.parse<size_t>();
|
const auto formatVersion = parser.parse<size_t>();
|
||||||
|
|
||||||
if (formatVersion != 3)
|
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");
|
parser.expect<std::string>("end_version");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseMetricSection(utils::Parser<> &parser)
|
void Description::parseMetricSection(input::Parser<> &parser)
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("begin_metric");
|
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>();
|
const auto numberOfVariables = parser.parse<size_t>();
|
||||||
m_variables.reserve(numberOfVariables);
|
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>();
|
const auto numberOfMutexGroups = parser.parse<size_t>();
|
||||||
m_mutexGroups.reserve(numberOfMutexGroups);
|
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));
|
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));
|
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>();
|
const auto numberOfOperators = parser.parse<size_t>();
|
||||||
m_operators.reserve(numberOfOperators);
|
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>();
|
const auto numberOfAxiomRules = parser.parse<size_t>();
|
||||||
m_axiomRules.reserve(numberOfAxiomRules);
|
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;
|
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;
|
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;
|
InitialState initialState;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/input/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
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;
|
MutexGroup mutexGroup;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ MutexGroup MutexGroup::fromSAS(utils::Parser<> &parser, const Variables &variabl
|
|||||||
mutexGroup.m_facts.emplace_back(Fact::fromSAS(parser, variables));
|
mutexGroup.m_facts.emplace_back(Fact::fromSAS(parser, variables));
|
||||||
|
|
||||||
if (mutexGroup.m_facts[j].value() == Value::None)
|
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");
|
parser.expect<std::string>("end_mutex_group");
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include <plasp/output/Formatting.h>
|
||||||
#include <plasp/sas/VariableTransition.h>
|
#include <plasp/sas/VariableTransition.h>
|
||||||
#include <plasp/utils/Formatting.h>
|
|
||||||
|
|
||||||
namespace plasp
|
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_;
|
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") << "(";
|
stream << output::Keyword("action") << "(";
|
||||||
m_predicate.printAsASP(outputStream);
|
m_predicate.printAsASP(stream);
|
||||||
outputStream << ")";
|
stream << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <plasp/utils/Formatting.h>
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/output/Formatting.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -18,7 +18,7 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Predicate Predicate::fromSAS(utils::Parser<> &parser)
|
Predicate Predicate::fromSAS(input::Parser<> &parser)
|
||||||
{
|
{
|
||||||
Predicate predicate;
|
Predicate predicate;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ Predicate Predicate::fromSAS(utils::Parser<> &parser)
|
|||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
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;
|
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())
|
if (m_arguments.empty())
|
||||||
{
|
{
|
||||||
outputStream << m_name;
|
stream << m_name;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < m_arguments.size(); i++)
|
for (size_t i = 0; i < m_arguments.size(); i++)
|
||||||
{
|
{
|
||||||
if (i > 0)
|
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())
|
if (m_arguments.empty())
|
||||||
{
|
{
|
||||||
outputStream << utils::String(m_name);
|
stream << output::String(m_name.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
outputStream << "(" << utils::String(m_name);
|
stream << "(" << output::String(m_name.c_str());
|
||||||
|
|
||||||
for (size_t i = 0; i < m_arguments.size(); i++)
|
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/sas/TranslatorASP.h>
|
||||||
|
|
||||||
#include <plasp/utils/Formatting.h>
|
#include <plasp/output/Formatting.h>
|
||||||
|
|
||||||
namespace plasp
|
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_description(description),
|
||||||
m_outputStream(ostream)
|
m_outputStream(outputStream)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,30 +56,30 @@ void TranslatorASP::translate() const
|
|||||||
|
|
||||||
void TranslatorASP::translateRequirements() 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())
|
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())
|
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())
|
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
|
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();
|
const auto &initialStateFacts = m_description.initialState().facts();
|
||||||
|
|
||||||
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
m_outputStream << utils::RuleName("initialState") << "(";
|
m_outputStream << output::Function("initialState") << "(";
|
||||||
fact.variable().printNameAsASPPredicate(m_outputStream);
|
fact.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
fact.value().printAsASPPredicate(m_outputStream);
|
fact.value().printAsASPPredicate(m_outputStream);
|
||||||
@ -91,14 +91,14 @@ void TranslatorASP::translateInitialState() const
|
|||||||
|
|
||||||
void TranslatorASP::translateGoal() 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();
|
const auto &goalFacts = m_description.goal().facts();
|
||||||
|
|
||||||
std::for_each(goalFacts.cbegin(), goalFacts.cend(),
|
std::for_each(goalFacts.cbegin(), goalFacts.cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
m_outputStream << utils::RuleName("goal") << "(";
|
m_outputStream << output::Function("goal") << "(";
|
||||||
fact.variable().printNameAsASPPredicate(m_outputStream);
|
fact.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
fact.value().printAsASPPredicate(m_outputStream);
|
fact.value().printAsASPPredicate(m_outputStream);
|
||||||
@ -110,7 +110,7 @@ void TranslatorASP::translateGoal() const
|
|||||||
|
|
||||||
void TranslatorASP::translateVariables() const
|
void TranslatorASP::translateVariables() const
|
||||||
{
|
{
|
||||||
m_outputStream << utils::Heading2("variables");
|
m_outputStream << output::Heading2("variables");
|
||||||
|
|
||||||
const auto &variables = m_description.variables();
|
const auto &variables = m_description.variables();
|
||||||
|
|
||||||
@ -121,14 +121,14 @@ void TranslatorASP::translateVariables() const
|
|||||||
|
|
||||||
BOOST_ASSERT(!values.empty());
|
BOOST_ASSERT(!values.empty());
|
||||||
|
|
||||||
m_outputStream << std::endl << utils::RuleName("variable") << "(";
|
m_outputStream << std::endl << output::Function("variable") << "(";
|
||||||
variable.printNameAsASPPredicate(m_outputStream);
|
variable.printNameAsASPPredicate(m_outputStream);
|
||||||
m_outputStream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
|
|
||||||
std::for_each(values.cbegin(), values.cend(),
|
std::for_each(values.cbegin(), values.cend(),
|
||||||
[&](const auto &value)
|
[&](const auto &value)
|
||||||
{
|
{
|
||||||
m_outputStream << utils::RuleName("contains") << "(";
|
m_outputStream << output::Function("contains") << "(";
|
||||||
variable.printNameAsASPPredicate(m_outputStream);
|
variable.printNameAsASPPredicate(m_outputStream);
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
value.printAsASPPredicate(m_outputStream);
|
value.printAsASPPredicate(m_outputStream);
|
||||||
@ -141,7 +141,7 @@ void TranslatorASP::translateVariables() const
|
|||||||
|
|
||||||
void TranslatorASP::translateActions() const
|
void TranslatorASP::translateActions() const
|
||||||
{
|
{
|
||||||
m_outputStream << utils::Heading2("actions");
|
m_outputStream << output::Heading2("actions");
|
||||||
|
|
||||||
const auto &operators = m_description.operators();
|
const auto &operators = m_description.operators();
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ void TranslatorASP::translateActions() const
|
|||||||
std::for_each(operators.cbegin(), operators.cend(),
|
std::for_each(operators.cbegin(), operators.cend(),
|
||||||
[&](const auto &operator_)
|
[&](const auto &operator_)
|
||||||
{
|
{
|
||||||
m_outputStream << std::endl << utils::RuleName("action") << "(";
|
m_outputStream << std::endl << output::Function("action") << "(";
|
||||||
operator_.printPredicateAsASP(m_outputStream);
|
operator_.printPredicateAsASP(m_outputStream);
|
||||||
m_outputStream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ void TranslatorASP::translateActions() const
|
|||||||
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
||||||
[&](const auto &precondition)
|
[&](const auto &precondition)
|
||||||
{
|
{
|
||||||
m_outputStream << utils::RuleName("precondition") << "(";
|
m_outputStream << output::Function("precondition") << "(";
|
||||||
operator_.printPredicateAsASP(m_outputStream);
|
operator_.printPredicateAsASP(m_outputStream);
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
precondition.variable().printNameAsASPPredicate(m_outputStream);
|
precondition.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
@ -175,13 +175,13 @@ void TranslatorASP::translateActions() const
|
|||||||
{
|
{
|
||||||
const auto &conditions = effect.conditions();
|
const auto &conditions = effect.conditions();
|
||||||
|
|
||||||
m_outputStream << utils::RuleName("postcondition") << "(";
|
m_outputStream << output::Function("postcondition") << "(";
|
||||||
operator_.printPredicateAsASP(m_outputStream);
|
operator_.printPredicateAsASP(m_outputStream);
|
||||||
|
|
||||||
if (conditions.empty())
|
if (conditions.empty())
|
||||||
m_outputStream << ", " << utils::Keyword("effect") << "(" << utils::Reserved("unconditional") << "), ";
|
m_outputStream << ", " << output::Keyword("effect") << "(" << output::Reserved("unconditional") << "), ";
|
||||||
else
|
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);
|
effect.postcondition().variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
@ -193,8 +193,8 @@ void TranslatorASP::translateActions() const
|
|||||||
{
|
{
|
||||||
// Conditions of conditional effects
|
// Conditions of conditional effects
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< utils::RuleName("precondition") << "("
|
<< output::Function("precondition") << "("
|
||||||
<< utils::Keyword("effect") << "(" << utils::Number(std::to_string(currentEffectID)) << "), ";
|
<< output::Keyword("effect") << "(" << output::Number<decltype(currentEffectID)>(currentEffectID) << "), ";
|
||||||
condition.variable().printNameAsASPPredicate(m_outputStream);
|
condition.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
condition.value().printAsASPPredicate(m_outputStream);
|
condition.value().printAsASPPredicate(m_outputStream);
|
||||||
@ -205,9 +205,9 @@ void TranslatorASP::translateActions() const
|
|||||||
currentEffectID++;
|
currentEffectID++;
|
||||||
});
|
});
|
||||||
|
|
||||||
m_outputStream << utils::RuleName("costs") << "(";
|
m_outputStream << output::Function("costs") << "(";
|
||||||
operator_.printPredicateAsASP(m_outputStream);
|
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
|
void TranslatorASP::translateMutexes() const
|
||||||
{
|
{
|
||||||
m_outputStream << utils::Heading2("mutex groups");
|
m_outputStream << output::Heading2("mutex groups");
|
||||||
|
|
||||||
const auto &mutexGroups = m_description.mutexGroups();
|
const auto &mutexGroups = m_description.mutexGroups();
|
||||||
|
|
||||||
@ -229,9 +229,9 @@ void TranslatorASP::translateMutexes() const
|
|||||||
|
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< utils::RuleName("mutexGroup") << "("
|
<< output::Function("mutexGroup") << "("
|
||||||
<< utils::Keyword("mutexGroup") << "("
|
<< output::Keyword("mutexGroup") << "("
|
||||||
<< utils::Number(mutexGroupID)
|
<< output::Number<decltype(mutexGroupID)>(mutexGroupID)
|
||||||
<< "))." << std::endl;
|
<< "))." << std::endl;
|
||||||
|
|
||||||
const auto &facts = mutexGroup.facts();
|
const auto &facts = mutexGroup.facts();
|
||||||
@ -239,7 +239,7 @@ void TranslatorASP::translateMutexes() const
|
|||||||
std::for_each(facts.cbegin(), facts.cend(),
|
std::for_each(facts.cbegin(), facts.cend(),
|
||||||
[&](const auto &fact)
|
[&](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);
|
fact.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
fact.value().printAsASPPredicate(m_outputStream);
|
fact.value().printAsASPPredicate(m_outputStream);
|
||||||
@ -252,7 +252,7 @@ void TranslatorASP::translateMutexes() const
|
|||||||
|
|
||||||
void TranslatorASP::translateAxiomRules() const
|
void TranslatorASP::translateAxiomRules() const
|
||||||
{
|
{
|
||||||
m_outputStream << utils::Heading2("axiom rules");
|
m_outputStream << output::Heading2("axiom rules");
|
||||||
|
|
||||||
const auto &axiomRules = m_description.axiomRules();
|
const auto &axiomRules = m_description.axiomRules();
|
||||||
|
|
||||||
@ -266,9 +266,9 @@ void TranslatorASP::translateAxiomRules() const
|
|||||||
|
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< utils::RuleName("axiomRule") << "("
|
<< output::Function("axiomRule") << "("
|
||||||
<< utils::Keyword("axiomRule") << "("
|
<< output::Keyword("axiomRule") << "("
|
||||||
<< utils::Number(axiomRuleID)
|
<< output::Number<decltype(axiomRuleID)>(axiomRuleID)
|
||||||
<< "))." << std::endl;
|
<< "))." << std::endl;
|
||||||
|
|
||||||
const auto &conditions = axiomRule.conditions();
|
const auto &conditions = axiomRule.conditions();
|
||||||
@ -277,8 +277,8 @@ void TranslatorASP::translateAxiomRules() const
|
|||||||
[&](const auto &condition)
|
[&](const auto &condition)
|
||||||
{
|
{
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< utils::RuleName("precondition") << "("
|
<< output::Function("precondition") << "("
|
||||||
<< utils::Keyword("axiomRule") << "(" << utils::Number(axiomRuleID) << "), ";
|
<< output::Keyword("axiomRule") << "(" << output::Number<decltype(axiomRuleID)>(axiomRuleID) << "), ";
|
||||||
condition.variable().printNameAsASPPredicate(m_outputStream);
|
condition.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
condition.value().printAsASPPredicate(m_outputStream);
|
condition.value().printAsASPPredicate(m_outputStream);
|
||||||
@ -288,9 +288,9 @@ void TranslatorASP::translateAxiomRules() const
|
|||||||
const auto &postcondition = axiomRule.postcondition();
|
const auto &postcondition = axiomRule.postcondition();
|
||||||
|
|
||||||
m_outputStream
|
m_outputStream
|
||||||
<< utils::RuleName("postcondition") << "("
|
<< output::Function("postcondition") << "("
|
||||||
<< utils::Keyword("axiomRule") << "(" << utils::Number(axiomRuleID) << "), "
|
<< output::Keyword("axiomRule") << "(" << output::Number<decltype(axiomRuleID)>(axiomRuleID) << "), "
|
||||||
<< utils::Keyword("effect") << "(" << utils::Reserved("unconditional") << "), ";
|
<< output::Keyword("effect") << "(" << output::Reserved("unconditional") << "), ";
|
||||||
postcondition.variable().printNameAsASPPredicate(m_outputStream);
|
postcondition.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_outputStream << ", ";
|
m_outputStream << ", ";
|
||||||
postcondition.value().printAsASPPredicate(m_outputStream);
|
postcondition.value().printAsASPPredicate(m_outputStream);
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <plasp/input/ParserException.h>
|
||||||
|
#include <plasp/output/Formatting.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
#include <plasp/utils/Formatting.h>
|
|
||||||
#include <plasp/utils/ParserException.h>
|
|
||||||
|
|
||||||
namespace plasp
|
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>();
|
const auto sasSign = parser.parse<std::string>();
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ Value Value::fromSAS(utils::Parser<> &parser)
|
|||||||
else if (sasSign == "NegatedAtom")
|
else if (sasSign == "NegatedAtom")
|
||||||
value.m_sign = Value::Sign::Negative;
|
value.m_sign = Value::Sign::Negative;
|
||||||
else
|
else
|
||||||
throw utils::ParserException(parser.coordinate(), "invalid value sign “" + sasSign + "”");
|
throw input::ParserException(parser.location(), "invalid value sign “" + sasSign + "”");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -90,7 +90,7 @@ Value Value::fromSAS(utils::Parser<> &parser)
|
|||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
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;
|
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>();
|
const auto valueID = parser.parse<int>();
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ const Value &Value::referenceFromSAS(utils::Parser<> &parser, const Variable &va
|
|||||||
return Value::Any;
|
return Value::Any;
|
||||||
|
|
||||||
if (valueID < 0 || static_cast<size_t>(valueID) >= variable.values().size())
|
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];
|
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
|
// TODO: do not compare by value
|
||||||
if (*this == Value::None)
|
if (*this == Value::None)
|
||||||
{
|
{
|
||||||
outputStream << utils::Keyword("value") << "(" << utils::Reserved("none") << ")";
|
stream << output::Keyword("value") << "(" << output::Reserved("none") << ")";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
outputStream << utils::Keyword("value") << "(" << utils::String(m_name) << ", "
|
stream << output::Keyword("value") << "(" << output::String(m_name.c_str()) << ", "
|
||||||
<< (m_sign == Sign::Positive ? utils::Boolean("true") : utils::Boolean("false")) << ")";
|
<< (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)
|
if (m_sign == Value::Sign::Positive)
|
||||||
outputStream << "Atom ";
|
stream << "Atom ";
|
||||||
else
|
else
|
||||||
outputStream << "NegatedAtom ";
|
stream << "NegatedAtom ";
|
||||||
|
|
||||||
outputStream << m_name;
|
stream << m_name;
|
||||||
|
|
||||||
if (!m_hasArguments)
|
if (!m_hasArguments)
|
||||||
outputStream << "()";
|
stream << "()";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <plasp/utils/Formatting.h>
|
#include <plasp/input/ParserException.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/output/Formatting.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -23,7 +23,7 @@ Variable::Variable()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Variable Variable::fromSAS(utils::Parser<> &parser)
|
Variable Variable::fromSAS(input::Parser<> &parser)
|
||||||
{
|
{
|
||||||
Variable variable;
|
Variable variable;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ Variable Variable::fromSAS(utils::Parser<> &parser)
|
|||||||
|
|
||||||
// <none of those> values are only allowed at the end
|
// <none of those> values are only allowed at the end
|
||||||
if (j < numberOfValues - 1 && variable.m_values[j] == Value::None)
|
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");
|
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
|
// 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>();
|
const auto variableID = parser.parse<size_t>();
|
||||||
|
|
||||||
if (variableID >= variables.size())
|
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];
|
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;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -33,7 +33,7 @@ TEST_CASE("[PDDL normalization] PDDL expressions are correctly reduced", "[PDDL
|
|||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
n1->reduced()->print(output);
|
n1->reduced()->print(output);
|
||||||
|
|
||||||
REQUIRE(output.str() == "(not (not (and (or (or (not (a)) (b)) (c)) (d))))");
|
CHECK(output.str() == "(not (not (and (or (or (not (a)) (b)) (c)) (d))))");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -63,7 +63,7 @@ TEST_CASE("[PDDL normalization] PDDL expressions are correctly simplified", "[PD
|
|||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
a1->simplified()->print(output);
|
a1->simplified()->print(output);
|
||||||
|
|
||||||
REQUIRE(output.str() == "(and (a) (b) (c) (d) (or (e) (f) (g) (h)))");
|
CHECK(output.str() == "(and (a) (b) (c) (d) (or (e) (f) (g) (h)))");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -78,7 +78,7 @@ TEST_CASE("[PDDL normalization] Implications are correctly replaced", "[PDDL nor
|
|||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
i->normalized()->print(output);
|
i->normalized()->print(output);
|
||||||
|
|
||||||
REQUIRE(output.str() == "(or (not (a)) (b))");
|
CHECK(output.str() == "(or (not (a)) (b))");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -94,7 +94,7 @@ TEST_CASE("[PDDL normalization] Double negations are correctly replaced", "[PDDL
|
|||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
n1->normalized()->print(output);
|
n1->normalized()->print(output);
|
||||||
|
|
||||||
REQUIRE(output.str() == "(a)");
|
CHECK(output.str() == "(a)");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -112,7 +112,7 @@ TEST_CASE("[PDDL normalization] De Morgan’s rule is correctly applied to negat
|
|||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
n->normalized()->print(output);
|
n->normalized()->print(output);
|
||||||
|
|
||||||
REQUIRE(output.str() == "(or (not (a)) (not (b)) (not (c)))");
|
CHECK(output.str() == "(or (not (a)) (not (b)) (not (c)))");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -130,7 +130,7 @@ TEST_CASE("[PDDL normalization] De Morgan’s rule is correctly applied to negat
|
|||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
n->normalized()->print(output);
|
n->normalized()->print(output);
|
||||||
|
|
||||||
REQUIRE(output.str() == "(and (not (a)) (not (b)) (not (c)))");
|
CHECK(output.str() == "(and (not (a)) (not (b)) (not (c)))");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -153,5 +153,5 @@ TEST_CASE("[PDDL normalization] Expressions inside double negations are also nor
|
|||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
n1->normalized()->print(output);
|
n1->normalized()->print(output);
|
||||||
|
|
||||||
REQUIRE(output.str() == "(or (not (a)) (not (b)) (not (c)))");
|
CHECK(output.str() == "(or (not (a)) (not (b)) (not (c)))");
|
||||||
}
|
}
|
||||||
|
@ -18,26 +18,29 @@ using namespace plasp::pddl;
|
|||||||
|
|
||||||
TEST_CASE("[PDDL parser] The Blocks World domain is parsed correctly", "[PDDL parser]")
|
TEST_CASE("[PDDL parser] The Blocks World domain is parsed correctly", "[PDDL parser]")
|
||||||
{
|
{
|
||||||
const auto description = Description::fromFile("data/blocksworld-domain.pddl");
|
plasp::output::Logger logger;
|
||||||
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
|
const auto description = Description::fromFile("data/blocksworld-domain.pddl", context);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(description.domain());
|
REQUIRE_NOTHROW(description.domain());
|
||||||
|
|
||||||
const auto &domain = description.domain();
|
const auto &domain = description.domain();
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
REQUIRE(domain.name() == "blocks");
|
CHECK(domain.name() == "blocks");
|
||||||
|
|
||||||
// Requirements
|
// Requirements
|
||||||
REQUIRE(domain.requirements().size() == 2u);
|
REQUIRE(domain.requirements().size() == 2u);
|
||||||
REQUIRE(domain.requirements()[0].type() == Requirement::Type::STRIPS);
|
CHECK(domain.requirements()[0].type() == Requirement::Type::STRIPS);
|
||||||
REQUIRE(domain.requirements()[1].type() == Requirement::Type::Typing);
|
CHECK(domain.requirements()[1].type() == Requirement::Type::Typing);
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
REQUIRE(domain.types().size() == 1u);
|
REQUIRE(domain.types().size() == 1u);
|
||||||
|
|
||||||
const auto &block = *domain.types()[0];
|
const auto &block = *domain.types()[0];
|
||||||
|
|
||||||
REQUIRE(block.name() == "block");
|
CHECK(block.name() == "block");
|
||||||
REQUIRE(block.parentTypes().size() == 0u);
|
REQUIRE(block.parentTypes().size() == 0u);
|
||||||
|
|
||||||
// Predicates
|
// Predicates
|
||||||
@ -45,67 +48,70 @@ TEST_CASE("[PDDL parser] The Blocks World domain is parsed correctly", "[PDDL pa
|
|||||||
|
|
||||||
const auto &on = *domain.predicates()[0];
|
const auto &on = *domain.predicates()[0];
|
||||||
|
|
||||||
REQUIRE(on.name() == "on");
|
CHECK(on.name() == "on");
|
||||||
REQUIRE(on.arguments().size() == 2u);
|
REQUIRE(on.arguments().size() == 2u);
|
||||||
REQUIRE(on.arguments()[0]->name() == "x");
|
CHECK(on.arguments()[0]->name() == "x");
|
||||||
const auto &onArgument0Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[0]->type());
|
const auto &onArgument0Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[0]->type());
|
||||||
REQUIRE(&onArgument0Type == &block);
|
CHECK(&onArgument0Type == &block);
|
||||||
REQUIRE(on.arguments()[1]->name() == "y");
|
CHECK(on.arguments()[1]->name() == "y");
|
||||||
const auto &onArgument1Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[1]->type());
|
const auto &onArgument1Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[1]->type());
|
||||||
REQUIRE(&onArgument1Type == &block);
|
CHECK(&onArgument1Type == &block);
|
||||||
|
|
||||||
const auto &handempty = *domain.predicates()[3];
|
const auto &handempty = *domain.predicates()[3];
|
||||||
|
|
||||||
REQUIRE(handempty.name() == "handempty");
|
CHECK(handempty.name() == "handempty");
|
||||||
REQUIRE(handempty.arguments().empty());
|
CHECK(handempty.arguments().empty());
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
REQUIRE(domain.actions().size() == 4u);
|
REQUIRE(domain.actions().size() == 4u);
|
||||||
|
|
||||||
const auto &pickUp = *domain.actions()[0];
|
const auto &pickUp = *domain.actions()[0];
|
||||||
|
|
||||||
REQUIRE(pickUp.name() == "pick-up");
|
CHECK(pickUp.name() == "pick-up");
|
||||||
REQUIRE(pickUp.parameters().size() == 1u);
|
REQUIRE(pickUp.parameters().size() == 1u);
|
||||||
REQUIRE(pickUp.parameters()[0]->name() == "x");
|
CHECK(pickUp.parameters()[0]->name() == "x");
|
||||||
REQUIRE(pickUp.parameters()[0]->type() == &block);
|
CHECK(pickUp.parameters()[0]->type() == &block);
|
||||||
|
|
||||||
const auto &pickUpPre = dynamic_cast<const expressions::And &>(*pickUp.precondition());
|
const auto &pickUpPre = dynamic_cast<const expressions::And &>(*pickUp.precondition());
|
||||||
REQUIRE(pickUpPre.arguments().size() == 3u);
|
REQUIRE(pickUpPre.arguments().size() == 3u);
|
||||||
const auto &pickUpPre0 = dynamic_cast<const expressions::Predicate &>(*pickUpPre.arguments()[0]);
|
const auto &pickUpPre0 = dynamic_cast<const expressions::Predicate &>(*pickUpPre.arguments()[0]);
|
||||||
REQUIRE(pickUpPre0.name() == "clear");
|
CHECK(pickUpPre0.name() == "clear");
|
||||||
REQUIRE(pickUpPre0.arguments().size() == 1u);
|
REQUIRE(pickUpPre0.arguments().size() == 1u);
|
||||||
const auto &pickUpPre00 = dynamic_cast<const expressions::Variable &>(*pickUpPre0.arguments()[0]);
|
const auto &pickUpPre00 = dynamic_cast<const expressions::Variable &>(*pickUpPre0.arguments()[0]);
|
||||||
REQUIRE(pickUpPre00.name() == "x");
|
CHECK(pickUpPre00.name() == "x");
|
||||||
REQUIRE(pickUpPre00.type() == &block);
|
CHECK(pickUpPre00.type() == &block);
|
||||||
REQUIRE(&pickUpPre00 == pickUp.parameters()[0].get());
|
CHECK(&pickUpPre00 == pickUp.parameters()[0].get());
|
||||||
const auto &pickUpPre2 = dynamic_cast<const expressions::Predicate &>(*pickUpPre.arguments()[2]);
|
const auto &pickUpPre2 = dynamic_cast<const expressions::Predicate &>(*pickUpPre.arguments()[2]);
|
||||||
REQUIRE(pickUpPre2.name() == "handempty");
|
CHECK(pickUpPre2.name() == "handempty");
|
||||||
REQUIRE(pickUpPre2.arguments().size() == 0u);
|
CHECK(pickUpPre2.arguments().empty());
|
||||||
|
|
||||||
const auto &pickUpEff = dynamic_cast<const expressions::And &>(*pickUp.effect());
|
const auto &pickUpEff = dynamic_cast<const expressions::And &>(*pickUp.effect());
|
||||||
REQUIRE(pickUpEff.arguments().size() == 4u);
|
REQUIRE(pickUpEff.arguments().size() == 4u);
|
||||||
const auto &pickUpEff0 = dynamic_cast<const expressions::Not &>(*pickUpEff.arguments()[0]);
|
const auto &pickUpEff0 = dynamic_cast<const expressions::Not &>(*pickUpEff.arguments()[0]);
|
||||||
const auto &pickUpEff00 = dynamic_cast<const expressions::Predicate &>(*pickUpEff0.argument());
|
const auto &pickUpEff00 = dynamic_cast<const expressions::Predicate &>(*pickUpEff0.argument());
|
||||||
REQUIRE(pickUpEff00.name() == "ontable");
|
CHECK(pickUpEff00.name() == "ontable");
|
||||||
REQUIRE(pickUpEff00.arguments().size() == 1u);
|
REQUIRE(pickUpEff00.arguments().size() == 1u);
|
||||||
const auto &pickUpEff000 = dynamic_cast<const expressions::Variable &>(*pickUpEff00.arguments()[0]);
|
const auto &pickUpEff000 = dynamic_cast<const expressions::Variable &>(*pickUpEff00.arguments()[0]);
|
||||||
REQUIRE(pickUpEff000.name() == "x");
|
CHECK(pickUpEff000.name() == "x");
|
||||||
REQUIRE(pickUpEff000.type() == &block);
|
CHECK(pickUpEff000.type() == &block);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[PDDL parser] A Blocks World problem is parsed correctly", "[PDDL parser]")
|
TEST_CASE("[PDDL parser] A Blocks World problem is parsed correctly", "[PDDL parser]")
|
||||||
{
|
{
|
||||||
const auto description = Description::fromFiles({"data/blocksworld-domain.pddl", "data/blocksworld-problem.pddl"});
|
plasp::output::Logger logger;
|
||||||
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
|
const auto description = Description::fromFiles({"data/blocksworld-domain.pddl", "data/blocksworld-problem.pddl"}, context);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(description.problem());
|
REQUIRE_NOTHROW(description.problem());
|
||||||
|
|
||||||
const auto &problem = description.problem();
|
const auto &problem = description.problem();
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
REQUIRE(problem.name() == "blocks-4-0");
|
CHECK(problem.name() == "blocks-4-0");
|
||||||
REQUIRE(problem.domain().name() == "blocks");
|
CHECK(problem.domain().name() == "blocks");
|
||||||
|
|
||||||
// Requirements
|
// Requirements
|
||||||
// TODO: compute domain vs. problem requirements correctly and check them
|
// TODO: compute domain vs. problem requirements correctly and check them
|
||||||
@ -113,26 +119,26 @@ TEST_CASE("[PDDL parser] A Blocks World problem is parsed correctly", "[PDDL par
|
|||||||
// Objects
|
// Objects
|
||||||
REQUIRE(problem.objects().size() == 4u);
|
REQUIRE(problem.objects().size() == 4u);
|
||||||
|
|
||||||
REQUIRE(problem.objects()[0]->name() == "d");
|
CHECK(problem.objects()[0]->name() == "d");
|
||||||
REQUIRE(problem.objects()[0]->type() != nullptr);
|
REQUIRE(problem.objects()[0]->type() != nullptr);
|
||||||
REQUIRE(problem.objects()[0]->type()->name() == "block");
|
CHECK(problem.objects()[0]->type()->name() == "block");
|
||||||
REQUIRE(problem.objects()[3]->name() == "c");
|
CHECK(problem.objects()[3]->name() == "c");
|
||||||
REQUIRE(problem.objects()[3]->type() != nullptr);
|
REQUIRE(problem.objects()[3]->type() != nullptr);
|
||||||
REQUIRE(problem.objects()[3]->type()->name() == "block");
|
CHECK(problem.objects()[3]->type()->name() == "block");
|
||||||
|
|
||||||
// Initial State
|
// Initial State
|
||||||
const auto &facts = problem.initialState().facts();
|
const auto &facts = problem.initialState().facts();
|
||||||
|
|
||||||
REQUIRE(facts.size() == 9u);
|
REQUIRE(facts.size() == 9u);
|
||||||
const auto &fact0 = dynamic_cast<const expressions::Predicate &>(*facts[0].get());
|
const auto &fact0 = dynamic_cast<const expressions::Predicate &>(*facts[0].get());
|
||||||
REQUIRE(fact0.name() == "clear");
|
CHECK(fact0.name() == "clear");
|
||||||
REQUIRE(fact0.arguments().size() == 1u);
|
REQUIRE(fact0.arguments().size() == 1u);
|
||||||
const auto &fact00 = dynamic_cast<const expressions::Constant &>(*fact0.arguments()[0]);
|
const auto &fact00 = dynamic_cast<const expressions::Constant &>(*fact0.arguments()[0]);
|
||||||
REQUIRE(fact00.name() == "c");
|
CHECK(fact00.name() == "c");
|
||||||
REQUIRE(fact00.type() != nullptr);
|
REQUIRE(fact00.type() != nullptr);
|
||||||
REQUIRE(fact00.type()->name() == "block");
|
CHECK(fact00.type()->name() == "block");
|
||||||
const auto &fact8 = dynamic_cast<const expressions::Predicate &>(*facts[8].get());
|
const auto &fact8 = dynamic_cast<const expressions::Predicate &>(*facts[8].get());
|
||||||
REQUIRE(fact8.name() == "handempty");
|
CHECK(fact8.name() == "handempty");
|
||||||
REQUIRE(fact8.arguments().size() == 0u);
|
REQUIRE(fact8.arguments().size() == 0u);
|
||||||
|
|
||||||
// Goal
|
// Goal
|
||||||
@ -140,37 +146,40 @@ TEST_CASE("[PDDL parser] A Blocks World problem is parsed correctly", "[PDDL par
|
|||||||
|
|
||||||
REQUIRE(goal.arguments().size() == 3u);
|
REQUIRE(goal.arguments().size() == 3u);
|
||||||
const auto &goal0 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[0]);
|
const auto &goal0 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[0]);
|
||||||
REQUIRE(goal0.name() == "on");
|
CHECK(goal0.name() == "on");
|
||||||
REQUIRE(goal0.arguments().size() == 2u);
|
REQUIRE(goal0.arguments().size() == 2u);
|
||||||
const auto &goal00 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[0]);
|
const auto &goal00 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[0]);
|
||||||
REQUIRE(goal00.name() == "d");
|
CHECK(goal00.name() == "d");
|
||||||
const auto &goal01 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[1]);
|
const auto &goal01 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[1]);
|
||||||
REQUIRE(goal01.name() == "c");
|
CHECK(goal01.name() == "c");
|
||||||
const auto &goal2 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[2]);
|
const auto &goal2 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[2]);
|
||||||
REQUIRE(goal2.name() == "on");
|
CHECK(goal2.name() == "on");
|
||||||
REQUIRE(goal2.arguments().size() == 2u);
|
REQUIRE(goal2.arguments().size() == 2u);
|
||||||
const auto &goal20 = dynamic_cast<const expressions::Constant &>(*goal2.arguments()[0]);
|
const auto &goal20 = dynamic_cast<const expressions::Constant &>(*goal2.arguments()[0]);
|
||||||
REQUIRE(goal20.name() == "b");
|
CHECK(goal20.name() == "b");
|
||||||
const auto &goal21 = dynamic_cast<const expressions::Constant &>(*goal2.arguments()[1]);
|
const auto &goal21 = dynamic_cast<const expressions::Constant &>(*goal2.arguments()[1]);
|
||||||
REQUIRE(goal21.name() == "a");
|
CHECK(goal21.name() == "a");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[PDDL parser] The Storage domain is parsed correctly", "[PDDL parser]")
|
TEST_CASE("[PDDL parser] The Storage domain is parsed correctly", "[PDDL parser]")
|
||||||
{
|
{
|
||||||
const auto description = plasp::pddl::Description::fromFile("data/storage-domain.pddl");
|
plasp::output::Logger logger;
|
||||||
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
|
const auto description = plasp::pddl::Description::fromFile("data/storage-domain.pddl", context);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(description.domain());
|
REQUIRE_NOTHROW(description.domain());
|
||||||
|
|
||||||
const auto &domain = description.domain();
|
const auto &domain = description.domain();
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
REQUIRE(domain.name() == "storage-propositional");
|
CHECK(domain.name() == "storage-propositional");
|
||||||
|
|
||||||
// Requirements
|
// Requirements
|
||||||
REQUIRE(domain.requirements().size() == 1u);
|
REQUIRE(domain.requirements().size() == 1u);
|
||||||
REQUIRE(domain.requirements()[0].type() == Requirement::Type::Typing);
|
CHECK(domain.requirements()[0].type() == Requirement::Type::Typing);
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
REQUIRE(domain.types().size() == 10u);
|
REQUIRE(domain.types().size() == 10u);
|
||||||
@ -184,81 +193,84 @@ TEST_CASE("[PDDL parser] The Storage domain is parsed correctly", "[PDDL parser]
|
|||||||
|
|
||||||
const auto &hoistParents = hoist.parentTypes();
|
const auto &hoistParents = hoist.parentTypes();
|
||||||
REQUIRE(hoistParents.size() == 1u);
|
REQUIRE(hoistParents.size() == 1u);
|
||||||
REQUIRE(std::find(hoistParents.cbegin(), hoistParents.cend(), &object) != hoistParents.cend());
|
CHECK(std::find(hoistParents.cbegin(), hoistParents.cend(), &object) != hoistParents.cend());
|
||||||
|
|
||||||
const auto &areaParents = area.parentTypes();
|
const auto &areaParents = area.parentTypes();
|
||||||
REQUIRE(areaParents.size() == 2u);
|
REQUIRE(areaParents.size() == 2u);
|
||||||
REQUIRE(std::find(areaParents.cbegin(), areaParents.cend(), &object) != areaParents.cend());
|
CHECK(std::find(areaParents.cbegin(), areaParents.cend(), &object) != areaParents.cend());
|
||||||
REQUIRE(std::find(areaParents.cbegin(), areaParents.cend(), &surface) != areaParents.cend());
|
CHECK(std::find(areaParents.cbegin(), areaParents.cend(), &surface) != areaParents.cend());
|
||||||
|
|
||||||
// Predicates
|
// Predicates
|
||||||
REQUIRE(domain.predicates().size() == 8u);
|
REQUIRE(domain.predicates().size() == 8u);
|
||||||
|
|
||||||
const auto &on = *domain.predicates()[5];
|
const auto &on = *domain.predicates()[5];
|
||||||
|
|
||||||
REQUIRE(on.name() == "on");
|
CHECK(on.name() == "on");
|
||||||
REQUIRE(on.arguments().size() == 2u);
|
REQUIRE(on.arguments().size() == 2u);
|
||||||
REQUIRE(on.arguments()[0]->name() == "c");
|
CHECK(on.arguments()[0]->name() == "c");
|
||||||
const auto &onArgument0Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[0]->type());
|
const auto &onArgument0Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[0]->type());
|
||||||
REQUIRE(&onArgument0Type == &crate);
|
CHECK(&onArgument0Type == &crate);
|
||||||
REQUIRE(on.arguments()[1]->name() == "s");
|
CHECK(on.arguments()[1]->name() == "s");
|
||||||
const auto &onArgument1Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[1]->type());
|
const auto &onArgument1Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[1]->type());
|
||||||
REQUIRE(&onArgument1Type == &storearea);
|
CHECK(&onArgument1Type == &storearea);
|
||||||
|
|
||||||
const auto &in = *domain.predicates()[1];
|
const auto &in = *domain.predicates()[1];
|
||||||
REQUIRE(in.name() == "in");
|
CHECK(in.name() == "in");
|
||||||
REQUIRE(in.arguments().size() == 2u);
|
REQUIRE(in.arguments().size() == 2u);
|
||||||
REQUIRE(in.arguments()[0]->name() == "x");
|
CHECK(in.arguments()[0]->name() == "x");
|
||||||
const auto &inArgument0Type = dynamic_cast<const expressions::Either &>(*in.arguments()[0]->type());
|
const auto &inArgument0Type = dynamic_cast<const expressions::Either &>(*in.arguments()[0]->type());
|
||||||
REQUIRE(inArgument0Type.arguments().size() == 2u);
|
REQUIRE(inArgument0Type.arguments().size() == 2u);
|
||||||
const auto &inArgument0Type0 = dynamic_cast<const expressions::PrimitiveType &>(*inArgument0Type.arguments()[0]);
|
const auto &inArgument0Type0 = dynamic_cast<const expressions::PrimitiveType &>(*inArgument0Type.arguments()[0]);
|
||||||
REQUIRE(&inArgument0Type0 == &storearea);
|
CHECK(&inArgument0Type0 == &storearea);
|
||||||
const auto &inArgument0Type1 = dynamic_cast<const expressions::PrimitiveType &>(*inArgument0Type.arguments()[1]);
|
const auto &inArgument0Type1 = dynamic_cast<const expressions::PrimitiveType &>(*inArgument0Type.arguments()[1]);
|
||||||
REQUIRE(&inArgument0Type1 == &crate);
|
CHECK(&inArgument0Type1 == &crate);
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
REQUIRE(domain.actions().size() == 5u);
|
REQUIRE(domain.actions().size() == 5u);
|
||||||
|
|
||||||
const auto &drop = *domain.actions()[1];
|
const auto &drop = *domain.actions()[1];
|
||||||
|
|
||||||
REQUIRE(drop.name() == "drop");
|
CHECK(drop.name() == "drop");
|
||||||
REQUIRE(drop.parameters().size() == 5u);
|
REQUIRE(drop.parameters().size() == 5u);
|
||||||
REQUIRE(drop.parameters()[3]->name() == "a2");
|
CHECK(drop.parameters()[3]->name() == "a2");
|
||||||
REQUIRE(drop.parameters()[3]->type() == &area);
|
CHECK(drop.parameters()[3]->type() == &area);
|
||||||
|
|
||||||
const auto &dropPre = dynamic_cast<const expressions::And &>(*drop.precondition());
|
const auto &dropPre = dynamic_cast<const expressions::And &>(*drop.precondition());
|
||||||
REQUIRE(dropPre.arguments().size() == 5u);
|
REQUIRE(dropPre.arguments().size() == 5u);
|
||||||
const auto &dropPre2 = dynamic_cast<const expressions::Predicate &>(*dropPre.arguments()[2]);
|
const auto &dropPre2 = dynamic_cast<const expressions::Predicate &>(*dropPre.arguments()[2]);
|
||||||
REQUIRE(dropPre2.name() == "lifting");
|
CHECK(dropPre2.name() == "lifting");
|
||||||
REQUIRE(dropPre2.arguments().size() == 2u);
|
REQUIRE(dropPre2.arguments().size() == 2u);
|
||||||
const auto &dropPre21 = dynamic_cast<const expressions::Variable &>(*dropPre2.arguments()[1]);
|
const auto &dropPre21 = dynamic_cast<const expressions::Variable &>(*dropPre2.arguments()[1]);
|
||||||
REQUIRE(dropPre21.name() == "c");
|
CHECK(dropPre21.name() == "c");
|
||||||
REQUIRE(dropPre21.type() == &crate);
|
CHECK(dropPre21.type() == &crate);
|
||||||
|
|
||||||
const auto &dropEff = dynamic_cast<const expressions::And &>(*drop.effect());
|
const auto &dropEff = dynamic_cast<const expressions::And &>(*drop.effect());
|
||||||
REQUIRE(dropEff.arguments().size() == 5u);
|
REQUIRE(dropEff.arguments().size() == 5u);
|
||||||
const auto &dropEff2 = dynamic_cast<const expressions::Not &>(*dropEff.arguments()[2]);
|
const auto &dropEff2 = dynamic_cast<const expressions::Not &>(*dropEff.arguments()[2]);
|
||||||
const auto &dropEff20 = dynamic_cast<const expressions::Predicate &>(*dropEff2.argument());
|
const auto &dropEff20 = dynamic_cast<const expressions::Predicate &>(*dropEff2.argument());
|
||||||
REQUIRE(dropEff20.name() == "clear");
|
CHECK(dropEff20.name() == "clear");
|
||||||
REQUIRE(dropEff20.arguments().size() == 1u);
|
REQUIRE(dropEff20.arguments().size() == 1u);
|
||||||
const auto &dropEff200 = dynamic_cast<const expressions::Variable &>(*dropEff20.arguments()[0]);
|
const auto &dropEff200 = dynamic_cast<const expressions::Variable &>(*dropEff20.arguments()[0]);
|
||||||
REQUIRE(dropEff200.name() == "a1");
|
CHECK(dropEff200.name() == "a1");
|
||||||
REQUIRE(dropEff200.type() == &storearea);
|
CHECK(dropEff200.type() == &storearea);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[PDDL parser] A Storage problem is parsed correctly", "[PDDL parser]")
|
TEST_CASE("[PDDL parser] A Storage problem is parsed correctly", "[PDDL parser]")
|
||||||
{
|
{
|
||||||
const auto description = Description::fromFiles({"data/storage-domain.pddl", "data/storage-problem.pddl"});
|
plasp::output::Logger logger;
|
||||||
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
|
const auto description = Description::fromFiles({"data/storage-domain.pddl", "data/storage-problem.pddl"}, context);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(description.problem());
|
REQUIRE_NOTHROW(description.problem());
|
||||||
|
|
||||||
const auto &problem = description.problem();
|
const auto &problem = description.problem();
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
REQUIRE(problem.name() == "storage-1");
|
CHECK(problem.name() == "storage-1");
|
||||||
REQUIRE(problem.domain().name() == "storage-propositional");
|
CHECK(problem.domain().name() == "storage-propositional");
|
||||||
|
|
||||||
// Requirements
|
// Requirements
|
||||||
// TODO: compute domain vs. problem requirements correctly and check them
|
// TODO: compute domain vs. problem requirements correctly and check them
|
||||||
@ -266,57 +278,60 @@ TEST_CASE("[PDDL parser] A Storage problem is parsed correctly", "[PDDL parser]"
|
|||||||
// Objects
|
// Objects
|
||||||
REQUIRE(problem.objects().size() == 7u);
|
REQUIRE(problem.objects().size() == 7u);
|
||||||
|
|
||||||
REQUIRE(problem.objects()[0]->name() == "depot0-1-1");
|
CHECK(problem.objects()[0]->name() == "depot0-1-1");
|
||||||
REQUIRE(problem.objects()[0]->type() != nullptr);
|
REQUIRE(problem.objects()[0]->type() != nullptr);
|
||||||
REQUIRE(problem.objects()[0]->type()->name() == "storearea");
|
CHECK(problem.objects()[0]->type()->name() == "storearea");
|
||||||
REQUIRE(problem.objects()[6]->name() == "loadarea");
|
CHECK(problem.objects()[6]->name() == "loadarea");
|
||||||
REQUIRE(problem.objects()[6]->type() != nullptr);
|
REQUIRE(problem.objects()[6]->type() != nullptr);
|
||||||
REQUIRE(problem.objects()[6]->type()->name() == "transitarea");
|
CHECK(problem.objects()[6]->type()->name() == "transitarea");
|
||||||
|
|
||||||
// Initial State
|
// Initial State
|
||||||
const auto &facts = problem.initialState().facts();
|
const auto &facts = problem.initialState().facts();
|
||||||
|
|
||||||
REQUIRE(facts.size() == 10u);
|
REQUIRE(facts.size() == 10u);
|
||||||
const auto &fact0 = dynamic_cast<const expressions::Predicate &>(*facts[0].get());
|
const auto &fact0 = dynamic_cast<const expressions::Predicate &>(*facts[0].get());
|
||||||
REQUIRE(fact0.name() == "in");
|
CHECK(fact0.name() == "in");
|
||||||
REQUIRE(fact0.arguments().size() == 2u);
|
REQUIRE(fact0.arguments().size() == 2u);
|
||||||
const auto &fact01 = dynamic_cast<const expressions::Constant &>(*fact0.arguments()[1]);
|
const auto &fact01 = dynamic_cast<const expressions::Constant &>(*fact0.arguments()[1]);
|
||||||
REQUIRE(fact01.name() == "depot0");
|
CHECK(fact01.name() == "depot0");
|
||||||
REQUIRE(fact01.type() != nullptr);
|
REQUIRE(fact01.type() != nullptr);
|
||||||
REQUIRE(fact01.type()->name() == "depot");
|
CHECK(fact01.type()->name() == "depot");
|
||||||
const auto &fact9 = dynamic_cast<const expressions::Predicate &>(*facts[9].get());
|
const auto &fact9 = dynamic_cast<const expressions::Predicate &>(*facts[9].get());
|
||||||
REQUIRE(fact9.name() == "available");
|
CHECK(fact9.name() == "available");
|
||||||
REQUIRE(fact9.arguments().size() == 1u);
|
REQUIRE(fact9.arguments().size() == 1u);
|
||||||
const auto &fact90 = dynamic_cast<const expressions::Constant &>(*fact9.arguments()[0]);
|
const auto &fact90 = dynamic_cast<const expressions::Constant &>(*fact9.arguments()[0]);
|
||||||
REQUIRE(fact90.name() == "hoist0");
|
CHECK(fact90.name() == "hoist0");
|
||||||
REQUIRE(fact90.type() != nullptr);
|
REQUIRE(fact90.type() != nullptr);
|
||||||
REQUIRE(fact90.type()->name() == "hoist");
|
CHECK(fact90.type()->name() == "hoist");
|
||||||
|
|
||||||
// Goal
|
// Goal
|
||||||
const auto &goal = dynamic_cast<const expressions::And &>(problem.goal());
|
const auto &goal = dynamic_cast<const expressions::And &>(problem.goal());
|
||||||
|
|
||||||
REQUIRE(goal.arguments().size() == 1u);
|
REQUIRE(goal.arguments().size() == 1u);
|
||||||
const auto &goal0 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[0]);
|
const auto &goal0 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[0]);
|
||||||
REQUIRE(goal0.name() == "in");
|
CHECK(goal0.name() == "in");
|
||||||
REQUIRE(goal0.arguments().size() == 2u);
|
REQUIRE(goal0.arguments().size() == 2u);
|
||||||
const auto &goal00 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[0]);
|
const auto &goal00 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[0]);
|
||||||
REQUIRE(goal00.name() == "crate0");
|
CHECK(goal00.name() == "crate0");
|
||||||
const auto &goal01 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[1]);
|
const auto &goal01 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[1]);
|
||||||
REQUIRE(goal01.name() == "depot0");
|
CHECK(goal01.name() == "depot0");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[PDDL parser] Constants are parsed correctly", "[PDDL parser]")
|
TEST_CASE("[PDDL parser] Constants are parsed correctly", "[PDDL parser]")
|
||||||
{
|
{
|
||||||
const auto description = Description::fromFile("data/woodworking-domain.pddl");
|
plasp::output::Logger logger;
|
||||||
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
|
const auto description = Description::fromFile("data/woodworking-domain.pddl", context);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(description.domain());
|
REQUIRE_NOTHROW(description.domain());
|
||||||
|
|
||||||
const auto &domain = description.domain();
|
const auto &domain = description.domain();
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
REQUIRE(domain.name() == "woodworking");
|
CHECK(domain.name() == "woodworking");
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
const auto &acolour = *domain.types()[0];
|
const auto &acolour = *domain.types()[0];
|
||||||
@ -325,11 +340,11 @@ TEST_CASE("[PDDL parser] Constants are parsed correctly", "[PDDL parser]")
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
REQUIRE(domain.constants().size() == 8u);
|
REQUIRE(domain.constants().size() == 8u);
|
||||||
REQUIRE(domain.constants()[0]->type() == &surface);
|
CHECK(domain.constants()[0]->type() == &surface);
|
||||||
REQUIRE(domain.constants()[2]->type() == &surface);
|
CHECK(domain.constants()[2]->type() == &surface);
|
||||||
REQUIRE(domain.constants()[3]->type() == &treatmentstatus);
|
CHECK(domain.constants()[3]->type() == &treatmentstatus);
|
||||||
REQUIRE(domain.constants()[6]->type() == &treatmentstatus);
|
CHECK(domain.constants()[6]->type() == &treatmentstatus);
|
||||||
REQUIRE(domain.constants()[7]->type() == &acolour);
|
CHECK(domain.constants()[7]->type() == &acolour);
|
||||||
|
|
||||||
// TODO: add test with constants in predicates
|
// TODO: add test with constants in predicates
|
||||||
}
|
}
|
||||||
@ -338,68 +353,179 @@ TEST_CASE("[PDDL parser] Constants are parsed correctly", "[PDDL parser]")
|
|||||||
|
|
||||||
TEST_CASE("[PDDL parser] White spaces are ignored", "[PDDL parser]")
|
TEST_CASE("[PDDL parser] White spaces are ignored", "[PDDL parser]")
|
||||||
{
|
{
|
||||||
REQUIRE_NOTHROW(Description::fromFile("data/white-space-test.pddl"));
|
plasp::output::Logger logger;
|
||||||
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
|
CHECK_NOTHROW(Description::fromFile("data/white-space-test.pddl", context));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[PDDL parser] Missing or unmatching domain descriptions are detected", "[PDDL parser]")
|
TEST_CASE("[PDDL parser] Missing or unmatching domain descriptions are detected", "[PDDL parser]")
|
||||||
{
|
{
|
||||||
REQUIRE_THROWS_AS(Description::fromFile("data/blocksworld-problem.pddl"), ConsistencyException);
|
plasp::output::Logger logger;
|
||||||
REQUIRE_THROWS_AS(Description::fromFiles({"data/blocksworld-problem.pddl", "data/storage-domain.pddl"}), plasp::utils::ParserException);
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS_AS(Description::fromFile("data/blocksworld-problem.pddl", context), ConsistencyException);
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS_AS(Description::fromFiles({"data/blocksworld-problem.pddl", "data/storage-domain.pddl"}, context), plasp::input::ParserException);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[PDDL parser] Common PDDL syntax errors are detected", "[PDDL parser]")
|
TEST_CASE("[PDDL parser] Common PDDL syntax errors are detected", "[PDDL parser]")
|
||||||
{
|
{
|
||||||
REQUIRE_NOTHROW(Description::fromFile("data/pddl-syntax/domain-valid.pddl"));
|
plasp::output::Logger logger;
|
||||||
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-1.pddl"));
|
SECTION("")
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-2.pddl"));
|
{
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-3.pddl"));
|
CHECK_NOTHROW(Description::fromFile("data/pddl-syntax/domain-valid.pddl", context));
|
||||||
|
}
|
||||||
|
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-1.pddl"));
|
SECTION("")
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-2.pddl"));
|
{
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-3.pddl"));
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-1.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-2.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-3.pddl", context));
|
||||||
|
}
|
||||||
|
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-1.pddl"));
|
SECTION("")
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-2.pddl"));
|
{
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-3.pddl"));
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-1.pddl", context));
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-4.pddl"));
|
}
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-5.pddl"));
|
SECTION("")
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-6.pddl"));
|
{
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-7.pddl"));
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-2.pddl", context));
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-8.pddl"));
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-3.pddl", context));
|
||||||
|
}
|
||||||
|
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-1.pddl"));
|
SECTION("")
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-2.pddl"));
|
{
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-3.pddl"));
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-1.pddl", context));
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-4.pddl"));
|
}
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-5.pddl"));
|
SECTION("")
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-6.pddl"));
|
{
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-7.pddl"));
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-2.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-3.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-4.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-5.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-6.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-7.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-8.pddl", context));
|
||||||
|
}
|
||||||
|
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-types-1.pddl"));
|
SECTION("")
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-types-2.pddl"));
|
{
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-types-3.pddl"));
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-1.pddl", context));
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-types-4.pddl"));
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-2.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-3.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-4.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-5.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-6.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-7.pddl", context));
|
||||||
|
}
|
||||||
|
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-1.pddl"));
|
SECTION("")
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-2.pddl"));
|
{
|
||||||
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-3.pddl"));
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-1.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-2.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-3.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-4.pddl", context));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-1.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-2.pddl", context));
|
||||||
|
}
|
||||||
|
SECTION("")
|
||||||
|
{
|
||||||
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-3.pddl", context));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[PDDL parser] Former issues are fixed", "[PDDL parser]")
|
TEST_CASE("[PDDL parser] Former issues are fixed", "[PDDL parser]")
|
||||||
{
|
{
|
||||||
// Check white space issues with constants and parsing unsupported sections
|
plasp::output::Logger logger;
|
||||||
REQUIRE_NOTHROW(Description::fromFile("data/issues/issue-1.pddl"));
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
// Check white space issues with empty n-ary predicates
|
SECTION("white space issues with constants and parsing unsupported sections")
|
||||||
REQUIRE_NOTHROW(Description::fromFile("data/issues/issue-2.pddl"));
|
{
|
||||||
|
CHECK_NOTHROW(Description::fromFile("data/issues/issue-1.pddl", context));
|
||||||
// Check that comments are correctly ignored
|
}
|
||||||
REQUIRE_NOTHROW(Description::fromFile("data/issues/issue-3.pddl"));
|
|
||||||
|
SECTION("white space issues with empty n-ary predicates")
|
||||||
|
{
|
||||||
|
CHECK_NOTHROW(Description::fromFile("data/issues/issue-2.pddl", context));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("comments are correctly ignored")
|
||||||
|
{
|
||||||
|
CHECK_NOTHROW(Description::fromFile("data/issues/issue-3.pddl", context));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,17 +14,20 @@ boost::iostreams::stream<boost::iostreams::null_sink> nullStream((boost::iostrea
|
|||||||
|
|
||||||
TEST_CASE("[PDDL translation] Former issues are fixed", "[PDDL translation]")
|
TEST_CASE("[PDDL translation] Former issues are fixed", "[PDDL translation]")
|
||||||
{
|
{
|
||||||
// Check that translating domains without typing information works
|
plasp::output::Logger logger;
|
||||||
|
Context context(Parser(), logger);
|
||||||
|
|
||||||
|
SECTION("translating domains without typing information works")
|
||||||
{
|
{
|
||||||
auto description = Description::fromFile("data/issues/issue-4.pddl");
|
auto description = Description::fromFile("data/issues/issue-4.pddl", context);
|
||||||
const auto translator = TranslatorASP(description, description.context().logger.outputStream());
|
const auto translator = TranslatorASP(description, description.context().logger.outputStream());
|
||||||
REQUIRE_NOTHROW(translator.translate());
|
CHECK_NOTHROW(translator.translate());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that translating the simple blocks world domain works
|
SECTION("translating the simple blocks world domain works")
|
||||||
{
|
{
|
||||||
auto description = Description::fromFile("data/issues/issue-5.pddl");
|
auto description = Description::fromFile("data/issues/issue-5.pddl", context);
|
||||||
const auto translator = TranslatorASP(description, description.context().logger.outputStream());
|
const auto translator = TranslatorASP(description, description.context().logger.outputStream());
|
||||||
REQUIRE_NOTHROW(translator.translate());
|
CHECK_NOTHROW(translator.translate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,64 +48,64 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] A valid SAS file is parsed
|
|||||||
{
|
{
|
||||||
const auto description = plasp::sas::Description::fromStream(m_philosophersTestFile);
|
const auto description = plasp::sas::Description::fromStream(m_philosophersTestFile);
|
||||||
|
|
||||||
REQUIRE_FALSE(description.usesActionCosts());
|
CHECK_FALSE(description.usesActionCosts());
|
||||||
|
|
||||||
REQUIRE(description.variables().size() == 37u);
|
REQUIRE(description.variables().size() == 37u);
|
||||||
REQUIRE(description.variables()[0].axiomLayer() == -1);
|
CHECK(description.variables()[0].axiomLayer() == -1);
|
||||||
REQUIRE(description.variables()[0].values()[0].sign() == plasp::sas::Value::Sign::Positive);
|
CHECK(description.variables()[0].values()[0].sign() == plasp::sas::Value::Sign::Positive);
|
||||||
REQUIRE(description.variables()[0].values()[0].name() == "activate(philosopher-0, forks--pid-rfork)");
|
CHECK(description.variables()[0].values()[0].name() == "activate(philosopher-0, forks--pid-rfork)");
|
||||||
REQUIRE(description.variables()[36].axiomLayer() == -1);
|
CHECK(description.variables()[36].axiomLayer() == -1);
|
||||||
REQUIRE(description.variables()[36].values()[1].sign() == plasp::sas::Value::Sign::Negative);
|
CHECK(description.variables()[36].values()[1].sign() == plasp::sas::Value::Sign::Negative);
|
||||||
REQUIRE(description.variables()[36].values()[1].name() == "queue-tail-msg(forks-1-, fork)");
|
CHECK(description.variables()[36].values()[1].name() == "queue-tail-msg(forks-1-, fork)");
|
||||||
|
|
||||||
REQUIRE(description.mutexGroups().size() == 8u);
|
REQUIRE(description.mutexGroups().size() == 8u);
|
||||||
REQUIRE(description.mutexGroups()[0].facts().size() == 9u);
|
REQUIRE(description.mutexGroups()[0].facts().size() == 9u);
|
||||||
REQUIRE(&description.mutexGroups()[0].facts()[0].value() == &description.variables()[0].values()[0]);
|
CHECK(&description.mutexGroups()[0].facts()[0].value() == &description.variables()[0].values()[0]);
|
||||||
REQUIRE(description.mutexGroups()[7].facts().size() == 2u);
|
REQUIRE(description.mutexGroups()[7].facts().size() == 2u);
|
||||||
REQUIRE(&description.mutexGroups()[7].facts()[1].value() == &description.variables()[34].values()[1]);
|
CHECK(&description.mutexGroups()[7].facts()[1].value() == &description.variables()[34].values()[1]);
|
||||||
|
|
||||||
REQUIRE(description.initialState().facts().size() == 37u);
|
REQUIRE(description.initialState().facts().size() == 37u);
|
||||||
REQUIRE(&description.initialState().facts()[0].value() == &description.variables()[0].values()[8]);
|
CHECK(&description.initialState().facts()[0].value() == &description.variables()[0].values()[8]);
|
||||||
REQUIRE(&description.initialState().facts()[36].value() == &description.variables()[36].values()[1]);
|
CHECK(&description.initialState().facts()[36].value() == &description.variables()[36].values()[1]);
|
||||||
|
|
||||||
REQUIRE(description.goal().facts().size() == 2u);
|
REQUIRE(description.goal().facts().size() == 2u);
|
||||||
REQUIRE(&description.goal().facts()[0].value() == &description.variables()[6].values()[0]);
|
CHECK(&description.goal().facts()[0].value() == &description.variables()[6].values()[0]);
|
||||||
REQUIRE(&description.goal().facts()[1].value() == &description.variables()[7].values()[0]);
|
CHECK(&description.goal().facts()[1].value() == &description.variables()[7].values()[0]);
|
||||||
|
|
||||||
REQUIRE(description.operators().size() == 34u);
|
REQUIRE(description.operators().size() == 34u);
|
||||||
REQUIRE(description.operators()[0].predicate().name() == "activate-trans");
|
CHECK(description.operators()[0].predicate().name() == "activate-trans");
|
||||||
REQUIRE(description.operators()[0].predicate().arguments().size() == 5u);
|
REQUIRE(description.operators()[0].predicate().arguments().size() == 5u);
|
||||||
REQUIRE(description.operators()[0].predicate().arguments()[0] == "philosopher-0");
|
CHECK(description.operators()[0].predicate().arguments()[0] == "philosopher-0");
|
||||||
REQUIRE(description.operators()[0].predicate().arguments()[4] == "state-3");
|
CHECK(description.operators()[0].predicate().arguments()[4] == "state-3");
|
||||||
REQUIRE(description.operators()[0].preconditions().size() == 3u);
|
REQUIRE(description.operators()[0].preconditions().size() == 3u);
|
||||||
REQUIRE(&description.operators()[0].preconditions()[0].value() == &description.variables()[4].values()[4]);
|
CHECK(&description.operators()[0].preconditions()[0].value() == &description.variables()[4].values()[4]);
|
||||||
REQUIRE(&description.operators()[0].preconditions()[1].value() == &description.variables()[16].values()[1]);
|
CHECK(&description.operators()[0].preconditions()[1].value() == &description.variables()[16].values()[1]);
|
||||||
REQUIRE(&description.operators()[0].preconditions()[2].value() == &description.variables()[0].values()[8]);
|
CHECK(&description.operators()[0].preconditions()[2].value() == &description.variables()[0].values()[8]);
|
||||||
REQUIRE(description.operators()[0].effects().size() == 1u);
|
REQUIRE(description.operators()[0].effects().size() == 1u);
|
||||||
REQUIRE(description.operators()[0].effects()[0].conditions().size() == 0u);
|
REQUIRE(description.operators()[0].effects()[0].conditions().size() == 0u);
|
||||||
REQUIRE(&description.operators()[0].effects()[0].postcondition().value() == &description.variables()[0].values()[0]);
|
CHECK(&description.operators()[0].effects()[0].postcondition().value() == &description.variables()[0].values()[0]);
|
||||||
REQUIRE(description.operators()[33].predicate().name() == "queue-write");
|
CHECK(description.operators()[33].predicate().name() == "queue-write");
|
||||||
REQUIRE(description.operators()[33].predicate().arguments().size() == 4u);
|
REQUIRE(description.operators()[33].predicate().arguments().size() == 4u);
|
||||||
REQUIRE(description.operators()[33].predicate().arguments()[0] == "philosopher-1");
|
CHECK(description.operators()[33].predicate().arguments()[0] == "philosopher-1");
|
||||||
REQUIRE(description.operators()[33].predicate().arguments()[3] == "fork");
|
CHECK(description.operators()[33].predicate().arguments()[3] == "fork");
|
||||||
REQUIRE(description.operators()[33].preconditions().size() == 2u);
|
REQUIRE(description.operators()[33].preconditions().size() == 2u);
|
||||||
REQUIRE(&description.operators()[33].preconditions()[0].value() == &description.variables()[1].values()[3]);
|
CHECK(&description.operators()[33].preconditions()[0].value() == &description.variables()[1].values()[3]);
|
||||||
REQUIRE(&description.operators()[33].preconditions()[1].value() == &description.variables()[2].values()[2]);
|
CHECK(&description.operators()[33].preconditions()[1].value() == &description.variables()[2].values()[2]);
|
||||||
REQUIRE(description.operators()[33].effects().size() == 3u);
|
REQUIRE(description.operators()[33].effects().size() == 3u);
|
||||||
REQUIRE(description.operators()[33].effects()[0].conditions().size() == 0u);
|
REQUIRE(description.operators()[33].effects()[0].conditions().size() == 0u);
|
||||||
REQUIRE(&description.operators()[33].effects()[0].postcondition().value() == &description.variables()[1].values()[7]);
|
CHECK(&description.operators()[33].effects()[0].postcondition().value() == &description.variables()[1].values()[7]);
|
||||||
REQUIRE(&description.operators()[33].effects()[2].postcondition().value() == &description.variables()[35].values()[0]);
|
CHECK(&description.operators()[33].effects()[2].postcondition().value() == &description.variables()[35].values()[0]);
|
||||||
|
|
||||||
REQUIRE(description.axiomRules().size() == 33u);
|
REQUIRE(description.axiomRules().size() == 33u);
|
||||||
REQUIRE(description.axiomRules()[0].conditions().size() == 4u);
|
REQUIRE(description.axiomRules()[0].conditions().size() == 4u);
|
||||||
REQUIRE(&description.axiomRules()[0].conditions()[0].value() == &description.variables()[0].values()[0]);
|
CHECK(&description.axiomRules()[0].conditions()[0].value() == &description.variables()[0].values()[0]);
|
||||||
REQUIRE(&description.axiomRules()[0].conditions()[2].value() == &description.variables()[27].values()[0]);
|
CHECK(&description.axiomRules()[0].conditions()[2].value() == &description.variables()[27].values()[0]);
|
||||||
REQUIRE(&description.axiomRules()[0].conditions()[3].value() == &description.variables()[8].values()[1]);
|
CHECK(&description.axiomRules()[0].conditions()[3].value() == &description.variables()[8].values()[1]);
|
||||||
REQUIRE(&description.axiomRules()[0].postcondition().value() == &description.variables()[8].values()[0]);
|
CHECK(&description.axiomRules()[0].postcondition().value() == &description.variables()[8].values()[0]);
|
||||||
REQUIRE(description.axiomRules()[32].conditions().size() == 2u);
|
REQUIRE(description.axiomRules()[32].conditions().size() == 2u);
|
||||||
REQUIRE(&description.axiomRules()[32].conditions()[0].value() == &description.variables()[15].values()[0]);
|
CHECK(&description.axiomRules()[32].conditions()[0].value() == &description.variables()[15].values()[0]);
|
||||||
REQUIRE(&description.axiomRules()[32].conditions()[1].value() == &description.variables()[25].values()[0]);
|
CHECK(&description.axiomRules()[32].conditions()[1].value() == &description.variables()[25].values()[0]);
|
||||||
REQUIRE(&description.axiomRules()[32].postcondition().value() == &description.variables()[25].values()[1]);
|
CHECK(&description.axiomRules()[32].postcondition().value() == &description.variables()[25].values()[1]);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
@ -123,8 +123,8 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] Trailing empty parentheses
|
|||||||
{
|
{
|
||||||
const auto description = plasp::sas::Description::fromStream(m_blocksworldTestFile);
|
const auto description = plasp::sas::Description::fromStream(m_blocksworldTestFile);
|
||||||
|
|
||||||
REQUIRE(description.variables()[4].values()[0].name() == "handempty");
|
CHECK(description.variables()[4].values()[0].name() == "handempty");
|
||||||
REQUIRE(description.variables()[5].values()[0].name() == "holding(a)");
|
CHECK(description.variables()[5].values()[0].name() == "holding(a)");
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
@ -141,8 +141,8 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] “none” values are corr
|
|||||||
const auto description = plasp::sas::Description::fromStream(m_freecellTestFile);
|
const auto description = plasp::sas::Description::fromStream(m_freecellTestFile);
|
||||||
|
|
||||||
// TODO: compare by identity, not value
|
// TODO: compare by identity, not value
|
||||||
REQUIRE(description.variables()[0].values()[3] == plasp::sas::Value::None);
|
CHECK(description.variables()[0].values()[3] == plasp::sas::Value::None);
|
||||||
REQUIRE(description.variables()[5].values()[6] == plasp::sas::Value::None);
|
CHECK(description.variables()[5].values()[6] == plasp::sas::Value::None);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
@ -158,19 +158,19 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] SAS requirements are parse
|
|||||||
{
|
{
|
||||||
const auto description = plasp::sas::Description::fromStream(m_cavedivingTestFile);
|
const auto description = plasp::sas::Description::fromStream(m_cavedivingTestFile);
|
||||||
|
|
||||||
REQUIRE(description.usesActionCosts());
|
CHECK(description.usesActionCosts());
|
||||||
REQUIRE(description.usesConditionalEffects());
|
CHECK(description.usesConditionalEffects());
|
||||||
REQUIRE_FALSE(description.usesAxiomRules());
|
CHECK_FALSE(description.usesAxiomRules());
|
||||||
|
|
||||||
REQUIRE(description.operators().size() == 496u);
|
REQUIRE(description.operators().size() == 496u);
|
||||||
|
|
||||||
REQUIRE(description.operators()[0].costs() == 1u);
|
CHECK(description.operators()[0].costs() == 1u);
|
||||||
REQUIRE(description.operators()[172].costs() == 10u);
|
CHECK(description.operators()[172].costs() == 10u);
|
||||||
REQUIRE(description.operators()[173].costs() == 63u);
|
CHECK(description.operators()[173].costs() == 63u);
|
||||||
|
|
||||||
REQUIRE(description.operators()[172].effects().size() == 3u);
|
REQUIRE(description.operators()[172].effects().size() == 3u);
|
||||||
REQUIRE(description.operators()[172].effects()[1].conditions().size() == 1u);
|
REQUIRE(description.operators()[172].effects()[1].conditions().size() == 1u);
|
||||||
REQUIRE(&description.operators()[172].effects()[1].conditions()[0].value() == &description.variables()[1].values()[4]);
|
CHECK(&description.operators()[172].effects()[1].conditions()[0].value() == &description.variables()[1].values()[4]);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
@ -183,5 +183,5 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] SAS requirements are parse
|
|||||||
TEST_CASE("[SAS parser] Former issues are fixed", "[SAS parser]")
|
TEST_CASE("[SAS parser] Former issues are fixed", "[SAS parser]")
|
||||||
{
|
{
|
||||||
// Check issue where unexpected whitespaces in SAS files led to a parsing error
|
// Check issue where unexpected whitespaces in SAS files led to a parsing error
|
||||||
REQUIRE_NOTHROW(plasp::sas::Description::fromFile("data/issues/issue-6.sas"));
|
CHECK_NOTHROW(plasp::sas::Description::fromFile("data/issues/issue-6.sas"));
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/input/Parser.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/input/ParserException.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
|
TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
|
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
|
||||||
plasp::utils::Parser<> p("input", s);
|
plasp::input::Parser<> p("input", s);
|
||||||
|
|
||||||
REQUIRE(p.parse<std::string>() == "identifier");
|
REQUIRE(p.parse<std::string>() == "identifier");
|
||||||
REQUIRE(p.parse<size_t>() == 5u);
|
REQUIRE(p.parse<size_t>() == 5u);
|
||||||
@ -19,7 +19,7 @@ TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
|
|||||||
REQUIRE(p.parse<int>() == 100);
|
REQUIRE(p.parse<int>() == 100);
|
||||||
REQUIRE(p.parse<size_t>() == 200u);
|
REQUIRE(p.parse<size_t>() == 200u);
|
||||||
REQUIRE(p.parse<int>() == -300);
|
REQUIRE(p.parse<int>() == -300);
|
||||||
REQUIRE_THROWS_AS(p.parse<size_t>(), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.parse<size_t>(), plasp::input::ParserException);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -27,7 +27,7 @@ TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
|
|||||||
TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
|
TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
|
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
|
||||||
plasp::utils::Parser<> p("input", s);
|
plasp::input::Parser<> p("input", s);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.expect<std::string>("identifier"));
|
REQUIRE_NOTHROW(p.expect<std::string>("identifier"));
|
||||||
REQUIRE_NOTHROW(p.expect<size_t>(5u));
|
REQUIRE_NOTHROW(p.expect<size_t>(5u));
|
||||||
@ -38,31 +38,31 @@ TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
|
|||||||
REQUIRE_NOTHROW(p.expect<int>(100));
|
REQUIRE_NOTHROW(p.expect<int>(100));
|
||||||
REQUIRE_NOTHROW(p.expect<size_t>(200u));
|
REQUIRE_NOTHROW(p.expect<size_t>(200u));
|
||||||
REQUIRE_NOTHROW(p.expect<int>(-300));
|
REQUIRE_NOTHROW(p.expect<int>(-300));
|
||||||
REQUIRE_THROWS_AS(p.expect<size_t>(-400), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.expect<size_t>(-400), plasp::input::ParserException);
|
||||||
|
|
||||||
p.seek(0);
|
p.seek(0);
|
||||||
REQUIRE_THROWS_AS(p.expect<std::string>("error"), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.expect<std::string>("error"), plasp::input::ParserException);
|
||||||
|
|
||||||
p.seek(14);
|
p.seek(14);
|
||||||
REQUIRE_THROWS_AS(p.expect<size_t>(6u), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.expect<size_t>(6u), plasp::input::ParserException);
|
||||||
|
|
||||||
p.seek(17);
|
p.seek(17);
|
||||||
REQUIRE_THROWS_AS(p.expect<int>(-50), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.expect<int>(-50), plasp::input::ParserException);
|
||||||
|
|
||||||
p.seek(24);
|
p.seek(24);
|
||||||
REQUIRE_THROWS_AS(p.expect<bool>(true), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.expect<bool>(true), plasp::input::ParserException);
|
||||||
|
|
||||||
p.seek(26);
|
p.seek(26);
|
||||||
REQUIRE_THROWS_AS(p.expect<bool>(false), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.expect<bool>(false), plasp::input::ParserException);
|
||||||
|
|
||||||
p.seek(28);
|
p.seek(28);
|
||||||
REQUIRE_THROWS_AS(p.expect<int>(101), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.expect<int>(101), plasp::input::ParserException);
|
||||||
|
|
||||||
p.seek(31);
|
p.seek(31);
|
||||||
REQUIRE_THROWS_AS(p.expect<size_t>(201), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.expect<size_t>(201), plasp::input::ParserException);
|
||||||
|
|
||||||
p.seek(34);
|
p.seek(34);
|
||||||
REQUIRE_THROWS_AS(p.expect<int>(-299), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p.expect<int>(-299), plasp::input::ParserException);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -70,9 +70,9 @@ TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
|
|||||||
TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser]")
|
TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s(" identifier 5 \n-51\t 0 1");
|
std::stringstream s(" identifier 5 \n-51\t 0 1");
|
||||||
plasp::utils::Parser<> p("input", s);
|
plasp::input::Parser<> p("input", s);
|
||||||
|
|
||||||
plasp::utils::Parser<>::Position pos;
|
plasp::input::Parser<>::Position pos;
|
||||||
|
|
||||||
pos = p.position();
|
pos = p.position();
|
||||||
REQUIRE(p.testAndReturn<std::string>("error") == false);
|
REQUIRE(p.testAndReturn<std::string>("error") == false);
|
||||||
@ -130,136 +130,136 @@ TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser
|
|||||||
TEST_CASE("[parser] The end of the input stream is correctly handled", "[parser]")
|
TEST_CASE("[parser] The end of the input stream is correctly handled", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s1("test");
|
std::stringstream s1("test");
|
||||||
plasp::utils::Parser<> p1("input", s1);
|
plasp::input::Parser<> p1("input", s1);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p1.expect<std::string>("test"));
|
REQUIRE_NOTHROW(p1.expect<std::string>("test"));
|
||||||
REQUIRE_THROWS_AS(p1.parse<std::string>(), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p1.parse<std::string>(), plasp::input::ParserException);
|
||||||
|
|
||||||
std::stringstream s2("test1 test2 test3");
|
std::stringstream s2("test1 test2 test3");
|
||||||
plasp::utils::Parser<> p2("input", s2);
|
plasp::input::Parser<> p2("input", s2);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p2.expect<std::string>("test1"));
|
REQUIRE_NOTHROW(p2.expect<std::string>("test1"));
|
||||||
REQUIRE_NOTHROW(p2.expect<std::string>("test2"));
|
REQUIRE_NOTHROW(p2.expect<std::string>("test2"));
|
||||||
REQUIRE_NOTHROW(p2.expect<std::string>("test3"));
|
REQUIRE_NOTHROW(p2.expect<std::string>("test3"));
|
||||||
REQUIRE_THROWS_AS(p2.parse<std::string>(), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p2.parse<std::string>(), plasp::input::ParserException);
|
||||||
|
|
||||||
std::stringstream s3("-127");
|
std::stringstream s3("-127");
|
||||||
plasp::utils::Parser<> p3("input", s3);
|
plasp::input::Parser<> p3("input", s3);
|
||||||
|
|
||||||
p3.expect<int>(-127);
|
p3.expect<int>(-127);
|
||||||
REQUIRE_THROWS_AS(p3.parse<int>(), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p3.parse<int>(), plasp::input::ParserException);
|
||||||
|
|
||||||
std::stringstream s4("128 -1023 -4095");
|
std::stringstream s4("128 -1023 -4095");
|
||||||
plasp::utils::Parser<> p4("input", s4);
|
plasp::input::Parser<> p4("input", s4);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p4.expect<size_t>(128));
|
REQUIRE_NOTHROW(p4.expect<size_t>(128));
|
||||||
REQUIRE_NOTHROW(p4.expect<int>(-1023));
|
REQUIRE_NOTHROW(p4.expect<int>(-1023));
|
||||||
REQUIRE_NOTHROW(p4.expect<int>(-4095));
|
REQUIRE_NOTHROW(p4.expect<int>(-4095));
|
||||||
REQUIRE_THROWS_AS(p4.parse<int>(), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p4.parse<int>(), plasp::input::ParserException);
|
||||||
|
|
||||||
std::stringstream s5("0");
|
std::stringstream s5("0");
|
||||||
plasp::utils::Parser<> p5("input", s5);
|
plasp::input::Parser<> p5("input", s5);
|
||||||
|
|
||||||
p5.expect<bool>(false);
|
p5.expect<bool>(false);
|
||||||
REQUIRE_THROWS_AS(p5.parse<bool>(), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p5.parse<bool>(), plasp::input::ParserException);
|
||||||
|
|
||||||
std::stringstream s6("0 1 0");
|
std::stringstream s6("0 1 0");
|
||||||
plasp::utils::Parser<> p6("input", s6);
|
plasp::input::Parser<> p6("input", s6);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p6.expect<bool>(false));
|
REQUIRE_NOTHROW(p6.expect<bool>(false));
|
||||||
REQUIRE_NOTHROW(p6.expect<bool>(true));
|
REQUIRE_NOTHROW(p6.expect<bool>(true));
|
||||||
REQUIRE_NOTHROW(p6.expect<bool>(false));
|
REQUIRE_NOTHROW(p6.expect<bool>(false));
|
||||||
REQUIRE_THROWS_AS(p6.parse<bool>(), plasp::utils::ParserException);
|
REQUIRE_THROWS_AS(p6.parse<bool>(), plasp::input::ParserException);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[parser] While parsing, the cursor coordinate is as expcected", "[parser]")
|
TEST_CASE("[parser] While parsing, the cursor location is as expcected", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s("123 \n4\ntest1\n test2\ntest3 \ntest4\n\n\n\n");
|
std::stringstream s("123 \n4\ntest1\n test2\ntest3 \ntest4\n\n\n\n");
|
||||||
plasp::utils::Parser<> p("input", s);
|
plasp::input::Parser<> p("input", s);
|
||||||
|
|
||||||
const auto startPosition = p.position();
|
const auto startPosition = p.position();
|
||||||
|
|
||||||
plasp::utils::StreamCoordinate c;
|
plasp::input::Location l;
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 1u);
|
REQUIRE(l.rowStart == 1u);
|
||||||
REQUIRE(c.column == 1u);
|
REQUIRE(l.columnStart == 1u);
|
||||||
REQUIRE(p.currentCharacter() == '1');
|
REQUIRE(p.currentCharacter() == '1');
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.advance());
|
REQUIRE_NOTHROW(p.advance());
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 1u);
|
REQUIRE(l.rowStart == 1u);
|
||||||
REQUIRE(c.column == 2u);
|
REQUIRE(l.columnStart == 2u);
|
||||||
REQUIRE(p.currentCharacter() == '2');
|
REQUIRE(p.currentCharacter() == '2');
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.advance());
|
REQUIRE_NOTHROW(p.advance());
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 1u);
|
REQUIRE(l.rowStart == 1u);
|
||||||
REQUIRE(c.column == 3u);
|
REQUIRE(l.columnStart == 3u);
|
||||||
REQUIRE(p.currentCharacter() == '3');
|
REQUIRE(p.currentCharacter() == '3');
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.advance());
|
REQUIRE_NOTHROW(p.advance());
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 1u);
|
REQUIRE(l.rowStart == 1u);
|
||||||
REQUIRE(c.column == 4u);
|
REQUIRE(l.columnStart == 4u);
|
||||||
REQUIRE(p.currentCharacter() == ' ');
|
REQUIRE(p.currentCharacter() == ' ');
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.advance());
|
REQUIRE_NOTHROW(p.advance());
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 1u);
|
REQUIRE(l.rowStart == 1u);
|
||||||
REQUIRE(c.column == 5u);
|
REQUIRE(l.columnStart == 5u);
|
||||||
REQUIRE(p.currentCharacter() == '\n');
|
REQUIRE(p.currentCharacter() == '\n');
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.advance());
|
REQUIRE_NOTHROW(p.advance());
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 2u);
|
REQUIRE(l.rowStart == 2u);
|
||||||
REQUIRE(c.column == 1u);
|
REQUIRE(l.columnStart == 1u);
|
||||||
REQUIRE(p.currentCharacter() == '4');
|
REQUIRE(p.currentCharacter() == '4');
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.advance());
|
REQUIRE_NOTHROW(p.advance());
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.expect<std::string>("test1"));
|
REQUIRE_NOTHROW(p.expect<std::string>("test1"));
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 3u);
|
REQUIRE(l.rowStart == 3u);
|
||||||
REQUIRE(c.column == 6u);
|
REQUIRE(l.columnStart == 6u);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.expect<std::string>("test2"));
|
REQUIRE_NOTHROW(p.expect<std::string>("test2"));
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 4u);
|
REQUIRE(l.rowStart == 4u);
|
||||||
REQUIRE(c.column == 7u);
|
REQUIRE(l.columnStart == 7u);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.expect<std::string>("test3"));
|
REQUIRE_NOTHROW(p.expect<std::string>("test3"));
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 5u);
|
REQUIRE(l.rowStart == 5u);
|
||||||
REQUIRE(c.column == 6u);
|
REQUIRE(l.columnStart == 6u);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.skipLine());
|
REQUIRE_NOTHROW(p.skipLine());
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 6u);
|
REQUIRE(l.rowStart == 6u);
|
||||||
REQUIRE(c.column == 1u);
|
REQUIRE(l.columnStart == 1u);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.skipLine());
|
REQUIRE_NOTHROW(p.skipLine());
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 7u);
|
REQUIRE(l.rowStart == 7u);
|
||||||
REQUIRE(c.column == 1u);
|
REQUIRE(l.columnStart == 1u);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.skipWhiteSpace());
|
REQUIRE_NOTHROW(p.skipWhiteSpace());
|
||||||
|
|
||||||
c = p.coordinate();
|
l = p.location();
|
||||||
REQUIRE(c.row == 10u);
|
REQUIRE(l.rowStart == 10u);
|
||||||
REQUIRE(c.column == 1u);
|
REQUIRE(l.columnStart == 1u);
|
||||||
REQUIRE(p.atEnd());
|
REQUIRE(p.atEnd());
|
||||||
|
|
||||||
p.reset();
|
p.reset();
|
||||||
@ -285,30 +285,30 @@ TEST_CASE("[parser] While parsing, the cursor coordinate is as expcected", "[par
|
|||||||
TEST_CASE("[parser] Comments are correctly removed", "[parser]")
|
TEST_CASE("[parser] Comments are correctly removed", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s1("; comment at beginning\ntest1; comment in between\ntest2; comment at end");
|
std::stringstream s1("; comment at beginning\ntest1; comment in between\ntest2; comment at end");
|
||||||
plasp::utils::Parser<> p1("input", s1);
|
plasp::input::Parser<> p1("input", s1);
|
||||||
|
|
||||||
p1.removeComments(";", "\n", false);
|
p1.removeComments(";", "\n", false);
|
||||||
|
|
||||||
plasp::utils::StreamCoordinate c;
|
plasp::input::Location l;
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p1.expect<std::string>("test1"));
|
REQUIRE_NOTHROW(p1.expect<std::string>("test1"));
|
||||||
|
|
||||||
c = p1.coordinate();
|
l = p1.location();
|
||||||
REQUIRE(c.row == 2u);
|
REQUIRE(l.rowStart == 2u);
|
||||||
REQUIRE(c.column == 6u);
|
REQUIRE(l.columnStart == 6u);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p1.expect<std::string>("test2"));
|
REQUIRE_NOTHROW(p1.expect<std::string>("test2"));
|
||||||
|
|
||||||
c = p1.coordinate();
|
l = p1.location();
|
||||||
REQUIRE(c.row == 3u);
|
REQUIRE(l.rowStart == 3u);
|
||||||
REQUIRE(c.column == 6u);
|
REQUIRE(l.columnStart == 6u);
|
||||||
|
|
||||||
p1.skipWhiteSpace();
|
p1.skipWhiteSpace();
|
||||||
|
|
||||||
REQUIRE(p1.atEnd());
|
REQUIRE(p1.atEnd());
|
||||||
|
|
||||||
std::stringstream s2("test;");
|
std::stringstream s2("test;");
|
||||||
plasp::utils::Parser<> p2("input", s2);
|
plasp::input::Parser<> p2("input", s2);
|
||||||
|
|
||||||
p2.removeComments(";", "\n", false);
|
p2.removeComments(";", "\n", false);
|
||||||
|
|
||||||
@ -319,7 +319,7 @@ TEST_CASE("[parser] Comments are correctly removed", "[parser]")
|
|||||||
REQUIRE(p2.atEnd());
|
REQUIRE(p2.atEnd());
|
||||||
|
|
||||||
std::stringstream s3("/* comment at start */ test1 /* comment in between */ test2 /*");
|
std::stringstream s3("/* comment at start */ test1 /* comment in between */ test2 /*");
|
||||||
plasp::utils::Parser<> p3("input", s3);
|
plasp::input::Parser<> p3("input", s3);
|
||||||
|
|
||||||
p3.removeComments("/*", "*/", true);
|
p3.removeComments("/*", "*/", true);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user