yin parser CHANGE add support for enum element
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 09a774d..9f5582b 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -1697,7 +1697,7 @@
     /* get value */
     LY_CHECK_RET(get_argument(ctx, data, enum_kw == YANG_ENUM ? Y_STR_ARG : Y_IDENTIF_ARG, NULL, &word, &buf, &word_len));
     if (enum_kw == YANG_ENUM) {
-        ret = lysp_check_enum_name(ctx, word, word_len);
+        ret = lysp_check_enum_name(ctx, (const char *)word, word_len);
         LY_CHECK_ERR_RET(ret, free(buf), ret);
     } else { /* YANG_BIT */
 
diff --git a/src/parser_yin.c b/src/parser_yin.c
index e8ec242..a671848 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -470,25 +470,41 @@
     return yin_parse_content(ctx, subelems, 6, data, YANG_PATTERN, NULL, &restr->exts);
 }
 
+/**
+ * @brief Parse enum or bit element.
+ *
+ * @param[in,out] ctx YIN parser context for logging and to store current state.
+ * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of current element.
+ * @param[in,out] data Data to read from, always moved to currently handled character.
+ * @param[in] enum_kw Identification of actual keyword, can be set to YANG_BIT or YANG_ENUM.
+ * @param[in,out] enums Enums or bits to add to.
+ *
+ * @return LY_ERR values.
+ */
 static LY_ERR
-yin_parse_bit(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data,
-              struct lysp_type *type)
+yin_parse_enum_bit(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data,
+                   enum yang_keyword enum_kw, struct lysp_type *type)
 {
-    struct lysp_type_enum *bit;
-    LY_ARRAY_NEW_RET(ctx->xml_ctx.ctx, type->bits, bit, LY_EMEM);
-    LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_NAME, &bit->name, Y_IDENTIF_ARG, YANG_BIT));
-    type->flags |= LYS_SET_BIT;
-    CHECK_UNIQUENESS((struct lys_parser_ctx *)ctx, type->bits, name, "bit", bit->name);
+    assert(enum_kw == YANG_BIT || enum_kw == YANG_ENUM);
+    struct lysp_type_enum *en;
+    LY_ARRAY_NEW_RET(ctx->xml_ctx.ctx, type->enums, en, LY_EMEM);
+    LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_NAME, &en->name, Y_IDENTIF_ARG, enum_kw));
+    type->flags |= (enum_kw == YANG_ENUM) ? LYS_SET_ENUM : LYS_SET_BIT;
+    if (enum_kw == YANG_ENUM) {
+        LY_CHECK_RET(lysp_check_enum_name((struct lys_parser_ctx *)ctx, en->name, strlen(en->name)));
+        YANG_CHECK_NONEMPTY((struct lys_parser_ctx *)ctx, NULL, strlen(en->name), "enum");
+    }
+    CHECK_UNIQUENESS((struct lys_parser_ctx *)ctx, type->enums, name, ly_stmt2str(enum_kw), en->name);
 
     struct yin_subelement subelems[6] = {
-                                            {YANG_DESCRIPTION, &bit->dsc, YIN_SUBELEM_UNIQUE},
-                                            {YANG_IF_FEATURE, &bit->iffeatures, 0},
-                                            {YANG_POSITION, &bit->value, YIN_SUBELEM_UNIQUE},
-                                            {YANG_REFERENCE, &bit->ref, YIN_SUBELEM_UNIQUE},
-                                            {YANG_STATUS, &bit->flags, YIN_SUBELEM_UNIQUE},
+                                            {YANG_DESCRIPTION, &en->dsc, YIN_SUBELEM_UNIQUE},
+                                            {YANG_IF_FEATURE, &en->iffeatures, 0},
+                                            {(enum_kw == YANG_ENUM) ? YANG_VALUE : YANG_POSITION, &en->value, YIN_SUBELEM_UNIQUE},
+                                            {YANG_REFERENCE, &en->ref, YIN_SUBELEM_UNIQUE},
+                                            {YANG_STATUS, &en->flags, YIN_SUBELEM_UNIQUE},
                                             {YANG_CUSTOM, NULL, 0}
                                         };
-    return yin_parse_content(ctx, subelems, 6, data, YANG_BIT, NULL, &bit->exts);
+    return yin_parse_content(ctx, subelems, 6, data, enum_kw, NULL, &en->exts);
 }
 
 /**
@@ -958,7 +974,8 @@
                     ret = yin_parse_belongs_to(ctx, subelem_attrs, data, (struct lysp_submodule *)subelem_info_rec->dest, exts);
                     break;
                 case YANG_BIT:
-                    ret = yin_parse_bit(ctx, subelem_attrs, data, (struct lysp_type *)subelem_info_rec->dest);
+                case YANG_ENUM:
+                    ret = yin_parse_enum_bit(ctx, subelem_attrs, data, kw, (struct lysp_type *)subelem_info_rec->dest);
                     break;
                 case YANG_CASE:
                     break;
@@ -983,8 +1000,6 @@
                     break;
                 case YANG_DEVIATION:
                     break;
-                case YANG_ENUM:
-                    break;
                 case YANG_ERROR_APP_TAG:
                     ret = yin_parse_simple_element(ctx, subelem_attrs, data, kw, (const char **)subelem_info_rec->dest,
                                                    YIN_ARG_VALUE, Y_STR_ARG, exts);
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index 2118af7..d5e42c5 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -425,7 +425,7 @@
 }
 
 LY_ERR
-lysp_check_enum_name(struct lys_parser_ctx *ctx, char *name, size_t name_len)
+lysp_check_enum_name(struct lys_parser_ctx *ctx, const char *name, size_t name_len)
 {
     if (!name_len) {
         LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Enum name must not be zero-length.");
diff --git a/src/tree_schema_internal.h b/src/tree_schema_internal.h
index 2ae20d1..9efe64e 100644
--- a/src/tree_schema_internal.h
+++ b/src/tree_schema_internal.h
@@ -201,7 +201,7 @@
  *
  * @return LY_ERR values
  */
-LY_ERR lysp_check_enum_name(struct lys_parser_ctx *ctx, char *name, size_t name_len);
+LY_ERR lysp_check_enum_name(struct lys_parser_ctx *ctx, const char *name, size_t name_len);
 
 /**
  * @brief Find and parse module of the given name.