lang: ast: add diag for do keyword in inline for-loop
This commit is contained in:
@@ -81,6 +81,27 @@ static struct token_parse_result parse_do(
|
||||
= parser_get_state(ctx, struct for_parser_state);
|
||||
|
||||
if (state->s_inline) {
|
||||
struct ivy_diag *diag = parser_push_diag(
|
||||
ctx, IVY_LANG_E_INCORRECT_INLINE_FOR_LOOP,
|
||||
IVY_LANG_MSG_DO_UNEXPECTED_IN_INLINE_FOR, tok);
|
||||
ivy_diag_push_msg(
|
||||
diag, IVY_LANG_MSG_PREVIOUS_EXPRESSION_IS_FOR_BODY);
|
||||
const struct ivy_char_cell *x = &state->s_body->n_end;
|
||||
const struct ivy_char_cell *z = &tok->t_end;
|
||||
|
||||
const struct ivy_diag_amendment a[] = {
|
||||
IVY_DIAG_ADD(x->c_row, x->c_col + 1, "."),
|
||||
};
|
||||
const size_t nr_a = sizeof a / sizeof a[0];
|
||||
|
||||
const struct ivy_diag_highlight hl[] = {
|
||||
IVY_DIAG_HL(
|
||||
HINT, x->c_row, x->c_col + 1, x->c_row,
|
||||
x->c_col + 1),
|
||||
};
|
||||
const size_t nr_hl = sizeof hl / sizeof hl[0];
|
||||
|
||||
ivy_diag_push_snippet(diag, x->c_row, z->c_row, a, nr_a, hl, nr_hl);
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,20 @@
|
||||
|
||||
static const struct ivy_diag_class diag_classes[] = {
|
||||
ERROR_CLASS(IVY_LANG_E_UNRECOGNISED_SYMBOL, "Unrecognised symbol"),
|
||||
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_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 previous expression 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];
|
||||
|
||||
|
||||
@@ -8,11 +8,14 @@ struct ivy_diag_ctx;
|
||||
enum ivy_lang_diag_code {
|
||||
IVY_LANG_E_NONE = 0,
|
||||
IVY_LANG_E_UNRECOGNISED_SYMBOL,
|
||||
IVY_LANG_E_INCORRECT_INLINE_FOR_LOOP,
|
||||
};
|
||||
|
||||
enum ivy_lang_diag_msg {
|
||||
IVY_LANG_MSG_NONE = 0,
|
||||
IVY_LANG_MSG_UNKNOWN_SYMBOL_ENCOUNTERED,
|
||||
IVY_LANG_MSG_DO_UNEXPECTED_IN_INLINE_FOR,
|
||||
IVY_LANG_MSG_PREVIOUS_EXPRESSION_IS_FOR_BODY,
|
||||
};
|
||||
|
||||
IVY_API enum ivy_status ivy_lang_diag_ctx_init(struct ivy_diag_ctx *ctx);
|
||||
|
||||
Reference in New Issue
Block a user