From bd67a2a5f264e106086533c071a8022ae6ad8f5b Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sun, 6 Jan 2019 16:31:36 +0100 Subject: [PATCH] Support for empty yang string added, eg `default "";` if-feature added in yang parser at several places. --- CHANGELOG.md | 1 + lib/src/clixon_yang_parse.l | 2 +- lib/src/clixon_yang_parse.y | 23 +++++++++++++++++------ test/lib.sh | 8 ++++++++ test/test_openconfig.sh | 23 +++++++++-------------- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 937eeac7..d0728483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,6 +112,7 @@ * \{ { BEGIN(KEYWORD); return *yytext; } . { return *yytext; } -[0-9][0-9]* { clixon_yang_parselval.string = strdup(yytext); +\-?[0-9][0-9]* { clixon_yang_parselval.string = strdup(yytext); return INT; } ; { BEGIN(KEYWORD); return *yytext; } \{ { BEGIN(KEYWORD); return *yytext; } diff --git a/lib/src/clixon_yang_parse.y b/lib/src/clixon_yang_parse.y index aef0cc07..31fee4c8 100644 --- a/lib/src/clixon_yang_parse.y +++ b/lib/src/clixon_yang_parse.y @@ -641,7 +641,8 @@ identity_substmts : identity_substmts identity_substmt { clicon_debug(2,"identity-substmts -> identity-substmt"); } ; -identity_substmt : base_stmt { clicon_debug(2,"identity-substmt -> base-stmt"); } +identity_substmt : if_feature_stmt { clicon_debug(2,"identity-substmt -> if-feature-stmt"); } + | base_stmt { clicon_debug(2,"identity-substmt -> base-stmt"); } | status_stmt { clicon_debug(2,"identity-substmt -> status-stmt"); } | description_stmt { clicon_debug(2,"identity-substmt -> description-stmt"); } | reference_stmt { clicon_debug(2,"identity-substmt -> reference-stmt"); } @@ -876,7 +877,8 @@ enum_substmts : enum_substmts enum_substmt { clicon_debug(2,"enum-substmts -> enum-substmt"); } ; -enum_substmt : value_stmt { clicon_debug(2,"enum-substmt -> value-stmt"); } +enum_substmt : if_feature_stmt { clicon_debug(2,"enum-substmt -> if-feature-stmt"); } + | value_stmt { clicon_debug(2,"enum-substmt -> value-stmt"); } | status_stmt { clicon_debug(2,"enum-substmt -> status-stmt"); } | description_stmt { clicon_debug(2,"enum-substmt -> description-stmt"); } | reference_stmt { clicon_debug(2,"enum-substmt -> reference-stmt"); } @@ -911,7 +913,8 @@ bit_substmts : bit_substmts bit_substmt { clicon_debug(2,"bit-substmts -> bit-substmt"); } ; -bit_substmt : position_stmt { clicon_debug(2,"bit-substmt -> positition-stmt"); } +bit_substmt : if_feature_stmt { clicon_debug(2,"bit-substmt -> if-feature-stmt"); } + | position_stmt { clicon_debug(2,"bit-substmt -> positition-stmt"); } | status_stmt { clicon_debug(2,"bit-substmt -> status-stmt"); } | description_stmt { clicon_debug(2,"bit-substmt -> description-stmt"); } | reference_stmt { clicon_debug(2,"bit-substmt -> reference-stmt"); } @@ -1318,9 +1321,16 @@ refine_substmts : refine_substmts refine_substmt { clicon_debug(2,"refine-substmts -> refine-substmt"); } ; -refine_substmt : must_stmt { clicon_debug(2,"refine-substmt -> must-stmt"); } - | mandatory_stmt { clicon_debug(2,"refine-substmt -> mandatory-stmt"); } +refine_substmt : if_feature_stmt { clicon_debug(2,"refine-substmt -> if-feature-stmt"); } + | must_stmt { clicon_debug(2,"refine-substmt -> must-stmt"); } + | presence_stmt { clicon_debug(2,"refine-substmt -> presence-stmt"); } | default_stmt { clicon_debug(2,"refine-substmt -> default-stmt"); } + | config_stmt { clicon_debug(2,"refine-substmt -> config-stmt"); } + | mandatory_stmt { clicon_debug(2,"refine-substmt -> mandatory-stmt"); } + | min_elements_stmt { clicon_debug(2,"refine-substmt -> min-elements-stmt"); } + | max_elements_stmt { clicon_debug(2,"refine-substmt -> max-elements-stmt"); } + | description_stmt { clicon_debug(2,"refine-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"refine-substmt -> reference-stmt"); } | unknown_stmt { clicon_debug(2,"refine-substmt -> unknown-stmt");} | { clicon_debug(2,"refine-substmt -> "); } ; @@ -1561,7 +1571,8 @@ qstrings : qstrings '+' qstring { $$=$1; clicon_debug(2,"qstrings-> qstring"); } ; -qstring : DQ ustring DQ { $$=$2; clicon_debug(2,"string-> \" ustring \"");} +qstring : DQ ustring DQ { $$=$2; clicon_debug(2,"string-> \" ustring \"");} + | DQ DQ { $$=strdup(""); clicon_debug(2,"string-> \" \"");} | SQ ustring SQ { $$=$2; clicon_debug(2,"string-> ' ustring '"); } ; diff --git a/test/lib.sh b/test/lib.sh index 3d82e32d..be102a62 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -13,6 +13,14 @@ testname= # If set, enable debugging (of backend) : ${DBG:=0} +# Parse yangmodels from https://github.com/YangModels/yang +# Recommended: checkout yangmodels elsewhere in the tree and set the env +# to that +: ${YANGMODELS=$(pwd)/yang} + +# Parse yang openconfig models from https://github.com/openconfig/public +: ${OPENCONFIG=$(pwd)/public} + # For memcheck #clixon_cli="valgrind --leak-check=full --show-leak-kinds=all clixon_cli" clixon_cli=clixon_cli diff --git a/test/test_openconfig.sh b/test/test_openconfig.sh index f59333e2..47574fa2 100755 --- a/test/test_openconfig.sh +++ b/test/test_openconfig.sh @@ -6,29 +6,24 @@ # - release/models/wifi/types/openconfig-wifi-types.yang # issue: https://github.com/clicon/clixon/issues/59 # -OPENCONFIG=public -OCDIR=$OPENCONFIG/release/models - -# Clone openconfig dir if not there -if [ ! -d public ]; then - git clone https://github.com/openconfig/public -#else -# (cd public; -# #git pull -# ) -fi - -# include err() and new() functions and creates $dir -. ./lib.sh # Yang specifics: multi-keys and empty type APPNAME=example + # include err() and new() functions and creates $dir . ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/test.yang +new "openconfig" +if [ ! -d "$OPENCONFIG" ]; then + err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?" +fi + +OCDIR=$OPENCONFIG/release/models + + cat < $cfg $cfg