From: Wolfgang Bumiller Date: Fri, 27 Jul 2012 11:07:16 +0000 (+0200) Subject: factoring out the closing-paren handling code since it'll be used recursively X-Git-Tag: 0.1-rc1~386 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6b85f3d3702c3677bbb34b2af7d2b02a1201a1a1;p=xonotic%2Fgmqcc.git factoring out the closing-paren handling code since it'll be used recursively --- diff --git a/parser.c b/parser.c index 75c6911..f95e7e0 100644 --- a/parser.c +++ b/parser.c @@ -391,6 +391,27 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy) return true; } +static bool parser_close_paren(parser_t *parser, shunt *sy) +{ + if (!sy->ops_count) { + parseerror(parser, "unmatched closing paren"); + return false; + } + if (sy->ops[sy->ops_count-1].paren == 1) { + parseerror(parser, "empty parenthesis expression"); + return false; + } + while (sy->ops_count) { + if (sy->ops[sy->ops_count-1].paren == 1) { + sy->ops_count--; + break; + } + if (!parser_sy_pop(parser, sy)) + return false; + } + return true; +} + static ast_expression* parser_expression(parser_t *parser) { ast_expression *expr = NULL; @@ -461,22 +482,8 @@ static ast_expression* parser_expression(parser_t *parser) else if (parser->tok == ')') { /* we do expect an operator next */ /* closing an opening paren */ - if (!sy.ops_count) { - parseerror(parser, "unmatched closing paren"); + if (!parser_close_paren(parser, &sy)) goto onerr; - } - if (sy.ops[sy.ops_count-1].paren == 1) { - parseerror(parser, "empty parenthesis expression"); - goto onerr; - } - while (sy.ops_count) { - if (sy.ops[sy.ops_count-1].paren == 1) { - sy.ops_count--; - break; - } - if (!parser_sy_pop(parser, &sy)) - goto onerr; - } } else if (parser->tok != TOKEN_OPERATOR) { parseerror(parser, "expected operator or end of statement");