diff --git a/include/plasp/utils/ParserWarning.h b/include/plasp/utils/ParserWarning.h new file mode 100644 index 0000000..060ef9a --- /dev/null +++ b/include/plasp/utils/ParserWarning.h @@ -0,0 +1,59 @@ +#ifndef __PLASP__UTILS__PARSER_WARNING_H +#define __PLASP__UTILS__PARSER_WARNING_H + +#include +#include + +#include + +namespace plasp +{ +namespace utils +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// ParserWarning +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class ParserWarning: public std::exception +{ + public: + explicit ParserWarning(const utils::Parser &parser) + : ParserWarning(parser, "Unspecified parser warning") + { + } + + explicit ParserWarning(const utils::Parser &parser, const char *message) + : ParserWarning(parser, static_cast(message)) + { + } + + explicit ParserWarning(const utils::Parser &parser, const std::string &message) + : m_message{std::to_string(parser.row()) + ":" + std::to_string(parser.column()) + "\t" + message} + { + } + + ~ParserWarning() throw() + { + } + + const char *what() const throw() + { + if (m_message.empty()) + return "Unspecified parser warning"; + + return m_message.c_str(); + } + + private: + std::string m_message; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif