Skip to content
Snippets Groups Projects
Commit 3186ef71 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

added new exception files

parent 07504778
No related branches found
No related tags found
1 merge request!26parser cleanup and fixes
#ifndef CDO_EXCEPTION_H
#define CDO_EXCEPTION_H
#include <string>
#include <stdexcept>
struct CdoException : std::logic_error
{
CdoException(std::string p_msg,std::string p_file, std::string p_line) : std::logic_error(p_msg), file(p_file), line(p_line) {}
std::string file;
std::string line;
};
#endif
#ifndef CDO_NODE_ATTACH_EXCEPTION_H
#define CDO_NODE_ATTACH_EXCEPTION_H
#include <vector>
#include <string>
#include <memory>
#include "cdo_exception.h"
struct NodeAttachException : public CdoException
{
std::vector<std::string>::const_iterator iter;
NodeAttachException(std::shared_ptr<Node> p_node, const std::string &p_msg, std::string p_file = "?", std::string p_line = "?")
: CdoException(p_msg,p_file, p_line) ,iter(p_node->iter){};
NodeAttachException(std::vector<std::string>::const_iterator p_iter, const std::string &p_msg, std::string p_file = "?", std::string p_line = "?")
: CdoException(p_msg,p_file, p_line), iter(p_iter){};
};
#endif
#include <vector>
#include <string>
#include "cdo_syntax_error.h"
#include "mpmo_color.h"
InternalCdoSyntaxError::InternalCdoSyntaxError(std::vector<std::string>::const_iterator p_iter, const std::string &p_msg,
std::string p_file, std::string p_line)
: CdoException(p_msg, p_file, p_line), iter(p_iter)
{
}
CdoSyntaxError::CdoSyntaxError(InternalCdoSyntaxError &e, std::vector<std::string> &p_argv, std::string context)
: InternalCdoSyntaxError(e.iter, e.message, e.file, e.line)
{
std::string padding = "";
std::string errLine = "";
bool addPadding = true;
for (auto it = p_argv.begin(); it < p_argv.end(); it++)
{
if (it != e.iter)
{
if (addPadding) padding += std::string((*it).length() + 1, ' ');
errLine += *it;
}
else
{
if (addPadding) padding += std::string((*it).length() / 2, ' ');
addPadding = false;
errLine += Red("\033[4m" + *it + "\033[0m");
}
errLine += " ";
}
message = errLine + " \n" + padding + "^ " + e.what();
#ifdef EXCEPTION_EXTRA_INFO
message += "\n Thrown from " + file + ": " + line + "\n";
#endif
}
const char *
CdoSyntaxError::what() const throw()
{
return message.c_str();
};
#ifndef CDO_SYNTAX_ERROR_H
#define CDO_SYNTAX_ERROR_H
#include <vector>
#include <string>
#include "cdo_exception.h" //TODO MOVE CdoException from node to cdoException.h
//
struct InternalCdoSyntaxError : CdoException
{
std::vector<std::string>::const_iterator iter;
std::string message;
InternalCdoSyntaxError(std::vector<std::string>::const_iterator p_iter, const std::string &p_msg, std::string p_file = "?",
std::string p_line = "?");
};
struct CdoSyntaxError : InternalCdoSyntaxError
{
CdoSyntaxError(InternalCdoSyntaxError &e, std::vector<std::string> &p_argv, std::string context);
CdoSyntaxError(InternalCdoSyntaxError &e);
const char *what() const throw() override;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment