mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 06:58:45 +00:00
47 lines
1.3 KiB
C++
47 lines
1.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
|
|
<< ", "
|
|
<< start_position.second
|
|
<< "] - ["
|
|
<< end_position.first
|
|
<< ", "
|
|
<< end_position.second
|
|
<< ']';
|
|
}
|
|
|
|
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";
|
|
exit(1);
|
|
}
|
|
|
|
inline void HandleInternalError(const std::string& message, const std::string& place) {
|
|
std::cout << "Internal Error: " << message << " at " << place << ".\n";
|
|
exit(1);
|
|
}
|
|
|
|
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";
|
|
exit(1);
|
|
}
|
|
|
|
// ...
|
|
|
|
} // namespace error_handling
|