From d48b8a8fadc3a90a7436a3c10b9476a65e4c4dde Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sat, 24 Apr 2021 12:31:40 +0200 Subject: [PATCH] -Yang Deviation/deviate : added yacc/lex syntax --- CHANGELOG.md | 6 ++ apps/restconf/restconf_api_native.c | 1 + codecov.yml | 3 +- lib/src/clixon_yang_parse.l | 22 +++-- lib/src/clixon_yang_parse.y | 124 ++++++++++++++++++++-------- 5 files changed, 111 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcef7c22..83c41a82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,12 @@ ## 5.2.0 Expected: June 2021 +### New features + +* Yang Deviation/deviate [deviation statement not yet support #211](https://github.com/clicon/clixon/issues/211) + * See RFC7950 Sec 5.6.3 + * Work-in-progress + ### Minor features * Add default network namespace constant: `RESTCONF_NETNS_DEFAULT` with default value "default". diff --git a/apps/restconf/restconf_api_native.c b/apps/restconf/restconf_api_native.c index d7822eb7..2190f1a3 100644 --- a/apps/restconf/restconf_api_native.c +++ b/apps/restconf/restconf_api_native.c @@ -132,6 +132,7 @@ restconf_reply_send(void *req0, evhtp_connection_t *conn; struct evbuffer *eb = NULL; + clicon_debug(1, "%s code:%d", __FUNCTION__, code); req->status = code; if ((reason_phrase = restconf_code2reason(code)) == NULL) reason_phrase=""; diff --git a/codecov.yml b/codecov.yml index 0a0c5744..f7ba12da 100644 --- a/codecov.yml +++ b/codecov.yml @@ -20,4 +20,5 @@ comment: require_changes: no ignore: - - "util" # ignore folders and all its contents + - "util/" # ignore folders and all its contents + diff --git a/lib/src/clixon_yang_parse.l b/lib/src/clixon_yang_parse.l index fd84265c..f032c814 100644 --- a/lib/src/clixon_yang_parse.l +++ b/lib/src/clixon_yang_parse.l @@ -92,6 +92,7 @@ clixon_yang_parsewrap(void) identifier [A-Za-z_][A-Za-z0-9_\-\.]* %x KEYWORD +%x DEVIATE %s BOOLEAN %s INTEGER %s STRARG @@ -106,12 +107,12 @@ identifier [A-Za-z_][A-Za-z0-9_\-\.]* %% /* Common tokens */ -[ \t] -<> { return MY_EOF; } -\n { _YY->yy_linenum++; } -\r -"/*" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT1); } -"//" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT2); } +[ \t] +<> { return MY_EOF; } +\n { _YY->yy_linenum++; } +\r +"/*" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT1); } +"//" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT2); } input { return K_INPUT; } /* No argument */ @@ -163,7 +164,7 @@ identifier [A-Za-z_][A-Za-z0-9_\-\.]* contact { BEGIN(STRING); return K_CONTACT; } default { BEGIN(STRING); return K_DEFAULT; } description { BEGIN(STRING); return K_DESCRIPTION; } -deviate { BEGIN(STRING); return K_DEVIATE; } +deviate { BEGIN(DEVIATE); 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; } @@ -182,7 +183,7 @@ identifier [A-Za-z_][A-Za-z0-9_\-\.]* pattern { BEGIN(STRING); return K_PATTERN; } presence { BEGIN(STRING); return K_PRESENCE; } unique { BEGIN(STRING); return K_UNIQUE; } -range { BEGIN(STRING); return K_RANGE; } +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; } @@ -197,6 +198,11 @@ identifier [A-Za-z_][A-Za-z0-9_\-\.]* . { clixon_yang_parselval.string = strdup(yytext); BEGIN(UNKNOWN); return CHARS; } +not-supported { BEGIN(KEYWORD); return D_NOT_SUPPORTED; } +add { BEGIN(KEYWORD); return D_ADD; } +delete { BEGIN(KEYWORD); return D_DELETE; } +replace { BEGIN(KEYWORD); return D_REPLACE; } +. { BEGIN(KEYWORD); return *yytext; } : { return *yytext; } ; { BEGIN(KEYWORD); return *yytext; } \{ { BEGIN(KEYWORD); return *yytext; } diff --git a/lib/src/clixon_yang_parse.y b/lib/src/clixon_yang_parse.y index ad171346..a6b979de 100644 --- a/lib/src/clixon_yang_parse.y +++ b/lib/src/clixon_yang_parse.y @@ -156,6 +156,13 @@ %token K_YIN_ELEMENT +/* Deviate keywords + */ +%token D_NOT_SUPPORTED +%token D_ADD +%token D_DELETE +%token D_REPLACE + %lex-param {void *_yy} /* Add this argument to parse() and lex() function */ %parse-param {void *_yy} @@ -1522,46 +1529,93 @@ deviation_substmts : deviation_substmts deviation_substmt deviation_substmt : description_stmt { _PARSE_DEBUG("deviation-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("deviation-substmt -> reference-stmt"); } - | deviate_stmt { _PARSE_DEBUG("deviation-substmt -> deviate-stmt"); } + | deviate_not_supported_stmt { _PARSE_DEBUG("yang-stmt -> deviate-not-supported-stmt");} + | deviate_add_stmt { _PARSE_DEBUG("deviation-stmt -> deviate-add-stmt");} + | deviate_delete_stmt { _PARSE_DEBUG("deviation-stmt -> deviate-delete-stmt");} + | deviate_replace_stmt { _PARSE_DEBUG("deviation-stmt -> deviate-replace-stmt");} ; -/* RFC7950 differentiates between deviate-not-supported, deviate-add, - * deviate-replave, and deviate-delete. Here all are bundled into a single - * deviate rule. For now, until "deviate" gets supported. - */ -deviate_stmt : K_DEVIATE string ';' - { if (ysp_add(_yy, Y_DEVIATE, $2, NULL) == NULL) _YYERROR("notification_stmt"); - _PARSE_DEBUG("deviate-not-supported-stmt -> DEVIATE string ;"); } - | K_DEVIATE string - { if (ysp_add_push(_yy, Y_DEVIATE, $2, NULL) == NULL) _YYERROR("deviate_stmt"); } - '{' deviate_substmts '}' +deviate_not_supported_stmt + : K_DEVIATE D_NOT_SUPPORTED ';' + { if (ysp_add(_yy, Y_DEVIATE, strdup("not-supported") /* D_NOT_SUPPORTED*/, NULL) == NULL) _YYERROR("notification_stmt"); + _PARSE_DEBUG("deviate-not-supported-stmt -> DEVIATE not-supported ;"); } + ; + +deviate_add_stmt : K_DEVIATE D_ADD ';' + { if (ysp_add(_yy, Y_DEVIATE, strdup("add") /* D_NOT_SUPPORTED*/, NULL) == NULL) _YYERROR("notification_stmt"); + _PARSE_DEBUG("deviate-add-stmt -> DEVIATE add ;"); } + | K_DEVIATE D_ADD + { if (ysp_add_push(_yy, Y_DEVIATE, strdup("add"), NULL) == NULL) _YYERROR("deviate_stmt"); } + '{' deviate_add_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("deviate_stmt"); - _PARSE_DEBUG("deviate-stmt -> DEVIATE string { deviate-substmts }"); } + _PARSE_DEBUG("deviate-add-stmt -> DEVIATE add { deviate-substmts }"); } ; -/* RFC7950 differentiates between deviate-not-supported, deviate-add, - * deviate-replave, and deviate-delete. Here all are bundled into a single - * deviate-substmt rule. For now, until "deviate" gets supported. - */ -deviate_substmts : deviate_substmts deviate_substmt - { _PARSE_DEBUG("deviate-substmts -> deviate-substmts deviate-substmt"); } - | deviate_substmt - { _PARSE_DEBUG("deviate-substmts -> deviate-substmt"); } +deviate_add_substmts : deviate_add_substmts deviate_add_substmt + { _PARSE_DEBUG("deviate-add-substmts -> deviate-add-substmts deviate-add-substmt"); } + | deviate_add_substmt + { _PARSE_DEBUG("deviate-add-substmts -> deviate-add-substmt"); } ; -/* Bundled */ -deviate_substmt : type_stmt { _PARSE_DEBUG("deviate-substmt -> type-stmt"); } - | units_stmt { _PARSE_DEBUG("deviate-substmt -> units-stmt"); } - | must_stmt { _PARSE_DEBUG("deviate-substmt -> must-stmt"); } - | unique_stmt { _PARSE_DEBUG("deviate-substmt -> unique-stmt"); } - | default_stmt { _PARSE_DEBUG("deviate-substmt -> default-stmt"); } - | config_stmt { _PARSE_DEBUG("deviate-substmt -> config-stmt"); } - | mandatory_stmt { _PARSE_DEBUG("deviate-substmt -> mandatory-stmt"); } - | min_elements_stmt { _PARSE_DEBUG("deviate-substmt -> min-elements-stmt"); } - | max_elements_stmt { _PARSE_DEBUG("deviate-substmt -> max-elements-stmt"); } - | { _PARSE_DEBUG("deviate-substmt -> "); } +deviate_add_substmt : units_stmt { _PARSE_DEBUG("deviate-add-substmt -> units-stmt"); } + | must_stmt { _PARSE_DEBUG("deviate-add-substmt -> must-stmt"); } + | unique_stmt { _PARSE_DEBUG("deviate-add-substmt -> unique-stmt"); } + | default_stmt { _PARSE_DEBUG("deviate-add-substmt -> default-stmt"); } + | config_stmt { _PARSE_DEBUG("deviate-add-substmt -> config-stmt"); } + | mandatory_stmt { _PARSE_DEBUG("deviate-add-substmt -> mandatory-stmt"); } + | min_elements_stmt { _PARSE_DEBUG("deviate-add-substmt -> min-elements-stmt"); } + | max_elements_stmt { _PARSE_DEBUG("deviate-add-substmt -> max-elements-stmt"); } + | { _PARSE_DEBUG("deviate-add-substmt -> "); } ; +deviate_delete_stmt : K_DEVIATE D_DELETE ';' + { if (ysp_add(_yy, Y_DEVIATE, strdup("add") /* D_NOT_SUPPORTED*/, NULL) == NULL) _YYERROR("notification_stmt"); + _PARSE_DEBUG("deviate-delete-stmt -> DEVIATE add ;"); } + | K_DEVIATE D_DELETE + { if (ysp_add_push(_yy, Y_DEVIATE, strdup("add"), NULL) == NULL) _YYERROR("deviate_stmt"); } + '{' deviate_delete_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("deviate_stmt"); + _PARSE_DEBUG("deviate-delete-stmt -> DEVIATE add { deviate-substmts }"); } + ; + +deviate_delete_substmts : deviate_delete_substmts deviate_delete_substmt + { _PARSE_DEBUG("deviate-delete-substmts -> deviate-delete-substmts deviate-delete-substmt"); } + | deviate_delete_substmt + { _PARSE_DEBUG("deviate-delete-substmts -> deviate-delete-substmt"); } + ; +deviate_delete_substmt : units_stmt { _PARSE_DEBUG("deviate-delete-substmt -> units-stmt"); } + | must_stmt { _PARSE_DEBUG("deviate-delete-substmt -> must-stmt"); } + | unique_stmt { _PARSE_DEBUG("deviate-delete-substmt -> unique-stmt"); } + | default_stmt { _PARSE_DEBUG("deviate-delete-substmt -> default-stmt"); } + | { _PARSE_DEBUG("deviate-delete-substmt -> "); } + ; + + +deviate_replace_stmt : K_DEVIATE D_REPLACE ';' + { if (ysp_add(_yy, Y_DEVIATE, strdup("add") /* D_NOT_SUPPORTED*/, NULL) == NULL) _YYERROR("notification_stmt"); + _PARSE_DEBUG("deviate-replace-stmt -> DEVIATE add ;"); } + | K_DEVIATE D_REPLACE + { if (ysp_add_push(_yy, Y_DEVIATE, strdup("add"), NULL) == NULL) _YYERROR("deviate_stmt"); } + '{' deviate_replace_substmts '}' + { if (ystack_pop(_yy) < 0) _YYERROR("deviate_stmt"); + _PARSE_DEBUG("deviate-replace-stmt -> DEVIATE add { deviate-substmts }"); } + ; + +deviate_replace_substmts : deviate_replace_substmts deviate_replace_substmt + { _PARSE_DEBUG("deviate-replace-substmts -> deviate-replace-substmts deviate-replace-substmt"); } + | deviate_replace_substmt + { _PARSE_DEBUG("deviate-replace-substmts -> deviate-replace-substmt"); } + ; +deviate_replace_substmt : type_stmt { _PARSE_DEBUG("deviate-replace-substmt -> type-stmt"); } + | units_stmt { _PARSE_DEBUG("deviate-replace-substmt -> units-stmt"); } + | default_stmt { _PARSE_DEBUG("deviate-replace-substmt -> default-stmt"); } + | config_stmt { _PARSE_DEBUG("deviate-replace-substmt -> config-stmt"); } + | mandatory_stmt { _PARSE_DEBUG("deviate-replace-substmt -> mandatory-stmt"); } + | min_elements_stmt { _PARSE_DEBUG("deviate-replace-substmt -> min-elements-stmt"); } + | max_elements_stmt { _PARSE_DEBUG("deviate-replace-substmt -> max-elements-stmt"); } + | { _PARSE_DEBUG("deviate-replace-substmt -> "); } + ; + /* Represents the usage of an extension unknown-statement = prefix ":" identifier [sep string] optsep (";" / @@ -1612,12 +1666,10 @@ yang_stmt : action_stmt { _PARSE_DEBUG("yang-stmt -> action-stmt"); | container_stmt { _PARSE_DEBUG("yang-stmt -> container-stmt");} | default_stmt { _PARSE_DEBUG("yang-stmt -> default-stmt");} | description_stmt { _PARSE_DEBUG("yang-stmt -> description-stmt");} - | deviate_stmt { _PARSE_DEBUG("yang-stmt -> deviate-stmt");} - /* deviate is not yet implemented, the above may be replaced by the following lines + | deviate_not_supported_stmt { _PARSE_DEBUG("yang-stmt -> deviate-not-supported-stmt");} | deviate_add_stmt { _PARSE_DEBUG("yang-stmt -> deviate-add-stmt");} - | deviate_delete_stmt { _PARSE_DEBUG("yang-stmt -> deviate-add-stmt");} - | deviate_replace_stmt { _PARSE_DEBUG("yang-stmt -> deviate-add-stmt");} - */ + | deviate_delete_stmt { _PARSE_DEBUG("yang-stmt -> deviate-delete-stmt");} + | deviate_replace_stmt { _PARSE_DEBUG("yang-stmt -> deviate-replace-stmt");} | deviation_stmt { _PARSE_DEBUG("yang-stmt -> deviation-stmt");} | enum_stmt { _PARSE_DEBUG("yang-stmt -> enum-stmt");} | error_app_tag_stmt { _PARSE_DEBUG("yang-stmt -> error-app-tag-stmt");}