2025-05-08 20:31:28 +01:00
|
|
|
#include <ivy/diag.h>
|
|
|
|
|
#include <ivy/lang/diag.h>
|
|
|
|
|
|
|
|
|
|
#define ERROR_CLASS(id, title) \
|
|
|
|
|
[id] = {.c_type = IVY_DIAG_ERROR, .c_title = (title)}
|
|
|
|
|
|
|
|
|
|
#define MSG(id, content) [id] = {.msg_content = (content)}
|
|
|
|
|
|
|
|
|
|
static const struct ivy_diag_class diag_classes[] = {
|
|
|
|
|
ERROR_CLASS(IVY_LANG_E_UNRECOGNISED_SYMBOL, "Unrecognised symbol"),
|
2025-11-07 09:49:24 +00:00
|
|
|
ERROR_CLASS(IVY_LANG_E_MISSING_WHITESPACE, "Missing whitespace"),
|
2025-09-08 15:48:38 +01:00
|
|
|
ERROR_CLASS(IVY_LANG_E_UNDEFINED_VARIABLE, "Undefined variable"),
|
2025-05-08 22:32:23 +01:00
|
|
|
ERROR_CLASS(
|
|
|
|
|
IVY_LANG_E_INCORRECT_INLINE_FOR_LOOP,
|
|
|
|
|
"Incorrect inline for-loop"),
|
2025-05-08 20:31:28 +01:00
|
|
|
};
|
|
|
|
|
static const size_t nr_diag_classes = sizeof diag_classes / sizeof diag_classes[0];
|
|
|
|
|
|
|
|
|
|
static const struct ivy_diag_msg diag_msg[] = {
|
|
|
|
|
MSG(IVY_LANG_MSG_UNKNOWN_SYMBOL_ENCOUNTERED,
|
|
|
|
|
"encountered a symbol that is not part of the Ivy syntax."),
|
2025-11-07 09:49:24 +00:00
|
|
|
MSG(IVY_LANG_MSG_WHITESPACE_REQUIRED_AROUND_BINARY_OP,
|
|
|
|
|
"There must be a space between a binary operator and its "
|
|
|
|
|
"operands."),
|
2025-09-08 15:48:38 +01:00
|
|
|
MSG(IVY_LANG_MSG_ASSIGN_TO_UNDEFINED_VARIABLE,
|
|
|
|
|
"cannot use modify-and-assign operator on an undefined variable."),
|
2025-05-08 22:32:23 +01:00
|
|
|
MSG(IVY_LANG_MSG_DO_UNEXPECTED_IN_INLINE_FOR,
|
|
|
|
|
"`[yellow]do[reset]` is not used in inline for-loops."),
|
|
|
|
|
MSG(IVY_LANG_MSG_PREVIOUS_EXPRESSION_IS_FOR_BODY,
|
2025-05-09 13:39:02 +01:00
|
|
|
"the expression before `[yellow]for[reset]` is used as the "
|
|
|
|
|
"for-loop body. perhaps you forgot a [blue]statement "
|
|
|
|
|
"separator[reset]?"),
|
2025-05-08 20:31:28 +01:00
|
|
|
};
|
|
|
|
|
static const size_t nr_diag_msg = sizeof diag_msg / sizeof diag_msg[0];
|
|
|
|
|
|
|
|
|
|
enum ivy_status ivy_lang_diag_ctx_init(struct ivy_diag_ctx *ctx)
|
|
|
|
|
{
|
|
|
|
|
ivy_diag_ctx_set_class_definitions(ctx, diag_classes, nr_diag_msg);
|
|
|
|
|
ivy_diag_ctx_set_msg_definitions(ctx, diag_msg, nr_diag_msg);
|
|
|
|
|
|
|
|
|
|
return IVY_OK;
|
|
|
|
|
}
|