# HG changeset patch # User Mike Becker # Date 1432813719 -7200 # Node ID 44ffe073b5e30271aa1cf6048aa14378fc32d990 # Parent 5744a3dee7666564b39f1c27d9427a383048e44c fixed logical expression parser diff -r 5744a3dee766 -r 44ffe073b5e3 libidav/davqlparser.c --- a/libidav/davqlparser.c Thu May 28 12:22:55 2015 +0200 +++ b/libidav/davqlparser.c Thu May 28 13:48:39 2015 +0200 @@ -459,10 +459,6 @@ case '(': token->tokenclass = DAVQL_TOKEN_OPENP; break; case ')': token->tokenclass = DAVQL_TOKEN_CLOSEP; break; case ',': token->tokenclass = DAVQL_TOKEN_COMMA; break; - case '=': token->tokenclass = DAVQL_TOKEN_EQ; break; - case '<': token->tokenclass = DAVQL_TOKEN_LT; break; - case '>': token->tokenclass = DAVQL_TOKEN_GT; break; - case '!': token->tokenclass = DAVQL_TOKEN_EXCLAIM; break; default: token->tokenclass = strchr(special_token_symbols, firstchar) ? DAVQL_TOKEN_OPERATOR : DAVQL_TOKEN_IDENTIFIER; @@ -1104,7 +1100,9 @@ } } - int consumed = dav_parse_expression(stmt, token, expr->right); + DavQLExpression rexpr; + memset(&rexpr, 0, sizeof(DavQLExpression)); + int consumed = dav_parse_expression(stmt, token, &rexpr); if (stmt->errorcode) { return 0; } @@ -1118,6 +1116,8 @@ total_consumed += consumed; expr->left = malloc(sizeof(DavQLExpression)); memcpy(expr->left, &bexpr, sizeof(DavQLExpression)); + expr->right = malloc(sizeof(DavQLExpression)); + memcpy(expr->right, &rexpr, sizeof(DavQLExpression)); return total_consumed; } @@ -1136,13 +1136,13 @@ // RULE: "not ", LogicalExpression if (token_is(token, DAVQL_TOKEN_OPERATOR) && tokenvalue_is(token, "not")) { - token = token->next; expr->type = DAVQL_LOGICAL; expr->op = DAVQL_NOT; expr->left = calloc(1, sizeof(DavQLExpression)); expr->srctext = token_sstr(token); - - int consumed = dav_parse_logical_expr(stmt, token, expr->left); + + token = token->next; + int consumed = dav_parse_bool_expr(stmt, token, expr->left); if (stmt->errorcode) { return 0; } @@ -1182,7 +1182,7 @@ return 0; } } - // RULE: BooleanExpression + // RULE: BooleanPrimary else { return dav_parse_bool_prim(stmt, token, expr); } @@ -1276,7 +1276,7 @@ // RULE: "depth", "=", (Number | "infinity") if (tokenvalue_is(token, "depth")) { token = token->next; total_consumed++; - if (token_is(token, DAVQL_TOKEN_EQ)) { + if (tokenvalue_is(token, "=")) { token = token->next; total_consumed++; if (tokenvalue_is(token, "infinity")) { stmt->depth = DAV_DEPTH_INFINITY; @@ -1319,19 +1319,13 @@ } static int dav_parse_orderby_clause(DavQLStatement *stmt, UcxList *token) { + + // RULE: OrderByCriterion, {",", OrderByCriterion}; + // OrderByCriterion = (Identifier | Number), [" asc"|" desc"]; return 0; } /** - * Semantic analysis of a get statement. - * @param stmt the statement to analyze. - */ -static void dav_analyze_get_statement(DavQLStatement *stmt) { - // TODO: make it so -} - - -/** * Parser of a get statement. * @param stmt the statement object that shall contain the syntax tree * @param tokens the token list @@ -1428,8 +1422,6 @@ dav_error_in_context(DAVQL_ERROR_UNEXPECTED_TOKEN, _error_unexpected_token, stmt, tokens); } - } else { - dav_analyze_get_statement(stmt); } } diff -r 5744a3dee766 -r 44ffe073b5e3 libidav/davqlparser.h --- a/libidav/davqlparser.h Thu May 28 12:22:55 2015 +0200 +++ b/libidav/davqlparser.h Thu May 28 13:48:39 2015 +0200 @@ -50,7 +50,6 @@ DAVQL_TOKEN_IDENTIFIER, DAVQL_TOKEN_FMTSPEC, DAVQL_TOKEN_STRING, DAVQL_TOKEN_NUMBER, DAVQL_TOKEN_TIMESTAMP, DAVQL_TOKEN_COMMA, DAVQL_TOKEN_OPENP, DAVQL_TOKEN_CLOSEP, - DAVQL_TOKEN_EQ, DAVQL_TOKEN_LT, DAVQL_TOKEN_GT, DAVQL_TOKEN_EXCLAIM, DAVQL_TOKEN_OPERATOR } davqltokenclass_t; @@ -181,8 +180,8 @@ * String = "'", {?Character? - "'" | "'''"} , "'" | "%s"; * Timestamp = "%t"; // TODO: maybe introduce a real literal * - * LogicalExpression = BooleanLiteral, [LogicalOperator, LogicalExpression]; - * BooleanExpression = "not ", LogicalExpression + * LogicalExpression = BooleanExpression, [LogicalOperator, LogicalExpression]; + * BooleanExpression = "not ", BooleanExpression * | "(", LogicalExpression, ")" * | BooleanPrimary; * BooleanPrimary = Expression, (" like " | " unlike "), String