diff --git a/include/plasp/pddl/Context.h b/include/plasp/pddl/Context.h index 52b182b..7d01495 100644 --- a/include/plasp/pddl/Context.h +++ b/include/plasp/pddl/Context.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace plasp { @@ -31,6 +32,7 @@ class Context } utils::Parser &parser; + utils::Logger logger; expressions::PrimitiveTypes primitiveTypes; //std::unordered_map primitiveTypesHashMap; diff --git a/include/plasp/utils/Logger.h b/include/plasp/utils/Logger.h new file mode 100644 index 0000000..c8b47f9 --- /dev/null +++ b/include/plasp/utils/Logger.h @@ -0,0 +1,37 @@ +#ifndef __PLASP__UTILS__LOGGER_H +#define __PLASP__UTILS__LOGGER_H + +#include + +#include + +namespace plasp +{ +namespace utils +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Logger +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class Logger +{ + public: + Logger(); + + void setPedantic(bool isPedantic = true); + + void parserWarning(const Parser &parser, const std::string &text); + + private: + bool m_isPedantic; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif diff --git a/src/plasp/pddl/expressions/PrimitiveType.cpp b/src/plasp/pddl/expressions/PrimitiveType.cpp index de09e1b..14bfae4 100644 --- a/src/plasp/pddl/expressions/PrimitiveType.cpp +++ b/src/plasp/pddl/expressions/PrimitiveType.cpp @@ -129,7 +129,7 @@ PrimitiveType *PrimitiveType::parseExisting(Context &context) { // Primitive type "object" is implicitly declared if (typeName != "object") - throw ConsistencyException("Primitive type \"" + typeName + "\" used but never declared"); + context.logger.parserWarning(context.parser, "Primitive type \"" + typeName + "\" used but never declared"); return create(typeName, context); } diff --git a/src/plasp/utils/Logger.cpp b/src/plasp/utils/Logger.cpp new file mode 100644 index 0000000..fa3d0aa --- /dev/null +++ b/src/plasp/utils/Logger.cpp @@ -0,0 +1,41 @@ +#include + +#include + +namespace plasp +{ +namespace utils +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Logger +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +Logger::Logger() +: m_isPedantic{false} +{ +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +void Logger::setPedantic(bool isPedantic) +{ + m_isPedantic = isPedantic; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +void Logger::parserWarning(const Parser &parser, const std::string &text) +{ + if (m_isPedantic) + throw ParserWarning(parser, text); + + std::cerr << "Warning: " << parser.row() << ":" << parser.column() << "\t" << text << std::endl; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +}