From 12660b1e4a2c58fa80c86611378d520e2be39058 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 18 Feb 2018 19:02:06 -0800 Subject: [PATCH] Allow last expression in code to not be terminated by a semicolon. --- src/parser.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/parser.c b/src/parser.c index 8be589d..2dc17a8 100644 --- a/src/parser.c +++ b/src/parser.c @@ -361,7 +361,17 @@ libab_result _parse_statement(struct parser_state* state, libab_tree** store_int _parser_is_char(state, '(') || _parser_is_type(state, TOKEN_OP_PREFIX)) { result = _parse_expression(state, store_into); - if(result == LIBAB_SUCCESS) result = _parser_consume_char(state, ';'); + if(result == LIBAB_SUCCESS) { + if(_parser_is_char(state, ';') || _parser_eof(state)) { + _parser_state_step(state); + } else { + result = LIBAB_UNEXPECTED; + + libab_tree_free_recursive(*store_into); + free(*store_into); + *store_into = NULL; + } + } } return result;