From b19adef236bfb33d9494645e832d7d678f6e4086 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 24 Feb 2018 20:07:44 -0800 Subject: [PATCH] Abstract creating nodes with both strings and vectors. --- src/parser.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/parser.c b/src/parser.c index eb414f9..2ac2ad0 100644 --- a/src/parser.c +++ b/src/parser.c @@ -141,6 +141,19 @@ libab_result _parser_construct_node_vec(libab_lexer_match* match, libab_tree** i return result; } +libab_result _parser_construct_node_both(struct parser_state* state, libab_lexer_match* match, libab_tree** store_into) { + libab_result result = _parser_construct_node_string(state, match, store_into); + if(result == LIBAB_SUCCESS) { + result = libab_convert_ds_result(vec_init(&(*store_into)->children)); + if(result != LIBAB_SUCCESS) { + free((*store_into)->string_value); + free(*store_into); + *store_into = NULL; + } + } + return result; +} + libab_result _parse_if(struct parser_state* state, libab_tree** store_into) { libab_result result = LIBAB_SUCCESS; libab_tree* condition = NULL; @@ -239,18 +252,12 @@ libab_result _parser_append_atom(struct parser_state* state, ll* append_to) { } libab_result _parser_construct_op(struct parser_state* state, libab_lexer_match* match, libab_tree** into) { - libab_result result = _parser_construct_node_string(state, match, into); + libab_result result = _parser_construct_node_both(state, match, into); if(result == LIBAB_SUCCESS) { - result = libab_convert_ds_result(vec_init(&(*into)->children)); - if(result == LIBAB_SUCCESS) { - (*into)->variant = (match->type == TOKEN_OP_INFIX) ? OP : UNARY_OP; - } else { - free((*into)->string_value); - free(*into); - *into = NULL; - } + (*into)->variant = (match->type == TOKEN_OP_INFIX) ? OP : UNARY_OP; } + return result; } libab_result _parser_append_op_node(struct parser_state* state, libab_lexer_match* match, ll* append_to) {