2023-04-17 18:56:58 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-05-05 11:59:02 +03:00
|
|
|
#include "interpreter_tree.hpp"
|
2023-04-07 12:13:31 +03:00
|
|
|
#include <iostream>
|
2023-05-05 11:59:02 +03:00
|
|
|
#include <pthread.h>
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 18:56:58 +03:00
|
|
|
namespace error_handling {
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-05-05 11:59:02 +03:00
|
|
|
inline void PrintPosition(std::ostream& out,
|
|
|
|
|
std::pair<size_t, size_t> start_position,
|
|
|
|
|
std::pair<size_t, size_t> end_position) {
|
|
|
|
|
out << '['
|
2023-05-08 20:34:36 +03:00
|
|
|
<< start_position.first + 1
|
2023-05-05 11:59:02 +03:00
|
|
|
<< ", "
|
2023-05-08 20:34:36 +03:00
|
|
|
<< start_position.second + 1
|
2023-05-05 11:59:02 +03:00
|
|
|
<< "] - ["
|
2023-05-08 20:34:36 +03:00
|
|
|
<< end_position.first + 1
|
2023-05-05 11:59:02 +03:00
|
|
|
<< ", "
|
2023-05-08 20:34:36 +03:00
|
|
|
<< end_position.second + 1
|
2023-05-05 11:59:02 +03:00
|
|
|
<< ']';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void HandleParsingError(const std::string& message,
|
|
|
|
|
std::pair<size_t, size_t> start_position,
|
|
|
|
|
std::pair<size_t, size_t> end_position) {
|
2023-05-13 22:40:33 +03:00
|
|
|
std::cout << "\x1b[1;31mParsing Error:\x1b[0m " << message << " at ";
|
2023-05-05 11:59:02 +03:00
|
|
|
PrintPosition(std::cout, start_position, end_position);
|
|
|
|
|
std::cout << ".\n";
|
2023-04-07 12:13:31 +03:00
|
|
|
exit(1);
|
|
|
|
|
}
|
2023-04-17 18:56:58 +03:00
|
|
|
|
2023-05-11 15:14:02 +03:00
|
|
|
inline void HandleGeneralError(const std::string& message) {
|
2023-05-13 22:40:33 +03:00
|
|
|
std::cout << "\x1b[1;31mGeneral Error:\x1b[0m " << message << ".\n";
|
2023-05-11 15:14:02 +03:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 18:56:58 +03:00
|
|
|
inline void HandleInternalError(const std::string& message, const std::string& place) {
|
2023-05-13 22:40:33 +03:00
|
|
|
std::cout << "\x1b[1;31mInternal Error:\x1b[0m " << message << " at " << place << ".\n";
|
2023-04-17 18:56:58 +03:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 11:59:02 +03:00
|
|
|
inline void HandleTypecheckError(const std::string& message,
|
2023-05-13 22:40:33 +03:00
|
|
|
const interpreter::tokens::BaseNode& node) {
|
|
|
|
|
std::cout << "\x1b[1;31mTypecheck Error:\x1b[0m " << message << " at ";
|
2023-05-05 11:59:02 +03:00
|
|
|
PrintPosition(std::cout, node.start_position, node.end_position);
|
|
|
|
|
std::cout << ".\n";
|
2023-04-17 18:56:58 +03:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-09 14:55:04 +03:00
|
|
|
inline void HandleRuntimeError(const std::string& message,
|
2023-05-13 22:40:33 +03:00
|
|
|
const interpreter::tokens::BaseNode& node) {
|
|
|
|
|
std::cout << "\x1b[1;31mRuntime Error:\x1b[0m " << message << " at ";
|
2023-05-09 14:55:04 +03:00
|
|
|
PrintPosition(std::cout, node.start_position, node.end_position);
|
|
|
|
|
std::cout << ".\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 18:56:58 +03:00
|
|
|
} // namespace error_handling
|