mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 15:08:45 +00:00
71 lines
2.3 KiB
C++
71 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include "interpreter_tree.hpp"
|
|
#include <iostream>
|
|
#include <pthread.h>
|
|
|
|
namespace error_handling {
|
|
|
|
inline void PrintPosition(std::ostream& out,
|
|
std::pair<size_t, size_t> start_position,
|
|
std::pair<size_t, size_t> end_position) {
|
|
out << '['
|
|
<< start_position.first + 1
|
|
<< ", "
|
|
<< start_position.second + 1
|
|
<< "] - ["
|
|
<< end_position.first + 1
|
|
<< ", "
|
|
<< end_position.second + 1
|
|
<< ']';
|
|
}
|
|
|
|
inline void HandleParsingError(const std::string& message,
|
|
std::pair<size_t, size_t> start_position,
|
|
std::pair<size_t, size_t> end_position) {
|
|
std::cerr << "\x1b[1;31mParsing Error:\x1b[0m " << message << " at ";
|
|
PrintPosition(std::cerr, start_position, end_position);
|
|
std::cerr << ".\n";
|
|
exit(1);
|
|
}
|
|
|
|
inline void HandleGeneralError(const std::string& message) {
|
|
std::cerr << "\x1b[1;31mGeneral Error:\x1b[0m " << message << ".\n";
|
|
exit(1);
|
|
}
|
|
|
|
inline void HandleInternalError(const std::string& message, const std::string& place) {
|
|
std::cerr << "\x1b[1;31mInternal Error:\x1b[0m " << message << " at " << place << ".\n";
|
|
exit(1);
|
|
}
|
|
|
|
inline void HandleTypecheckError(const std::string& message,
|
|
const interpreter::tokens::BaseNode& node) {
|
|
std::cerr << "\x1b[1;31mTypecheck Error:\x1b[0m " << message << " at ";
|
|
PrintPosition(std::cerr, node.start_position, node.end_position);
|
|
std::cerr << ".\n";
|
|
exit(1);
|
|
}
|
|
|
|
inline void HandleRuntimeError(const std::string& message,
|
|
const interpreter::tokens::BaseNode& node) {
|
|
std::cerr << "\x1b[1;31mRuntime Error:\x1b[0m " << message << " at ";
|
|
PrintPosition(std::cerr, node.start_position, node.end_position);
|
|
std::cerr << ".\n";
|
|
exit(1);
|
|
}
|
|
|
|
inline void HandleNamesError(const std::string& message,
|
|
const interpreter::tokens::BaseNode& node) {
|
|
std::cerr << "\x1b[1;31mNames Error:\x1b[0m " << message << " at ";
|
|
PrintPosition(std::cerr, node.start_position, node.end_position);
|
|
std::cerr << ".\n";
|
|
exit(1);
|
|
}
|
|
|
|
template<typename T>
|
|
inline void DebugPrint(const T& value) {
|
|
std::cerr << "\x1b[1;33mDebug:\x1b[0m " << value << '\n';
|
|
}
|
|
|
|
} // namespace error_handling
|