Merge branch 'develop' of github.com:potassco/plasp into feature-normalization
This commit is contained in:
23
lib/colorlog/CMakeLists.txt
Normal file
23
lib/colorlog/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
project(colorlog)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Werror ${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
if (CMAKE_GENERATOR STREQUAL "Ninja" AND
|
||||
((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR
|
||||
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)))
|
||||
# Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support.
|
||||
# Rationale in https://github.com/ninja-build/ninja/issues/814
|
||||
set(CMAKE_CXX_FLAGS "-fdiagnostics-color=always ${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
add_subdirectory(src)
|
291
lib/colorlog/include/colorlog/ColorStream.h
Normal file
291
lib/colorlog/include/colorlog/ColorStream.h
Normal file
@@ -0,0 +1,291 @@
|
||||
#ifndef __COLOR_LOG__COLOR_STREAM_H
|
||||
#define __COLOR_LOG__COLOR_STREAM_H
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
310
lib/colorlog/include/colorlog/Formatting.h
Normal file
310
lib/colorlog/include/colorlog/Formatting.h
Normal file
@@ -0,0 +1,310 @@
|
||||
#ifndef __COLOR_LOG__FORMATTING_H
|
||||
#define __COLOR_LOG__FORMATTING_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Formatting
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class Color
|
||||
{
|
||||
Default = 39,
|
||||
Black = 30,
|
||||
Red = 31,
|
||||
Green = 32,
|
||||
Yellow = 33,
|
||||
Blue = 34,
|
||||
Magenta = 35,
|
||||
Cyan = 36,
|
||||
LightGray = 37,
|
||||
DarkGray = 90,
|
||||
LightRed = 91,
|
||||
LightGreen = 92,
|
||||
LightYellow = 93,
|
||||
LightBlue = 94,
|
||||
LightMagenta = 95,
|
||||
LightCyan = 96,
|
||||
White = 97
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class FontWeight
|
||||
{
|
||||
Normal = 21,
|
||||
Bold = 1
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Format
|
||||
{
|
||||
Color color = Color::Default;
|
||||
FontWeight fontWeight = FontWeight::Normal;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Format &format)
|
||||
{
|
||||
if (!stream.supportsColor())
|
||||
return stream;
|
||||
|
||||
const auto fontWeightCode = static_cast<int>(format.fontWeight);
|
||||
const auto colorCode = static_cast<int>(format.color);
|
||||
|
||||
return (stream << "\033[" << fontWeightCode << ";" << colorCode << "m");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct ResetFormat
|
||||
{
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const ResetFormat &)
|
||||
{
|
||||
if (!stream.supportsColor())
|
||||
return stream;
|
||||
|
||||
return (stream << "\033[0m");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Function
|
||||
{
|
||||
Function(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Function &function)
|
||||
{
|
||||
return (stream
|
||||
<< 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
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Operator
|
||||
{
|
||||
Operator(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Operator &operator_)
|
||||
{
|
||||
return (stream << operator_.name);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
struct Number
|
||||
{
|
||||
Number(T value)
|
||||
: value{value}
|
||||
{
|
||||
}
|
||||
|
||||
T value;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Number<T> &number)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::Yellow, FontWeight::Normal})
|
||||
<< number.value
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Variable
|
||||
{
|
||||
Variable(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Variable &variable)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::Green, FontWeight::Bold})
|
||||
<< variable.name
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct String
|
||||
{
|
||||
String(const char *content)
|
||||
: content{content}
|
||||
{
|
||||
}
|
||||
|
||||
const char *content;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const String &string)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::Green, FontWeight::Normal})
|
||||
<< "\"" << string.content << "\""
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Boolean
|
||||
{
|
||||
Boolean(const char *value)
|
||||
: value{value}
|
||||
{
|
||||
}
|
||||
|
||||
const char *value;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Boolean &boolean)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::Red, FontWeight::Normal})
|
||||
<< boolean.value
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Reserved
|
||||
{
|
||||
Reserved(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Reserved &reserved)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::White, FontWeight::Normal})
|
||||
<< reserved.name
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Heading1
|
||||
{
|
||||
Heading1(const char *content)
|
||||
: content{content}
|
||||
{
|
||||
}
|
||||
|
||||
const char *content;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Heading1 &heading1)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::Blue, FontWeight::Bold})
|
||||
<< "%---------------------------------------" << std::endl
|
||||
<< "% " << heading1.content << std::endl
|
||||
<< "%---------------------------------------"
|
||||
<< ResetFormat()
|
||||
<< std::endl);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Heading2
|
||||
{
|
||||
Heading2(const char *content)
|
||||
: content{content}
|
||||
{
|
||||
}
|
||||
|
||||
const char *content;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Heading2 &heading2)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::Blue, FontWeight::Bold})
|
||||
<< "% " << heading2.content
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
#endif
|
53
lib/colorlog/include/colorlog/Logger.h
Normal file
53
lib/colorlog/include/colorlog/Logger.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef __COLOR_LOG__LOGGER_H
|
||||
#define __COLOR_LOG__LOGGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
#include <colorlog/Priority.h>
|
||||
|
||||
#include <tokenize/Location.h>
|
||||
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Logger
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
explicit Logger();
|
||||
explicit Logger(ColorStream &&outputStream);
|
||||
explicit Logger(ColorStream &&outputStream, ColorStream &&errorStream);
|
||||
|
||||
ColorStream &outputStream();
|
||||
ColorStream &errorStream();
|
||||
|
||||
// The priority from which on messages should be printed
|
||||
void setLogPriority(Priority logPriority);
|
||||
// Messages with this priority (or higher) will terminate the program’s execution
|
||||
void setAbortPriority(Priority abortPriority);
|
||||
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 tokenize::Location &location, const char *message);
|
||||
void log(Priority priority, const tokenize::Location &location, const std::string &message);
|
||||
|
||||
private:
|
||||
ColorStream m_outputStream;
|
||||
ColorStream m_errorStream;
|
||||
|
||||
Priority m_logPriority;
|
||||
Priority m_abortPriority;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
#endif
|
63
lib/colorlog/include/colorlog/Priority.h
Normal file
63
lib/colorlog/include/colorlog/Priority.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef __COLOR_LOG__PRIORITY_H
|
||||
#define __COLOR_LOG__PRIORITY_H
|
||||
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
21
lib/colorlog/src/CMakeLists.txt
Normal file
21
lib/colorlog/src/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
set(target colorlog)
|
||||
|
||||
file(GLOB core_sources "colorlog/*.cpp")
|
||||
file(GLOB core_headers "../include/colorlog/*.h")
|
||||
|
||||
set(includes
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/../../lib/tokenize/include
|
||||
)
|
||||
|
||||
set(sources
|
||||
${core_sources}
|
||||
${core_headers}
|
||||
)
|
||||
|
||||
set(libraries
|
||||
)
|
||||
|
||||
add_library(${target} ${sources})
|
||||
target_include_directories(${target} PRIVATE ${includes})
|
||||
target_link_libraries(${target} ${libraries})
|
165
lib/colorlog/src/colorlog/Logger.cpp
Normal file
165
lib/colorlog/src/colorlog/Logger.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
#include <colorlog/Logger.h>
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
namespace colorlog
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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::Info},
|
||||
m_abortPriority{Priority::Error}
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &Logger::outputStream()
|
||||
{
|
||||
return m_outputStream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &Logger::errorStream()
|
||||
{
|
||||
return m_errorStream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::setLogPriority(Priority logPriority)
|
||||
{
|
||||
m_logPriority = logPriority;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::setAbortPriority(Priority abortPriority)
|
||||
{
|
||||
m_abortPriority = abortPriority;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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) &&
|
||||
priorityID < static_cast<int>(m_abortPriority))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_errorStream
|
||||
<< priorityFormat(priority) << priorityName(priority) << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< MessageBodyFormat << message
|
||||
<< ResetFormat() << std::endl;
|
||||
|
||||
if (priority != Priority::Error && priorityID >= static_cast<int>(m_abortPriority))
|
||||
throw std::runtime_error("received warning (treated as error by configuration)");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const std::string &message)
|
||||
{
|
||||
log(priority, message.c_str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const tokenize::Location &location, const char *message)
|
||||
{
|
||||
const auto priorityID = static_cast<int>(priority);
|
||||
|
||||
// Always show messages that lead to program termination
|
||||
if (priorityID < static_cast<int>(m_logPriority) &&
|
||||
priorityID < static_cast<int>(m_abortPriority))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_errorStream
|
||||
<< LocationFormat
|
||||
<< location.sectionStart << ":" << location.rowStart << ":" << location.columnStart << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< priorityFormat(priority) << priorityName(priority) << ":"
|
||||
<< ResetFormat() << " "
|
||||
<< MessageBodyFormat << message
|
||||
<< ResetFormat() << std::endl;
|
||||
|
||||
// TODO: print original warning message
|
||||
// TODO: refactor
|
||||
if (priority != Priority::Error && priorityID >= static_cast<int>(m_abortPriority))
|
||||
throw std::runtime_error("received warning (treated as error by configuration)");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Logger::log(Priority priority, const tokenize::Location &location, const std::string &message)
|
||||
{
|
||||
log(priority, location, message.c_str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
@@ -61,23 +61,6 @@ struct ConstantDeclaration
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Dummy
|
||||
{
|
||||
explicit Dummy(std::string name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
|
||||
Dummy(const Dummy &other) = delete;
|
||||
Dummy &operator=(const Dummy &&other) = delete;
|
||||
Dummy(Dummy &&other) = default;
|
||||
Dummy &operator=(Dummy &&other) = default;
|
||||
|
||||
std::string name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct PrimitiveType
|
||||
{
|
||||
explicit PrimitiveType(PrimitiveTypeDeclaration *declaration)
|
||||
@@ -288,6 +271,7 @@ struct And: public NAry<And<Argument>, Argument>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: make binary expression
|
||||
template<class Argument>
|
||||
struct At
|
||||
{
|
||||
|
728
lib/pddlparse/include/pddlparse/ASTOutput.h
Normal file
728
lib/pddlparse/include/pddlparse/ASTOutput.h
Normal file
@@ -0,0 +1,728 @@
|
||||
#ifndef __PDDL_PARSE__AST_OUTPUT_H
|
||||
#define __PDDL_PARSE__AST_OUTPUT_H
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/detail/parsing/Requirement.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace ast
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Output
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct PrintContext
|
||||
{
|
||||
size_t indentationLevel{0};
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Identifier
|
||||
{
|
||||
Identifier(const char *content)
|
||||
: content{content}
|
||||
{
|
||||
}
|
||||
|
||||
Identifier(const std::string &content)
|
||||
: content{content.c_str()}
|
||||
{
|
||||
}
|
||||
|
||||
const char *content;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Identifier &identifier)
|
||||
{
|
||||
return (stream
|
||||
<< colorlog::Format({colorlog::Color::Green, colorlog::FontWeight::Normal})
|
||||
<< identifier.content << colorlog::ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Type
|
||||
{
|
||||
Type(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
|
||||
Type(const std::string &name)
|
||||
: name{name.c_str()}
|
||||
{
|
||||
}
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Type &type)
|
||||
{
|
||||
return (stream
|
||||
<< colorlog::Format({colorlog::Color::Red, colorlog::FontWeight::Normal})
|
||||
<< type.name << colorlog::ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Constant
|
||||
{
|
||||
Constant(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
|
||||
Constant(const std::string &name)
|
||||
: name{name.c_str()}
|
||||
{
|
||||
}
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Constant &constant)
|
||||
{
|
||||
return (stream
|
||||
<< colorlog::Format({colorlog::Color::Yellow, colorlog::FontWeight::Normal})
|
||||
<< constant.name << colorlog::ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
colorlog::ColorStream &printIndentedNewline(colorlog::ColorStream &stream, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << std::endl;
|
||||
|
||||
for (size_t i = 0; i < printContext.indentationLevel; i++)
|
||||
stream << "\t";
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Forward declarations
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Constant &constant, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ConstantDeclaration &constantDeclaration, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveType &primitiveType, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveTypeDeclaration &primitiveTypeDeclaration, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variable &variable, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const VariableDeclaration &variableDeclaration, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predicate &predicate, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PredicateDeclaration &predicateDeclaration, detail::PrintContext &printContext);
|
||||
|
||||
template<class Derived, class ArgumentLeft, class ArgumentRight = ArgumentLeft>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Binary<Derived, ArgumentLeft, ArgumentRight> &binary, detail::PrintContext &printContext);
|
||||
template<class Derived, class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const NAry<Derived, Argument> &nAry, detail::PrintContext &printContext);
|
||||
template<class Derived, class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Quantified<Derived, Argument> &quantified, detail::PrintContext &printContext);
|
||||
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const At<Argument> &at, detail::PrintContext &printContext);
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Not<Argument> ¬_, detail::PrintContext &printContext);
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Action &action, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Domain &domain, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const InitialState &initialState, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Problem &problem, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Requirement &requirement, detail::PrintContext &printContext);
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Description &description, detail::PrintContext &printContext);
|
||||
|
||||
template<class ValueType>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::unique_ptr<ValueType> &variant, detail::PrintContext &printContext);
|
||||
template<class ValueType>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::vector<ValueType> &variant, detail::PrintContext &printContext);
|
||||
template<class Variant>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variant &variant, detail::PrintContext &printContext);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Primitives
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Constant &constant, detail::PrintContext &)
|
||||
{
|
||||
return stream << detail::Constant(constant.declaration->name);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ConstantDeclaration &constantDeclaration, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << detail::Constant(constantDeclaration.name);
|
||||
|
||||
if (constantDeclaration.type)
|
||||
{
|
||||
stream << " - ";
|
||||
print(stream, constantDeclaration.type.value(), printContext);
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveType &primitiveType, detail::PrintContext &)
|
||||
{
|
||||
return stream << detail::Type(primitiveType.declaration->name);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PrimitiveTypeDeclaration &primitiveTypeDeclaration, detail::PrintContext &printContext)
|
||||
{
|
||||
if (primitiveTypeDeclaration.parentTypes.empty())
|
||||
return (stream << detail::Type(primitiveTypeDeclaration.name));
|
||||
|
||||
if (!primitiveTypeDeclaration.parentTypes.empty())
|
||||
for (const auto &parentType : primitiveTypeDeclaration.parentTypes)
|
||||
{
|
||||
if (&parentType != &primitiveTypeDeclaration.parentTypes.front())
|
||||
printIndentedNewline(stream, printContext);
|
||||
|
||||
stream << detail::Type(primitiveTypeDeclaration.name) << " - " << detail::Type(parentType->declaration->name);
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Unsupported &unsupported, detail::PrintContext &)
|
||||
{
|
||||
const auto unsupportedName = "<unsupported " + unsupported.type + ">";
|
||||
|
||||
return (stream << colorlog::Reserved(unsupportedName.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variable &variable, detail::PrintContext &)
|
||||
{
|
||||
const auto variableName = "?" + variable.declaration->name;
|
||||
|
||||
return (stream << colorlog::Variable(variableName.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const VariableDeclaration &variableDeclaration, detail::PrintContext &printContext)
|
||||
{
|
||||
const auto variableName = "?" + variableDeclaration.name;
|
||||
|
||||
stream << colorlog::Variable(variableName.c_str());
|
||||
|
||||
if (variableDeclaration.type)
|
||||
{
|
||||
stream << " - ";
|
||||
print(stream, *variableDeclaration.type, printContext);
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Compounds
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Predicate &predicate, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << detail::Identifier(predicate.declaration->name) << " ";
|
||||
|
||||
for (const auto &argument : predicate.arguments)
|
||||
{
|
||||
if (&argument != &predicate.arguments.front())
|
||||
stream << " ";
|
||||
|
||||
print(stream, argument, printContext);
|
||||
}
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const PredicateDeclaration &predicateDeclaration, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << detail::Identifier(predicateDeclaration.name);
|
||||
|
||||
for (const auto ¶meter : predicateDeclaration.parameters)
|
||||
{
|
||||
stream << " ";
|
||||
print(stream, *parameter, printContext);
|
||||
}
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Expressions: Base Classes
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived, class ArgumentLeft, class ArgumentRight>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Binary<Derived, ArgumentLeft, ArgumentRight> &binary, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << colorlog::Keyword(Derived::Identifier);
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, binary.argumentLeft, printContext);
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, binary.argumentRight, printContext);
|
||||
|
||||
printContext.indentationLevel--;
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived, class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const NAry<Derived, Argument> &nAry, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << colorlog::Keyword(Derived::Identifier);
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
for (const auto &argument : nAry.arguments)
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, argument, printContext);
|
||||
}
|
||||
|
||||
printContext.indentationLevel--;
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived, class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Quantified<Derived, Argument> &quantified, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << colorlog::Keyword(Derived::Identifier);
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, quantified.parameters, printContext);
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, quantified.argument, printContext);
|
||||
|
||||
printContext.indentationLevel--;
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Expressions
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const And<Argument> &and_, detail::PrintContext &printContext)
|
||||
{
|
||||
return print(stream, static_cast<const NAry<And<Argument>, Argument> &>(and_), printContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const At<Argument> &at, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << colorlog::Keyword("at");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << colorlog::Number<decltype(at.timePoint)>(at.timePoint);
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, at.argument, printContext);
|
||||
|
||||
printContext.indentationLevel--;
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Either<Argument> &either, detail::PrintContext &printContext)
|
||||
{
|
||||
return print(stream, static_cast<const NAry<Either<Argument>, Argument> &>(either), printContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Exists<Argument> &exists, detail::PrintContext &printContext)
|
||||
{
|
||||
return print(stream, static_cast<const Quantified<Exists<Argument>, Argument> &>(exists), printContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const ForAll<Argument> &forAll, detail::PrintContext &printContext)
|
||||
{
|
||||
return print(stream, static_cast<const Quantified<ForAll<Argument>, Argument> &>(forAll), printContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Imply<Argument> &imply, detail::PrintContext &printContext)
|
||||
{
|
||||
return print(stream, static_cast<const Binary<Imply<Argument>, Argument> &>(imply), printContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Not<Argument> ¬_, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << colorlog::Keyword("not");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, not_.argument, printContext);
|
||||
|
||||
printContext.indentationLevel--;
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Or<Argument> &or_, detail::PrintContext &printContext)
|
||||
{
|
||||
return print(stream, static_cast<const NAry<Or<Argument>, Argument> &>(or_), printContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class ArgumentLeft, class ArgumentRight>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const When<ArgumentLeft, ArgumentRight> &when, detail::PrintContext &printContext)
|
||||
{
|
||||
return print(stream, static_cast<const Binary<When<ArgumentLeft, ArgumentRight>, ArgumentLeft, ArgumentRight> &>(when), printContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PDDL Structure
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Action &action, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << colorlog::Keyword(":action") << " " << detail::Identifier(action.name);
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
if (!action.parameters.empty())
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":parameters");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, action.parameters, printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
if (action.precondition)
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":precondition");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, action.precondition.value(), printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
if (action.effect)
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":effect");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, action.effect.value(), printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
printContext.indentationLevel--;
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Domain &domain, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << colorlog::Keyword("define") << " (" << colorlog::Keyword("domain") << " " << detail::Identifier(domain.name) << ")";
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
if (!domain.requirements.empty())
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":requirements");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, domain.requirements, printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
if (!domain.types.empty())
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":types");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, domain.types, printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
if (!domain.constants.empty())
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":constants");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, domain.constants, printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
if (!domain.predicates.empty())
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":predicates");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, domain.predicates, printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
if (!domain.actions.empty())
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, domain.actions, printContext);
|
||||
}
|
||||
|
||||
printContext.indentationLevel--;
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const InitialState &initialState, detail::PrintContext &printContext)
|
||||
{
|
||||
assert(!initialState.facts.empty());
|
||||
|
||||
stream << "(" << colorlog::Keyword(":init");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, initialState.facts, printContext);
|
||||
|
||||
printContext.indentationLevel--;
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Problem &problem, detail::PrintContext &printContext)
|
||||
{
|
||||
stream << "(" << colorlog::Keyword("define") << " (" << colorlog::Keyword("problem") << " " << detail::Identifier(problem.name) << ")";
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":domain") << " " << detail::Identifier(problem.domain->name) << ")";
|
||||
|
||||
if (!problem.requirements.empty())
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":requirements");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, problem.requirements, printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
if (!problem.objects.empty())
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":objects");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, problem.objects, printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
if (!problem.initialState.facts.empty())
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, problem.initialState, printContext);
|
||||
}
|
||||
|
||||
if (problem.goal)
|
||||
{
|
||||
printIndentedNewline(stream, printContext);
|
||||
stream << "(" << colorlog::Keyword(":goal");
|
||||
|
||||
printContext.indentationLevel++;
|
||||
|
||||
printIndentedNewline(stream, printContext);
|
||||
print(stream, problem.goal.value(), printContext);
|
||||
stream << ")";
|
||||
|
||||
printContext.indentationLevel--;
|
||||
}
|
||||
|
||||
printContext.indentationLevel--;
|
||||
|
||||
return (stream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Requirement &requirement, detail::PrintContext &)
|
||||
{
|
||||
auto requirementName = std::string(":") + pddl::detail::toString(requirement);
|
||||
|
||||
return (stream << detail::Identifier(requirementName.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Description &description, detail::PrintContext &printContext)
|
||||
{
|
||||
print(stream, *description.domain, printContext);
|
||||
stream << std::endl;
|
||||
|
||||
if (description.problem)
|
||||
{
|
||||
stream << std::endl;
|
||||
print(stream, *description.problem.value(), printContext);
|
||||
stream << std::endl;
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const Description &description)
|
||||
{
|
||||
detail::PrintContext printContext;
|
||||
|
||||
return print(stream, description, printContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Variants
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class ValueType>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::unique_ptr<ValueType> &uniquePointer, detail::PrintContext &printContext)
|
||||
{
|
||||
assert(uniquePointer);
|
||||
return print(stream, *uniquePointer, printContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class ValueType>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const std::vector<ValueType> &vector, detail::PrintContext &printContext)
|
||||
{
|
||||
for (const auto &element : vector)
|
||||
{
|
||||
if (&element != &vector.front())
|
||||
printIndentedNewline(stream, printContext);
|
||||
|
||||
print(stream, element, printContext);
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Variant>
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variant &variant, detail::PrintContext &printContext)
|
||||
{
|
||||
variant.match([&](const auto &x){return print(stream, x, printContext);});
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -11,6 +11,7 @@ file(GLOB detail_parsing_headers "../include/pddlparse/detail/parsing/*.h")
|
||||
|
||||
set(includes
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/../../lib/colorlog/include
|
||||
${PROJECT_SOURCE_DIR}/../../lib/tokenize/include
|
||||
${PROJECT_SOURCE_DIR}/../../lib/variant/include
|
||||
)
|
||||
|
Reference in New Issue
Block a user