From 28bd698968260c0597c44ac7c6b6dd89f1b778cf Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 19 Feb 2019 22:54:12 +0100 Subject: [PATCH] [Issue with bare axis names](https://github.com/clicon/clixon/issues/54) --- CHANGELOG.md | 1 + lib/src/clixon_xpath_parse.l | 34 +++++++++++++++++++--------------- lib/src/clixon_xpath_parse.y | 3 +-- test/test_xpath.sh | 11 ++++++++++- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02df0c2d..0718eb21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -155,6 +155,7 @@ * New config option: CLICON_CLI_MODEL_TREENAME defining name of generated syntax tree if CLIXON_CLI_GENMODEL is set. ### Corrected Bugs +* [Issue with bare axis names](https://github.com/clicon/clixon/issues/54) * Did not check for missing keys in validate. [Key of a list isn't mandatory](https://github.com/clicon/clixon/issues/73) * Problem here is that you can still add keys via netconf - since validation is a separate step, but in cli or restconf it should not be possible. * Partially corrected: [yang type range statement does not support multiple values](https://github.com/clicon/clixon/issues/59). diff --git a/lib/src/clixon_xpath_parse.l b/lib/src/clixon_xpath_parse.l index a886dd70..0e0e7909 100644 --- a/lib/src/clixon_xpath_parse.l +++ b/lib/src/clixon_xpath_parse.l @@ -94,8 +94,7 @@ real ({digit}+[.]{digit}*)|({digit}*[.]{digit}+) \r { } <> { return X_EOF; } ".." { return DOUBLEDOT; } -[()\[\]\.@,/:|] { return *yytext; } -"::" { return DOUBLECOLON; } +[()\[\]\.,/:|] { return *yytext; } and { clixon_xpath_parselval.intval = clicon_str2int(xpopmap, yytext); return LOGOP; } or { clixon_xpath_parselval.intval = clicon_str2int(xpopmap, yytext); return LOGOP; } div { clixon_xpath_parselval.intval = clicon_str2int(xpopmap,yytext); return ADDOP; } @@ -110,24 +109,28 @@ real ({digit}+[.]{digit}*)|({digit}*[.]{digit}+) last { clixon_xpath_parselval.string = strdup(yytext); return FUNCTIONNAME; } position { clixon_xpath_parselval.string = strdup(yytext); return FUNCTIONNAME; } count { clixon_xpath_parselval.string = strdup(yytext); return FUNCTIONNAME; } -ancestor { clixon_xpath_parselval.intval = A_ANCESTOR; return AXISNAME; } -ancestor-or-self { clixon_xpath_parselval.intval = A_ANCESTOR_OR_SELF; return AXISNAME; } -attribute { clixon_xpath_parselval.intval = A_ATTRIBUTE; return AXISNAME; } -child { clixon_xpath_parselval.intval = A_CHILD; return AXISNAME; } -descendant { clixon_xpath_parselval.intval = A_DESCENDANT; return AXISNAME; } -descendant-or-self { clixon_xpath_parselval.intval = A_DESCENDANT_OR_SELF; return AXISNAME; } -following { clixon_xpath_parselval.intval = A_FOLLOWING; return AXISNAME; } -following-sibling { clixon_xpath_parselval.intval = A_FOLLOWING_SIBLING; return AXISNAME; } -namespace { clixon_xpath_parselval.intval = A_NAMESPACE; return AXISNAME; } -parent { clixon_xpath_parselval.intval = A_PARENT; return AXISNAME; } -preceding { clixon_xpath_parselval.intval = A_PRECEEDING; return AXISNAME; } -preceding-sibling { clixon_xpath_parselval.intval = A_PRECEEDING_SIBLING; return AXISNAME; } -self { clixon_xpath_parselval.intval = A_SELF; return AXISNAME; } + +@ { return *yytext; } +ancestor:: { clixon_xpath_parselval.intval = A_ANCESTOR; return AXISNAME; } +ancestor-or-self:: { clixon_xpath_parselval.intval = A_ANCESTOR_OR_SELF; return AXISNAME; } +attribute:: { clixon_xpath_parselval.intval = A_ATTRIBUTE; return AXISNAME; } +child:: { clixon_xpath_parselval.intval = A_CHILD; return AXISNAME; } +descendant:: { clixon_xpath_parselval.intval = A_DESCENDANT; return AXISNAME; } +descendant-or-self:: { clixon_xpath_parselval.intval = A_DESCENDANT_OR_SELF; return AXISNAME; } +following:: { clixon_xpath_parselval.intval = A_FOLLOWING; return AXISNAME; } +following-sibling:: { clixon_xpath_parselval.intval = A_FOLLOWING_SIBLING; return AXISNAME; } +namespace:: { clixon_xpath_parselval.intval = A_NAMESPACE; return AXISNAME; } +parent:: { clixon_xpath_parselval.intval = A_PARENT; return AXISNAME; } +preceding:: { clixon_xpath_parselval.intval = A_PRECEEDING; return AXISNAME; } +preceding-sibling:: { clixon_xpath_parselval.intval = A_PRECEEDING_SIBLING; return AXISNAME; } +self:: { clixon_xpath_parselval.intval = A_SELF; return AXISNAME; } + current { clixon_xpath_parselval.string = strdup(yytext); return NODETYPE; } comment { clixon_xpath_parselval.string = strdup(yytext); return NODETYPE; } text { clixon_xpath_parselval.string = strdup(yytext); return NODETYPE; } processing-instructions { clixon_xpath_parselval.string = strdup(yytext); return NODETYPE; } node { clixon_xpath_parselval.string = strdup(yytext); return NODETYPE; } + \" { BEGIN(QLITERAL); return QUOTE; } \' { BEGIN(ALITERAL); return APOST; } \-?({integer}|{real}) { sscanf(yytext,"%lf",&clixon_xpath_parselval.dval); return NUMBER;} @@ -135,6 +138,7 @@ real ({digit}+[.]{digit}*)|({digit}*[.]{digit}+) return NAME; /* rather be catch-all */ } . { fprintf(stderr,"LEXICAL ERROR\n"); return -1; } + \" { BEGIN(TOKEN); return QUOTE; } . { clixon_xpath_parselval.string = strdup(yytext); return CHAR;} diff --git a/lib/src/clixon_xpath_parse.y b/lib/src/clixon_xpath_parse.y index db672129..3c47da84 100644 --- a/lib/src/clixon_xpath_parse.y +++ b/lib/src/clixon_xpath_parse.y @@ -63,7 +63,6 @@ %token NAME %token NODETYPE %token DOUBLEDOT -%token DOUBLECOLON %token DOUBLESLASH %token FUNCTIONNAME @@ -243,7 +242,7 @@ step : axisspec nodetest predicates {$$=xp_new(XP_STEP,$1,0.0, NULL, NULL | DOUBLEDOT predicates { $$=xp_new(XP_STEP, A_PARENT, 0.0,NULL, NULL, NULL, $2); clicon_debug(2,"step-> .."); } ; -axisspec : AXISNAME DOUBLECOLON { clicon_debug(2,"axisspec-> AXISNAME(%d) ::", $1); $$=$1;} +axisspec : AXISNAME { clicon_debug(2,"axisspec-> AXISNAME(%d) ::", $1); $$=$1;} | '@' { $$=A_ATTRIBUTE; clicon_debug(2,"axisspec-> @"); } | { clicon_debug(2,"axisspec-> "); $$=A_CHILD;} ; diff --git a/test/test_xpath.sh b/test/test_xpath.sh index 4ca2dd12..5cf902a9 100755 --- a/test/test_xpath.sh +++ b/test/test_xpath.sh @@ -11,7 +11,6 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi xml=$dir/xml.xml xml2=$dir/xml2.xml xml3=$dir/xml3.xml -xml4=$dir/xml4.xml cat < $xml @@ -59,6 +58,7 @@ cat < $xml2 ethernet 1500 + urn:example:foo EOF @@ -174,6 +174,15 @@ expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType != \"atm\" or (ifM new "xpath .[name='bar']" expecteof "$clixon_util_xpath -f $xml2 -p .[name='bar'] -i /aaa/bbb/routing/ribs/rib" 0 "" "^nodeset:0:barmyfamily$" +new "xpath /aaa/bbb/namespace (namespace is xpath axisname)" +echo "$clixon_util_xpath -f $xml2 -p /aaa/bbb/namespace" +expecteof "$clixon_util_xpath -f $xml2 -p /aaa/bbb/namespace" 0 "" "^nodeset:0:urn:example:foo$" + +# See https://github.com/clicon/clixon/issues/54 +# But it is not only axis names. There are also, for example, nodetype like this example: +#new "xpath /aaa/bbb/comment (comment is xpath nodetype)" +#expecteof "$clixon_util_xpath -f $xml2 -p /aaa/bbb/comment" 0 "" "^kalle$" + new "Multiple entries" new "xpath bbb[ccc='foo']" expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc='foo']" 0 "" "^nodeset:0:foo42bar1:99foo$"