#include #include #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"), ERROR_CLASS(IVY_LANG_E_UNDEFINED_VARIABLE, "Undefined variable"), ERROR_CLASS( IVY_LANG_E_INCORRECT_INLINE_FOR_LOOP, "Incorrect inline for-loop"), }; 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."), MSG(IVY_LANG_MSG_ASSIGN_TO_UNDEFINED_VARIABLE, "cannot use modify-and-assign operator on an undefined variable."), 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, "the expression before `[yellow]for[reset]` is used as the " "for-loop body. perhaps you forgot a [blue]statement " "separator[reset]?"), }; 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; }