Thu, 28 May 2015 14:34:46 +0200
fixed paranthsis ambiguity for logical and normal expressions
libidav/davqlparser.c | file | annotate | diff | comparison | revisions |
--- a/libidav/davqlparser.c Thu May 28 14:15:32 2015 +0200 +++ b/libidav/davqlparser.c Thu May 28 14:34:46 2015 +0200 @@ -1162,33 +1162,29 @@ } // RULE: "(", LogicalExpression, ")" else if (token_is(token, DAVQL_TOKEN_OPENP)) { - token = token->next; - - int consumed = dav_parse_logical_expr(stmt, token, expr); - if (stmt->errorcode) { - return 0; - } - if (!consumed) { - dav_error_in_context(DAVQL_ERROR_MISSING_EXPR, - _error_missing_expr, stmt, token); - return 0; - } - - token = ucx_list_get(token, consumed); - - if (token_is(token, DAVQL_TOKEN_CLOSEP)) { - token = token->next; - return consumed + 2; + int consumed = dav_parse_logical_expr(stmt, token->next, expr); + if (consumed) { + token = ucx_list_get(token->next, consumed); + + if (token_is(token, DAVQL_TOKEN_CLOSEP)) { + token = token->next; + return consumed + 2; + } else { + dav_error_in_context(DAVQL_ERROR_MISSING_PAR, _error_missing_par, + stmt, token); + return 0; + } } else { - dav_error_in_context(DAVQL_ERROR_MISSING_PAR, _error_missing_par, - stmt, token); - return 0; + // don't handle errors here, we can also try a boolean primary + stmt->errorcode = 0; + if (stmt->errormessage) { + free(stmt->errormessage); + } } } + // RULE: BooleanPrimary - else { - return dav_parse_bool_prim(stmt, token, expr); - } + return dav_parse_bool_prim(stmt, token, expr); } static int dav_parse_logical_expr(DavQLStatement *stmt, UcxList *token,