yin parser CHANGE add support for yang-version element
diff --git a/src/parser_yin.c b/src/parser_yin.c
index cd5c433..59fa8d9 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -723,6 +723,7 @@
                     ret = yin_parse_when(ctx, subelem_attrs, data, (struct lysp_when **)subelem_info_rec->dest);
                     break;
                 case YANG_YANG_VERSION:
+                    ret = yin_parse_yangversion(ctx, subelem_attrs, data, (uint8_t *)subelem_info_rec->dest, exts);
                     break;
                 case YANG_YIN_ELEMENT:
                     ret = yin_parse_yin_element_element(ctx, subelem_attrs, data, (uint16_t *)subelem_info_rec->dest, exts);
@@ -775,12 +776,10 @@
 yin_parse_revision_date(struct yin_parser_ctx *ctx, struct yin_arg_record **attrs, const char **data, char *rev,
                         struct lysp_ext_instance **exts)
 {
-    LY_ERR ret = LY_SUCCESS;
     const char *temp_rev;
     struct yin_subelement subelems[1] = {{YANG_CUSTOM, NULL, 0}};
 
     LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_DATE, &temp_rev, Y_STR_ARG, YANG_REVISION_DATE));
-    LY_CHECK_RET(ret != LY_SUCCESS, ret);
     LY_CHECK_RET(lysp_check_date((struct lys_parser_ctx *)ctx, temp_rev, strlen(temp_rev), "revision-date") != LY_SUCCESS, LY_EVALID);
 
     strcpy(rev, temp_rev);
@@ -790,6 +789,29 @@
 }
 
 LY_ERR
+yin_parse_yangversion(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, uint8_t *version,
+                      struct lysp_ext_instance **exts)
+{
+    const char *temp_version = NULL;
+    struct yin_subelement subelems[1] = {{YANG_CUSTOM, NULL, 0}};
+
+    LY_CHECK_RET(yin_parse_attribute(ctx, &attrs, YIN_ARG_VALUE, &temp_version, Y_STR_ARG, YANG_YANG_VERSION));
+    if (strcmp(temp_version, "1.0") == 0) {
+        *version = LYS_VERSION_1_0;
+    } else if (strcmp(temp_version, "1.1") == 0) {
+        *version = LYS_VERSION_1_1;
+    } else {
+        LOGVAL_PARSER((struct lys_parser_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_version, "yang-version");
+        FREE_STRING(ctx->xml_ctx.ctx, temp_version);
+        return LY_EVALID;
+    }
+    FREE_STRING(ctx->xml_ctx.ctx, temp_version);
+    ctx->mod_version = *version;
+
+    return yin_parse_content(ctx, subelems, 1, data, YANG_YANG_VERSION, NULL, exts);
+}
+
+LY_ERR
 yin_parse_import(struct yin_parser_ctx *ctx, struct yin_arg_record **attrs, const char **data, struct lysp_module *mod)
 {
     struct lysp_import *imp;
@@ -802,7 +824,7 @@
                                          {YANG_REVISION_DATE, imp->rev, YIN_SUBELEM_UNIQUE},
                                          {YANG_CUSTOM, NULL, 0}};
 
-    /* parse import attributes  */
+    /* parse import attributes */
     LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_MODULE, &imp->name, Y_IDENTIF_ARG, YANG_IMPORT));
     LY_CHECK_RET(yin_parse_content(ctx, subelems, 5, data, YANG_IMPORT, NULL, &imp->exts));
     /* check prefix validity */
diff --git a/src/parser_yin.h b/src/parser_yin.h
index a827233..32060a5 100644
--- a/src/parser_yin.h
+++ b/src/parser_yin.h
@@ -117,6 +117,20 @@
                          struct lysp_ext_instance **exts);
 
 /**
+ * @brief Parse yang-version element.
+ *
+ * @param[in,out] ctx Yin parser context for logging and to store current state.
+ * @param[in] attrs Attributes of when element.
+ * @param[in] data Data to read from, always moved to currently handled character.
+ * @param[out] version Storage for the parsed information.
+ * @param[in,out] exts Extension instance to add to.
+ *
+ * @return LY_ERR values.
+ */
+LY_ERR yin_parse_yangversion(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, uint8_t *version,
+                             struct lysp_ext_instance **exts);
+
+/**
  * @brief Parse import element.
  *
  * @param[in,out] ctx Yin parser context for logging and to store current state.
diff --git a/tests/src/test_parser_yin.c b/tests/src/test_parser_yin.c
index 80be04d..df90385 100644
--- a/tests/src/test_parser_yin.c
+++ b/tests/src/test_parser_yin.c
@@ -765,6 +765,51 @@
     st->finished_correctly = true;
 }
 
+static void
+test_yin_parse_yangversion(void **state)
+{
+    struct state *st = *state;
+    LY_ERR ret = LY_SUCCESS;
+    struct sized_string name, prefix;
+    struct yin_arg_record *attrs = NULL;
+    uint8_t version;
+
+    const char *data = "<yang-version xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" value=\"1.0\">\n"
+                       "</yang-version>";
+    lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
+    yin_load_attributes(st->yin_ctx, &data, &attrs);
+    ret = yin_parse_yangversion(st->yin_ctx, attrs, &data, &version, NULL);
+    assert_int_equal(LY_SUCCESS, ret);
+    assert_true(version == LYS_VERSION_1_0);
+    assert_true(st->yin_ctx->mod_version == LYS_VERSION_1_0);
+    LY_ARRAY_FREE(attrs);
+    attrs = NULL;
+    st = reset_state(state);
+
+    data = "<yang-version xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" value=\"1.1\">\n"
+           "</yang-version>";
+    lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
+    yin_load_attributes(st->yin_ctx, &data, &attrs);
+    ret = yin_parse_yangversion(st->yin_ctx, attrs, &data, &version, NULL);
+    assert_int_equal(LY_SUCCESS, ret);
+    assert_true(version == LYS_VERSION_1_1);
+    assert_true(st->yin_ctx->mod_version == LYS_VERSION_1_1);
+    LY_ARRAY_FREE(attrs);
+    attrs = NULL;
+    st = reset_state(state);
+
+    data = "<yang-version xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" value=\"randomvalue\">\n"
+           "</yang-version>";
+    lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
+    yin_load_attributes(st->yin_ctx, &data, &attrs);
+    ret = yin_parse_yangversion(st->yin_ctx, attrs, &data, &version, NULL);
+    assert_int_equal(ret, LY_EVALID);
+    LY_ARRAY_FREE(attrs);
+    attrs = NULL;
+    logbuf_assert("Invalid value \"randomvalue\" of \"yang-version\". Line number 1.");
+    st->finished_correctly = true;
+}
+
 int
 main(void)
 {
@@ -780,6 +825,7 @@
         cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
         cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
         cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
+        cmocka_unit_test_setup_teardown(test_yin_parse_yangversion, setup_f, teardown_f),
         cmocka_unit_test(test_yin_match_argument_name),
     };