parsers CHANGE make difference between canonical and lexical forms of values
Accept all lexical forms of the input data, but keep them and print them
(i.e. transform them on parsing) in canonical form.
The implementation is not perfect in case of leafref and unions - there
can be a situation when to get the right data type, we need the comparable
(canonical) value, but to get the canonical value we need the correct data
type so it is a cyclic issue. In such a case we do not transform the given
value into a canonical form so it can lead to not resolved leafref.
This issue does not appear if the leafref values are provided always in
canonical form (simply with the same value as its target value printed
by libyang).
Fixes #175
diff --git a/src/parser_yin.c b/src/parser_yin.c
index 6beabcd..e8d9bf5 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -1318,7 +1318,7 @@
/* check default value (if not defined, there still could be some restrictions
* that need to be checked against a default value from a derived type) */
- if (unres_schema_add_str(module, unres, &tpdf->type, UNRES_TYPE_DFLT, tpdf->dflt) == -1) {
+ if (unres_schema_add_node(module, unres, &tpdf->type, UNRES_TYPE_DFLT, (struct lys_node *)(&tpdf->dflt)) == -1) {
goto error;
}
@@ -2370,12 +2370,15 @@
rc = EXIT_SUCCESS;
if (dflt_check->set.s[u]->nodetype == LYS_LEAF) {
leaf = (struct lys_node_leaf *)dflt_check->set.s[u];
- rc = unres_schema_add_str(module, unres, &leaf->type, UNRES_TYPE_DFLT, value = leaf->dflt);
+ value = leaf->dflt;
+ rc = unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, (struct lys_node *)(&leaf->dflt));
} else { /* LYS_LEAFLIST */
llist = (struct lys_node_leaflist *)dflt_check->set.s[u];
for (j = 0; j < llist->dflt_size; j++) {
- rc = unres_schema_add_str(module, unres, &llist->type, UNRES_TYPE_DFLT, value = llist->dflt[j]);
+ rc = unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT,
+ (struct lys_node *)(&llist->dflt[j]));
if (rc == -1) {
+ value = llist->dflt[j];
break;
}
}
@@ -3748,7 +3751,7 @@
/* check default value (if not defined, there still could be some restrictions
* that need to be checked against a default value from a derived type) */
- if (unres_schema_add_str(module, unres, &leaf->type, UNRES_TYPE_DFLT, leaf->dflt) == -1) {
+ if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, (struct lys_node *)(&leaf->dflt)) == -1) {
goto error;
}
@@ -4014,7 +4017,8 @@
/* check default value (if not defined, there still could be some restrictions
* that need to be checked against a default value from a derived type) */
for (r = 0; r < llist->dflt_size; r++) {
- if (unres_schema_add_str(module, unres, &llist->type, UNRES_TYPE_DFLT, llist->dflt[r]) == -1) {
+ if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT,
+ (struct lys_node *)(&llist->dflt[r])) == -1) {
goto error;
}
}