xpath REFACTOR individual equal and non-equal tokens
diff --git a/src/xpath.c b/src/xpath.c
index 494aa37..27fb0f7 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -94,17 +94,21 @@
return "NodeType";
case LYXP_TOKEN_FUNCNAME:
return "FunctionName";
- case LYXP_TOKEN_OPERATOR_LOG:
+ case LYXP_TOKEN_OPER_LOG:
return "Operator(Logic)";
- case LYXP_TOKEN_OPERATOR_COMP:
+ case LYXP_TOKEN_OPER_EQUAL:
+ return "Operator(Equal)";
+ case LYXP_TOKEN_OPER_NEQUAL:
+ return "Operator(Non-equal)";
+ case LYXP_TOKEN_OPER_COMP:
return "Operator(Comparison)";
- case LYXP_TOKEN_OPERATOR_MATH:
+ case LYXP_TOKEN_OPER_MATH:
return "Operator(Math)";
- case LYXP_TOKEN_OPERATOR_UNI:
+ case LYXP_TOKEN_OPER_UNI:
return "Operator(Union)";
- case LYXP_TOKEN_OPERATOR_PATH:
+ case LYXP_TOKEN_OPER_PATH:
return "Operator(Path)";
- case LYXP_TOKEN_OPERATOR_RPATH:
+ case LYXP_TOKEN_OPER_RPATH:
return "Operator(Recursive Path)";
case LYXP_TOKEN_LITERAL:
return "Literal";
@@ -1957,7 +1961,7 @@
lyxp_print_token(exp->tokens[*exp_idx]), &exp->expr[exp->tok_pos[*exp_idx]]);
return LY_EVALID;
}
- } while (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_PATH, LYXP_TOKEN_OPERATOR_RPATH));
+ } while (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_PATH, LYXP_TOKEN_OPER_RPATH));
return LY_SUCCESS;
}
@@ -1977,11 +1981,11 @@
{
LY_ERR rc;
- rc = exp_check_token2(ctx, exp, *exp_idx, LYXP_TOKEN_OPERATOR_PATH, LYXP_TOKEN_OPERATOR_RPATH);
+ rc = exp_check_token2(ctx, exp, *exp_idx, LYXP_TOKEN_OPER_PATH, LYXP_TOKEN_OPER_RPATH);
LY_CHECK_RET(rc);
/* '/' RelativeLocationPath? */
- if (exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_PATH) {
+ if (exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_PATH) {
/* '/' */
++(*exp_idx);
@@ -2269,8 +2273,8 @@
LY_CHECK_RET(rc);
goto predicate;
break;
- case LYXP_TOKEN_OPERATOR_PATH:
- case LYXP_TOKEN_OPERATOR_RPATH:
+ case LYXP_TOKEN_OPER_PATH:
+ case LYXP_TOKEN_OPER_RPATH:
/* AbsoluteLocationPath */
rc = reparse_absolute_location_path(ctx, exp, exp_idx);
LY_CHECK_RET(rc);
@@ -2301,7 +2305,7 @@
}
/* ('/' or '//') RelativeLocationPath */
- if (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_PATH, LYXP_TOKEN_OPERATOR_RPATH)) {
+ if (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_PATH, LYXP_TOKEN_OPER_RPATH)) {
/* '/' or '//' */
++(*exp_idx);
@@ -2332,7 +2336,7 @@
/* ('-')* */
prev_exp = *exp_idx;
- while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_MATH)
+ while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_MATH)
&& (exp->expr[exp->tok_pos[*exp_idx]] == '-')) {
exp_repeat_push(exp, prev_exp, LYXP_EXPR_UNARY);
++(*exp_idx);
@@ -2344,7 +2348,7 @@
LY_CHECK_RET(rc);
/* ('|' PathExpr)* */
- while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_UNI)) {
+ while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_UNI)) {
exp_repeat_push(exp, prev_exp, LYXP_EXPR_UNION);
++(*exp_idx);
@@ -2381,7 +2385,7 @@
goto reparse_multiplicative_expr;
/* ('+' / '-' MultiplicativeExpr)* */
- while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_MATH)
+ while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_MATH)
&& ((exp->expr[exp->tok_pos[*exp_idx]] == '+') || (exp->expr[exp->tok_pos[*exp_idx]] == '-'))) {
exp_repeat_push(exp, prev_add_exp, LYXP_EXPR_ADDITIVE);
++(*exp_idx);
@@ -2393,7 +2397,7 @@
LY_CHECK_RET(rc);
/* ('*' / 'div' / 'mod' UnaryExpr)* */
- while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_MATH)
+ while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_MATH)
&& ((exp->expr[exp->tok_pos[*exp_idx]] == '*') || (exp->tok_len[*exp_idx] == 3))) {
exp_repeat_push(exp, prev_mul_exp, LYXP_EXPR_MULTIPLICATIVE);
++(*exp_idx);
@@ -2432,8 +2436,7 @@
goto reparse_additive_expr;
/* ('=' / '!=' RelationalExpr)* */
- while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_COMP)
- && ((exp->expr[exp->tok_pos[*exp_idx]] == '=') || (exp->expr[exp->tok_pos[*exp_idx]] == '!'))) {
+ while (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_EQUAL, LYXP_TOKEN_OPER_NEQUAL)) {
exp_repeat_push(exp, prev_eq_exp, LYXP_EXPR_EQUALITY);
++(*exp_idx);
@@ -2444,8 +2447,7 @@
LY_CHECK_RET(rc);
/* ('<' / '>' / '<=' / '>=' AdditiveExpr)* */
- while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_COMP)
- && ((exp->expr[exp->tok_pos[*exp_idx]] == '<') || (exp->expr[exp->tok_pos[*exp_idx]] == '>'))) {
+ while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_COMP)) {
exp_repeat_push(exp, prev_rel_exp, LYXP_EXPR_RELATIONAL);
++(*exp_idx);
@@ -2478,7 +2480,7 @@
goto reparse_equality_expr;
/* ('or' AndExpr)* */
- while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_LOG) && (exp->tok_len[*exp_idx] == 2)) {
+ while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_LOG) && (exp->tok_len[*exp_idx] == 2)) {
exp_repeat_push(exp, prev_or_exp, LYXP_EXPR_OR);
++(*exp_idx);
@@ -2489,7 +2491,7 @@
LY_CHECK_RET(rc);
/* ('and' EqualityExpr)* */
- while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_LOG) && (exp->tok_len[*exp_idx] == 3)) {
+ while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_LOG) && (exp->tok_len[*exp_idx] == 3)) {
exp_repeat_push(exp, prev_and_exp, LYXP_EXPR_AND);
++(*exp_idx);
@@ -2721,64 +2723,77 @@
/* Operator '/', '//' */
if (!strncmp(&expr[parsed], "//", 2)) {
tok_len = 2;
- tok_type = LYXP_TOKEN_OPERATOR_RPATH;
+ tok_type = LYXP_TOKEN_OPER_RPATH;
} else {
tok_len = 1;
- tok_type = LYXP_TOKEN_OPERATOR_PATH;
+ tok_type = LYXP_TOKEN_OPER_PATH;
}
- } else if (!strncmp(&expr[parsed], "!=", 2) || !strncmp(&expr[parsed], "<=", 2)
- || !strncmp(&expr[parsed], ">=", 2)) {
+ } else if (!strncmp(&expr[parsed], "!=", 2)) {
- /* Operator '!=', '<=', '>=' */
+ /* Operator '!=' */
tok_len = 2;
- tok_type = LYXP_TOKEN_OPERATOR_COMP;
+ tok_type = LYXP_TOKEN_OPER_NEQUAL;
+
+ } else if (!strncmp(&expr[parsed], "<=", 2) || !strncmp(&expr[parsed], ">=", 2)) {
+
+ /* Operator '<=', '>=' */
+ tok_len = 2;
+ tok_type = LYXP_TOKEN_OPER_COMP;
} else if (expr[parsed] == '|') {
/* Operator '|' */
tok_len = 1;
- tok_type = LYXP_TOKEN_OPERATOR_UNI;
+ tok_type = LYXP_TOKEN_OPER_UNI;
} else if ((expr[parsed] == '+') || (expr[parsed] == '-')) {
/* Operator '+', '-' */
tok_len = 1;
- tok_type = LYXP_TOKEN_OPERATOR_MATH;
+ tok_type = LYXP_TOKEN_OPER_MATH;
- } else if ((expr[parsed] == '=') || (expr[parsed] == '<') || (expr[parsed] == '>')) {
+ } else if (expr[parsed] == '=') {
- /* Operator '=', '<', '>' */
+ /* Operator '=' */
tok_len = 1;
- tok_type = LYXP_TOKEN_OPERATOR_COMP;
+ tok_type = LYXP_TOKEN_OPER_EQUAL;
+
+ } else if ((expr[parsed] == '<') || (expr[parsed] == '>')) {
+
+ /* Operator '<', '>' */
+ tok_len = 1;
+ tok_type = LYXP_TOKEN_OPER_COMP;
} else if (ret->used && (ret->tokens[ret->used - 1] != LYXP_TOKEN_AT)
&& (ret->tokens[ret->used - 1] != LYXP_TOKEN_PAR1)
&& (ret->tokens[ret->used - 1] != LYXP_TOKEN_BRACK1)
&& (ret->tokens[ret->used - 1] != LYXP_TOKEN_COMMA)
- && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPERATOR_LOG)
- && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPERATOR_COMP)
- && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPERATOR_MATH)
- && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPERATOR_UNI)
- && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPERATOR_PATH)
- && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPERATOR_RPATH)) {
+ && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPER_LOG)
+ && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPER_EQUAL)
+ && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPER_NEQUAL)
+ && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPER_COMP)
+ && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPER_MATH)
+ && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPER_UNI)
+ && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPER_PATH)
+ && (ret->tokens[ret->used - 1] != LYXP_TOKEN_OPER_RPATH)) {
/* Operator '*', 'or', 'and', 'mod', or 'div' */
if (expr[parsed] == '*') {
tok_len = 1;
- tok_type = LYXP_TOKEN_OPERATOR_MATH;
+ tok_type = LYXP_TOKEN_OPER_MATH;
} else if (!strncmp(&expr[parsed], "or", 2)) {
tok_len = 2;
- tok_type = LYXP_TOKEN_OPERATOR_LOG;
+ tok_type = LYXP_TOKEN_OPER_LOG;
} else if (!strncmp(&expr[parsed], "and", 3)) {
tok_len = 3;
- tok_type = LYXP_TOKEN_OPERATOR_LOG;
+ tok_type = LYXP_TOKEN_OPER_LOG;
} else if (!strncmp(&expr[parsed], "mod", 3) || !strncmp(&expr[parsed], "div", 3)) {
tok_len = 3;
- tok_type = LYXP_TOKEN_OPERATOR_MATH;
+ tok_type = LYXP_TOKEN_OPER_MATH;
} else if (prev_function_check) {
LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_XPATH, "Invalid character 0x%x ('%c'), perhaps \"%.*s\" is supposed to be a function call.",
@@ -6730,34 +6745,23 @@
cur_idx = *exp_idx;
/* '[' */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_BRACK1)) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_BRACK1));
++cur_idx;
/* '.' */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_DOT)) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_DOT));
++cur_idx;
/* '=' */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_OPERATOR_COMP)
- || (exp->expr[exp->tok_pos[cur_idx]] != '=')) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_EQUAL));
++cur_idx;
/* value */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_LITERAL)) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_LITERAL));
++cur_idx;
/* ']' */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_BRACK2)) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_BRACK2));
++cur_idx;
/* success */
@@ -6800,34 +6804,23 @@
cur_idx = *exp_idx;
for (i = 0; i < key_count; ++i) {
/* '[' */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_BRACK1)) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, cur_idx, LYXP_TOKEN_BRACK1));
++cur_idx;
/* key-name */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_NAMETEST)) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, cur_idx, LYXP_TOKEN_NAMETEST));
++cur_idx;
/* '=' */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_OPERATOR_COMP)
- || (exp->expr[exp->tok_pos[cur_idx]] != '=')) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, cur_idx, LYXP_TOKEN_OPER_EQUAL));
++cur_idx;
/* key-value */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_LITERAL)) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, cur_idx, LYXP_TOKEN_LITERAL));
++cur_idx;
/* ']' */
- if ((exp->used == cur_idx) || (exp->tokens[cur_idx] != LYXP_TOKEN_BRACK2)) {
- return LY_EINVAL;
- }
+ LY_CHECK_RET(lyxp_check_token(NULL, exp, cur_idx, LYXP_TOKEN_BRACK2));
++cur_idx;
}
@@ -7161,7 +7154,7 @@
default:
LOGINT_RET(set ? set->ctx : NULL);
}
- } while (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_PATH, LYXP_TOKEN_OPERATOR_RPATH));
+ } while (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_PATH, LYXP_TOKEN_OPER_RPATH));
return LY_SUCCESS;
}
@@ -7552,8 +7545,8 @@
parent_pos_pred = 1;
goto predicate;
- case LYXP_TOKEN_OPERATOR_PATH:
- case LYXP_TOKEN_OPERATOR_RPATH:
+ case LYXP_TOKEN_OPER_PATH:
+ case LYXP_TOKEN_OPER_RPATH:
/* AbsoluteLocationPath */
rc = eval_absolute_location_path(exp, exp_idx, set, options);
LY_CHECK_RET(rc);
@@ -7604,10 +7597,10 @@
}
/* ('/' or '//') RelativeLocationPath */
- if (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_PATH, LYXP_TOKEN_OPERATOR_RPATH)) {
+ if (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_PATH, LYXP_TOKEN_OPER_RPATH)) {
/* evaluate '/' or '//' */
- if (exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_PATH) {
+ if (exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_PATH) {
all_desc = 0;
} else {
all_desc = 1;
@@ -7655,7 +7648,7 @@
/* ('|' PathExpr)* */
for (i = 0; i < repeat; ++i) {
- assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_UNI);
+ assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_UNI);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
@@ -7708,7 +7701,7 @@
/* ('-')+ */
this_op = *exp_idx;
for (i = 0; i < repeat; ++i) {
- assert(!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_MATH) && (exp->expr[exp->tok_pos[*exp_idx]] == '-'));
+ assert(!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPER_MATH) && (exp->expr[exp->tok_pos[*exp_idx]] == '-'));
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
@@ -7767,7 +7760,7 @@
for (i = 0; i < repeat; ++i) {
this_op = *exp_idx;
- assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_MATH);
+ assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_MATH);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
@@ -7835,7 +7828,7 @@
for (i = 0; i < repeat; ++i) {
this_op = *exp_idx;
- assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_MATH);
+ assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_MATH);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
@@ -7905,7 +7898,7 @@
for (i = 0; i < repeat; ++i) {
this_op = *exp_idx;
- assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_COMP);
+ assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_COMP);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
@@ -7972,7 +7965,7 @@
for (i = 0; i < repeat; ++i) {
this_op = *exp_idx;
- assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_COMP);
+ assert((exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_EQUAL) || (exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_NEQUAL));
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
@@ -8044,7 +8037,7 @@
/* ('and' EqualityExpr)* */
for (i = 0; i < repeat; ++i) {
- assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_LOG);
+ assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_LOG);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (!set || !set->val.bool ? "skipped" : "parsed"),
lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
@@ -8114,7 +8107,7 @@
/* ('or' AndExpr)* */
for (i = 0; i < repeat; ++i) {
- assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_LOG);
+ assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPER_LOG);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (!set || set->val.bool ? "skipped" : "parsed"),
lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);