lang: ast: fix error when parsing message handler keyword-message selector

This commit is contained in:
2024-12-06 13:23:02 +00:00
parent d3813dc514
commit 7ba0a05332

View File

@@ -93,7 +93,10 @@ static struct token_parse_result parse_label(
struct ivy_ast_selector_node *sel
= (struct ivy_ast_selector_node *)state->s_base.s_node;
if (state->s_prev != IVY_TOK_IDENT && state->s_prev != IVY_SYM_LEFT_PAREN) {
if (sel->n_recipient == IVY_SELECTOR_RECIPIENT_NONE && state->s_prev != IVY_TOK_IDENT
&& state->s_prev != IVY_SYM_LEFT_PAREN) {
/* if recipient is not NONE, this selector appears at the beginning of a message
* handler. only then is a label without a preceding identifier allowed. */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
@@ -174,12 +177,28 @@ static struct token_parse_result parse_pipe(
struct ivy_ast_selector_node *sel
= (struct ivy_ast_selector_node *)state->s_base.s_node;
if (!b_queue_empty(&sel->n_arg_labels)
&& state->s_prev != IVY_SYM_RIGHT_PAREN) {
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
switch (state->s_prev) {
case IVY_SYM_RIGHT_PAREN:
/* this looks like a complex message selector */
if (b_queue_empty(&sel->n_arg_labels) || b_queue_empty(&sel->n_arg_names)) {
/* no message args */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
if (state->s_prev != IVY_TOK_IDENT) {
if (!sel->n_msg_name) {
/* no message name */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
break;
case IVY_TOK_IDENT:
/* this looks like a unary or keyword message. */
if (!b_queue_empty(&sel->n_arg_labels) && b_queue_empty(&sel->n_arg_names)) {
/* keyword message with no arg names. */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
break;
default:
/* not sure what we're parsing. unknown token at end of selector. */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}