mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-05 22:48:43 +00:00
76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include "basic_nodes.hpp"
|
|
#include "tree_sitter_wrapper.hpp"
|
|
#include "utils.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
namespace error_handling {
|
|
|
|
inline void handle_internal_error(
|
|
std::string_view message, const nodes::Node &node,
|
|
const std::source_location &location = std::source_location::current()) {
|
|
std::cerr << "\x1b[1;31mInternal Error:\x1b[0m " << message << " at ";
|
|
print_position(std::cerr, node.get_start_position(), node.get_end_position());
|
|
std::cerr << ".\n";
|
|
print_source_location(std::cerr, location);
|
|
exit(1);
|
|
}
|
|
|
|
inline void handle_internal_error(
|
|
std::string_view message, parser::ParseTree::Node node,
|
|
const std::source_location &location = std::source_location::current()) {
|
|
std::cerr << "\x1b[1;31mInternal Error:\x1b[0m " << message << " at ";
|
|
print_position(std::cerr, node.get_start_point(), node.get_end_point());
|
|
std::cerr << ".\n";
|
|
print_source_location(std::cerr, location);
|
|
exit(1);
|
|
}
|
|
|
|
inline void handle_parsing_error(
|
|
std::string_view message, parser::ParseTree::Node parse_node,
|
|
const std::source_location &location = std::source_location::current()) {
|
|
std::cerr << "\x1b[1;31mParsing Error:\x1b[0m " << message << " at ";
|
|
print_position(std::cerr, parse_node.get_start_point(),
|
|
parse_node.get_end_point());
|
|
std::cerr << ".\n";
|
|
print_source_location(std::cerr, location);
|
|
exit(1);
|
|
}
|
|
|
|
inline void handle_typecheck_error(
|
|
std::string_view message, nodes::Node node,
|
|
const std::source_location &location = std::source_location::current()) {
|
|
std::cerr << "\x1b[1;31mTypecheck Error:\x1b[0m " << message << " at ";
|
|
print_position(std::cerr, node.get_start_position(), node.get_end_position());
|
|
std::cerr << ".\n";
|
|
print_source_location(std::cerr, location);
|
|
exit(1);
|
|
}
|
|
|
|
inline void handle_runtime_error(
|
|
std::string_view message, nodes::Node node,
|
|
const std::source_location &location = std::source_location::current()) {
|
|
std::cerr << "\x1b[1;31mRuntime Error:\x1b[0m " << message << " at ";
|
|
print_position(std::cerr, node.get_start_position(), node.get_end_position());
|
|
std::cerr << ".\n";
|
|
print_source_location(std::cerr, location);
|
|
exit(1);
|
|
}
|
|
|
|
inline void handle_names_error(
|
|
std::string_view message, nodes::Node node,
|
|
const std::source_location &location = std::source_location::current()) {
|
|
std::cerr << "\x1b[1;31mNames Error:\x1b[0m " << message << " at ";
|
|
print_position(std::cerr, node.get_start_position(), node.get_end_position());
|
|
std::cerr << ".\n";
|
|
print_source_location(std::cerr, location);
|
|
exit(1);
|
|
}
|
|
|
|
template <typename T> inline void debug_print(const T &value) {
|
|
std::cerr << "\x1b[1;33mDebug:\x1b[0m " << value << '\n';
|
|
}
|
|
|
|
} // namespace error_handling
|