Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

85 wiersze
3.3 KiB

#pragma once
#include "lexer.h"
#include <sstream>
#include <stdexcept>
namespace molasses {
namespace details {
template<typename... RestT>
std::string concatenate_builder_impl(std::stringstream& stream)
requires(sizeof...(RestT) == 0)
{
return stream.str();
}
template<typename FirstT, typename... RestT>
std::string concatenate_builder_impl(std::stringstream& stream, FirstT first, RestT... rest) {
stream << first;
return concatenate_builder_impl(stream, rest...);
}
template<typename... RestT>
std::string concatenate_builder(RestT... rest) {
std::stringstream stream{};
return concatenate_builder_impl(stream, rest...);
}
}
struct build_system_error : std::runtime_error {
explicit build_system_error(const std::string& message)
: std::runtime_error(message) {}
};
struct interpreter_error : std::runtime_error {
explicit interpreter_error(const std::string& message)
: std::runtime_error(message) {}
};
struct parser_error : public std::runtime_error {
explicit parser_error(const std::string& str)
: std::runtime_error(str) {}
};
struct type_input_error : public parser_error {
type_input_error()
: parser_error("Bad type provided") {}
// TODO: Better error message
};
struct value_missing_error : public parser_error {
value_missing_error()
: parser_error("Expected value, none provided") {}
// TODO: Better error message
};
struct procedure_stack_error : public parser_error {
procedure_stack_error()
: parser_error("Expected the stack to look like the return stack upon completion\n") {}
// TODO: Better error message
};
struct unexpected_token_error : public parser_error {
unexpected_token_error(const symbol& sym, const std::string& found, const std::string& expected)
: parser_error(details::concatenate_builder(
"Unexpected token encountered\n", "\tAt ", sym.file_name, ":", sym.line, ":", sym.column, "\n",
"\tExpected ", expected, "\n", "\tFound ", found, "\n"
)) {}
};
struct expecting_token_error : public parser_error {
expecting_token_error(const std::string& expected, const std::string& context)
: parser_error(details::concatenate_builder(
"An expected token has not been encountered before the end of the input\n", "\tExpected ", expected,
"\n", "\t", context, "\n"
)) {}
// TODO: Better error message
};
struct unknown_token_error : public parser_error {
explicit unknown_token_error(const symbol& sym)
: parser_error(details::concatenate_builder(
"An unknown token has been encountered\n", "\tAt ", sym.file_name, ":", sym.line, ":", sym.column,
"\n"
)) {}
// TODO: Better error message
};
struct type_expected_with_modifier_error : public parser_error {
type_expected_with_modifier_error()
: parser_error("A type is expected before a modifier") {}
// TODO: Better error message
};
}