yin parser CHANGE add support for typedef element
diff --git a/src/parser_yin.c b/src/parser_yin.c
index a94edd3..8532b9a 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -1215,6 +1215,46 @@
 }
 
 /**
+ * @brief Parse typedef 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] typedef_meta Meta information about node parent and typedefs to add to.
+ *
+ * @return LY_ERR values.
+ */
+static LY_ERR
+yin_parse_typedef(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data,
+                  struct typedef_meta *typedef_meta)
+{
+    struct lysp_tpdf *tpdf;
+    LY_ARRAY_NEW_RET(ctx->xml_ctx.ctx, *typedef_meta->typedefs, tpdf, LY_EMEM);
+
+    /* parse argument */
+    LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_NAME, &tpdf->name, Y_IDENTIF_ARG, YANG_TYPEDEF));
+
+    /* parse content */
+    struct yin_subelement subelems[7] = {
+                                            {YANG_DEFAULT, &tpdf->dflt, YIN_SUBELEM_UNIQUE},
+                                            {YANG_DESCRIPTION, &tpdf->dsc, YIN_SUBELEM_UNIQUE},
+                                            {YANG_REFERENCE, &tpdf->ref, YIN_SUBELEM_UNIQUE},
+                                            {YANG_STATUS, &tpdf->flags, YIN_SUBELEM_UNIQUE},
+                                            {YANG_TYPE, &tpdf->type, YIN_SUBELEM_UNIQUE | YIN_SUBELEM_MANDATORY},
+                                            {YANG_UNITS, &tpdf->units, YIN_SUBELEM_UNIQUE},
+                                            {YANG_CUSTOM, NULL, 0},
+                                         };
+    LY_CHECK_RET(yin_parse_content(ctx, subelems, 7, data, YANG_TYPEDEF, NULL, &tpdf->exts));
+
+    /* store data for collision check */
+    if (typedef_meta->parent && !(typedef_meta->parent->nodetype & (LYS_GROUPING | LYS_ACTION | LYS_INOUT | LYS_NOTIF))) {
+        ly_set_add(&ctx->tpdfs_nodes, typedef_meta->parent, 0);
+    }
+
+    return LY_SUCCESS;
+}
+
+/**
  * @brief Map keyword type to substatement info.
  *
  * @param[in] kw Keyword type.
@@ -1569,6 +1609,7 @@
                     ret = yin_parse_type(ctx, attrs, data, type);
                     break;
                 case YANG_TYPEDEF:
+                    ret = yin_parse_typedef(ctx, attrs, data, (struct typedef_meta *)subelem->dest);
                     break;
                 case YANG_UNIQUE:
                     ret = yin_parse_simple_elements(ctx, attrs, data, kw, (const char ***)subelem->dest,
diff --git a/src/parser_yin.h b/src/parser_yin.h
index b356991..a8674b9 100644
--- a/src/parser_yin.h
+++ b/src/parser_yin.h
@@ -57,8 +57,10 @@
 };
 
 struct yin_parser_ctx {
-    struct lyxml_context xml_ctx;  /**< context for xml parser */
+    struct ly_set tpdfs_nodes;
+    struct ly_set grps_nodes;
     uint8_t mod_version;           /**< module's version */
+    struct lyxml_context xml_ctx;  /**< context for xml parser */
 };
 
 /* flags to encode cardinality of subelement */
@@ -88,12 +90,18 @@
     const char **argument;  /**< Argument value */
 };
 
-/* Maet information passed to functions working with tree schema such as yin_parse_any */
+/* Meta information passed to functions working with tree schema such as yin_parse_any */
 struct tree_node_meta {
     struct lysp_node *parent;       /**< parent node */
     struct lysp_node **siblings;    /**< linked list of siblings */
 };
 
+/* Meta information passed to yin_parse_typedef */
+struct typedef_meta {
+    struct lysp_node *parent;       /**< parent node */
+    struct lysp_tpdf **typedefs;    /**< [Sized array](@ref sizedarrays) of typedefs */
+};
+
 /**
  * @brief Match argument name.
  *
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index f6aa3d3..ae23ff0 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -155,7 +155,7 @@
     }
 }
 
-static void
+void
 lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf)
 {
     FREE_STRING(ctx, tpdf->name);
diff --git a/src/tree_schema_internal.h b/src/tree_schema_internal.h
index 76e5413..e90f8cc 100644
--- a/src/tree_schema_internal.h
+++ b/src/tree_schema_internal.h
@@ -89,12 +89,12 @@
  * @brief internal context for schema parsers
  */
 struct lys_parser_ctx {
-    struct ly_ctx *ctx;
-    uint64_t line;      /**< line number */
     struct ly_set tpdfs_nodes;
     struct ly_set grps_nodes;
-    uint64_t indent;    /**< current position on the line for YANG indentation */
     uint8_t mod_version; /**< module's version */
+    struct ly_ctx *ctx;
+    uint64_t line;      /**< line number */
+    uint64_t indent;    /**< current position on the line for YANG indentation */
 };
 
 /**