From 052fc5b94362cbc8245939be0adedd6eb7ee027e Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 24 Feb 2018 20:07:54 -0800 Subject: [PATCH] Fix bugs in the if-statement parser. --- src/parser.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/parser.c b/src/parser.c index 2ac2ad0..3440830 100644 --- a/src/parser.c +++ b/src/parser.c @@ -164,11 +164,10 @@ libab_result _parse_if(struct parser_state* state, libab_tree** store_into) { result = _parser_construct_node_vec(state->current_match, store_into); if(result == LIBAB_SUCCESS) { (*store_into)->variant = IF; + _parser_state_step(state); } - } - - if(result == LIBAB_SUCCESS) { - result = _parser_consume_type(state, TOKEN_KW_IF); + } else { + result = LIBAB_UNEXPECTED; } if(result == LIBAB_SUCCESS) { @@ -211,8 +210,8 @@ libab_result _parse_if(struct parser_state* state, libab_tree** store_into) { if(condition) libab_tree_free_recursive(condition); if(if_branch) libab_tree_free_recursive(if_branch); if(else_branch) libab_tree_free_recursive(else_branch); + if(*store_into) libab_tree_free(*store_into); - libab_tree_free(*store_into); free(*store_into); *store_into = NULL; }