From 56da97cb5beb7ec9d55819b8b852bea24e7c9618 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sun, 25 Nov 2018 18:24:13 +0100 Subject: [PATCH] Openconfig yang specs parsed: https://github.com/openconfig/public --- CHANGELOG.md | 10 +- lib/src/clixon_yang.c | 2 +- lib/src/clixon_yang_parse.l | 225 ++--- lib/src/clixon_yang_parse.y | 1679 +++++++++++++++++++---------------- test/test_openconfig.sh | 24 + test/test_yang_parse.sh | 18 +- 6 files changed, 1065 insertions(+), 893 deletions(-) create mode 100755 test/test_openconfig.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 749d361e..a80cdd9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,15 @@ * [Roadmap](ROADMAP.md) (Uncommitted and unprioritized) ### Major New features +* More complete Yang parser + * YANG parser cardinality checked (only modules level yet) + * See https://github.com/clicon/clixon/issues/84 + * Openconfig yang specs parsed: https://github.com/openconfig/public + ### API changes on existing features (you may need to change your code) -* Yang parser is stricter (see cardinality below) which may break parsing of slack yang specs. +* Yang parser is stricter (see above) which may break parsing of existing yang specs. + ### Minor changes -* YANG parser cardinality checked (only modules level yet) - * See https://github.com/clicon/clixon/issues/48 * XML parser conformance to W3 spec * Names lexically correct (NCName) * Syntactically Correct handling of ': */ if ((id = strchr(vec[1], ':')) == NULL){ /* no prefix */ - clicon_log(LOG_WARNING, "%s: Absolute schema nodeid must have prefix", __FUNCTION__); + clicon_log(LOG_WARNING, "%s: Absolute schema nodeid %s must have prefix", __FUNCTION__, schema_nodeid); goto ok; } if ((prefix = strdup(vec[1])) == NULL){ diff --git a/lib/src/clixon_yang_parse.l b/lib/src/clixon_yang_parse.l index 9b9c7fad..58715c0c 100644 --- a/lib/src/clixon_yang_parse.l +++ b/lib/src/clixon_yang_parse.l @@ -33,6 +33,7 @@ * Yang parser. Hopefully useful but not complete * @see https://tools.ietf.org/html/rfc6020 YANG 1.0 * @see https://tools.ietf.org/html/rfc7950 YANG 1.1 +* */ %{ @@ -81,20 +82,20 @@ clixon_yang_parsewrap(void) The argument is a string Example: keyword argument ; keyword ; keyword { keyword argument; } keyword - - STRING0 corresponds to string rule - ARGUMENT corresponds to identifier-arg-str,unique-arg-str,key-arg-str, etc. - more to do here. */ %} +identifier [A-Za-z_][A-Za-z0-9_\-\.]* + %x KEYWORD -%s ARGUMENT -%s STRING0 -%s STRING1 -%s STRING2 +%s BOOLEAN +%s INTEGER +%s STRARG +%s STRING +%s STRINGDQ +%s STRINGSQ %s ESCAPE %s COMMENT1 %s COMMENT2 @@ -102,84 +103,91 @@ clixon_yang_parsewrap(void) %% /* Common tokens */ -[ \t] -<> { return MY_EOF; } -\n { _YY->yy_linenum++; } -"/*" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT1); } -"//" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT2); } +[ \t] +<> { return MY_EOF; } +\n { _YY->yy_linenum++; } +"/*" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT1); } +"//" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT2); } -\} { return *yytext; } - /* RFC 6020 keywords */ -action { BEGIN(ARGUMENT); return K_ACTION; } -anydata { BEGIN(ARGUMENT); return K_ANYDATA; } -anyxml { BEGIN(ARGUMENT); return K_ANYXML; } -argument { BEGIN(ARGUMENT); return K_ARGUMENT; } -augment { BEGIN(ARGUMENT); return K_AUGMENT; } -base { BEGIN(ARGUMENT); return K_BASE; } -belongs-to { BEGIN(ARGUMENT); return K_BELONGS_TO; } -bit { BEGIN(ARGUMENT); return K_BIT; } -case { BEGIN(ARGUMENT); return K_CASE; } -choice { BEGIN(ARGUMENT); return K_CHOICE; } -config { BEGIN(ARGUMENT); return K_CONFIG; } -contact { BEGIN(STRING0); return K_CONTACT; } -container { BEGIN(ARGUMENT); return K_CONTAINER; } -default { BEGIN(STRING0); return K_DEFAULT; } -description { BEGIN(STRING0); return K_DESCRIPTION; } -deviate { BEGIN(ARGUMENT); return K_DEVIATE; } -deviation { BEGIN(ARGUMENT); return K_DEVIATION; } -enum { BEGIN(STRING0); return K_ENUM; } -error-app-tag { BEGIN(STRING0); return K_ERROR_APP_TAG; } -error-message { BEGIN(STRING0); return K_ERROR_MESSAGE; } -extension { BEGIN(ARGUMENT); return K_EXTENSION; } -feature { BEGIN(ARGUMENT); return K_FEATURE; } -fraction-digits { BEGIN(ARGUMENT); return K_FRACTION_DIGITS; } -grouping { BEGIN(ARGUMENT); return K_GROUPING; } -identity { BEGIN(ARGUMENT); return K_IDENTITY; } -if-feature { BEGIN(ARGUMENT); return K_IF_FEATURE; } -import { BEGIN(ARGUMENT); return K_IMPORT; } -include { BEGIN(ARGUMENT); return K_INCLUDE; } -input { BEGIN(ARGUMENT); return K_INPUT; } -key { BEGIN(ARGUMENT); return K_KEY; } -leaf { BEGIN(ARGUMENT); return K_LEAF; } -leaf-list { BEGIN(ARGUMENT); return K_LEAF_LIST; } -length { BEGIN(ARGUMENT); return K_LENGTH; } -list { BEGIN(ARGUMENT); return K_LIST; } -mandatory { BEGIN(ARGUMENT); return K_MANDATORY; } -max-elements { BEGIN(ARGUMENT); return K_MAX_ELEMENTS; } -min-elements { BEGIN(ARGUMENT); return K_MIN_ELEMENTS; } -module { BEGIN(ARGUMENT); return K_MODULE; } -must { BEGIN(STRING0); return K_MUST; } -namespace { BEGIN(ARGUMENT); return K_NAMESPACE; } -notification { BEGIN(ARGUMENT); return K_NOTIFICATION; } -ordered-by { BEGIN(ARGUMENT); return K_ORDERED_BY; } -organization { BEGIN(STRING0); return K_ORGANIZATION; } -output { BEGIN(ARGUMENT); return K_OUTPUT; } -path { BEGIN(ARGUMENT); return K_PATH; } -pattern { BEGIN(STRING0); return K_PATTERN; } -position { BEGIN(ARGUMENT); return K_POSITION; } -prefix { BEGIN(ARGUMENT); return K_PREFIX; } -presence { BEGIN(STRING0); return K_PRESENCE; } -range { BEGIN(ARGUMENT); return K_RANGE; } -reference { BEGIN(STRING0); return K_REFERENCE; } -refine { BEGIN(ARGUMENT); return K_REFINE; } -require-instance { BEGIN(ARGUMENT); return K_REQUIRE_INSTANCE; } -revision { BEGIN(ARGUMENT); return K_REVISION; } -revision-date { BEGIN(ARGUMENT); return K_REVISION_DATE; } -rpc { BEGIN(ARGUMENT); return K_RPC; } -status { BEGIN(ARGUMENT); return K_STATUS; } -submodule { BEGIN(ARGUMENT); return K_SUBMODULE; } -type { BEGIN(ARGUMENT); return K_TYPE; } -typedef { BEGIN(ARGUMENT); return K_TYPEDEF; } -unique { BEGIN(ARGUMENT); return K_UNIQUE; } -units { BEGIN(STRING0); return K_UNITS; } -uses { BEGIN(ARGUMENT); return K_USES; } -value { BEGIN(ARGUMENT); return K_VALUE; } -when { BEGIN(STRING0); return K_WHEN; } -yang-version { BEGIN(ARGUMENT); return K_YANG_VERSION; } -yin-element { BEGIN(ARGUMENT); return K_YIN_ELEMENT; } +input { return K_INPUT; } /* No argument */ +output { return K_OUTPUT;} /* No argument */ + /* RFC 7950 keywords using identifier */ +action { BEGIN(STRARG); return K_ACTION; } +anydata { BEGIN(STRARG); return K_ANYDATA; } +anyxml { BEGIN(STRARG); return K_ANYXML; } +argument { BEGIN(STRARG); return K_ARGUMENT; } +base { BEGIN(STRARG); return K_BASE; } +belongs-to { BEGIN(STRARG); return K_BELONGS_TO; } +bit { BEGIN(STRARG); return K_BIT; } +case { BEGIN(STRARG); return K_CASE; } +choice { BEGIN(STRARG); return K_CHOICE; } +container { BEGIN(STRARG); return K_CONTAINER; } +extension { BEGIN(STRARG); return K_EXTENSION; } +feature { BEGIN(STRARG); return K_FEATURE; } +grouping { BEGIN(STRARG); return K_GROUPING; } +identity { BEGIN(STRARG); return K_IDENTITY; } +import { BEGIN(STRARG); return K_IMPORT; } +include { BEGIN(STRARG); return K_INCLUDE; } +leaf { BEGIN(STRARG); return K_LEAF; } +leaf-list { BEGIN(STRARG); return K_LEAF_LIST; } +list { BEGIN(STRARG); return K_LIST; } +module { BEGIN(STRARG); return K_MODULE; } +notification { BEGIN(STRARG); return K_NOTIFICATION; } +prefix { BEGIN(STRARG); return K_PREFIX; } +refine { BEGIN(STRARG); return K_REFINE; } +rpc { BEGIN(STRARG); return K_RPC; } +submodule { BEGIN(STRARG); return K_SUBMODULE; } +type { BEGIN(STRARG); return K_TYPE; } +typedef { BEGIN(STRARG); return K_TYPEDEF; } +uses { BEGIN(STRARG); return K_USES; } + + /* RFC 7950 keywords using boolean string arguments */ +config { BEGIN(BOOLEAN); return K_CONFIG; } +mandatory { BEGIN(BOOLEAN); return K_MANDATORY; } +require-instance { BEGIN(BOOLEAN); return K_REQUIRE_INSTANCE; } +yin-element { BEGIN(BOOLEAN); return K_YIN_ELEMENT; } + + /* RFC 7950 keywords using integer string argument */ +min-elements { BEGIN(INTEGER); return K_MIN_ELEMENTS; } +position { BEGIN(INTEGER); return K_POSITION; } +value { BEGIN(INTEGER); return K_VALUE; } + + /* RFC 7950 keywords using strings */ +augment { BEGIN(STRING); return K_AUGMENT; } +contact { BEGIN(STRING); return K_CONTACT; } +default { BEGIN(STRING); return K_DEFAULT; } +description { BEGIN(STRING); return K_DESCRIPTION; } +deviate { BEGIN(STRING); return K_DEVIATE; } +deviation { BEGIN(STRING); return K_DEVIATION; } +enum { BEGIN(STRING); return K_ENUM; } +error-app-tag { BEGIN(STRING); return K_ERROR_APP_TAG; } +error-message { BEGIN(STRING); return K_ERROR_MESSAGE; } +fraction-digits { BEGIN(STRING); return K_FRACTION_DIGITS; } +if-feature { BEGIN(STRING); return K_IF_FEATURE; } +key { BEGIN(STRING); return K_KEY; } +length { BEGIN(STRING); return K_LENGTH; } +max-elements { BEGIN(STRING); return K_MAX_ELEMENTS; } +must { BEGIN(STRING); return K_MUST; } +namespace { BEGIN(STRING); return K_NAMESPACE; } +ordered-by { BEGIN(STRING); return K_ORDERED_BY; } +organization { BEGIN(STRING); return K_ORGANIZATION; } +path { BEGIN(STRING); return K_PATH; } +pattern { BEGIN(STRING); return K_PATTERN; } +presence { BEGIN(STRING); return K_PRESENCE; } +unique { BEGIN(STRING); return K_UNIQUE; } +range { BEGIN(STRING); return K_RANGE; } +reference { BEGIN(STRING); return K_REFERENCE; } +revision { BEGIN(STRING); return K_REVISION; } +revision-date { BEGIN(STRING); return K_REVISION_DATE; } +status { BEGIN(STRING); return K_STATUS; } +units { BEGIN(STRING); return K_UNITS; } +when { BEGIN(STRING); return K_WHEN; } +yang-version { BEGIN(STRING); return K_YANG_VERSION; } : { return *yytext; } +\{ { return *yytext; } +\} { return *yytext; } ; { return *yytext; } . { clixon_yang_parselval.string = strdup(yytext); BEGIN(UNKNOWN); return CHAR; } @@ -190,34 +198,43 @@ clixon_yang_parsewrap(void) . { clixon_yang_parselval.string = strdup(yytext); return CHAR; } +true { clixon_yang_parselval.string = strdup(yytext); + return BOOL; } +false { clixon_yang_parselval.string = strdup(yytext); + return BOOL; } +; { BEGIN(KEYWORD); return *yytext; } +\{ { BEGIN(KEYWORD); return *yytext; } +. { return *yytext; } +[0-9][0-9]* { clixon_yang_parselval.string = strdup(yytext); + return INT; } +; { BEGIN(KEYWORD); return *yytext; } +\{ { BEGIN(KEYWORD); return *yytext; } +. { return *yytext; } -; { BEGIN(KEYWORD); return *yytext; } -\{ { BEGIN(KEYWORD); return *yytext; } -\" { _YY->yy_lex_string_state =ARGUMENT; BEGIN(STRING1); return DQ; } -\' { _YY->yy_lex_string_state =ARGUMENT; BEGIN(STRING2); return DQ; } -\+ { return *yytext; /* many arg rules dont like this */ } -: { return *yytext; /* many arg rules dont like this */ } -. { clixon_yang_parselval.string = strdup(yytext); - return CHAR;} +\{ { BEGIN(KEYWORD); return *yytext; } +; { BEGIN(KEYWORD); return *yytext; } +{identifier} { clixon_yang_parselval.string = strdup(yytext); + return IDENTIFIER;} +. { return *yytext; } -\{ { BEGIN(KEYWORD); return *yytext; } -; { BEGIN(KEYWORD); return *yytext; } -\" { _YY->yy_lex_string_state =STRING0; BEGIN(STRING1); return DQ; } -\' { _YY->yy_lex_string_state =STRING0; BEGIN(STRING2); return DQ; } -\+ { return *yytext; } -. { clixon_yang_parselval.string = strdup(yytext); +\{ { BEGIN(KEYWORD); return *yytext; } +; { BEGIN(KEYWORD); return *yytext; } +\" { _YY->yy_lex_string_state =STRING; BEGIN(STRINGDQ); return DQ; } +\' { _YY->yy_lex_string_state =STRING; BEGIN(STRINGSQ); return SQ; } +\+ { return *yytext; } +. { clixon_yang_parselval.string = strdup(yytext); return CHAR;} -\\ { _YY->yy_lex_state = STRING1; BEGIN(ESCAPE); } -\" { BEGIN(_YY->yy_lex_string_state); return DQ; } -\n { _YY->yy_linenum++; clixon_yang_parselval.string = strdup(yytext); return CHAR;} -. { clixon_yang_parselval.string = strdup(yytext); - return CHAR;} +\\ { _YY->yy_lex_state = STRINGDQ; BEGIN(ESCAPE); } +\" { BEGIN(_YY->yy_lex_string_state); return DQ; } +\n { _YY->yy_linenum++; clixon_yang_parselval.string = strdup(yytext); return CHAR;} +. { clixon_yang_parselval.string = strdup(yytext); + return CHAR;} -\' { BEGIN(_YY->yy_lex_string_state); return DQ; } -\n { _YY->yy_linenum++; clixon_yang_parselval.string = strdup(yytext); return CHAR;} -. { clixon_yang_parselval.string = strdup(yytext); +\' { BEGIN(_YY->yy_lex_string_state); return SQ; } +\n { _YY->yy_linenum++; clixon_yang_parselval.string = strdup(yytext); return CHAR;} +. { clixon_yang_parselval.string = strdup(yytext); return CHAR;} . { BEGIN(_YY->yy_lex_state); diff --git a/lib/src/clixon_yang_parse.y b/lib/src/clixon_yang_parse.y index 0a1fd81c..f947c833 100644 --- a/lib/src/clixon_yang_parse.y +++ b/lib/src/clixon_yang_parse.y @@ -34,9 +34,23 @@ * Yang parser. Hopefully useful but not complete * @see https://tools.ietf.org/html/rfc6020 YANG 1.0 * @see https://tools.ietf.org/html/rfc7950 YANG 1.1 + * + * How identifiers map + * IDENTIFIER = [A-Za-z_][A-Za-z0-9_\-\.] + * prefix = IDENTIFIER + * identifier_arg = IDENTIFIER + * identifier_ref = prefix : IDENTIFIER + * node_identier = prefix : IDENTIFIER + * + * Missing top-level statements (will break parser if in yang spec): + * - error-app-tag-stmt + * - any-data-stmt + * Missing args (just strings); + * - length-arg-str + * - path-arg-str + * - date-arg-str */ - %start file %union { @@ -46,16 +60,25 @@ %token MY_EOF %token DQ /* Double quote: " */ -%token CHAR +%token SQ /* Single quote: ' */ +%token CHAR +%token IDENTIFIER +%token BOOL +%token INT %type ustring %type qstrings %type qstring %type string -%type id_arg_str -%type config_arg_str -%type integer_value -%type identifier_ref_arg_str +%type integer_value_str +%type identifier_ref +%type abs_schema_nodeid +%type desc_schema_node_str +%type desc_schema_nodeid +%type node_identifier +%type identifier_str +%type identifier_ref_str +%type bool_str /* rfc 6020 keywords @@ -295,31 +318,38 @@ ysp_add_push(struct clicon_yang_yacc_arg *yy, return ys; } -/* identifier-ref-arg-str has a [prefix :] id and prefix_id joins the id with an - optional prefix into a single string */ +/*! Join two string with delimiter. + * @param[in] str1 string 1 (will be freed) (optional) + * @param[in] del delimiter string (not freed) cannot be NULL (but "") + * @param[in] str2 string 2 (will be freed) + */ static char* -prefix_id_join(char *prefix, - char *id) +string_del_join(char *str1, + char *del, + char *str2) { char *str; int len; - if (prefix){ - len = strlen(prefix) + strlen(id) + 2; - if ((str = malloc(len)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); - return NULL; - } - snprintf(str, len, "%s:%s", prefix, id); - free(prefix); - free(id); + len = strlen(str2) + 1; + + if (str1) + len += strlen(str1); + len += strlen(del); + if ((str = malloc(len)) == NULL){ + clicon_err(OE_UNIX, errno, "malloc"); + return NULL; + } + if (str1){ + snprintf(str, len, "%s%s%s", str1, del, str2); + free(str1); } else - str = id; + snprintf(str, len, "%s%s", del, str2); + free(str2); return str; } - %} %% @@ -339,20 +369,20 @@ file : module_stmt MY_EOF /* For extensions */ unknown_stmt : ustring ':' ustring ';' - { char *id; if ((id=prefix_id_join($1, $3)) == NULL) _YYERROR("0"); + { char *id; if ((id=string_del_join($1, ":", $3)) == NULL) _YYERROR("0"); if (ysp_add(_yy, Y_UNKNOWN, id, NULL) == NULL) _YYERROR("0"); clicon_debug(2,"unknown-stmt -> ustring : ustring"); } | ustring ':' ustring ' ' string ';' - { char *id; if ((id=prefix_id_join($1, $3)) == NULL) _YYERROR("0"); + { char *id; if ((id=string_del_join($1, ":", $3)) == NULL) _YYERROR("0"); if (ysp_add(_yy, Y_UNKNOWN, id, $5) == NULL){ _YYERROR("0"); } clicon_debug(2,"unknown-stmt -> ustring : ustring string"); if ($5) free($5); } ; -/* module */ -module_stmt : K_MODULE id_arg_str +/* module identifier-arg-str */ +module_stmt : K_MODULE identifier_str { if ((_YY->yy_module = ysp_add_push(_yy, Y_MODULE, $2)) == NULL) _YYERROR("1"); } '{' module_substmts '}' @@ -376,7 +406,7 @@ module_substmt : module_header_stmts { clicon_debug(2,"module-substmt -> module- ; /* submodule */ -submodule_stmt : K_SUBMODULE id_arg_str '{' submodule_substmts '}' +submodule_stmt : K_SUBMODULE identifier_str '{' submodule_substmts '}' { if ((_YY->yy_module = ysp_add_push(_yy, Y_SUBMODULE, $2)) == NULL) _YYERROR("3"); clicon_debug(2,"submodule -> id-arg-str { submodule-stmts }"); } @@ -398,6 +428,17 @@ submodule_substmt : submodule_header_stmts | { clicon_debug(2,"submodule-substmt ->");} ; +/* linkage */ +linkage_stmts : linkage_stmts linkage_stmt + { clicon_debug(2,"linkage-stmts -> linkage-stmts linkage-stmt"); } + | linkage_stmt + { clicon_debug(2,"linkage-stmts -> linkage-stmt"); } + ; + +linkage_stmt : import_stmt { clicon_debug(2,"linkage-stmt -> import-stmt"); } + | include_stmt { clicon_debug(2,"linkage-stmt -> include-stmt"); } + ; + /* module-header */ module_header_stmts : module_header_stmts module_header_stmt { clicon_debug(2,"module-header-stmts -> module-header-stmts module-header-stmt"); } @@ -422,22 +463,81 @@ submodule_header_stmt : yang_version_stmt | belongs_to_stmt { clicon_debug(2,"submodule-header-stmt -> belongs-to-stmt"); } ; -/* linkage */ -linkage_stmts : linkage_stmts linkage_stmt - { clicon_debug(2,"linkage-stmts -> linkage-stmts linkage-stmt"); } - | linkage_stmt - { clicon_debug(2,"linkage-stmts -> linkage-stmt"); } +/* yang-version-stmt = yang-version-keyword yang-version-arg-str */ +yang_version_stmt : K_YANG_VERSION string ';' + { if (ysp_add(_yy, Y_YANG_VERSION, $2, NULL) == NULL) _YYERROR("83"); + clicon_debug(2,"yang-version-stmt -> YANG-VERSION string"); } ; -linkage_stmt : import_stmt { clicon_debug(2,"linkage-stmt -> import-stmt"); } - | include_stmt { clicon_debug(2,"linkage-stmt -> include-stmt"); } +/* import */ +import_stmt : K_IMPORT identifier_str + { if (ysp_add_push(_yy, Y_IMPORT, $2) == NULL) _YYERROR("81"); } + '{' import_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("82"); + clicon_debug(2,"import-stmt -> IMPORT id-arg-str { import-substmts }");} ; -/* revision */ -revision_stmts : revision_stmts revision_stmt - { clicon_debug(2,"revision-stmts -> revision-stmts revision-stmt"); } - | revision_stmt - { clicon_debug(2,"revision-stmts -> "); } +import_substmts : import_substmts import_substmt + { clicon_debug(2,"import-substmts -> import-substmts import-substm");} + | import_substmt + { clicon_debug(2,"import-substmts ->");} + ; + +import_substmt : prefix_stmt { clicon_debug(2,"import-stmt -> prefix-stmt"); } + | revision_date_stmt { clicon_debug(2,"import-stmt -> revision-date-stmt"); } + ; + +include_stmt : K_INCLUDE identifier_str ';' + { if (ysp_add(_yy, Y_INCLUDE, $2, NULL)== NULL) _YYERROR("97"); + clicon_debug(2,"include-stmt -> id-arg-str"); } + | K_INCLUDE identifier_str '{' revision_date_stmt '}' + { if (ysp_add(_yy, Y_INCLUDE, $2, NULL)== NULL) _YYERROR("98"); + clicon_debug(2,"include-stmt -> id-arg-str { revision-date-stmt }"); } + ; + +/* namespace-stmt = namespace-keyword sep uri-str */ +namespace_stmt : K_NAMESPACE string stmtend + { if (ysp_add(_yy, Y_NAMESPACE, $2, NULL)== NULL) _YYERROR("99"); + clicon_debug(2,"namespace-stmt -> NAMESPACE string"); } + ; + +prefix_stmt : K_PREFIX identifier_str ';' /* XXX prefix-arg-str */ + { if (ysp_add(_yy, Y_PREFIX, $2, NULL)== NULL) _YYERROR("100"); + clicon_debug(2,"prefix-stmt -> PREFIX string ;");} + ; + +belongs_to_stmt : K_BELONGS_TO identifier_str ';' + + { if (ysp_add(_yy, Y_BELONGS_TO, $2, NULL)== NULL) _YYERROR("100"); + clicon_debug(2,"belongs-to-stmt -> BELONGS-TO id-arg-str ;");} + | K_BELONGS_TO identifier_str '{' prefix_stmt '}' + { if (ysp_add(_yy, Y_BELONGS_TO, $2, NULL)== NULL) _YYERROR("98"); + clicon_debug(2,"belongs-to-stmt -> BELONGS-TO id-arg-str { prefix-stmt } ");} + ; + +organization_stmt: K_ORGANIZATION string ';' + { if (ysp_add(_yy, Y_ORGANIZATION, $2, NULL)== NULL) _YYERROR("102"); + clicon_debug(2,"organization-stmt -> ORGANIZATION string ;");} + ; + +contact_stmt : K_CONTACT string ';' + { if (ysp_add(_yy, Y_CONTACT, $2, NULL)== NULL) _YYERROR("95"); + clicon_debug(2,"contact-stmt -> CONTACT string"); } + ; + +description_stmt: K_DESCRIPTION string ';' + { if (ysp_add(_yy, Y_DESCRIPTION, $2, NULL)== NULL) _YYERROR("101"); + clicon_debug(2,"description-stmt -> DESCRIPTION string ;");} + ; + +reference_stmt: K_REFERENCE string ';' + { if (ysp_add(_yy, Y_REFERENCE, $2, NULL)== NULL) _YYERROR("105"); + clicon_debug(2,"reference-stmt -> REFERENCE string ;");} + ; + +units_stmt : K_UNITS string ';' + { if (ysp_add(_yy, Y_UNITS, $2, NULL)== NULL) _YYERROR("93"); + clicon_debug(2,"units-stmt -> UNITS string"); } ; revision_stmt : K_REVISION string ';' /* XXX date-arg-str */ @@ -463,469 +563,118 @@ revision_substmt : description_stmt { clicon_debug(2,"revision-substmt -> descri ; - -/* meta */ -meta_stmts : meta_stmts meta_stmt { clicon_debug(2,"meta-stmts -> meta-stmts meta-stmt"); } - | meta_stmt { clicon_debug(2,"meta-stmts -> meta-stmt"); } +/* revision */ +revision_stmts : revision_stmts revision_stmt + { clicon_debug(2,"revision-stmts -> revision-stmts revision-stmt"); } + | revision_stmt + { clicon_debug(2,"revision-stmts -> "); } ; -meta_stmt : organization_stmt { clicon_debug(2,"meta-stmt -> organization-stmt"); } - | contact_stmt { clicon_debug(2,"meta-stmt -> contact-stmt"); } - | description_stmt { clicon_debug(2,"meta-stmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"meta-stmt -> reference-stmt"); } +revision_date_stmt : K_REVISION_DATE string ';' /* XXX date-arg-str */ + { if (ysp_add(_yy, Y_REVISION_DATE, $2, NULL) == NULL) _YYERROR("96"); + clicon_debug(2,"revision-date-stmt -> date;"); } ; -/* body */ -body_stmts : body_stmts body_stmt { clicon_debug(2,"body-stmts -> body-stmts body-stmt"); } - | body_stmt { clicon_debug(2,"body-stmts -> body-stmt");} +/* Extension */ +extension_stmt: K_EXTENSION identifier_str ';' + { if (ysp_add(_yy, Y_EXTENSION, $2, NULL) == NULL) _YYERROR("59"); + clicon_debug(2,"extenstion-stmt -> EXTENSION id-arg-str ;"); } + | K_EXTENSION identifier_str + { if (ysp_add_push(_yy, Y_EXTENSION, $2) == NULL) _YYERROR("60"); } + '{' extension_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("61"); + clicon_debug(2,"extension-stmt -> FEATURE id-arg-str { extension-substmts }"); } + ; + + +/* extension substmts */ +extension_substmts : extension_substmts extension_substmt + { clicon_debug(2,"extension-substmts -> extension-substmts extension-substmt"); } + | extension_substmt + { clicon_debug(2,"extension-substmts -> extension-substmt"); } ; -body_stmt : extension_stmt { clicon_debug(2,"body-stmt -> extension-stmt");} - | feature_stmt { clicon_debug(2,"body-stmt -> feature-stmt");} - | identity_stmt { clicon_debug(2,"body-stmt -> identity-stmt");} - | typedef_stmt { clicon_debug(2,"body-stmt -> typedef-stmt");} - | grouping_stmt { clicon_debug(2,"body-stmt -> grouping-stmt");} - | data_def_stmt { clicon_debug(2,"body-stmt -> data-def-stmt");} - | augment_stmt { clicon_debug(2,"body-stmt -> augment-stmt");} - | rpc_stmt { clicon_debug(2,"body-stmt -> rpc-stmt");} - | notification_stmt { clicon_debug(2,"body-stmt -> notification-stmt");} +extension_substmt : argument_stmt { clicon_debug(2,"extension-substmt -> argument-stmt"); } + | status_stmt { clicon_debug(2,"extension-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"extension-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"extension-substmt -> reference-stmt"); } + | unknown_stmt { clicon_debug(2,"extension-substmt -> unknown-stmt");} + | { clicon_debug(2,"extension-substmt -> "); } ; -data_def_stmt : container_stmt { clicon_debug(2,"data-def-stmt -> container-stmt");} - | leaf_stmt { clicon_debug(2,"data-def-stmt -> leaf-stmt");} - | leaf_list_stmt { clicon_debug(2,"data-def-stmt -> leaf-list-stmt");} - | list_stmt { clicon_debug(2,"data-def-stmt -> list-stmt");} - | choice_stmt { clicon_debug(2,"data-def-stmt -> choice-stmt");} - | anyxml_stmt { clicon_debug(2,"data-def-stmt -> anyxml-stmt");} - | uses_stmt { clicon_debug(2,"data-def-stmt -> uses-stmt");} +argument_stmt : K_ARGUMENT identifier_str ';' { free($2); } + | K_ARGUMENT identifier_str '{' yin_element_stmt1 '}' { free($2); } + ; + +/* Example of optional rule, eg [yin-element-stmt] */ +yin_element_stmt1 : K_YIN_ELEMENT bool_str stmtend {free($2);} + ; + +/* Identity */ +identity_stmt : K_IDENTITY identifier_str ';' + { if (ysp_add(_yy, Y_IDENTITY, $2, NULL) == NULL) _YYERROR("65"); + clicon_debug(2,"identity-stmt -> IDENTITY string ;"); } + + | K_IDENTITY identifier_str + { if (ysp_add_push(_yy, Y_IDENTITY, $2) == NULL) _YYERROR("66"); } + '{' identity_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("67"); + clicon_debug(2,"identity-stmt -> IDENTITY string { identity-substmts }"); } ; -/* container */ -container_stmt : K_CONTAINER id_arg_str ';' - { if (ysp_add(_yy, Y_CONTAINER, $2, NULL) == NULL) _YYERROR("7"); - clicon_debug(2,"container-stmt -> CONTAINER id-arg-str ;");} - | K_CONTAINER id_arg_str - { if (ysp_add_push(_yy, Y_CONTAINER, $2) == NULL) _YYERROR("8"); } - '{' container_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("9"); - clicon_debug(2,"container-stmt -> CONTAINER id-arg-str { container-substmts }");} +identity_substmts : identity_substmts identity_substmt + { clicon_debug(2,"identity-substmts -> identity-substmts identity-substmt"); } + | identity_substmt + { clicon_debug(2,"identity-substmts -> identity-substmt"); } ; -container_substmts : container_substmts container_substmt - | container_substmt +identity_substmt : 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"); } + | unknown_stmt { clicon_debug(2,"identity-substmt -> unknown-stmt");} + | { clicon_debug(2,"identity-substmt -> "); } ; -container_substmt : when_stmt { clicon_debug(2,"container-substmt -> when-stmt"); } - | if_feature_stmt { clicon_debug(2,"container-substmt -> if-feature-stmt"); } - | must_stmt { clicon_debug(2,"container-substmt -> must-stmt"); } - | presence_stmt { clicon_debug(2,"container-substmt -> presence-stmt"); } - | config_stmt { clicon_debug(2,"container-substmt -> config-stmt"); } - | status_stmt { clicon_debug(2,"container-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"container-substmt -> description-stmt");} - | reference_stmt { clicon_debug(2,"container-substmt -> reference-stmt"); } - | typedef_stmt { clicon_debug(2,"container-substmt -> typedef-stmt"); } - | grouping_stmt { clicon_debug(2,"container-substmt -> grouping-stmt"); } - | data_def_stmt { clicon_debug(2,"container-substmt -> data-def-stmt");} - | action_stmt { clicon_debug(2,"container-substmt -> action-stmt");} - | notification_stmt { clicon_debug(2,"container-substmt -> notification-stmt");} - | unknown_stmt { clicon_debug(2,"container-substmt -> unknown-stmt");} - | { clicon_debug(2,"container-substmt ->");} +base_stmt : K_BASE identifier_ref_str ';' + { if (ysp_add(_yy, Y_BASE, $2, NULL)== NULL) _YYERROR("90"); + clicon_debug(2,"base-stmt -> BASE identifier-ref-arg-str"); } ; -/* leaf */ -leaf_stmt : K_LEAF id_arg_str ';' - { if (ysp_add(_yy, Y_LEAF, $2, NULL) == NULL) _YYERROR("10"); - clicon_debug(2,"leaf-stmt -> LEAF id-arg-str ;");} - | K_LEAF id_arg_str - { if (ysp_add_push(_yy, Y_LEAF, $2) == NULL) _YYERROR("11"); } - '{' leaf_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("12"); - clicon_debug(2,"leaf-stmt -> LEAF id-arg-str { lead-substmts }");} +/* Feature */ +feature_stmt : K_FEATURE identifier_str ';' + { if (ysp_add(_yy, Y_FEATURE, $2, NULL) == NULL) _YYERROR("62"); + clicon_debug(2,"feature-stmt -> FEATURE id-arg-str ;"); } + | K_FEATURE identifier_str + { if (ysp_add_push(_yy, Y_FEATURE, $2) == NULL) _YYERROR("63"); } + '{' feature_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("64"); + clicon_debug(2,"feature-stmt -> FEATURE id-arg-str { feature-substmts }"); } ; -leaf_substmts : leaf_substmts leaf_substmt - | leaf_substmt +/* feature substmts */ +feature_substmts : feature_substmts feature_substmt + { clicon_debug(2,"feature-substmts -> feature-substmts feature-substmt"); } + | feature_substmt + { clicon_debug(2,"feature-substmts -> feature-substmt"); } ; -leaf_substmt : when_stmt { clicon_debug(2,"leaf-substmt -> when-stmt"); } - | if_feature_stmt { clicon_debug(2,"leaf-substmt -> if-feature-stmt"); } - | type_stmt { clicon_debug(2,"leaf-substmt -> type-stmt"); } - | units_stmt { clicon_debug(2,"leaf-substmt -> units-stmt"); } - | must_stmt { clicon_debug(2,"leaf-substmt -> must-stmt"); } - | default_stmt { clicon_debug(2,"leaf-substmt -> default-stmt"); } - | config_stmt { clicon_debug(2,"leaf-substmt -> config-stmt"); } - | mandatory_stmt { clicon_debug(2,"leaf-substmt -> mandatory-stmt"); } - | status_stmt { clicon_debug(2,"leaf-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"leaf-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"leaf-substmt -> reference-stmt"); } - | unknown_stmt { clicon_debug(2,"leaf-substmt -> unknown-stmt");} - | { clicon_debug(2,"leaf-substmt ->"); } +feature_substmt : if_feature_stmt { clicon_debug(2,"feature-substmt -> if-feature-stmt"); } + | status_stmt { clicon_debug(2,"feature-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"feature-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"feature-substmt -> reference-stmt"); } + | unknown_stmt { clicon_debug(2,"feature-substmt -> unknown-stmt");} + | { clicon_debug(2,"feature-substmt -> "); } ; -/* leaf-list */ -leaf_list_stmt : K_LEAF_LIST id_arg_str ';' - { if (ysp_add(_yy, Y_LEAF_LIST, $2, NULL) == NULL) _YYERROR("13"); - clicon_debug(2,"leaf-list-stmt -> LEAF id-arg-str ;");} - | K_LEAF_LIST id_arg_str - { if (ysp_add_push(_yy, Y_LEAF_LIST, $2) == NULL) _YYERROR("14"); } - '{' leaf_list_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("15"); - clicon_debug(2,"leaf-list-stmt -> LEAF-LIST id-arg-str { lead-substmts }");} +/* if-feature-stmt = if-feature-keyword sep if-feature-expr-str */ +if_feature_stmt : K_IF_FEATURE string stmtend + { if (ysp_add(_yy, Y_IF_FEATURE, $2, NULL) == NULL) _YYERROR("85"); + clicon_debug(2,"if-feature-stmt -> IF-FEATURE identifier-ref-arg-str"); } ; -leaf_list_substmts : leaf_list_substmts leaf_list_substmt - | leaf_list_substmt - ; - -leaf_list_substmt : when_stmt { clicon_debug(2,"leaf-list-substmt -> when-stmt"); } - | if_feature_stmt { clicon_debug(2,"leaf-list-substmt -> if-feature-stmt"); } - | type_stmt { clicon_debug(2,"leaf-list-substmt -> type-stmt"); } - | units_stmt { clicon_debug(2,"leaf-list-substmt -> units-stmt"); } - | must_stmt { clicon_debug(2,"leaf-list-substmt -> must-stmt"); } - | config_stmt { clicon_debug(2,"leaf-list-substmt -> config-stmt"); } - | min_elements_stmt { clicon_debug(2,"leaf-list-substmt -> min-elements-stmt"); } - | max_elements_stmt { clicon_debug(2,"leaf-list-substmt -> max-elements-stmt"); } - | ordered_by_stmt { clicon_debug(2,"leaf-list-substmt -> ordered-by-stmt"); } - | status_stmt { clicon_debug(2,"leaf-list-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"leaf-list-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"leaf-list-substmt -> reference-stmt"); } - | unknown_stmt { clicon_debug(2,"leaf-list-substmt -> unknown-stmt");} - | { clicon_debug(2,"leaf-list-stmt ->"); } - ; - -/* list */ -list_stmt : K_LIST id_arg_str ';' - { if (ysp_add(_yy, Y_LIST, $2, NULL) == NULL) _YYERROR("16"); - clicon_debug(2,"list-stmt -> LIST id-arg-str ;"); } - | K_LIST id_arg_str - { if (ysp_add_push(_yy, Y_LIST, $2) == NULL) _YYERROR("17"); } - '{' list_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("18"); - clicon_debug(2,"list-stmt -> LIST id-arg-str { list-substmts }"); } - ; - -list_substmts : list_substmts list_substmt - { clicon_debug(2,"list-substmts -> list-substmts list-substmt"); } - | list_substmt - { clicon_debug(2,"list-substmts -> list-substmt"); } - ; - -list_substmt : when_stmt { clicon_debug(2,"list-substmt -> when-stmt"); } - | if_feature_stmt { clicon_debug(2,"list-substmt -> if-feature-stmt"); } - | must_stmt { clicon_debug(2,"list-substmt -> must-stmt"); } - | key_stmt { clicon_debug(2,"list-substmt -> key-stmt"); } - | unique_stmt { clicon_debug(2,"list-substmt -> unique-stmt"); } - | config_stmt { clicon_debug(2,"list-substmt -> config-stmt"); } - | min_elements_stmt { clicon_debug(2,"list-substmt -> min-elements-stmt"); } - | max_elements_stmt { clicon_debug(2,"list-substmt -> max-elements-stmt"); } - | ordered_by_stmt { clicon_debug(2,"list-substmt -> ordered-by-stmt"); } - | status_stmt { clicon_debug(2,"list-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"list-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"list-substmt -> reference-stmt"); } - | typedef_stmt { clicon_debug(2,"list-substmt -> typedef-stmt"); } - | grouping_stmt { clicon_debug(2,"list-substmt -> grouping-stmt"); } - | data_def_stmt { clicon_debug(2,"list-substmt -> data-def-stmt"); } - | action_stmt { clicon_debug(2,"list-substmt -> action-stmt"); } - | notification_stmt { clicon_debug(2,"list-substmt -> notification-stmt"); } - | unknown_stmt { clicon_debug(2,"list-substmt -> unknown-stmt");} - | { clicon_debug(2,"list-substmt -> "); } - ; - -/* choice */ -choice_stmt : K_CHOICE id_arg_str ';' - { if (ysp_add(_yy, Y_CHOICE, $2, NULL) == NULL) _YYERROR("19"); - clicon_debug(2,"choice-stmt -> CHOICE id-arg-str ;"); } - | K_CHOICE id_arg_str - { if (ysp_add_push(_yy, Y_CHOICE, $2) == NULL) _YYERROR("20"); } - '{' choice_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("21"); - clicon_debug(2,"choice-stmt -> CHOICE id-arg-str { choice-substmts }"); } - ; - -choice_substmts : choice_substmts choice_substmt - { clicon_debug(2,"choice-substmts -> choice-substmts choice-substmt"); } - | choice_substmt - { clicon_debug(2,"choice-substmts -> choice-substmt"); } - ; - -choice_substmt : when_stmt { clicon_debug(2,"choice-substmt -> when-stmt"); } - | if_feature_stmt { clicon_debug(2,"choice-substmt -> if-feature-stmt"); } - | default_stmt { clicon_debug(2,"choice-substmt -> default-stmt"); } - | config_stmt { clicon_debug(2,"choice-substmt -> config-stmt"); } - | mandatory_stmt { clicon_debug(2,"choice-substmt -> mandatory-stmt"); } - | status_stmt { clicon_debug(2,"choice-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"choice-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"choice-substmt -> reference-stmt"); } - | short_case_stmt { clicon_debug(2,"choice-substmt -> short-case-stmt");} - | case_stmt { clicon_debug(2,"choice-substmt -> case-stmt");} - | unknown_stmt { clicon_debug(2,"choice-substmt -> unknown-stmt");} - | { clicon_debug(2,"choice-substmt -> "); } - ; - -/* short-case */ -short_case_stmt : container_stmt { clicon_debug(2,"short-case-substmt -> container-stmt"); } - | leaf_stmt { clicon_debug(2,"short-case-substmt -> leaf-stmt"); } - | leaf_list_stmt { clicon_debug(2,"short-case-substmt -> leaf-list-stmt"); } - | list_stmt { clicon_debug(2,"short-case-substmt -> list-stmt"); } - | anyxml_stmt { clicon_debug(2,"short-case-substmt -> anyxml-stmt");} - ; - -/* case */ -case_stmt : K_CASE id_arg_str ';' - { if (ysp_add(_yy, Y_CASE, $2, NULL) == NULL) _YYERROR("22"); - clicon_debug(2,"case-stmt -> CASE id-arg-str ;"); } - | K_CASE id_arg_str - { if (ysp_add_push(_yy, Y_CASE, $2) == NULL) _YYERROR("23"); } - '{' case_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("24"); - clicon_debug(2,"case-stmt -> CASE id-arg-str { case-substmts }"); } - ; - -case_substmts : case_substmts case_substmt - { clicon_debug(2,"case-substmts -> case-substmts case-substmt"); } - | case_substmt - { clicon_debug(2,"case-substmts -> case-substmt"); } - ; - -case_substmt : when_stmt { clicon_debug(2,"case-substmt -> when-stmt"); } - | if_feature_stmt { clicon_debug(2,"case-substmt -> if-feature-stmt"); } - | status_stmt { clicon_debug(2,"case-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"case-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"case-substmt -> reference-stmt"); } - | data_def_stmt { clicon_debug(2,"case-substmt -> data-def-stmt");} - | unknown_stmt { clicon_debug(2,"case-substmt -> unknown-stmt");} - | { clicon_debug(2,"case-substmt -> "); } - ; - - -/* anyxml */ -anyxml_stmt : K_ANYXML id_arg_str ';' - { if (ysp_add(_yy, Y_ANYXML, $2, NULL) == NULL) _YYERROR("25"); - clicon_debug(2,"anyxml-stmt -> ANYXML id-arg-str ;"); } - | K_ANYXML id_arg_str - { if (ysp_add_push(_yy, Y_ANYXML, $2) == NULL) _YYERROR("26"); } - '{' anyxml_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("27"); - clicon_debug(2,"anyxml-stmt -> ANYXML id-arg-str { anyxml-substmts }"); } - ; - -anyxml_substmts : anyxml_substmts anyxml_substmt - { clicon_debug(2,"anyxml-substmts -> anyxml-substmts anyxml-substmt"); } - | anyxml_substmt - { clicon_debug(2,"anyxml-substmts -> anyxml-substmt"); } - ; - -anyxml_substmt : when_stmt { clicon_debug(2,"anyxml-substmt -> when-stmt"); } - | if_feature_stmt { clicon_debug(2,"anyxml-substmt -> if-feature-stmt"); } - | must_stmt { clicon_debug(2,"anyxml-substmt -> must-stmt"); } - | config_stmt { clicon_debug(2,"anyxml-substmt -> config-stmt"); } - | mandatory_stmt { clicon_debug(2,"anyxml-substmt -> mandatory-stmt"); } - | status_stmt { clicon_debug(2,"anyxml-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"anyxml-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"anyxml-substmt -> reference-stmt"); } - | ustring ':' ustring ';' { free($1); free($3); clicon_debug(2,"anyxml-substmt -> anyxml extension"); } - ; - -/* uses */ -uses_stmt : K_USES identifier_ref_arg_str ';' - { if (ysp_add(_yy, Y_USES, $2, NULL) == NULL) _YYERROR("28"); - clicon_debug(2,"uses-stmt -> USES id-arg-str ;"); } - | K_USES identifier_ref_arg_str - { if (ysp_add_push(_yy, Y_USES, $2) == NULL) _YYERROR("29"); } - '{' uses_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("30"); - clicon_debug(2,"uses-stmt -> USES id-arg-str { uses-substmts }"); } - ; - -uses_substmts : uses_substmts uses_substmt - { clicon_debug(2,"uses-substmts -> uses-substmts uses-substmt"); } - | uses_substmt - { clicon_debug(2,"uses-substmts -> uses-substmt"); } - ; - -uses_substmt : when_stmt { clicon_debug(2,"uses-substmt -> when-stmt"); } - | if_feature_stmt { clicon_debug(2,"uses-substmt -> if-feature-stmt"); } - | status_stmt { clicon_debug(2,"uses-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"uses-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"uses-substmt -> reference-stmt"); } - | refine_stmt { clicon_debug(2,"uses-substmt -> refine-stmt"); } - | uses_augment_stmt { clicon_debug(2,"uses-substmt -> uses-augment-stmt"); } - | unknown_stmt { clicon_debug(2,"uses-substmt -> unknown-stmt");} - | { clicon_debug(2,"uses-substmt -> "); } - ; - -/* refine XXX need further refining */ -refine_stmt : K_REFINE id_arg_str ';' - { if (ysp_add(_yy, Y_REFINE, $2, NULL) == NULL) _YYERROR("31"); - clicon_debug(2,"refine-stmt -> REFINE id-arg-str ;"); } - | K_REFINE id_arg_str - { if (ysp_add_push(_yy, Y_REFINE, $2) == NULL) _YYERROR("32"); } - '{' refine_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("33"); - clicon_debug(2,"refine-stmt -> REFINE id-arg-str { refine-substmts }"); } - ; - -refine_substmts : refine_substmts refine_substmt - { clicon_debug(2,"refine-substmts -> refine-substmts refine-substmt"); } - | 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"); } - | default_stmt { clicon_debug(2,"refine-substmt -> default-stmt"); } - | unknown_stmt { clicon_debug(2,"refine-substmt -> unknown-stmt");} - | { clicon_debug(2,"refine-substmt -> "); } - ; - -/* augment */ -uses_augment_stmt : augment_stmt; - -augment_stmt : K_AUGMENT string - { if (ysp_add_push(_yy, Y_AUGMENT, $2) == NULL) _YYERROR("34"); } - '{' augment_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("35"); - clicon_debug(2,"augment-stmt -> AUGMENT string { augment-substmts }"); } - ; - -augment_substmts : augment_substmts augment_substmt - { clicon_debug(2,"augment-substmts -> augment-substmts augment-substmt"); } - | augment_substmt - { clicon_debug(2,"augment-substmts -> augment-substmt"); } - ; - -augment_substmt : when_stmt { clicon_debug(2,"augment-substmt -> when-stmt"); } - | if_feature_stmt { clicon_debug(2,"augment-substmt -> if-feature-stmt"); } - | status_stmt { clicon_debug(2,"augment-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"augment-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"augment-substmt -> reference-stmt"); } - | data_def_stmt { clicon_debug(2,"augment-substmt -> data-def-stmt"); } - | case_stmt { clicon_debug(2,"augment-substmt -> case-stmt");} - | action_stmt { clicon_debug(2,"augment-substmt -> action-stmt");} - | notification_stmt { clicon_debug(2,"augment-substmt -> notification-stmt");} - | { clicon_debug(2,"augment-substmt -> "); } - ; - -/* when */ -when_stmt : K_WHEN string ';' - { if (ysp_add(_yy, Y_WHEN, $2, NULL) == NULL) _YYERROR("36"); - clicon_debug(2,"when-stmt -> WHEN string ;"); } - | K_WHEN string - { if (ysp_add_push(_yy, Y_WHEN, $2) == NULL) _YYERROR("37"); } - '{' when_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("38"); - clicon_debug(2,"when-stmt -> WHEN string { when-substmts }"); } - ; - -when_substmts : when_substmts when_substmt - { clicon_debug(2,"when-substmts -> when-substmts when-substmt"); } - | when_substmt - { clicon_debug(2,"when-substmts -> when-substmt"); } - ; - -when_substmt : description_stmt { clicon_debug(2,"when-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"when-substmt -> reference-stmt"); } - | { clicon_debug(2,"when-substmt -> "); } - ; - -/* rpc */ -rpc_stmt : K_RPC id_arg_str ';' - { if (ysp_add(_yy, Y_RPC, $2, NULL) == NULL) _YYERROR("39"); - clicon_debug(2,"rpc-stmt -> RPC id-arg-str ;"); } - | K_RPC id_arg_str - { if (ysp_add_push(_yy, Y_RPC, $2) == NULL) _YYERROR("40"); } - '{' rpc_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("41"); - clicon_debug(2,"rpc-stmt -> RPC id-arg-str { rpc-substmts }"); } - ; - -rpc_substmts : rpc_substmts rpc_substmt - { clicon_debug(2,"rpc-substmts -> rpc-substmts rpc-substmt"); } - | rpc_substmt - { clicon_debug(2,"rpc-substmts -> rpc-substmt"); } - ; - -rpc_substmt : if_feature_stmt { clicon_debug(2,"rpc-substmt -> if-feature-stmt"); } - | status_stmt { clicon_debug(2,"rpc-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"rpc-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"rpc-substmt -> reference-stmt"); } - | typedef_stmt { clicon_debug(2,"rpc-substmt -> typedef-stmt"); } - | grouping_stmt { clicon_debug(2,"rpc-substmt -> grouping-stmt"); } - | input_stmt { clicon_debug(2,"rpc-substmt -> input-stmt"); } - | output_stmt { clicon_debug(2,"rpc-substmt -> output-stmt"); } - | { clicon_debug(2,"rpc-substmt -> "); } - ; - -/* action */ -action_stmt : K_ACTION id_arg_str ';' - { if (ysp_add(_yy, Y_ACTION, $2, NULL) == NULL) _YYERROR("39"); - clicon_debug(2,"action-stmt -> ACTION id-arg-str ;"); } - | K_ACTION id_arg_str - { if (ysp_add_push(_yy, Y_ACTION, $2) == NULL) _YYERROR("40"); } - '{' rpc_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("41"); - clicon_debug(2,"action-stmt -> ACTION id-arg-str { rpc-substmts }"); } - ; - -/* input */ -input_stmt : K_INPUT - { if (ysp_add_push(_yy, Y_INPUT, NULL) == NULL) _YYERROR("42"); } - '{' input_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("43"); - clicon_debug(2,"input-stmt -> INPUT { input-substmts }"); } - ; - -input_substmts : input_substmts input_substmt - { clicon_debug(2,"input-substmts -> input-substmts input-substmt"); } - | input_substmt - { clicon_debug(2,"input-substmts -> input-substmt"); } - ; - -input_substmt : typedef_stmt { clicon_debug(2,"input-substmt -> typedef-stmt"); } - | grouping_stmt { clicon_debug(2,"input-substmt -> grouping-stmt"); } - | data_def_stmt { clicon_debug(2,"input-substmt -> data-def-stmt"); } - | { clicon_debug(2,"input-substmt -> "); } - ; - -/* output */ -output_stmt : K_OUTPUT /* XXX reuse input-substatements since they are same */ - { if (ysp_add_push(_yy, Y_OUTPUT, NULL) == NULL) _YYERROR("44"); } - '{' input_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("45"); - clicon_debug(2,"output-stmt -> OUTPUT { input-substmts }"); } - ; - - -/* notification */ -notification_stmt : K_NOTIFICATION id_arg_str ';' - { if (ysp_add(_yy, Y_NOTIFICATION, $2, NULL) == NULL) _YYERROR("46"); - clicon_debug(2,"notification-stmt -> NOTIFICATION id-arg-str ;"); } - | K_NOTIFICATION id_arg_str - { if (ysp_add_push(_yy, Y_NOTIFICATION, $2) == NULL) _YYERROR("47"); } - '{' notification_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("48"); - clicon_debug(2,"notification-stmt -> NOTIFICATION id-arg-str { notification-substmts }"); } - ; - -notification_substmts : notification_substmts notification_substmt - { clicon_debug(2,"notification-substmts -> notification-substmts notification-substmt"); } - | notification_substmt - { clicon_debug(2,"notification-substmts -> notification-substmt"); } - ; - -notification_substmt : if_feature_stmt { clicon_debug(2,"notification-substmt -> if-feature-stmt"); } - | must_stmt { clicon_debug(2,"notification-substmt -> must-stmt"); } - | status_stmt { clicon_debug(2,"notification-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"notification-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"notification-substmt -> reference-stmt"); } - | typedef_stmt { clicon_debug(2,"notification-substmt -> typedef-stmt"); } - | grouping_stmt { clicon_debug(2,"notification-substmt -> grouping-stmt"); } - | data_def_stmt { clicon_debug(2,"notification-substmt -> data-def-stmt"); } - | { clicon_debug(2,"notification-substmt -> "); } - ; - /* Typedef */ -typedef_stmt : K_TYPEDEF id_arg_str +typedef_stmt : K_TYPEDEF identifier_str { if (ysp_add_push(_yy, Y_TYPEDEF, $2) == NULL) _YYERROR("46"); } '{' typedef_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("47"); @@ -949,10 +698,10 @@ typedef_substmt : type_stmt { clicon_debug(2,"typedef-substmt -> type-s ; /* Type */ -type_stmt : K_TYPE identifier_ref_arg_str ';' +type_stmt : K_TYPE identifier_ref_str ';' { if (ysp_add(_yy, Y_TYPE, $2, NULL) == NULL) _YYERROR("48"); clicon_debug(2,"type-stmt -> TYPE identifier-ref-arg-str ;");} - | K_TYPE identifier_ref_arg_str + | K_TYPE identifier_ref_str { if (ysp_add_push(_yy, Y_TYPE, $2) == NULL) _YYERROR("49"); } '{' type_body_stmts '}' @@ -966,8 +715,8 @@ type_stmt : K_TYPE identifier_ref_arg_str ';' */ type_body_stmts : type_body_stmts type_body_stmt { clicon_debug(2,"type-body-stmts -> type-body-stmts type-body-stmt"); } - | type_body_stmt - { clicon_debug(2,"type-body-stmts -> type-body-stmt"); } + | + { clicon_debug(2,"type-body-stmts -> "); } ; type_body_stmt/* numerical-restrictions */ @@ -991,31 +740,40 @@ type_body_stmt/* numerical-restrictions */ | type_stmt { clicon_debug(2,"type-body-stmt -> type-stmt"); } ; +/* range-stmt */ +range_stmt : K_RANGE string ';' /* XXX range-arg-str */ + { if (ysp_add(_yy, Y_RANGE, $2, NULL) == NULL) _YYERROR("68"); + clicon_debug(2,"range-stmt -> RANGE string ;"); } - -/* Grouping */ -grouping_stmt : K_GROUPING id_arg_str - { if (ysp_add_push(_yy, Y_GROUPING, $2) == NULL) _YYERROR("51"); } - '{' grouping_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("52"); - clicon_debug(2,"grouping-stmt -> GROUPING id-arg-str { grouping-substmts }"); } + | K_RANGE string + { if (ysp_add_push(_yy, Y_RANGE, $2) == NULL) _YYERROR("69"); } + '{' range_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("70"); + clicon_debug(2,"range-stmt -> RANGE string { range-substmts }"); } ; -grouping_substmts : grouping_substmts grouping_substmt - { clicon_debug(2,"grouping-substmts -> grouping-substmts grouping-substmt"); } - | grouping_substmt - { clicon_debug(2,"grouping-substmts -> grouping-substmt"); } +range_substmts : range_substmts range_substmt + { clicon_debug(2,"range-substmts -> range-substmts range-substmt"); } + | range_substmt + { clicon_debug(2,"range-substmts -> range-substmt"); } ; -grouping_substmt : status_stmt { clicon_debug(2,"grouping-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"grouping-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"grouping-substmt -> reference-stmt"); } - | typedef_stmt { clicon_debug(2,"grouping-substmt -> typedef-stmt"); } - | grouping_stmt { clicon_debug(2,"grouping-substmt -> grouping-stmt"); } - | data_def_stmt { clicon_debug(2,"grouping-substmt -> data-def-stmt"); } - | action_stmt { clicon_debug(2,"grouping-substmt -> action-stmt"); } - | notification_stmt { clicon_debug(2,"grouping-substmt -> notification-stmt"); } - | { clicon_debug(2,"grouping-substmt -> "); } +range_substmt : error_message_stmt { clicon_debug(2,"range-substmt -> error-message-stmt");} + | description_stmt { clicon_debug(2,"range-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"range-substmt -> reference-stmt"); } + | unknown_stmt { clicon_debug(2,"range-substmt -> unknown-stmt");} + | { clicon_debug(2,"range-substmt -> "); } + ; + +/* fraction-digits-stmt = fraction-digits-keyword fraction-digits-arg-str */ +fraction_digits_stmt : K_FRACTION_DIGITS string stmtend + { if (ysp_add(_yy, Y_FRACTION_DIGITS, $2, NULL) == NULL) _YYERROR("84"); + clicon_debug(2,"fraction-digits-stmt -> FRACTION-DIGITS string"); } + ; + +/* meta */ +meta_stmts : meta_stmts meta_stmt { clicon_debug(2,"meta-stmts -> meta-stmts meta-stmt"); } + | meta_stmt { clicon_debug(2,"meta-stmts -> meta-stmt"); } ; /* length-stmt */ @@ -1067,113 +825,12 @@ pattern_substmt : reference_stmt { clicon_debug(2,"pattern-substmt -> refere | { clicon_debug(2,"pattern-substmt -> "); } ; -/* Extension */ -extension_stmt: K_EXTENSION id_arg_str ';' - { if (ysp_add(_yy, Y_EXTENSION, $2, NULL) == NULL) _YYERROR("59"); - clicon_debug(2,"extenstion-stmt -> EXTENSION id-arg-str ;"); } - | K_EXTENSION id_arg_str - { if (ysp_add_push(_yy, Y_EXTENSION, $2) == NULL) _YYERROR("60"); } - '{' extension_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("61"); - clicon_debug(2,"extension-stmt -> FEATURE id-arg-str { extension-substmts }"); } - ; - - -/* extension substmts */ -extension_substmts : extension_substmts extension_substmt - { clicon_debug(2,"extension-substmts -> extension-substmts extension-substmt"); } - | extension_substmt - { clicon_debug(2,"extension-substmts -> extension-substmt"); } +default_stmt : K_DEFAULT string ';' + { if (ysp_add(_yy, Y_DEFAULT, $2, NULL)== NULL) _YYERROR("94"); + clicon_debug(2,"default-stmt -> DEFAULT string"); } ; -extension_substmt : argument_stmt { clicon_debug(2,"extension-substmt -> argument-stmt"); } - | status_stmt { clicon_debug(2,"extension-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"extension-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"extension-substmt -> reference-stmt"); } - | unknown_stmt { clicon_debug(2,"extension-substmt -> unknown-stmt");} - | { clicon_debug(2,"extension-substmt -> "); } - ; -argument_stmt : K_ARGUMENT id_arg_str ';' { free($2); } - | K_ARGUMENT id_arg_str '{' '}' { free($2); } - ; - -/* Feature */ -feature_stmt : K_FEATURE id_arg_str ';' - { if (ysp_add(_yy, Y_FEATURE, $2, NULL) == NULL) _YYERROR("62"); - clicon_debug(2,"feature-stmt -> FEATURE id-arg-str ;"); } - | K_FEATURE id_arg_str - { if (ysp_add_push(_yy, Y_FEATURE, $2) == NULL) _YYERROR("63"); } - '{' feature_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("64"); - clicon_debug(2,"feature-stmt -> FEATURE id-arg-str { feature-substmts }"); } - ; - -/* feature substmts */ -feature_substmts : feature_substmts feature_substmt - { clicon_debug(2,"feature-substmts -> feature-substmts feature-substmt"); } - | feature_substmt - { clicon_debug(2,"feature-substmts -> feature-substmt"); } - ; - -feature_substmt : if_feature_stmt { clicon_debug(2,"feature-substmt -> if-feature-stmt"); } - | status_stmt { clicon_debug(2,"feature-substmt -> status-stmt"); } - | description_stmt { clicon_debug(2,"feature-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"feature-substmt -> reference-stmt"); } - | unknown_stmt { clicon_debug(2,"feature-substmt -> unknown-stmt");} - | { clicon_debug(2,"feature-substmt -> "); } - ; - -/* Identity */ -identity_stmt : K_IDENTITY string ';' /* XXX identifier-arg-str */ - { if (ysp_add(_yy, Y_IDENTITY, $2, NULL) == NULL) _YYERROR("65"); - clicon_debug(2,"identity-stmt -> IDENTITY string ;"); } - - | K_IDENTITY string - { if (ysp_add_push(_yy, Y_IDENTITY, $2) == NULL) _YYERROR("66"); } - '{' identity_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("67"); - clicon_debug(2,"identity-stmt -> IDENTITY string { identity-substmts }"); } - ; - -identity_substmts : identity_substmts identity_substmt - { clicon_debug(2,"identity-substmts -> identity-substmts identity-substmt"); } - | identity_substmt - { clicon_debug(2,"identity-substmts -> identity-substmt"); } - ; - -identity_substmt : 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"); } - | unknown_stmt { clicon_debug(2,"identity-substmt -> unknown-stmt");} - | { clicon_debug(2,"identity-substmt -> "); } - ; - -/* range-stmt */ -range_stmt : K_RANGE string ';' /* XXX range-arg-str */ - { if (ysp_add(_yy, Y_RANGE, $2, NULL) == NULL) _YYERROR("68"); - clicon_debug(2,"range-stmt -> RANGE string ;"); } - - | K_RANGE string - { if (ysp_add_push(_yy, Y_RANGE, $2) == NULL) _YYERROR("69"); } - '{' range_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("70"); - clicon_debug(2,"range-stmt -> RANGE string { range-substmts }"); } - ; - -range_substmts : range_substmts range_substmt - { clicon_debug(2,"range-substmts -> range-substmts range-substmt"); } - | range_substmt - { clicon_debug(2,"range-substmts -> range-substmt"); } - ; - -range_substmt : error_message_stmt { clicon_debug(2,"range-substmt -> error-message-stmt");} - | description_stmt { clicon_debug(2,"range-substmt -> description-stmt"); } - | reference_stmt { clicon_debug(2,"range-substmt -> reference-stmt"); } - | unknown_stmt { clicon_debug(2,"range-substmt -> unknown-stmt");} - | { clicon_debug(2,"range-substmt -> "); } - ; /* enum-stmt */ enum_stmt : K_ENUM string ';' @@ -1200,11 +857,21 @@ enum_substmt : value_stmt { clicon_debug(2,"enum-substmt -> value-stm | { clicon_debug(2,"enum-substmt -> "); } ; +path_stmt : K_PATH string ';' /* XXX: path-arg-str */ + { if (ysp_add(_yy, Y_PATH, $2, NULL)== NULL) _YYERROR("91"); + clicon_debug(2,"path-stmt -> PATH string"); } + ; + +require_instance_stmt : K_REQUIRE_INSTANCE bool_str ';' + { if (ysp_add(_yy, Y_REQUIRE_INSTANCE, $2, NULL)== NULL) _YYERROR("92"); + clicon_debug(2,"require-instance-stmt -> REQUIRE-INSTANCE string"); } + ; + /* bit-stmt */ -bit_stmt : K_BIT string ';' +bit_stmt : K_BIT identifier_str ';' { if (ysp_add(_yy, Y_BIT, $2, NULL) == NULL) _YYERROR("74"); clicon_debug(2,"bit-stmt -> BIT string ;"); } - | K_BIT string + | K_BIT identifier_str { if (ysp_add_push(_yy, Y_BIT, $2) == NULL) _YYERROR("75"); } '{' bit_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("76"); @@ -1224,7 +891,44 @@ bit_substmt : position_stmt { clicon_debug(2,"bit-substmt -> positition | { clicon_debug(2,"bit-substmt -> "); } ; -/* mus-stmt */ +/* position-stmt = position-keyword position-value-arg-str */ +position_stmt : K_POSITION integer_value_str stmtend + { if (ysp_add(_yy, Y_POSITION, $2, NULL) == NULL) _YYERROR("87"); + clicon_debug(2,"position-stmt -> POSITION integer-value"); } + ; + +/* status-stmt = status-keyword sep status-arg-str XXX: current-keyword*/ +status_stmt : K_STATUS string stmtend + { if (ysp_add(_yy, Y_STATUS, $2, NULL) == NULL) _YYERROR("88"); + clicon_debug(2,"status-stmt -> STATUS string"); } + ; + +config_stmt : K_CONFIG bool_str ';' + { if (ysp_add(_yy, Y_CONFIG, $2, NULL) == NULL) _YYERROR("89"); + clicon_debug(2,"config-stmt -> CONFIG config-arg-str"); } + ; + +/* mandatory-stmt = mandatory-keyword mandatory-arg-str */ +mandatory_stmt: K_MANDATORY bool_str ';' + { yang_stmt *ys; + if ((ys = ysp_add(_yy, Y_MANDATORY, $2, NULL))== NULL) _YYERROR("106"); + clicon_debug(2,"mandatory-stmt -> MANDATORY mandatory-arg-str ;");} + ; + +presence_stmt: K_PRESENCE string ';' + { yang_stmt *ys; + if ((ys = ysp_add(_yy, Y_PRESENCE, $2, NULL))== NULL) _YYERROR("107"); + clicon_debug(2,"presence-stmt -> PRESENCE string ;");} + ; + +/* ordered-by-stmt = ordered-by-keyword sep ordered-by-arg-str */ +ordered_by_stmt: K_ORDERED_BY string stmtend + { yang_stmt *ys; + if ((ys = ysp_add(_yy, Y_ORDERED_BY, $2, NULL))== NULL) _YYERROR("108"); + clicon_debug(2,"ordered-by-stmt -> ORDERED-BY ordered-by-arg ;");} + ; + +/* must-stmt */ must_stmt : K_MUST string ';' { if (ysp_add(_yy, Y_MUST, $2, NULL) == NULL) _YYERROR("77"); clicon_debug(2,"must-stmt -> MUST string ;"); } @@ -1251,194 +955,571 @@ must_substmt : error_message_stmt { clicon_debug(2,"must-substmt -> error-mes /* error-message-stmt */ error_message_stmt : K_ERROR_MESSAGE string ';' { if (ysp_add(_yy, Y_ERROR_MESSAGE, $2, NULL) == NULL) _YYERROR("80"); } + ; -/* import */ -import_stmt : K_IMPORT id_arg_str - { if (ysp_add_push(_yy, Y_IMPORT, $2) == NULL) _YYERROR("81"); } - '{' import_substmts '}' - { if (ystack_pop(_yy) < 0) _YYERROR("82"); - clicon_debug(2,"import-stmt -> IMPORT id-arg-str { import-substmts }");} - ; +/* XXX error-app-tag-stmt */ -import_substmts : import_substmts import_substmt - { clicon_debug(2,"import-substmts -> import-substmts import-substm");} - | import_substmt - { clicon_debug(2,"import-substmts ->");} - ; - -import_substmt : prefix_stmt { clicon_debug(2,"import-stmt -> prefix-stmt"); } - | revision_date_stmt { clicon_debug(2,"import-stmt -> revision-date-stmt"); } - ; - - -/* Simple statements */ -yang_version_stmt : K_YANG_VERSION string ';' /* XXX yang-version-arg-str */ - { if (ysp_add(_yy, Y_YANG_VERSION, $2, NULL) == NULL) _YYERROR("83"); - clicon_debug(2,"yang-version-stmt -> YANG-VERSION string"); } - ; - -fraction_digits_stmt : K_FRACTION_DIGITS string ';' /* XXX: fraction-digits-arg-str */ - { if (ysp_add(_yy, Y_FRACTION_DIGITS, $2, NULL) == NULL) _YYERROR("84"); - clicon_debug(2,"fraction-digits-stmt -> FRACTION-DIGITS string"); } - ; - -if_feature_stmt : K_IF_FEATURE identifier_ref_arg_str ';' - { if (ysp_add(_yy, Y_IF_FEATURE, $2, NULL) == NULL) _YYERROR("85"); - clicon_debug(2,"if-feature-stmt -> IF-FEATURE identifier-ref-arg-str"); } - ; - -value_stmt : K_VALUE integer_value ';' - { if (ysp_add(_yy, Y_VALUE, $2, NULL) == NULL) _YYERROR("86"); - clicon_debug(2,"value-stmt -> VALUE integer-value"); } - ; - -position_stmt : K_POSITION integer_value ';' - { if (ysp_add(_yy, Y_POSITION, $2, NULL) == NULL) _YYERROR("87"); - clicon_debug(2,"position-stmt -> POSITION integer-value"); } - ; - -status_stmt : K_STATUS string ';' /* XXX: status-arg-str */ - { if (ysp_add(_yy, Y_STATUS, $2, NULL) == NULL) _YYERROR("88"); - clicon_debug(2,"status-stmt -> STATUS string"); } - ; - -config_stmt : K_CONFIG config_arg_str ';' - { if (ysp_add(_yy, Y_CONFIG, $2, NULL) == NULL) _YYERROR("89"); - clicon_debug(2,"config-stmt -> CONFIG config-arg-str"); } - ; - - -base_stmt : K_BASE identifier_ref_arg_str ';' - { if (ysp_add(_yy, Y_BASE, $2, NULL)== NULL) _YYERROR("90"); - clicon_debug(2,"base-stmt -> BASE identifier-ref-arg-str"); } - ; - -path_stmt : K_PATH string ';' /* XXX: path-arg-str */ - { if (ysp_add(_yy, Y_PATH, $2, NULL)== NULL) _YYERROR("91"); - clicon_debug(2,"path-stmt -> PATH string"); } - ; - -require_instance_stmt : K_REQUIRE_INSTANCE string ';' /* XXX: require-instance-arg-str */ - { if (ysp_add(_yy, Y_REQUIRE_INSTANCE, $2, NULL)== NULL) _YYERROR("92"); - clicon_debug(2,"require-instance-stmt -> REQUIRE-INSTANCE string"); } - ; - -units_stmt : K_UNITS string ';' - { if (ysp_add(_yy, Y_UNITS, $2, NULL)== NULL) _YYERROR("93"); - clicon_debug(2,"units-stmt -> UNITS string"); } - ; - -default_stmt : K_DEFAULT string ';' - { if (ysp_add(_yy, Y_DEFAULT, $2, NULL)== NULL) _YYERROR("94"); - clicon_debug(2,"default-stmt -> DEFAULT string"); } - ; - -contact_stmt : K_CONTACT string ';' - { if (ysp_add(_yy, Y_CONTACT, $2, NULL)== NULL) _YYERROR("95"); - clicon_debug(2,"contact-stmt -> CONTACT string"); } - ; - -revision_date_stmt : K_REVISION_DATE string ';' /* XXX date-arg-str */ - { if (ysp_add(_yy, Y_REVISION_DATE, $2, NULL) == NULL) _YYERROR("96"); - clicon_debug(2,"revision-date-stmt -> date;"); } - ; - -include_stmt : K_INCLUDE id_arg_str ';' - { if (ysp_add(_yy, Y_INCLUDE, $2, NULL)== NULL) _YYERROR("97"); - clicon_debug(2,"include-stmt -> id-arg-str"); } - | K_INCLUDE id_arg_str '{' revision_date_stmt '}' - { if (ysp_add(_yy, Y_INCLUDE, $2, NULL)== NULL) _YYERROR("98"); - clicon_debug(2,"include-stmt -> id-arg-str { revision-date-stmt }"); } - ; - -namespace_stmt : K_NAMESPACE string ';' /* XXX uri-str */ - { if (ysp_add(_yy, Y_NAMESPACE, $2, NULL)== NULL) _YYERROR("99"); - clicon_debug(2,"namespace-stmt -> NAMESPACE string"); } - ; - -prefix_stmt : K_PREFIX string ';' /* XXX prefix-arg-str */ - { if (ysp_add(_yy, Y_PREFIX, $2, NULL)== NULL) _YYERROR("100"); - clicon_debug(2,"prefix-stmt -> PREFIX string ;");} - ; - -belongs_to_stmt : K_BELONGS_TO id_arg_str ';' - - { if (ysp_add(_yy, Y_BELONGS_TO, $2, NULL)== NULL) _YYERROR("100"); - clicon_debug(2,"belongs-to-stmt -> BELONGS-TO id-arg-str ;");} - | K_BELONGS_TO id_arg_str '{' prefix_stmt '}' - { if (ysp_add(_yy, Y_BELONGS_TO, $2, NULL)== NULL) _YYERROR("98"); - clicon_debug(2,"belongs-to-stmt -> BELONGS-TO id-arg-str { prefix-stmt } ");} - ; - -description_stmt: K_DESCRIPTION string ';' - { if (ysp_add(_yy, Y_DESCRIPTION, $2, NULL)== NULL) _YYERROR("101"); - clicon_debug(2,"description-stmt -> DESCRIPTION string ;");} - ; - -organization_stmt: K_ORGANIZATION string ';' - { if (ysp_add(_yy, Y_ORGANIZATION, $2, NULL)== NULL) _YYERROR("102"); - clicon_debug(2,"organization-stmt -> ORGANIZATION string ;");} - ; - -min_elements_stmt: K_MIN_ELEMENTS integer_value ';' +/* min-elements-stmt = min-elements-keyword min-value-arg-str */ +min_elements_stmt: K_MIN_ELEMENTS integer_value_str stmtend { if (ysp_add(_yy, Y_MIN_ELEMENTS, $2, NULL)== NULL) _YYERROR("103"); clicon_debug(2,"min-elements-stmt -> MIN-ELEMENTS integer ;");} ; -max_elements_stmt: K_MAX_ELEMENTS integer_value ';' +/* max-elements-stmt = max-elements-keyword ("unbounded"|integer-value) + * XXX cannot use integer-value + */ +max_elements_stmt: K_MAX_ELEMENTS string ';' { if (ysp_add(_yy, Y_MAX_ELEMENTS, $2, NULL)== NULL) _YYERROR("104"); clicon_debug(2,"max-elements-stmt -> MIN-ELEMENTS integer ;");} ; -reference_stmt: K_REFERENCE string ';' - { if (ysp_add(_yy, Y_REFERENCE, $2, NULL)== NULL) _YYERROR("105"); - clicon_debug(2,"reference-stmt -> REFERENCE string ;");} +value_stmt : K_VALUE integer_value_str ';' + { if (ysp_add(_yy, Y_VALUE, $2, NULL) == NULL) _YYERROR("86"); + clicon_debug(2,"value-stmt -> VALUE integer-value"); } ; -mandatory_stmt: K_MANDATORY string ';' - { yang_stmt *ys; - if ((ys = ysp_add(_yy, Y_MANDATORY, $2, NULL))== NULL) _YYERROR("106"); - clicon_debug(2,"mandatory-stmt -> MANDATORY mandatory-arg-str ;");} +/* Grouping */ +grouping_stmt : K_GROUPING identifier_str + { if (ysp_add_push(_yy, Y_GROUPING, $2) == NULL) _YYERROR("51"); } + '{' grouping_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("52"); + clicon_debug(2,"grouping-stmt -> GROUPING id-arg-str { grouping-substmts }"); } ; -presence_stmt: K_PRESENCE string ';' - { yang_stmt *ys; - if ((ys = ysp_add(_yy, Y_PRESENCE, $2, NULL))== NULL) _YYERROR("107"); - clicon_debug(2,"presence-stmt -> PRESENCE string ;");} +grouping_substmts : grouping_substmts grouping_substmt + { clicon_debug(2,"grouping-substmts -> grouping-substmts grouping-substmt"); } + | grouping_substmt + { clicon_debug(2,"grouping-substmts -> grouping-substmt"); } ; -ordered_by_stmt: K_ORDERED_BY string ';' - { yang_stmt *ys; - if ((ys = ysp_add(_yy, Y_ORDERED_BY, $2, NULL))== NULL) _YYERROR("108"); - clicon_debug(2,"ordered-by-stmt -> ORDERED-BY ordered-by-arg ;");} +grouping_substmt : status_stmt { clicon_debug(2,"grouping-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"grouping-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"grouping-substmt -> reference-stmt"); } + | typedef_stmt { clicon_debug(2,"grouping-substmt -> typedef-stmt"); } + | grouping_stmt { clicon_debug(2,"grouping-substmt -> grouping-stmt"); } + | data_def_stmt { clicon_debug(2,"grouping-substmt -> data-def-stmt"); } + | action_stmt { clicon_debug(2,"grouping-substmt -> action-stmt"); } + | notification_stmt { clicon_debug(2,"grouping-substmt -> notification-stmt"); } + | { clicon_debug(2,"grouping-substmt -> "); } ; -key_stmt : K_KEY id_arg_str ';' /* XXX key_arg_str */ + +/* container */ +container_stmt : K_CONTAINER identifier_str ';' + { if (ysp_add(_yy, Y_CONTAINER, $2, NULL) == NULL) _YYERROR("7"); + clicon_debug(2,"container-stmt -> CONTAINER id-arg-str ;");} + | K_CONTAINER identifier_str + { if (ysp_add_push(_yy, Y_CONTAINER, $2) == NULL) _YYERROR("8"); } + '{' container_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("9"); + clicon_debug(2,"container-stmt -> CONTAINER id-arg-str { container-substmts }");} + ; + +container_substmts : container_substmts container_substmt + | container_substmt + ; + +container_substmt : when_stmt { clicon_debug(2,"container-substmt -> when-stmt"); } + | if_feature_stmt { clicon_debug(2,"container-substmt -> if-feature-stmt"); } + | must_stmt { clicon_debug(2,"container-substmt -> must-stmt"); } + | presence_stmt { clicon_debug(2,"container-substmt -> presence-stmt"); } + | config_stmt { clicon_debug(2,"container-substmt -> config-stmt"); } + | status_stmt { clicon_debug(2,"container-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"container-substmt -> description-stmt");} + | reference_stmt { clicon_debug(2,"container-substmt -> reference-stmt"); } + | typedef_stmt { clicon_debug(2,"container-substmt -> typedef-stmt"); } + | grouping_stmt { clicon_debug(2,"container-substmt -> grouping-stmt"); } + | data_def_stmt { clicon_debug(2,"container-substmt -> data-def-stmt");} + | action_stmt { clicon_debug(2,"container-substmt -> action-stmt");} + | notification_stmt { clicon_debug(2,"container-substmt -> notification-stmt");} + | unknown_stmt { clicon_debug(2,"container-substmt -> unknown-stmt");} + | { clicon_debug(2,"container-substmt ->");} + ; + +/* leaf */ +leaf_stmt : K_LEAF identifier_str ';' + { if (ysp_add(_yy, Y_LEAF, $2, NULL) == NULL) _YYERROR("10"); + clicon_debug(2,"leaf-stmt -> LEAF id-arg-str ;");} + | K_LEAF identifier_str + { if (ysp_add_push(_yy, Y_LEAF, $2) == NULL) _YYERROR("11"); } + '{' leaf_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("12"); + clicon_debug(2,"leaf-stmt -> LEAF id-arg-str { lead-substmts }");} + ; + +leaf_substmts : leaf_substmts leaf_substmt + | leaf_substmt + ; + +leaf_substmt : when_stmt { clicon_debug(2,"leaf-substmt -> when-stmt"); } + | if_feature_stmt { clicon_debug(2,"leaf-substmt -> if-feature-stmt"); } + | type_stmt { clicon_debug(2,"leaf-substmt -> type-stmt"); } + | units_stmt { clicon_debug(2,"leaf-substmt -> units-stmt"); } + | must_stmt { clicon_debug(2,"leaf-substmt -> must-stmt"); } + | default_stmt { clicon_debug(2,"leaf-substmt -> default-stmt"); } + | config_stmt { clicon_debug(2,"leaf-substmt -> config-stmt"); } + | mandatory_stmt { clicon_debug(2,"leaf-substmt -> mandatory-stmt"); } + | status_stmt { clicon_debug(2,"leaf-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"leaf-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"leaf-substmt -> reference-stmt"); } + | unknown_stmt { clicon_debug(2,"leaf-substmt -> unknown-stmt");} + | { clicon_debug(2,"leaf-substmt ->"); } + ; + +/* leaf-list */ +leaf_list_stmt : K_LEAF_LIST identifier_str ';' + { if (ysp_add(_yy, Y_LEAF_LIST, $2, NULL) == NULL) _YYERROR("13"); + clicon_debug(2,"leaf-list-stmt -> LEAF id-arg-str ;");} + | K_LEAF_LIST identifier_str + { if (ysp_add_push(_yy, Y_LEAF_LIST, $2) == NULL) _YYERROR("14"); } + '{' leaf_list_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("15"); + clicon_debug(2,"leaf-list-stmt -> LEAF-LIST id-arg-str { lead-substmts }");} + ; + +leaf_list_substmts : leaf_list_substmts leaf_list_substmt + | leaf_list_substmt + ; + +leaf_list_substmt : when_stmt { clicon_debug(2,"leaf-list-substmt -> when-stmt"); } + | if_feature_stmt { clicon_debug(2,"leaf-list-substmt -> if-feature-stmt"); } + | type_stmt { clicon_debug(2,"leaf-list-substmt -> type-stmt"); } + | units_stmt { clicon_debug(2,"leaf-list-substmt -> units-stmt"); } + | must_stmt { clicon_debug(2,"leaf-list-substmt -> must-stmt"); } + | config_stmt { clicon_debug(2,"leaf-list-substmt -> config-stmt"); } + | min_elements_stmt { clicon_debug(2,"leaf-list-substmt -> min-elements-stmt"); } + | max_elements_stmt { clicon_debug(2,"leaf-list-substmt -> max-elements-stmt"); } + | ordered_by_stmt { clicon_debug(2,"leaf-list-substmt -> ordered-by-stmt"); } + | status_stmt { clicon_debug(2,"leaf-list-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"leaf-list-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"leaf-list-substmt -> reference-stmt"); } + | unknown_stmt { clicon_debug(2,"leaf-list-substmt -> unknown-stmt");} + | { clicon_debug(2,"leaf-list-stmt ->"); } + ; + +/* list */ +list_stmt : K_LIST identifier_str ';' + { if (ysp_add(_yy, Y_LIST, $2, NULL) == NULL) _YYERROR("16"); + clicon_debug(2,"list-stmt -> LIST id-arg-str ;"); } + | K_LIST identifier_str + { if (ysp_add_push(_yy, Y_LIST, $2) == NULL) _YYERROR("17"); } + '{' list_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("18"); + clicon_debug(2,"list-stmt -> LIST id-arg-str { list-substmts }"); } + ; + +list_substmts : list_substmts list_substmt + { clicon_debug(2,"list-substmts -> list-substmts list-substmt"); } + | list_substmt + { clicon_debug(2,"list-substmts -> list-substmt"); } + ; + +list_substmt : when_stmt { clicon_debug(2,"list-substmt -> when-stmt"); } + | if_feature_stmt { clicon_debug(2,"list-substmt -> if-feature-stmt"); } + | must_stmt { clicon_debug(2,"list-substmt -> must-stmt"); } + | key_stmt { clicon_debug(2,"list-substmt -> key-stmt"); } + | unique_stmt { clicon_debug(2,"list-substmt -> unique-stmt"); } + | config_stmt { clicon_debug(2,"list-substmt -> config-stmt"); } + | min_elements_stmt { clicon_debug(2,"list-substmt -> min-elements-stmt"); } + | max_elements_stmt { clicon_debug(2,"list-substmt -> max-elements-stmt"); } + | ordered_by_stmt { clicon_debug(2,"list-substmt -> ordered-by-stmt"); } + | status_stmt { clicon_debug(2,"list-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"list-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"list-substmt -> reference-stmt"); } + | typedef_stmt { clicon_debug(2,"list-substmt -> typedef-stmt"); } + | grouping_stmt { clicon_debug(2,"list-substmt -> grouping-stmt"); } + | data_def_stmt { clicon_debug(2,"list-substmt -> data-def-stmt"); } + | action_stmt { clicon_debug(2,"list-substmt -> action-stmt"); } + | notification_stmt { clicon_debug(2,"list-substmt -> notification-stmt"); } + | unknown_stmt { clicon_debug(2,"list-substmt -> unknown-stmt");} + | { clicon_debug(2,"list-substmt -> "); } + ; + +/* key-stmt = key-keyword sep key-arg-str */ +key_stmt : K_KEY string stmtend { if (ysp_add(_yy, Y_KEY, $2, NULL)== NULL) _YYERROR("109"); clicon_debug(2,"key-stmt -> KEY id-arg-str ;");} ; -unique_stmt : K_UNIQUE id_arg_str ';' /* XXX key_arg_str */ +/* unique-stmt = unique-keyword unique-arg-str */ +unique_stmt : K_UNIQUE string stmtend { if (ysp_add(_yy, Y_UNIQUE, $2, NULL)== NULL) _YYERROR("110"); clicon_debug(2,"key-stmt -> KEY id-arg-str ;");} ; -config_arg_str : string { $$=$1; } /* XXX BOOL */ - ; - -integer_value : string { $$=$1; } - ; - -identifier_ref_arg_str : string - { if (($$=prefix_id_join(NULL, $1)) == NULL) _YYERROR("111"); - clicon_debug(2,"identifier-ref-arg-str -> string"); } - | string ':' string - { if (($$=prefix_id_join($1, $3)) == NULL) _YYERROR("112"); - clicon_debug(2,"identifier-ref-arg-str -> prefix : string"); } +/* choice */ +choice_stmt : K_CHOICE identifier_str ';' + { if (ysp_add(_yy, Y_CHOICE, $2, NULL) == NULL) _YYERROR("19"); + clicon_debug(2,"choice-stmt -> CHOICE id-arg-str ;"); } + | K_CHOICE identifier_str + { if (ysp_add_push(_yy, Y_CHOICE, $2) == NULL) _YYERROR("20"); } + '{' choice_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("21"); + clicon_debug(2,"choice-stmt -> CHOICE id-arg-str { choice-substmts }"); } ; -id_arg_str : string { $$=$1; clicon_debug(2,"id-arg-str -> string"); } - ; +choice_substmts : choice_substmts choice_substmt + { clicon_debug(2,"choice-substmts -> choice-substmts choice-substmt"); } + | choice_substmt + { clicon_debug(2,"choice-substmts -> choice-substmt"); } + ; + +choice_substmt : when_stmt { clicon_debug(2,"choice-substmt -> when-stmt"); } + | if_feature_stmt { clicon_debug(2,"choice-substmt -> if-feature-stmt"); } + | default_stmt { clicon_debug(2,"choice-substmt -> default-stmt"); } + | config_stmt { clicon_debug(2,"choice-substmt -> config-stmt"); } + | mandatory_stmt { clicon_debug(2,"choice-substmt -> mandatory-stmt"); } + | status_stmt { clicon_debug(2,"choice-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"choice-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"choice-substmt -> reference-stmt"); } + | short_case_stmt { clicon_debug(2,"choice-substmt -> short-case-stmt");} + | case_stmt { clicon_debug(2,"choice-substmt -> case-stmt");} + | unknown_stmt { clicon_debug(2,"choice-substmt -> unknown-stmt");} + | { clicon_debug(2,"choice-substmt -> "); } + ; + +/* case */ +case_stmt : K_CASE identifier_str ';' + { if (ysp_add(_yy, Y_CASE, $2, NULL) == NULL) _YYERROR("22"); + clicon_debug(2,"case-stmt -> CASE id-arg-str ;"); } + | K_CASE identifier_str + { if (ysp_add_push(_yy, Y_CASE, $2) == NULL) _YYERROR("23"); } + '{' case_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("24"); + clicon_debug(2,"case-stmt -> CASE id-arg-str { case-substmts }"); } + ; + +case_substmts : case_substmts case_substmt + { clicon_debug(2,"case-substmts -> case-substmts case-substmt"); } + | case_substmt + { clicon_debug(2,"case-substmts -> case-substmt"); } + ; + +case_substmt : when_stmt { clicon_debug(2,"case-substmt -> when-stmt"); } + | if_feature_stmt { clicon_debug(2,"case-substmt -> if-feature-stmt"); } + | status_stmt { clicon_debug(2,"case-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"case-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"case-substmt -> reference-stmt"); } + | data_def_stmt { clicon_debug(2,"case-substmt -> data-def-stmt");} + | unknown_stmt { clicon_debug(2,"case-substmt -> unknown-stmt");} + | { clicon_debug(2,"case-substmt -> "); } + ; + +anydata_stmt : K_ANYDATA identifier_str ';' + { if (ysp_add(_yy, Y_ANYDATA, $2, NULL) == NULL) _YYERROR("25"); + clicon_debug(2,"anydata-stmt -> ANYDATA id-arg-str ;"); } + | K_ANYDATA identifier_str + { if (ysp_add_push(_yy, Y_ANYDATA, $2) == NULL) _YYERROR("26"); } + '{' anyxml_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("27"); + clicon_debug(2,"anydata-stmt -> ANYDATA id-arg-str { anyxml-substmts }"); } + ; + +/* anyxml */ +anyxml_stmt : K_ANYXML identifier_str ';' + { if (ysp_add(_yy, Y_ANYXML, $2, NULL) == NULL) _YYERROR("25"); + clicon_debug(2,"anyxml-stmt -> ANYXML id-arg-str ;"); } + | K_ANYXML identifier_str + { if (ysp_add_push(_yy, Y_ANYXML, $2) == NULL) _YYERROR("26"); } + '{' anyxml_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("27"); + clicon_debug(2,"anyxml-stmt -> ANYXML id-arg-str { anyxml-substmts }"); } + ; + +anyxml_substmts : anyxml_substmts anyxml_substmt + { clicon_debug(2,"anyxml-substmts -> anyxml-substmts anyxml-substmt"); } + | anyxml_substmt + { clicon_debug(2,"anyxml-substmts -> anyxml-substmt"); } + ; + +anyxml_substmt : when_stmt { clicon_debug(2,"anyxml-substmt -> when-stmt"); } + | if_feature_stmt { clicon_debug(2,"anyxml-substmt -> if-feature-stmt"); } + | must_stmt { clicon_debug(2,"anyxml-substmt -> must-stmt"); } + | config_stmt { clicon_debug(2,"anyxml-substmt -> config-stmt"); } + | mandatory_stmt { clicon_debug(2,"anyxml-substmt -> mandatory-stmt"); } + | status_stmt { clicon_debug(2,"anyxml-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"anyxml-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"anyxml-substmt -> reference-stmt"); } + | ustring ':' ustring ';' { free($1); free($3); clicon_debug(2,"anyxml-substmt -> anyxml extension"); } + ; + +/* uses-stmt = uses-keyword identifier-ref-arg-str */ +uses_stmt : K_USES identifier_ref_str ';' + { if (ysp_add(_yy, Y_USES, $2, NULL) == NULL) _YYERROR("28"); + clicon_debug(2,"uses-stmt -> USES id-arg-str ;"); } + | K_USES identifier_ref_str + { if (ysp_add_push(_yy, Y_USES, $2) == NULL) _YYERROR("29"); } + '{' uses_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("30"); + clicon_debug(2,"uses-stmt -> USES id-arg-str { uses-substmts }"); } + ; + +uses_substmts : uses_substmts uses_substmt + { clicon_debug(2,"uses-substmts -> uses-substmts uses-substmt"); } + | uses_substmt + { clicon_debug(2,"uses-substmts -> uses-substmt"); } + ; + +uses_substmt : when_stmt { clicon_debug(2,"uses-substmt -> when-stmt"); } + | if_feature_stmt { clicon_debug(2,"uses-substmt -> if-feature-stmt"); } + | status_stmt { clicon_debug(2,"uses-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"uses-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"uses-substmt -> reference-stmt"); } + | refine_stmt { clicon_debug(2,"uses-substmt -> refine-stmt"); } + | uses_augment_stmt { clicon_debug(2,"uses-substmt -> uses-augment-stmt"); } + | unknown_stmt { clicon_debug(2,"uses-substmt -> unknown-stmt");} + | { clicon_debug(2,"uses-substmt -> "); } + ; + +/* refine-stmt = refine-keyword sep refine-arg-str */ +refine_stmt : K_REFINE desc_schema_node_str ';' + { if (ysp_add(_yy, Y_REFINE, $2, NULL) == NULL) _YYERROR("31"); + clicon_debug(2,"refine-stmt -> REFINE id-arg-str ;"); } + | K_REFINE desc_schema_node_str + { if (ysp_add_push(_yy, Y_REFINE, $2) == NULL) _YYERROR("32"); } + '{' refine_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("33"); + clicon_debug(2,"refine-stmt -> REFINE id-arg-str { refine-substmts }"); } + ; + +refine_substmts : refine_substmts refine_substmt + { clicon_debug(2,"refine-substmts -> refine-substmts refine-substmt"); } + | 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"); } + | default_stmt { clicon_debug(2,"refine-substmt -> default-stmt"); } + | unknown_stmt { clicon_debug(2,"refine-substmt -> unknown-stmt");} + | { clicon_debug(2,"refine-substmt -> "); } + ; + +/* uses-augment-stmt = augment-keyword augment-arg-str */ +uses_augment_stmt : K_AUGMENT desc_schema_node_str + { if (ysp_add_push(_yy, Y_AUGMENT, $2) == NULL) _YYERROR("34"); } + '{' augment_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("35"); + clicon_debug(2,"uses-augment-stmt -> AUGMENT desc-schema-node-str { augment-substmts }"); } + + +/* augment-stmt = augment-keyword sep augment-arg-str + * XXX abs-schema-nodeid-str is too difficult, it needs the + semantics + */ +augment_stmt : K_AUGMENT string + { if (ysp_add_push(_yy, Y_AUGMENT, $2) == NULL) _YYERROR("34"); } + '{' augment_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("35"); + clicon_debug(2,"augment-stmt -> AUGMENT abs-schema-node-str { augment-substmts }"); } + ; + +augment_substmts : augment_substmts augment_substmt + { clicon_debug(2,"augment-substmts -> augment-substmts augment-substmt"); } + | augment_substmt + { clicon_debug(2,"augment-substmts -> augment-substmt"); } + ; + +augment_substmt : when_stmt { clicon_debug(2,"augment-substmt -> when-stmt"); } + | if_feature_stmt { clicon_debug(2,"augment-substmt -> if-feature-stmt"); } + | status_stmt { clicon_debug(2,"augment-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"augment-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"augment-substmt -> reference-stmt"); } + | data_def_stmt { clicon_debug(2,"augment-substmt -> data-def-stmt"); } + | case_stmt { clicon_debug(2,"augment-substmt -> case-stmt");} + | action_stmt { clicon_debug(2,"augment-substmt -> action-stmt");} + | notification_stmt { clicon_debug(2,"augment-substmt -> notification-stmt");} + | { clicon_debug(2,"augment-substmt -> "); } + ; + +/* when */ +when_stmt : K_WHEN string ';' + { if (ysp_add(_yy, Y_WHEN, $2, NULL) == NULL) _YYERROR("36"); + clicon_debug(2,"when-stmt -> WHEN string ;"); } + | K_WHEN string + { if (ysp_add_push(_yy, Y_WHEN, $2) == NULL) _YYERROR("37"); } + '{' when_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("38"); + clicon_debug(2,"when-stmt -> WHEN string { when-substmts }"); } + ; + +when_substmts : when_substmts when_substmt + { clicon_debug(2,"when-substmts -> when-substmts when-substmt"); } + | when_substmt + { clicon_debug(2,"when-substmts -> when-substmt"); } + ; + +when_substmt : description_stmt { clicon_debug(2,"when-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"when-substmt -> reference-stmt"); } + | { clicon_debug(2,"when-substmt -> "); } + ; + +/* rpc */ +rpc_stmt : K_RPC identifier_str ';' + { if (ysp_add(_yy, Y_RPC, $2, NULL) == NULL) _YYERROR("39"); + clicon_debug(2,"rpc-stmt -> RPC id-arg-str ;"); } + | K_RPC identifier_str + { if (ysp_add_push(_yy, Y_RPC, $2) == NULL) _YYERROR("40"); } + '{' rpc_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("41"); + clicon_debug(2,"rpc-stmt -> RPC id-arg-str { rpc-substmts }"); } + ; + +rpc_substmts : rpc_substmts rpc_substmt + { clicon_debug(2,"rpc-substmts -> rpc-substmts rpc-substmt"); } + | rpc_substmt + { clicon_debug(2,"rpc-substmts -> rpc-substmt"); } + ; + +rpc_substmt : if_feature_stmt { clicon_debug(2,"rpc-substmt -> if-feature-stmt"); } + | status_stmt { clicon_debug(2,"rpc-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"rpc-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"rpc-substmt -> reference-stmt"); } + | typedef_stmt { clicon_debug(2,"rpc-substmt -> typedef-stmt"); } + | grouping_stmt { clicon_debug(2,"rpc-substmt -> grouping-stmt"); } + | input_stmt { clicon_debug(2,"rpc-substmt -> input-stmt"); } + | output_stmt { clicon_debug(2,"rpc-substmt -> output-stmt"); } + | { clicon_debug(2,"rpc-substmt -> "); } + ; + +/* action */ +action_stmt : K_ACTION identifier_str ';' + { if (ysp_add(_yy, Y_ACTION, $2, NULL) == NULL) _YYERROR("39"); + clicon_debug(2,"action-stmt -> ACTION id-arg-str ;"); } + | K_ACTION identifier_str + { if (ysp_add_push(_yy, Y_ACTION, $2) == NULL) _YYERROR("40"); } + '{' rpc_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("41"); + clicon_debug(2,"action-stmt -> ACTION id-arg-str { rpc-substmts }"); } + ; + +/* notification */ +notification_stmt : K_NOTIFICATION identifier_str ';' + { if (ysp_add(_yy, Y_NOTIFICATION, $2, NULL) == NULL) _YYERROR("46"); + clicon_debug(2,"notification-stmt -> NOTIFICATION id-arg-str ;"); } + | K_NOTIFICATION identifier_str + { if (ysp_add_push(_yy, Y_NOTIFICATION, $2) == NULL) _YYERROR("47"); } + '{' notification_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("48"); + clicon_debug(2,"notification-stmt -> NOTIFICATION id-arg-str { notification-substmts }"); } + ; + +notification_substmts : notification_substmts notification_substmt + { clicon_debug(2,"notification-substmts -> notification-substmts notification-substmt"); } + | notification_substmt + { clicon_debug(2,"notification-substmts -> notification-substmt"); } + ; + +notification_substmt : if_feature_stmt { clicon_debug(2,"notification-substmt -> if-feature-stmt"); } + | must_stmt { clicon_debug(2,"notification-substmt -> must-stmt"); } + | status_stmt { clicon_debug(2,"notification-substmt -> status-stmt"); } + | description_stmt { clicon_debug(2,"notification-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"notification-substmt -> reference-stmt"); } + | typedef_stmt { clicon_debug(2,"notification-substmt -> typedef-stmt"); } + | grouping_stmt { clicon_debug(2,"notification-substmt -> grouping-stmt"); } + | data_def_stmt { clicon_debug(2,"notification-substmt -> data-def-stmt"); } + | { clicon_debug(2,"notification-substmt -> "); } + ; + +/* deviation /oc-sys:system/oc-sys:config/oc-sys:hostname { + deviate not-supported; + } + * XXX abs-schema-nodeid-str is too difficult, it needs the + semantics + +*/ +deviation_stmt : K_DEVIATION string + { if (ysp_add_push(_yy, Y_DEVIATION, $2) == NULL) _YYERROR("47"); } + '{' deviation_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("48"); + clicon_debug(2,"deviation-stmt -> DEVIATION id-arg-str { notification-substmts }"); } + ; + +deviation_substmts : deviation_substmts deviation_substmt + { clicon_debug(2,"deviation-substmts -> deviation-substmts deviation-substmt"); } + | deviation_substmt + { clicon_debug(2,"deviation-substmts -> deviation-substmt"); } + ; + +deviation_substmt : description_stmt { clicon_debug(2,"deviation-substmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"deviation-substmt -> reference-stmt"); } + | deviate_not_supported_stmt { clicon_debug(2,"deviation-substmt -> deviate-not-supported-stmt"); } + ; + +deviate_not_supported_stmt : K_DEVIATE string { clicon_debug(2,"deviate-not-supported-stmt -> DEVIATE string"); } + ; + +meta_stmt : organization_stmt { clicon_debug(2,"meta-stmt -> organization-stmt"); } + | contact_stmt { clicon_debug(2,"meta-stmt -> contact-stmt"); } + | description_stmt { clicon_debug(2,"meta-stmt -> description-stmt"); } + | reference_stmt { clicon_debug(2,"meta-stmt -> reference-stmt"); } + ; + +/* body */ +body_stmts : body_stmts body_stmt { clicon_debug(2,"body-stmts -> body-stmts body-stmt"); } + | body_stmt { clicon_debug(2,"body-stmts -> body-stmt");} + ; + +body_stmt : extension_stmt { clicon_debug(2,"body-stmt -> extension-stmt");} + | feature_stmt { clicon_debug(2,"body-stmt -> feature-stmt");} + | identity_stmt { clicon_debug(2,"body-stmt -> identity-stmt");} + | typedef_stmt { clicon_debug(2,"body-stmt -> typedef-stmt");} + | grouping_stmt { clicon_debug(2,"body-stmt -> grouping-stmt");} + | data_def_stmt { clicon_debug(2,"body-stmt -> data-def-stmt");} + | augment_stmt { clicon_debug(2,"body-stmt -> augment-stmt");} + | rpc_stmt { clicon_debug(2,"body-stmt -> rpc-stmt");} + | notification_stmt { clicon_debug(2,"body-stmt -> notification-stmt");} + | deviation_stmt { clicon_debug(2,"body-stmt -> deviation-stmt");} + ; + +data_def_stmt : container_stmt { clicon_debug(2,"data-def-stmt -> container-stmt");} + | leaf_stmt { clicon_debug(2,"data-def-stmt -> leaf-stmt");} + | leaf_list_stmt { clicon_debug(2,"data-def-stmt -> leaf-list-stmt");} + | list_stmt { clicon_debug(2,"data-def-stmt -> list-stmt");} + | choice_stmt { clicon_debug(2,"data-def-stmt -> choice-stmt");} + | anydata_stmt { clicon_debug(2,"data-def-stmt -> anydata-stmt");} + | anyxml_stmt { clicon_debug(2,"data-def-stmt -> anyxml-stmt");} + | uses_stmt { clicon_debug(2,"data-def-stmt -> uses-stmt");} + ; + +/* short-case */ +short_case_stmt : container_stmt { clicon_debug(2,"short-case-substmt -> container-stmt"); } + | leaf_stmt { clicon_debug(2,"short-case-substmt -> leaf-stmt"); } + | leaf_list_stmt { clicon_debug(2,"short-case-substmt -> leaf-list-stmt"); } + | list_stmt { clicon_debug(2,"short-case-substmt -> list-stmt"); } + | anydata_stmt { clicon_debug(2,"short-case-substmt -> anydata-stmt");} + | anyxml_stmt { clicon_debug(2,"short-case-substmt -> anyxml-stmt");} + ; + + +/* input */ +input_stmt : K_INPUT + { if (ysp_add_push(_yy, Y_INPUT, NULL) == NULL) _YYERROR("42"); } + '{' input_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("43"); + clicon_debug(2,"input-stmt -> INPUT { input-substmts }"); } + ; + +input_substmts : input_substmts input_substmt + { clicon_debug(2,"input-substmts -> input-substmts input-substmt"); } + | input_substmt + { clicon_debug(2,"input-substmts -> input-substmt"); } + ; + +input_substmt : typedef_stmt { clicon_debug(2,"input-substmt -> typedef-stmt"); } + | grouping_stmt { clicon_debug(2,"input-substmt -> grouping-stmt"); } + | data_def_stmt { clicon_debug(2,"input-substmt -> data-def-stmt"); } + | { clicon_debug(2,"input-substmt -> "); } + ; + +/* output */ +output_stmt : K_OUTPUT /* XXX reuse input-substatements since they are same */ + { if (ysp_add_push(_yy, Y_OUTPUT, NULL) == NULL) _YYERROR("44"); } + '{' input_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("45"); + clicon_debug(2,"output-stmt -> OUTPUT { input-substmts }"); } + ; + + + string : qstrings { $$=$1; clicon_debug(2,"string -> qstrings (%s)", $1); } | ustring { $$=$1; clicon_debug(2,"string -> ustring (%s)", $1); } @@ -1457,7 +1538,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 \"");} + | SQ ustring SQ { $$=$2; clicon_debug(2,"string-> ' ustring '"); } ; /* unquoted string */ @@ -1473,6 +1555,67 @@ ustring : ustring CHAR ; +abs_schema_nodeid : abs_schema_nodeid '/' node_identifier + { if (($$=string_del_join($1, "/", $3)) == NULL) _YYERROR("0"); + clicon_debug(2,"absolute-schema-nodeid -> absolute-schema-nodeid / node-identifier"); } + | '/' node_identifier + { if (($$=string_del_join(NULL, "/", $2)) == NULL) _YYERROR("0"); + clicon_debug(2,"absolute-schema-nodeid -> / node-identifier"); } + ; + +desc_schema_node_str : desc_schema_nodeid + { $$=$1; clicon_debug(2,"descendant-schema-node-str -> descendant-node"); } + | '"' desc_schema_nodeid '"' + { $$=$2; clicon_debug(2,"descendant-schema-node-str -> descendant-node"); } + ; + +desc_schema_nodeid : node_identifier + { $$= $1; clicon_debug(2,"descendant-schema-nodeid -> node_identifier"); } + | node_identifier abs_schema_nodeid + { if (($$=string_del_join($1, " ", $2)) == NULL) _YYERROR("0");clicon_debug(2,"descendant-schema-nodeid -> node_identifier abs_schema_nodeid"); } + ; + +identifier_str : '"' IDENTIFIER '"' { $$ = $2; + clicon_debug(2,"identifier_str -> \" IDENTIFIER \" ");} + | IDENTIFIER { $$ = $1; + clicon_debug(2,"identifier_str -> IDENTIFIER ");} + ; + +identifier_ref_str : '"' identifier_ref '"' { $$ = $2; + clicon_debug(2,"identifier_ref_str -> \" identifier_ref \" ");} + | identifier_ref { $$ = $1; + clicon_debug(2,"identifier_ref_str -> identifier_ref ");} + ; + +integer_value_str : '"' INT '"' { $$=$2; } + | INT { $$=$1; } + ; + +bool_str : '"' BOOL '"' { $$ = $2; + clicon_debug(2,"bool_str -> \" BOOL \" ");} + | BOOL { $$ = $1; + clicon_debug(2,"bool_str -> BOOL ");} + ; + + +/* node-identifier = [prefix ":"] identifier */ +node_identifier : IDENTIFIER + { $$=$1; clicon_debug(2,"identifier-ref-arg-str -> string"); } + | IDENTIFIER ':' IDENTIFIER + { if (($$=string_del_join($1, ":", $3)) == NULL) _YYERROR("112"); + clicon_debug(2,"identifier-ref-arg-str -> prefix : string"); } + ; + +/* ;;; Basic Rules */ + +/* identifier-ref = [prefix ":"] identifier */ +identifier_ref : node_identifier { $$=$1;} + ; + +stmtend : ';' + | '{' '}' + | '{' unknown_stmt '}' + ; %% diff --git a/test/test_openconfig.sh b/test/test_openconfig.sh new file mode 100755 index 00000000..6ed5423b --- /dev/null +++ b/test/test_openconfig.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Parse yang openconfig tests +#PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_yang" +PROG=../util/clixon_util_yang +OPENCONFIG=~/syssrc/openconfig + +# include err() and new() functions and creates $dir +. ./lib.sh + +# Openconfig +# Files not parseable: +# - openconfig-access-points.yang +# - openconfig-access-points.yang +new "Openconfig" +files=$(find $OPENCONFIG -name "*.yang") +for f in $files; do + new "$f" + YANG=$(cat $f) + # NYI + expecteof "$PROG" 0 "$YANG" "module" +done +rm -rf $dir + + diff --git a/test/test_yang_parse.sh b/test/test_yang_parse.sh index c8024a3d..3790645f 100755 --- a/test/test_yang_parse.sh +++ b/test/test_yang_parse.sh @@ -1,27 +1,11 @@ #!/bin/bash # Test: YANG parser tests -# First an example yang, second all openconfig yangs -# Problem with this is that util only parses single file. it should -# call yang_parse(). #PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_yang" PROG=../util/clixon_util_yang -OPENCONFIG=~/syssrc/openconfig -exit 0 # nyi + # include err() and new() functions and creates $dir . ./lib.sh -# Openconfig -# Files not parseable: -# - openconfig-access-points.yang -# - openconfig-access-points.yang -new "Openconfig" -files=$(find $OPENCONFIG -name "*.yang") -for f in $files; do - new "$f" - YANG=$(cat $f) - # NYI - expecteof "$PROG" 0 "$YANG" "module" -done rm -rf $dir