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) {
|
|
|
|
|
std::cout << "Parsing Error: " << message << " at ";
|
|
|
|
|
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) {
|
|
|
|
|
std::cout << "General Error: " << message << ".\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 18:56:58 +03:00
|
|
|
inline void HandleInternalError(const std::string& message, const std::string& place) {
|
|
|
|
|
std::cout << "Internal Error: " << message << " at " << place << ".\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 11:59:02 +03:00
|
|
|
inline void HandleTypecheckError(const std::string& message,
|
|
|
|
|
const interpreter::tokens::BaseNode& node) { // TODO: place in code
|
|
|
|
|
std::cout << "Typecheck Error: " << message << " at ";
|
|
|
|
|
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,
|
|
|
|
|
const interpreter::tokens::BaseNode& node) { // TODO: place in code
|
|
|
|
|
std::cout << "Runtime Error: " << message << " at ";
|
|
|
|
|
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
|