xpath FEATURE improve token error messages
diff --git a/src/common.h b/src/common.h
index 09f0698..1a2a193 100644
--- a/src/common.h
+++ b/src/common.h
@@ -186,7 +186,8 @@
#define LY_VCODE_XP_EOE LYVE_XPATH, "Unterminated string delimited with %c (%.15s)."
#define LY_VCODE_XP_INEXPR LYVE_XPATH, "Invalid character number %u of expression \'%s\'."
#define LY_VCODE_XP_EOF LYVE_XPATH, "Unexpected XPath expression end."
-#define LY_VCODE_XP_INTOK LYVE_XPATH, "Unexpected XPath token %s (%.15s)."
+#define LY_VCODE_XP_INTOK LYVE_XPATH, "Unexpected XPath token \"%s\" (\"%.15s\")."
+#define LY_VCODE_XP_INTOK2 LYVE_XPATH, "Unexpected XPath token \"%s\" (\"%.15s\"), expected \"%s\"."
#define LY_VCODE_XP_INFUNC LYVE_XPATH, "Unknown XPath function \"%.*s\"."
#define LY_VCODE_XP_INARGCOUNT LYVE_XPATH, "Invalid number of arguments (%d) for the XPath function %.*s."
#define LY_VCODE_XP_INARGTYPE LYVE_XPATH, "Wrong type of argument #%d (%s) for the XPath function %s."
diff --git a/src/xpath.c b/src/xpath.c
index 7d5ddd9..102c4ce 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -1849,8 +1849,8 @@
if (want_tok && (exp->tokens[tok_idx] != want_tok)) {
if (ctx) {
- LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK,
- lyxp_print_token(exp->tokens[tok_idx]), &exp->expr[exp->tok_pos[tok_idx]]);
+ LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK2, lyxp_print_token(exp->tokens[tok_idx]),
+ &exp->expr[exp->tok_pos[tok_idx]], lyxp_print_token(want_tok));
}
return LY_ENOT;
}
@@ -1883,8 +1883,8 @@
if ((exp->tokens[tok_idx] != want_tok1) && (exp->tokens[tok_idx] != want_tok2)) {
if (ctx) {
- LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK,
- lyxp_print_token(exp->tokens[tok_idx]), &exp->expr[exp->tok_pos[tok_idx]]);
+ LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK, lyxp_print_token(exp->tokens[tok_idx]),
+ &exp->expr[exp->tok_pos[tok_idx]]);
}
return LY_ENOT;
}
diff --git a/tests/utests/data/test_new.c b/tests/utests/data/test_new.c
index 0d2fb28..a640dc8 100644
--- a/tests/utests/data/test_new.c
+++ b/tests/utests/data/test_new.c
@@ -116,7 +116,7 @@
lyd_free_tree(node);
assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[]", &node), LY_EVALID);
- logbuf_assert("Unexpected XPath token ] (]).");
+ logbuf_assert("Unexpected XPath token \"]\" (\"]\").");
assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[key1='a'][key2='b']", &node), LY_ENOTFOUND);
logbuf_assert("Not found node \"key1\" in path.");
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 95dd8a0..003a008 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -1864,14 +1864,14 @@
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = ../ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
- logbuf_assert("Unexpected XPath token .. (../ifname]/ip).");
+ logbuf_assert("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"FunctionName\".");
assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module tt {namespace urn:tt;prefix tt;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = current()../ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
- logbuf_assert("Unexpected XPath token .. (../ifname]/ip).");
+ logbuf_assert("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"]\".");
assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module uu {namespace urn:uu;prefix uu;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
@@ -1885,14 +1885,14 @@
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = current()/ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
- logbuf_assert("Unexpected XPath token NameTest (ifname]/ip).");
+ logbuf_assert("Unexpected XPath token \"NameTest\" (\"ifname]/ip\"), expected \"..\".");
assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ww {namespace urn:ww;prefix ww;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = current()/../]/ip\";}}}",
LYS_IN_YANG, &mod));
- logbuf_assert("Unexpected XPath token ] (]/ip).");
+ logbuf_assert("Unexpected XPath token \"]\" (\"]/ip\").");
assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module xx {namespace urn:xx;prefix xx;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"