diff --git a/mie/diag/diag.c b/mie/diag/diag.c index 4b195ae..c533167 100644 --- a/mie/diag/diag.c +++ b/mie/diag/diag.c @@ -76,7 +76,11 @@ void mie_diag_push_msg( return; } - if (msg >= dialect->d_nr_diag_msgs) { + if (msg >= dialect->d_nr_diag_msgs + || !dialect->d_diag_msgs[msg].msg_content) { + fprintf(stderr, "FATAL: %lu is not a valid %s diag msg\n", msg, + dialect_name); + abort(); return; } @@ -90,6 +94,20 @@ void mie_diag_push_msg( b_queue_push_back(&diag->diag_components, &c_msg->msg_base.c_entry); } +void mie_diag_push_string(struct mie_diag *diag, const char *str) +{ + struct mie_diag_c_msg *c_msg = malloc(sizeof *c_msg); + if (!c_msg) { + return; + } + + memset(c_msg, 0x0, sizeof *c_msg); + c_msg->msg_base.c_type = MIE_DIAG_COMPONENT_MSG; + c_msg->msg_content = b_strdup(str); + + b_queue_push_back(&diag->diag_components, &c_msg->msg_base.c_entry); +} + void mie_diag_push_snippet( struct mie_diag *diag, unsigned long first_line, unsigned long last_line, const struct mie_diag_amendment *amendments, size_t nr_amendments, diff --git a/mie/include/mie/diag/diag.h b/mie/include/mie/diag/diag.h index a59caa2..913ba76 100644 --- a/mie/include/mie/diag/diag.h +++ b/mie/include/mie/diag/diag.h @@ -4,6 +4,39 @@ #include #include +#define MIE_DIAG_HL(type, span) \ + { \ + .hl_type = MIE_DIAG_HIGHLIGHT_##type, \ + .hl_span = (span), \ + } + +#define MIE_DIAG_ADD(str, loc) \ + { \ + .a_type = MIE_DIAG_AMENDMENT_ADD, .__x = strlen(str), \ + .a_add = { \ + .a_loc = (loc), \ + .a_str = (str), \ + }, \ + } + +#define MIE_DIAG_REMOVE(len, llc) \ + { \ + .a_type = MIE_DIAG_AMENDMENT_REMOVE, \ + .a_remove = { \ + .a_loc = (loc), \ + .a_length = (len), \ + }, \ + } +#define MIE_DIAG_REPLACE(len, str, loc) \ + { \ + .a_type = MIE_DIAG_AMENDMENT_REPLACE, .__x = strlen(str), \ + .a_replace = { \ + .a_loc = (loc), \ + .a_length = (len), \ + .a_str = (str), \ + }, \ + } + struct mie_ctx; struct mie_diag_class; struct mie_diag_amendment; @@ -31,6 +64,7 @@ MIE_API void mie_diag_set_location( MIE_API void mie_diag_push_msg( struct mie_diag *diag, struct mie_ctx *ctx, const char *dialect, unsigned long msg, ...); +MIE_API void mie_diag_push_string(struct mie_diag *diag, const char *str); MIE_API void mie_diag_push_snippet( struct mie_diag *diag, unsigned long first_line, unsigned long last_line, const struct mie_diag_amendment *amendmends, size_t nr_amendments,