lang: ast: fix selector to_string not including keyword message labels
This commit is contained in:
@@ -93,7 +93,8 @@ static struct token_parse_result parse_label(
|
||||
struct ivy_ast_selector_node *sel
|
||||
= (struct ivy_ast_selector_node *)state->s_base.s_node;
|
||||
|
||||
if (sel->n_recipient == IVY_SELECTOR_RECIPIENT_NONE && state->s_prev != IVY_TOK_IDENT
|
||||
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. */
|
||||
@@ -180,7 +181,8 @@ static struct token_parse_result parse_pipe(
|
||||
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)) {
|
||||
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);
|
||||
}
|
||||
@@ -192,7 +194,8 @@ static struct token_parse_result parse_pipe(
|
||||
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)) {
|
||||
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);
|
||||
}
|
||||
@@ -224,7 +227,8 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
struct ivy_ast_selector_node *sel = (struct ivy_ast_selector_node *)node;
|
||||
|
||||
b_string_append_cstrf(str, "%s [", ivy_ast_node_type_to_string(node->n_type));
|
||||
b_string_append_cstrf(
|
||||
str, "%s [", ivy_ast_node_type_to_string(node->n_type));
|
||||
|
||||
switch (sel->n_recipient) {
|
||||
case IVY_SELECTOR_RECIPIENT_CLASS:
|
||||
@@ -255,22 +259,28 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
b_queue_iterator_begin(&sel->n_arg_names, &name_it);
|
||||
|
||||
int i = 0;
|
||||
while (b_queue_iterator_is_valid(&label_it)
|
||||
&& b_queue_iterator_is_valid(&name_it)) {
|
||||
while (b_queue_iterator_is_valid(&label_it)) {
|
||||
if (i > 0) {
|
||||
b_string_append_cstr(str, " ");
|
||||
}
|
||||
|
||||
struct ivy_token *label
|
||||
= b_unbox(struct ivy_token, label_it.entry, t_entry);
|
||||
struct ivy_token *name
|
||||
= b_unbox(struct ivy_token, name_it.entry, t_entry);
|
||||
struct ivy_token *label, *name;
|
||||
|
||||
if (label && name) {
|
||||
b_string_append_cstrf(str, "%s:%s", label->t_str, name->t_str);
|
||||
label = b_unbox(struct ivy_token, label_it.entry, t_entry);
|
||||
name = b_unbox(struct ivy_token, name_it.entry, t_entry);
|
||||
|
||||
if (label) {
|
||||
b_string_append_cstrf(str, "%s:", label->t_str);
|
||||
}
|
||||
|
||||
if (name) {
|
||||
b_string_append_cstrf(str, "%s", name->t_str);
|
||||
}
|
||||
|
||||
if (name) {
|
||||
i++;
|
||||
}
|
||||
|
||||
b_queue_iterator_next(&label_it);
|
||||
b_queue_iterator_next(&name_it);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user