From 6d6adf59556467e118f76868aa9d6aecf1f178e2 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 2 Dec 2024 10:59:49 +0000 Subject: [PATCH] lang: ast: fix parsing of consecutive unary messages --- lang/ast/expr.c | 50 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/lang/ast/expr.c b/lang/ast/expr.c index 76d0444..5ac8c89 100644 --- a/lang/ast/expr.c +++ b/lang/ast/expr.c @@ -205,6 +205,29 @@ static struct ivy_ast_node *create_operator_node_from_token(struct ivy_token *to return (struct ivy_ast_node *)new_op_node; } +static void print_expr_queues(struct expr_parser_state *state) +{ + b_queue_iterator it = {0}; + + printf("operators:"); + b_queue_foreach (&it, &state->s_operator_stack) { + struct ivy_ast_node *n + = b_unbox(struct ivy_ast_node, it.entry, n_entry); + fputc(' ', stdout); + print_operand(n); + } + + printf("\noperands:"); + b_queue_foreach (&it, &state->s_output_queue) { + struct ivy_ast_node *n + = b_unbox(struct ivy_ast_node, it.entry, n_entry); + fputc(' ', stdout); + print_operand(n); + } + + printf("\n"); +} + static void push_operator(struct expr_parser_state *state, struct ivy_ast_node *node) { const struct ivy_operator *op = get_operator_from_node(node); @@ -250,29 +273,7 @@ static void push_operator(struct expr_parser_state *state, struct ivy_ast_node * } b_queue_push_back(&state->s_operator_stack, &node->n_entry); -} - -static void print_expr_queues(struct expr_parser_state *state) -{ - b_queue_iterator it = {0}; - - printf("operators:"); - b_queue_foreach (&it, &state->s_operator_stack) { - struct ivy_ast_node *n - = b_unbox(struct ivy_ast_node, it.entry, n_entry); - fputc(' ', stdout); - print_operand(n); - } - - printf("\noperands:"); - b_queue_foreach (&it, &state->s_output_queue) { - struct ivy_ast_node *n - = b_unbox(struct ivy_ast_node, it.entry, n_entry); - fputc(' ', stdout); - print_operand(n); - } - - printf("\n"); + print_expr_queues(state); } static bool op_node_is_complete(struct ivy_ast_op_node *node) @@ -517,7 +518,8 @@ static struct token_parse_result parse_ident( struct token_parse_result result; - if (state->s_prev_component == EXPR_CMP_OPERAND) { + if (state->s_prev_component == EXPR_CMP_OPERAND + || state->s_prev_component == EXPR_CMP_MSG) { result = parse_operator(ctx, tok); state->s_prev_component = EXPR_CMP_MSG; } else {