parsers CHANGE move statements lists from YANG parser

Make the statements list available for other (YIN) parser and convert
stringify functions from the switch function to a faster macro providing
data from a constant string arrays.
diff --git a/src/common.c b/src/common.c
index 5cd0a90..03d2ff2 100644
--- a/src/common.c
+++ b/src/common.c
@@ -22,6 +22,123 @@
 #include "common.h"
 #include "tree_schema.h"
 
+const char *const ly_stmt_list[] = {
+    [YANG_ACTION] = "action",
+    [YANG_ANYDATA] = "anydata",
+    [YANG_ANYXML] = "anyxml",
+    [YANG_ARGUMENT] = "argument",
+    [YANG_AUGMENT] = "augment",
+    [YANG_BASE] = "base",
+    [YANG_BELONGS_TO] = "belongs-to",
+    [YANG_BIT] = "bit",
+    [YANG_CASE] = "case",
+    [YANG_CHOICE] = "choice",
+    [YANG_CONFIG] = "config",
+    [YANG_CONTACT] = "contact",
+    [YANG_CONTAINER] = "container",
+    [YANG_CUSTOM] = "<extension-instance>",
+    [YANG_DEFAULT] = "default",
+    [YANG_DESCRIPTION] = "description",
+    [YANG_DEVIATE] = "deviate",
+    [YANG_DEVIATION] = "deviation",
+    [YANG_ENUM] = "enum",
+    [YANG_ERROR_APP_TAG] = "error-app-tag",
+    [YANG_ERROR_MESSAGE] = "error-message",
+    [YANG_EXTENSION] = "extension",
+    [YANG_FEATURE] = "feature",
+    [YANG_FRACTION_DIGITS] = "fraction-digits",
+    [YANG_GROUPING] = "grouping",
+    [YANG_IDENTITY] = "identitiy",
+    [YANG_IF_FEATURE] = "if-feature",
+    [YANG_IMPORT] = "import",
+    [YANG_INCLUDE] = "include",
+    [YANG_INPUT] = "input",
+    [YANG_KEY] = "key",
+    [YANG_LEAF] = "leaf",
+    [YANG_LEAF_LIST] = "leaf-list",
+    [YANG_LENGTH] = "length",
+    [YANG_LIST] = "list",
+    [YANG_MANDATORY] = "mandatory",
+    [YANG_MAX_ELEMENTS] = "max-elements",
+    [YANG_MIN_ELEMENTS] = "min-elements",
+    [YANG_MODIFIER] = "modifier",
+    [YANG_MODULE] = "module",
+    [YANG_MUST] = "must",
+    [YANG_NAMESPACE] = "namespace",
+    [YANG_NOTIFICATION] = "notification",
+    [YANG_ORDERED_BY] = "ordered-by",
+    [YANG_ORGANIZATION] = "organization",
+    [YANG_OUTPUT] = "output",
+    [YANG_PATH] = "path",
+    [YANG_PATTERN] = "pattern",
+    [YANG_POSITION] = "position",
+    [YANG_PREFIX] = "prefix",
+    [YANG_PRESENCE] = "presence",
+    [YANG_RANGE] = "range",
+    [YANG_REFERENCE] = "reference",
+    [YANG_REFINE] = "refine",
+    [YANG_REQUIRE_INSTANCE] = "require-instance",
+    [YANG_REVISION] = "revision",
+    [YANG_REVISION_DATE] = "revision-date",
+    [YANG_RPC] = "rpc",
+    [YANG_STATUS] = "status",
+    [YANG_SUBMODULE] = "submodule",
+    [YANG_TYPE] = "type",
+    [YANG_TYPEDEF] = "typedef",
+    [YANG_UNIQUE] = "unique",
+    [YANG_UNITS] = "units",
+    [YANG_USES] = "uses",
+    [YANG_VALUE] = "value",
+    [YANG_WHEN] = "when",
+    [YANG_YANG_VERSION] = "yang-version",
+    [YANG_YIN_ELEMENT] = "yin-element",
+    [YANG_SEMICOLON] = ";",
+    [YANG_LEFT_BRACE] = "{",
+    [YANG_RIGHT_BRACE] = "}",
+};
+
+const char *const lyext_substmt_list[] = {
+    [LYEXT_SUBSTMT_ARGUMENT] = "argument",
+    [LYEXT_SUBSTMT_BASE] = "base",
+    [LYEXT_SUBSTMT_BELONGSTO] = "belongs-to",
+    [LYEXT_SUBSTMT_CONTACT] = "contact",
+    [LYEXT_SUBSTMT_DEFAULT] = "default",
+    [LYEXT_SUBSTMT_DESCRIPTION] = "description",
+    [LYEXT_SUBSTMT_ERRTAG] = "error-app-tag",
+    [LYEXT_SUBSTMT_ERRMSG] = "error-message",
+    [LYEXT_SUBSTMT_KEY] = "key",
+    [LYEXT_SUBSTMT_NAMESPACE] = "namespace",
+    [LYEXT_SUBSTMT_ORGANIZATION] = "organization",
+    [LYEXT_SUBSTMT_PATH] = "path",
+    [LYEXT_SUBSTMT_PREFIX] = "prefix",
+    [LYEXT_SUBSTMT_PRESENCE] = "presence",
+    [LYEXT_SUBSTMT_REFERENCE] = "reference",
+    [LYEXT_SUBSTMT_REVISIONDATE] = "revision-date",
+    [LYEXT_SUBSTMT_UNITS] = "units",
+    [LYEXT_SUBSTMT_VALUE] = "value",
+    [LYEXT_SUBSTMT_VERSION] = "yang-version",
+    [LYEXT_SUBSTMT_MODIFIER] = "modifier",
+    [LYEXT_SUBSTMT_REQINSTANCE] = "require-instance",
+    [LYEXT_SUBSTMT_YINELEM] = "yin-element",
+    [LYEXT_SUBSTMT_CONFIG] = "config",
+    [LYEXT_SUBSTMT_MANDATORY] = "mandatory",
+    [LYEXT_SUBSTMT_ORDEREDBY] = "ordered-by",
+    [LYEXT_SUBSTMT_STATUS] = "status",
+    [LYEXT_SUBSTMT_FRACDIGITS] = "fraction-digits",
+    [LYEXT_SUBSTMT_MAX] = "max-elements",
+    [LYEXT_SUBSTMT_MIN] = "min-elements",
+    [LYEXT_SUBSTMT_POSITION] = "position",
+    [LYEXT_SUBSTMT_UNIQUE] = "unique",
+    [LYEXT_SUBSTMT_IFFEATURE] = "if-feature",
+};
+
+const char *const ly_devmod_list[] = {
+    [LYS_DEV_NOT_SUPPORTED] = "not-supported",
+    [LYS_DEV_ADD] = "add",
+    [LYS_DEV_DELETE] = "delete",
+    [LYS_DEV_REPLACE] = "replace",
+};
+
 void *
 ly_realloc(void *ptr, size_t size)
 {
diff --git a/src/common.h b/src/common.h
index d684d2e..00fa346 100644
--- a/src/common.h
+++ b/src/common.h
@@ -20,6 +20,7 @@
 
 #include "config.h"
 #include "log.h"
+#include "tree_schema.h"
 
 #if __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__
 # define THREAD_LOCAL _Thread_local
@@ -31,13 +32,21 @@
 # error "Cannot define THREAD_LOCAL"
 #endif
 
+#define GETMACRO1(_1, NAME, ...) NAME
 #define GETMACRO2(_1, _2, NAME, ...) NAME
 #define GETMACRO3(_1, _2, _3, NAME, ...) NAME
 #define GETMACRO4(_1, _2, _3, _4, NAME, ...) NAME
 
 /*
- * logger
+ * If the compiler supports attribute to mark objects as hidden, mark all
+ * objects as hidden and export only objects explicitly marked to be part of
+ * the public API.
  */
+#define API __attribute__((visibility("default")))
+
+/******************************************************************************
+ * Logger
+ *****************************************************************************/
 
 /* internal logging options */
 enum int_log_opts {
@@ -89,7 +98,9 @@
  */
 #define LY_CHECK_GOTO(COND, GOTO) if (COND) {goto GOTO;}
 #define LY_CHECK_ERR_GOTO(COND, ERR, GOTO) if (COND) {ERR; goto GOTO;}
-#define LY_CHECK_RET(COND, RETVAL) if (COND) {return RETVAL;}
+#define LY_CHECK_RET1(RETVAL) if (RETVAL != LY_SUCCESS) {return RETVAL;}
+#define LY_CHECK_RET2(COND, RETVAL) if (COND) {return RETVAL;}
+#define LY_CHECK_RET(...) GETMACRO2(__VA_ARGS__, LY_CHECK_RET2, LY_CHECK_RET1)(__VA_ARGS__)
 #define LY_CHECK_ERR_RET(COND, ERR, RETVAL) if (COND) {ERR; return RETVAL;}
 
 #define LY_CHECK_ARG_GOTO1(CTX, ARG, GOTO) if (!ARG) {LOGARG(CTX, ARG);goto GOTO;}
@@ -114,16 +125,117 @@
 #define LY_VCODE_OOB         LYVE_SYNTAX_YANG, "Value \"%.*s\" is out of \"%s\" bounds."
 #define LY_VCODE_INDEV       LYVE_SYNTAX_YANG, "Deviate \"%s\" does not support keyword \"%s\"."
 
-/*
- * If the compiler supports attribute to mark objects as hidden, mark all
- * objects as hidden and export only objects explicitly marked to be part of
- * the public API.
- */
-#define API __attribute__((visibility("default")))
+/******************************************************************************
+ * Parsers
+ *****************************************************************************/
 
-/*
+enum yang_module_stmt {
+    Y_MOD_MODULE_HEADER,
+    Y_MOD_LINKAGE,
+    Y_MOD_META,
+    Y_MOD_REVISION,
+    Y_MOD_BODY
+};
+
+enum yang_arg {
+    Y_IDENTIF_ARG,
+    Y_PREF_IDENTIF_ARG,
+    Y_STR_ARG,
+    Y_MAYBE_STR_ARG
+};
+
+enum yang_keyword {
+    YANG_NONE = 0,
+    YANG_ACTION,
+    YANG_ANYDATA,
+    YANG_ANYXML,
+    YANG_ARGUMENT,
+    YANG_AUGMENT,
+    YANG_BASE,
+    YANG_BELONGS_TO,
+    YANG_BIT,
+    YANG_CASE,
+    YANG_CHOICE,
+    YANG_CONFIG,
+    YANG_CONTACT,
+    YANG_CONTAINER,
+    YANG_DEFAULT,
+    YANG_DESCRIPTION,
+    YANG_DEVIATE,
+    YANG_DEVIATION,
+    YANG_ENUM,
+    YANG_ERROR_APP_TAG,
+    YANG_ERROR_MESSAGE,
+    YANG_EXTENSION,
+    YANG_FEATURE,
+    YANG_FRACTION_DIGITS,
+    YANG_GROUPING,
+    YANG_IDENTITY,
+    YANG_IF_FEATURE,
+    YANG_IMPORT,
+    YANG_INCLUDE,
+    YANG_INPUT,
+    YANG_KEY,
+    YANG_LEAF,
+    YANG_LEAF_LIST,
+    YANG_LENGTH,
+    YANG_LIST,
+    YANG_MANDATORY,
+    YANG_MAX_ELEMENTS,
+    YANG_MIN_ELEMENTS,
+    YANG_MODIFIER,
+    YANG_MODULE,
+    YANG_MUST,
+    YANG_NAMESPACE,
+    YANG_NOTIFICATION,
+    YANG_ORDERED_BY,
+    YANG_ORGANIZATION,
+    YANG_OUTPUT,
+    YANG_PATH,
+    YANG_PATTERN,
+    YANG_POSITION,
+    YANG_PREFIX,
+    YANG_PRESENCE,
+    YANG_RANGE,
+    YANG_REFERENCE,
+    YANG_REFINE,
+    YANG_REQUIRE_INSTANCE,
+    YANG_REVISION,
+    YANG_REVISION_DATE,
+    YANG_RPC,
+    YANG_STATUS,
+    YANG_SUBMODULE,
+    YANG_TYPE,
+    YANG_TYPEDEF,
+    YANG_UNIQUE,
+    YANG_UNITS,
+    YANG_USES,
+    YANG_VALUE,
+    YANG_WHEN,
+    YANG_YANG_VERSION,
+    YANG_YIN_ELEMENT,
+
+    YANG_SEMICOLON,
+    YANG_LEFT_BRACE,
+    YANG_RIGHT_BRACE,
+    YANG_CUSTOM
+};
+
+/* list of the YANG statements strings */
+extern const char *const ly_stmt_list[];
+#define ly_stmt2str(STMT) ly_stmt_list[STMT]
+
+/* list of the extensions' substatements strings */
+extern const char *const lyext_substmt_list[];
+#define lyext_substmt2str(STMT) lyext_substmt_list[STMT]
+
+/* list of the deviate modifications strings */
+extern const char *const ly_devmod_list[];
+#define ly_devmod2str(TYPE) ly_devmod_list[TYPE]
+
+/******************************************************************************
  * Generic useful functions.
- */
+ *****************************************************************************/
 
 /**
  * @brief Wrapper for realloc() call. The only difference is that if it fails to
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 01195fe..cd11584 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -28,117 +28,21 @@
 #include "context.h"
 #include "libyang.h"
 
-#define YANG_ERR_GOTO(ERR, GO) if (ERR) goto GO;
-
-#define YANG_ERR_RET(ERR) if (ERR) return ERR;
-
 #define YANG_READ_SUBSTMT_FOR(CTX, DATA, KW, WORD, WORD_LEN, ERR) \
     ERR = get_keyword(CTX, DATA, &KW, &WORD, &WORD_LEN); \
-    YANG_ERR_RET(ERR); \
+    LY_CHECK_RET(ERR); \
     \
     if (KW == YANG_SEMICOLON) { \
         return ERR; \
     } \
     if (KW != YANG_LEFT_BRACE) { \
-        LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_SYNTAX_YANG, "Invalid keyword \"%s\", expected \";\" or \"{\".", kw2str(KW)); \
+        LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_SYNTAX_YANG, "Invalid keyword \"%s\", expected \";\" or \"{\".", ly_stmt2str(KW)); \
         return LY_EVALID; \
     } \
     for (ERR = get_keyword(CTX, DATA, &KW, &WORD, &WORD_LEN); \
             !ERR && (KW != YANG_RIGHT_BRACE); \
             ERR = get_keyword(CTX, DATA, &KW, &WORD, &WORD_LEN))
 
-enum yang_module_stmt {
-    Y_MOD_MODULE_HEADER,
-    Y_MOD_LINKAGE,
-    Y_MOD_META,
-    Y_MOD_REVISION,
-    Y_MOD_BODY
-};
-
-enum yang_arg {
-    Y_IDENTIF_ARG,
-    Y_PREF_IDENTIF_ARG,
-    Y_STR_ARG,
-    Y_MAYBE_STR_ARG
-};
-
-enum yang_keyword {
-    YANG_NONE = 0,
-    YANG_ACTION,
-    YANG_ANYDATA,
-    YANG_ANYXML,
-    YANG_ARGUMENT,
-    YANG_AUGMENT,
-    YANG_BASE,
-    YANG_BELONGS_TO,
-    YANG_BIT,
-    YANG_CASE,
-    YANG_CHOICE,
-    YANG_CONFIG,
-    YANG_CONTACT,
-    YANG_CONTAINER,
-    YANG_DEFAULT,
-    YANG_DESCRIPTION,
-    YANG_DEVIATE,
-    YANG_DEVIATION,
-    YANG_ENUM,
-    YANG_ERROR_APP_TAG,
-    YANG_ERROR_MESSAGE,
-    YANG_EXTENSION,
-    YANG_FEATURE,
-    YANG_FRACTION_DIGITS,
-    YANG_GROUPING,
-    YANG_IDENTITY,
-    YANG_IF_FEATURE,
-    YANG_IMPORT,
-    YANG_INCLUDE,
-    YANG_INPUT,
-    YANG_KEY,
-    YANG_LEAF,
-    YANG_LEAF_LIST,
-    YANG_LENGTH,
-    YANG_LIST,
-    YANG_MANDATORY,
-    YANG_MAX_ELEMENTS,
-    YANG_MIN_ELEMENTS,
-    YANG_MODIFIER,
-    YANG_MODULE,
-    YANG_MUST,
-    YANG_NAMESPACE,
-    YANG_NOTIFICATION,
-    YANG_ORDERED_BY,
-    YANG_ORGANIZATION,
-    YANG_OUTPUT,
-    YANG_PATH,
-    YANG_PATTERN,
-    YANG_POSITION,
-    YANG_PREFIX,
-    YANG_PRESENCE,
-    YANG_RANGE,
-    YANG_REFERENCE,
-    YANG_REFINE,
-    YANG_REQUIRE_INSTANCE,
-    YANG_REVISION,
-    YANG_REVISION_DATE,
-    YANG_RPC,
-    YANG_STATUS,
-    YANG_SUBMODULE,
-    YANG_TYPE,
-    YANG_TYPEDEF,
-    YANG_UNIQUE,
-    YANG_UNITS,
-    YANG_USES,
-    YANG_VALUE,
-    YANG_WHEN,
-    YANG_YANG_VERSION,
-    YANG_YIN_ELEMENT,
-
-    YANG_SEMICOLON,
-    YANG_LEFT_BRACE,
-    YANG_RIGHT_BRACE,
-    YANG_CUSTOM
-};
-
 static LY_ERR parse_container(struct ly_ctx *ctx, const char **data, struct lysp_node **siblings);
 static LY_ERR parse_uses(struct ly_ctx *ctx, const char **data, struct lysp_node **siblings);
 static LY_ERR parse_choice(struct ly_ctx *ctx, const char **data, struct lysp_node **siblings);
@@ -146,276 +50,6 @@
 static LY_ERR parse_list(struct ly_ctx *ctx, const char **data, struct lysp_node **siblings);
 static LY_ERR parse_grouping(struct ly_ctx *ctx, const char **data, struct lysp_grp **groupings);
 
-static const char *
-kw2str(enum yang_keyword kw)
-{
-    switch (kw) {
-    case YANG_ACTION:
-        return "action";
-    case YANG_ANYDATA:
-        return "anydata";
-    case YANG_ANYXML:
-        return "anyxml";
-    case YANG_ARGUMENT:
-        return "argument";
-    case YANG_AUGMENT:
-        return "augment";
-    case YANG_BASE:
-        return "base";
-    case YANG_BELONGS_TO:
-        return "belongs-to";
-    case YANG_BIT:
-        return "bit";
-    case YANG_CASE:
-        return "case";
-    case YANG_CHOICE:
-        return "choice";
-    case YANG_CONFIG:
-        return "config";
-    case YANG_CONTACT:
-        return "contact";
-    case YANG_CONTAINER:
-        return "container";
-    case YANG_CUSTOM:
-        return "<extension-instance>";
-    case YANG_DEFAULT:
-        return "default";
-    case YANG_DESCRIPTION:
-        return "description";
-    case YANG_DEVIATE:
-        return "deviate";
-    case YANG_DEVIATION:
-        return "deviation";
-    case YANG_ENUM:
-        return "enum";
-    case YANG_ERROR_APP_TAG:
-        return "error-app-tag";
-    case YANG_ERROR_MESSAGE:
-        return "error-message";
-    case YANG_EXTENSION:
-        return "extension";
-    case YANG_FEATURE:
-        return "feature";
-    case YANG_FRACTION_DIGITS:
-        return "fraction-digits";
-    case YANG_GROUPING:
-        return "grouping";
-    case YANG_IDENTITY:
-        return "identitiy";
-    case YANG_IF_FEATURE:
-        return "if-feature";
-    case YANG_IMPORT:
-        return "import";
-    case YANG_INCLUDE:
-        return "include";
-    case YANG_INPUT:
-        return "input";
-    case YANG_KEY:
-        return "key";
-    case YANG_LEAF:
-        return "leaf";
-    case YANG_LEAF_LIST:
-        return "leaf-list";
-    case YANG_LENGTH:
-        return "length";
-    case YANG_LIST:
-        return "list";
-    case YANG_MANDATORY:
-        return "mandatory";
-    case YANG_MAX_ELEMENTS:
-        return "max-elements";
-    case YANG_MIN_ELEMENTS:
-        return "min-elements";
-    case YANG_MODIFIER:
-        return "modifier";
-    case YANG_MODULE:
-        return "module";
-    case YANG_MUST:
-        return "must";
-    case YANG_NAMESPACE:
-        return "namespace";
-    case YANG_NOTIFICATION:
-        return "notification";
-    case YANG_ORDERED_BY:
-        return "ordered-by";
-    case YANG_ORGANIZATION:
-        return "organization";
-    case YANG_OUTPUT:
-        return "output";
-    case YANG_PATH:
-        return "path";
-    case YANG_PATTERN:
-        return "pattern";
-    case YANG_POSITION:
-        return "position";
-    case YANG_PREFIX:
-        return "prefix";
-    case YANG_PRESENCE:
-        return "presence";
-    case YANG_RANGE:
-        return "range";
-    case YANG_REFERENCE:
-        return "reference";
-    case YANG_REFINE:
-        return "refine";
-    case YANG_REQUIRE_INSTANCE:
-        return "require-instance";
-    case YANG_REVISION:
-        return "revision";
-    case YANG_REVISION_DATE:
-        return "revision-date";
-    case YANG_RPC:
-        return "rpc";
-    case YANG_STATUS:
-        return "status";
-    case YANG_SUBMODULE:
-        return "submodule";
-    case YANG_TYPE:
-        return "type";
-    case YANG_TYPEDEF:
-        return "typedef";
-    case YANG_UNIQUE:
-        return "unique";
-    case YANG_UNITS:
-        return "units";
-    case YANG_USES:
-        return "uses";
-    case YANG_VALUE:
-        return "value";
-    case YANG_WHEN:
-        return "when";
-    case YANG_YANG_VERSION:
-        return "yang-version";
-    case YANG_YIN_ELEMENT:
-        return "yin-element";
-    case YANG_SEMICOLON:
-        return ";";
-    case YANG_LEFT_BRACE:
-        return "{";
-    case YANG_RIGHT_BRACE:
-        return "}";
-    default:
-        return "";
-    }
-}
-
-static const char *
-substmt2str(LYEXT_SUBSTMT substmt)
-{
-    switch (substmt) {
-    case LYEXT_SUBSTMT_ARGUMENT:
-        return "argument";
-    case LYEXT_SUBSTMT_BASE:
-        return "base";
-    case LYEXT_SUBSTMT_BELONGSTO:
-        return "belongs-to";
-    case LYEXT_SUBSTMT_CONTACT:
-        return "contact";
-    case LYEXT_SUBSTMT_DEFAULT:
-        return "default";
-    case LYEXT_SUBSTMT_DESCRIPTION:
-        return "description";
-    case LYEXT_SUBSTMT_ERRTAG:
-        return "error-app-tag";
-    case LYEXT_SUBSTMT_ERRMSG:
-        return "error-message";
-    case LYEXT_SUBSTMT_KEY:
-        return "key";
-    case LYEXT_SUBSTMT_NAMESPACE:
-        return "namespace";
-    case LYEXT_SUBSTMT_ORGANIZATION:
-        return "organization";
-    case LYEXT_SUBSTMT_PATH:
-        return "path";
-    case LYEXT_SUBSTMT_PREFIX:
-        return "prefix";
-    case LYEXT_SUBSTMT_PRESENCE:
-        return "presence";
-    case LYEXT_SUBSTMT_REFERENCE:
-        return "reference";
-    case LYEXT_SUBSTMT_REVISIONDATE:
-        return "revision-date";
-    case LYEXT_SUBSTMT_UNITS:
-        return "units";
-    case LYEXT_SUBSTMT_VALUE:
-        return "value";
-    case LYEXT_SUBSTMT_VERSION:
-        return "yang-version";
-    case LYEXT_SUBSTMT_MODIFIER:
-        return "modifier";
-    case LYEXT_SUBSTMT_REQINSTANCE:
-        return "require-instance";
-    case LYEXT_SUBSTMT_YINELEM:
-        return "yin-element";
-    case LYEXT_SUBSTMT_CONFIG:
-        return "config";
-    case LYEXT_SUBSTMT_MANDATORY:
-        return "mandatory";
-    case LYEXT_SUBSTMT_ORDEREDBY:
-        return "ordered-by";
-    case LYEXT_SUBSTMT_STATUS:
-        return "status";
-    case LYEXT_SUBSTMT_FRACDIGITS:
-        return "fraction-digits";
-    case LYEXT_SUBSTMT_MAX:
-        return "max-elements";
-    case LYEXT_SUBSTMT_MIN:
-        return "min-elements";
-    case LYEXT_SUBSTMT_POSITION:
-        return "position";
-    case LYEXT_SUBSTMT_UNIQUE:
-        return "unique";
-    case LYEXT_SUBSTMT_IFFEATURE:
-        return "if-feature";
-    default:
-        return "";
-    }
-}
-
-static const char *
-nodetype2str(uint16_t nodetype)
-{
-    switch (nodetype) {
-    case LYS_CONTAINER:
-        return "container";
-    case LYS_CHOICE:
-        return "choice";
-    case LYS_LEAF:
-        return "leaf";
-    case LYS_LEAFLIST:
-        return "leaf-list";
-    case LYS_LIST:
-        return "list";
-    case LYS_ANYXML:
-        return "anyxml";
-    case LYS_CASE:
-        return "case";
-    case LYS_USES:
-        return "uses";
-    case LYS_ANYDATA:
-        return "anydata";
-    default:
-        return "";
-    }
-}
-
-static const char *
-devmod2str(uint8_t devmod)
-{
-    switch (devmod) {
-    case LYS_DEV_NOT_SUPPORTED:
-        return "not-supported";
-    case LYS_DEV_ADD:
-        return "add";
-    case LYS_DEV_DELETE:
-        return "delete";
-    case LYS_DEV_REPLACE:
-        return "replace";
-    default:
-        return "";
-    }
-}
-
 static LY_ERR
 buf_add_char(struct ly_ctx *ctx, char c, char **buf, int *buf_len, int buf_used)
 {
@@ -1328,7 +962,7 @@
 
     /* get optional argument */
     ret = get_string(ctx, data, Y_MAYBE_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         stmt->arg = lydict_insert_zc(ctx, word);
@@ -1345,12 +979,12 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         ret = parse_ext_substmt(ctx, data, word, word_len, &stmt->child);
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1374,7 +1008,7 @@
 
     /* get optional argument */
     ret = get_string(ctx, data, Y_MAYBE_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         e->argument = lydict_insert_zc(ctx, word);
@@ -1383,12 +1017,12 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         ret = parse_ext_substmt(ctx, data, word, word_len, &e->child);
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1403,13 +1037,13 @@
     enum yang_keyword kw;
 
     if (*value) {
-        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, substmt2str(substmt));
+        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, lyext_substmt2str(substmt));
         return LY_EVALID;
     }
 
     /* get value */
     ret = get_string(ctx, data, arg, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* store value and spend buf if allocated */
     if (buf) {
@@ -1419,19 +1053,19 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, substmt, substmt_index, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), substmt2str(substmt));
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt));
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1451,7 +1085,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if ((word_len == 3) && !strncmp(word, "1.0", word_len)) {
         mod->version = LYS_VERSION_1_0;
@@ -1465,19 +1099,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_VERSION, 0, &mod->exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "yang-version");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "yang-version");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1497,7 +1131,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         *belongsto = lydict_insert_zc(ctx, word);
@@ -1506,7 +1140,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_PREFIX:
@@ -1516,12 +1150,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_BELONGSTO, 0, exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "belongs-to");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "belongs-to");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* mandatory substatements */
     if (!*prefix) {
@@ -1547,7 +1181,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* check value */
     if (lysp_check_date(ctx, word, word_len, "revision-date")) {
@@ -1560,19 +1194,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_REVISIONDATE, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "revision-date");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "revision-date");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1590,7 +1224,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         inc->name = lydict_insert_zc(ctx, word);
@@ -1599,7 +1233,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -1615,12 +1249,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &inc->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "include");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "include");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1638,7 +1272,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         imp->name = lydict_insert_zc(ctx, word);
@@ -1647,7 +1281,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_PREFIX:
@@ -1666,12 +1300,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &imp->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "import");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "import");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* mandatory substatements */
     if (!imp->prefix) {
@@ -1695,7 +1329,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* check value */
     if (lysp_check_date(ctx, word, word_len, "revision")) {
@@ -1706,7 +1340,7 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -1719,12 +1353,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &rev->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "revision");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "revision");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1745,7 +1379,7 @@
 
     /* get value */
     ret = get_string(ctx, data, arg, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         (*texts)[count - 1] = lydict_insert_zc(ctx, word);
@@ -1754,19 +1388,19 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, substmt, count - 1, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), substmt2str(substmt));
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt));
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1786,7 +1420,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if ((word_len == 4) && !strncmp(word, "true", word_len)) {
         *flags |= LYS_CONFIG_W;
@@ -1800,19 +1434,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_CONFIG, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "config");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "config");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1832,7 +1466,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if ((word_len == 4) && !strncmp(word, "true", word_len)) {
         *flags |= LYS_MAND_TRUE;
@@ -1846,19 +1480,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_MANDATORY, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "mandatory");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "mandatory");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1873,7 +1507,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         restr->arg = lydict_insert_zc(ctx, word);
@@ -1882,7 +1516,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -1901,12 +1535,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &restr->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), kw2str(restr_kw));
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), ly_stmt2str(restr_kw));
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1936,7 +1570,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if ((word_len == 7) && !strncmp(word, "current", word_len)) {
         *flags |= LYS_STATUS_CURR;
@@ -1952,19 +1586,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_STATUS, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "status");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "status");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -1989,7 +1623,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         when->cond = lydict_insert_zc(ctx, word);
@@ -1998,7 +1632,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -2011,12 +1645,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &when->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "when");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "when");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2045,7 +1679,7 @@
 
     /* get name */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         any->name = lydict_insert_zc(ctx, word);
@@ -2055,7 +1689,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CONFIG:
@@ -2086,12 +1720,13 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &any->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), nodetype2str(any->nodetype));
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw),
+                   (any->nodetype & LYS_ANYDATA) == LYS_ANYDATA ? ly_stmt2str(YANG_ANYDATA) : ly_stmt2str(YANG_ANYXML));
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2108,17 +1743,17 @@
     enum yang_keyword kw;
 
     if (*flags & LYS_SET_VALUE) {
-        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, kw2str(val_kw));
+        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, ly_stmt2str(val_kw));
         return LY_EVALID;
     }
     *flags |= LYS_SET_VALUE;
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (!word_len || (word[0] == '+') || ((word[0] == '0') && (word_len > 1)) || ((val_kw == YANG_VALUE) && !strncmp(word, "-0", 2))) {
-        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INVAL, word_len, word, kw2str(val_kw));
+        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INVAL, word_len, word, ly_stmt2str(val_kw));
         free(buf);
         return LY_EVALID;
     }
@@ -2131,12 +1766,12 @@
     }
     /* we have not parsed the whole argument */
     if (ptr - word != word_len) {
-        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INVAL, word_len, word, kw2str(val_kw));
+        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INVAL, word_len, word, ly_stmt2str(val_kw));
         free(buf);
         return LY_EVALID;
     }
     if (errno == ERANGE) {
-        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_OOB, word_len, word, kw2str(val_kw));
+        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_OOB, word_len, word, ly_stmt2str(val_kw));
         free(buf);
         return LY_EVALID;
     }
@@ -2148,19 +1783,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, val_kw == YANG_VALUE ? LYEXT_SUBSTMT_VALUE : LYEXT_SUBSTMT_POSITION, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), kw2str(val_kw));
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), ly_stmt2str(val_kw));
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2178,7 +1813,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         enm->name = lydict_insert_zc(ctx, word);
@@ -2187,7 +1822,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -2210,12 +1845,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &enm->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), kw2str(enum_kw));
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), ly_stmt2str(enum_kw));
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2236,7 +1871,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (!word_len || (word[0] == '0') || !isdigit(word[0])) {
         LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INVAL, word_len, word, "fraction-digits");
@@ -2261,19 +1896,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_FRACDIGITS, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "fraction-digits");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "fraction-digits");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2295,7 +1930,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if ((word_len == 4) && !strncmp(word, "true", word_len)) {
         *reqinst = 1;
@@ -2307,19 +1942,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_REQINSTANCE, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "require-instance");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "require-instance");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2339,7 +1974,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if ((word_len != 12) || strncmp(word, "invert-match", word_len)) {
         LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INVAL, word_len, word, "modifier");
@@ -2359,19 +1994,19 @@
     *pat = lydict_insert_zc(ctx, buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_MODIFIER, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "modifier");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "modifier");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2389,7 +2024,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* add special meaning first byte */
     if (buf) {
@@ -2404,7 +2039,7 @@
     restr->arg = lydict_insert_zc(ctx, word);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -2426,12 +2061,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &restr->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "pattern");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "pattern");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2452,7 +2087,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_PREF_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         type->name = lydict_insert_zc(ctx, word);
@@ -2461,7 +2096,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_BASE:
@@ -2478,7 +2113,7 @@
             break;
         case YANG_LENGTH:
             if (type->length) {
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, ly_stmt2str(kw));
                 return LY_EVALID;
             }
             type->length = calloc(1, sizeof *type->length);
@@ -2494,7 +2129,7 @@
             break;
         case YANG_RANGE:
             if (type->range) {
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, ly_stmt2str(kw));
                 return LY_EVALID;
             }
             type->range = calloc(1, sizeof *type->range);
@@ -2515,12 +2150,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &type->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "when");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "when");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2550,7 +2185,7 @@
 
     /* get name */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         leaf->name = lydict_insert_zc(ctx, word);
@@ -2560,7 +2195,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CONFIG:
@@ -2600,12 +2235,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &leaf->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "leaf");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "leaf");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* mandatory substatements */
     if (!leaf->type.name) {
@@ -2633,7 +2268,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (!word_len || (word[0] == '0') || ((word[0] != 'u') && !isdigit(word[0]))) {
         LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INVAL, word_len, word, "max-elements");
@@ -2661,19 +2296,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_MAX, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "max-elements");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "max-elements");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2695,7 +2330,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (!word_len || !isdigit(word[0]) || ((word[0] == '0') && (word_len > 1))) {
         LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INVAL, word_len, word, "min-elements");
@@ -2720,19 +2355,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_MIN, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "min-elements");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "min-elements");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2752,7 +2387,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if ((word_len == 6) && !strncmp(word, "system", word_len)) {
         *flags |= LYS_ORDBY_SYSTEM;
@@ -2766,19 +2401,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_ORDEREDBY, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "ordered-by");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "ordered-by");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2808,7 +2443,7 @@
 
     /* get name */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         llist->name = lydict_insert_zc(ctx, word);
@@ -2818,7 +2453,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CONFIG:
@@ -2864,12 +2499,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &llist->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "llist");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "llist");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* mandatory substatements */
     if (!llist->type.name) {
@@ -2893,7 +2528,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         rf->nodeid = lydict_insert_zc(ctx, word);
@@ -2902,7 +2537,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CONFIG:
@@ -2939,12 +2574,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &rf->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "refine");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "refine");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -2962,7 +2597,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         tpdf->name = lydict_insert_zc(ctx, word);
@@ -2972,7 +2607,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DEFAULT:
@@ -2997,12 +2632,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &tpdf->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "typedef");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "typedef");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* mandatory substatements */
     if (!tpdf->type.name) {
@@ -3022,7 +2657,7 @@
     struct lysp_action_inout *inout;
 
     if (*inout_p) {
-        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, kw2str(kw));
+        LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_DUPSTMT, ly_stmt2str(kw));
         return LY_EVALID;
     }
 
@@ -3033,7 +2668,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_ANYDATA:
@@ -3072,12 +2707,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &inout->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "input/output");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "input/output");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3095,7 +2730,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         act->name = lydict_insert_zc(ctx, word);
@@ -3104,7 +2739,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -3137,12 +2772,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &act->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "action");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "action");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3160,7 +2795,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         notif->name = lydict_insert_zc(ctx, word);
@@ -3169,7 +2804,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -3221,12 +2856,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &notif->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "notification");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "notification");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3244,7 +2879,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         grp->name = lydict_insert_zc(ctx, word);
@@ -3253,7 +2888,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -3305,12 +2940,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &grp->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "augment");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "augment");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3328,7 +2963,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         aug->nodeid = lydict_insert_zc(ctx, word);
@@ -3337,7 +2972,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -3392,12 +3027,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &aug->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "augment");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "augment");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3427,7 +3062,7 @@
 
     /* get name */
     ret = get_string(ctx, data, Y_PREF_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         uses->name = lydict_insert_zc(ctx, word);
@@ -3437,7 +3072,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -3466,12 +3101,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &uses->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "uses");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "uses");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3501,7 +3136,7 @@
 
     /* get name */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         cas->name = lydict_insert_zc(ctx, word);
@@ -3511,7 +3146,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -3556,12 +3191,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &cas->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "case");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "case");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3591,7 +3226,7 @@
 
     /* get name */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         choic->name = lydict_insert_zc(ctx, word);
@@ -3601,7 +3236,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CONFIG:
@@ -3655,12 +3290,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &choic->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "choice");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "choice");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3690,7 +3325,7 @@
 
     /* get name */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         cont->name = lydict_insert_zc(ctx, word);
@@ -3700,7 +3335,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CONFIG:
@@ -3767,12 +3402,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &cont->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "container");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "container");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3802,7 +3437,7 @@
 
     /* get name */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         list->name = lydict_insert_zc(ctx, word);
@@ -3812,7 +3447,7 @@
 
     /* parse substatements */
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CONFIG:
@@ -3891,12 +3526,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &list->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "container");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "container");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3916,7 +3551,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if ((word_len == 4) && !strncmp(word, "true", word_len)) {
         *flags |= LYS_YINELEM_TRUE;
@@ -3930,19 +3565,19 @@
     free(buf);
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CUSTOM:
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_YINELEM, 0, exts);
-            YANG_ERR_RET(ret);
+            LY_CHECK_RET(ret);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "yin-element");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "yin-element");
             return LY_EVALID;
         }
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -3962,7 +3597,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         *argument = lydict_insert_zc(ctx, word);
@@ -3971,7 +3606,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_YIN_ELEMENT:
@@ -3981,12 +3616,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_ARGUMENT, 0, exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "argument");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "argument");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -4004,7 +3639,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         ex->name = lydict_insert_zc(ctx, word);
@@ -4013,7 +3648,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -4032,12 +3667,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &ex->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "extension");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "extension");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -4060,7 +3695,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if ((word_len == 13) && !strncmp(word, "not-supported", word_len)) {
         dev_mod = LYS_DEV_NOT_SUPPORTED;
@@ -4131,13 +3766,13 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_CONFIG:
             switch (dev_mod) {
             case LYS_DEV_NOT_SUPPORTED:
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, devmod2str(dev_mod), kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw));
                 return LY_EVALID;
             default:
                 ret = parse_config(ctx, data, d_flags, &d->exts);
@@ -4147,7 +3782,7 @@
         case YANG_DEFAULT:
             switch (dev_mod) {
             case LYS_DEV_NOT_SUPPORTED:
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, devmod2str(dev_mod), kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw));
                 return LY_EVALID;
             case LYS_DEV_REPLACE:
                 ret = parse_text_field(ctx, data, LYEXT_SUBSTMT_DEFAULT, 0, &d_rpl->dflt, Y_STR_ARG, &d->exts);
@@ -4160,7 +3795,7 @@
         case YANG_MANDATORY:
             switch (dev_mod) {
             case LYS_DEV_NOT_SUPPORTED:
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, devmod2str(dev_mod), kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw));
                 return LY_EVALID;
             default:
                 ret = parse_mandatory(ctx, data, d_flags, &d->exts);
@@ -4170,7 +3805,7 @@
         case YANG_MAX_ELEMENTS:
             switch (dev_mod) {
             case LYS_DEV_NOT_SUPPORTED:
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, devmod2str(dev_mod), kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw));
                 return LY_EVALID;
             default:
                 ret = parse_maxelements(ctx, data, d_max, d_flags, &d->exts);
@@ -4180,7 +3815,7 @@
         case YANG_MIN_ELEMENTS:
             switch (dev_mod) {
             case LYS_DEV_NOT_SUPPORTED:
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, devmod2str(dev_mod), kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw));
                 return LY_EVALID;
             default:
                 ret = parse_minelements(ctx, data, d_min, d_flags, &d->exts);
@@ -4190,7 +3825,7 @@
         case YANG_MUST:
             switch (dev_mod) {
             case LYS_DEV_NOT_SUPPORTED:
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, devmod2str(dev_mod), kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw));
                 return LY_EVALID;
             default:
                 ret = parse_restrs(ctx, data, kw, d_musts);
@@ -4202,7 +3837,7 @@
             case LYS_DEV_NOT_SUPPORTED:
             case LYS_DEV_ADD:
             case LYS_DEV_DELETE:
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, devmod2str(dev_mod), kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw));
                 return LY_EVALID;
             default:
                 d_rpl->type = calloc(1, sizeof *d_rpl->type);
@@ -4215,7 +3850,7 @@
             switch (dev_mod) {
             case LYS_DEV_NOT_SUPPORTED:
             case LYS_DEV_REPLACE:
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, devmod2str(dev_mod), kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw));
                 return LY_EVALID;
             default:
                 ret = parse_text_fields(ctx, data, LYEXT_SUBSTMT_UNIQUE, d_uniques, Y_STR_ARG, &d->exts);
@@ -4225,7 +3860,7 @@
         case YANG_UNITS:
             switch (dev_mod) {
             case LYS_DEV_NOT_SUPPORTED:
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, devmod2str(dev_mod), kw2str(kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw));
                 return LY_EVALID;
             default:
                 ret = parse_text_field(ctx, data, LYEXT_SUBSTMT_UNITS, 0, d_units, Y_STR_ARG, &d->exts);
@@ -4236,12 +3871,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &d->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "deviate");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "deviate");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -4259,7 +3894,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         dev->nodeid = lydict_insert_zc(ctx, word);
@@ -4268,7 +3903,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -4284,12 +3919,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &dev->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "deviation");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "deviation");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* mandatory substatements */
     if (!dev->deviates) {
@@ -4313,7 +3948,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         feat->name = lydict_insert_zc(ctx, word);
@@ -4322,7 +3957,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -4341,12 +3976,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &feat->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "feature");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "feature");
             return LY_EMEM;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -4364,7 +3999,7 @@
 
     /* get value */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         ident->name = lydict_insert_zc(ctx, word);
@@ -4373,7 +4008,7 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         case YANG_DESCRIPTION:
@@ -4395,12 +4030,12 @@
             ret = parse_ext(ctx, data, word, word_len, LYEXT_SUBSTMT_SELF, 0, &ident->exts);
             break;
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "identity");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "identity");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     return ret;
 }
@@ -4416,7 +4051,7 @@
 
     /* (sub)module name */
     ret = get_string(ctx, data, Y_IDENTIF_ARG, &word, &buf, &word_len);
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     if (buf) {
         mod->name = lydict_insert_zc(ctx, word);
@@ -4425,26 +4060,26 @@
     }
 
     YANG_READ_SUBSTMT_FOR(ctx, data, kw, word, word_len, ret) {
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
 
         switch (kw) {
         /* module header */
         case YANG_NAMESPACE:
         case YANG_PREFIX:
             if (mod->submodule) {
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "submodule");
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "submodule");
                 return LY_EVALID;
             }
             /* fallthrough */
         case YANG_BELONGS_TO:
             if ((kw == YANG_BELONGS_TO) && !mod->submodule) {
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), "module");
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "module");
                 return LY_EVALID;
             }
             /* fallthrough */
         case YANG_YANG_VERSION:
             if (mod_stmt > Y_MOD_MODULE_HEADER) {
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INORD, kw2str(kw), kw2str(prev_kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INORD, ly_stmt2str(kw), ly_stmt2str(prev_kw));
                 return LY_EVALID;
             }
             break;
@@ -4452,7 +4087,7 @@
         case YANG_INCLUDE:
         case YANG_IMPORT:
             if (mod_stmt > Y_MOD_LINKAGE) {
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INORD, kw2str(kw), kw2str(prev_kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INORD, ly_stmt2str(kw), ly_stmt2str(prev_kw));
                 return LY_EVALID;
             }
             mod_stmt = Y_MOD_LINKAGE;
@@ -4463,7 +4098,7 @@
         case YANG_DESCRIPTION:
         case YANG_REFERENCE:
             if (mod_stmt > Y_MOD_META) {
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INORD, kw2str(kw), kw2str(prev_kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INORD, ly_stmt2str(kw), ly_stmt2str(prev_kw));
                 return LY_EVALID;
             }
             mod_stmt = Y_MOD_META;
@@ -4472,7 +4107,7 @@
         /* revision */
         case YANG_REVISION:
             if (mod_stmt > Y_MOD_REVISION) {
-                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INORD, kw2str(kw), kw2str(prev_kw));
+                LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INORD, ly_stmt2str(kw), ly_stmt2str(prev_kw));
                 return LY_EVALID;
             }
             mod_stmt = Y_MOD_REVISION;
@@ -4603,12 +4238,12 @@
             break;
 
         default:
-            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, kw2str(kw), mod->submodule ? "submodule" : "module");
+            LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), mod->submodule ? "submodule" : "module");
             return LY_EVALID;
         }
-        YANG_ERR_RET(ret);
+        LY_CHECK_RET(ret);
     }
-    YANG_ERR_RET(ret);
+    LY_CHECK_RET(ret);
 
     /* mandatory substatements */
     if (mod->submodule) {
@@ -4643,11 +4278,11 @@
 
     /* "module"/"submodule" */
     ret = get_keyword(ctx, &data, &kw, &word, &word_len);
-    YANG_ERR_GOTO(ret, error);
+    LY_CHECK_GOTO(ret, error);
 
     if ((kw != YANG_MODULE) && (kw != YANG_SUBMODULE)) {
         LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_SYNTAX, "Invalid keyword \"%s\", expected \"module\" or \"submodule\".\n",
-               kw2str(kw));
+               ly_stmt2str(kw));
         goto error;
     }
 
@@ -4659,11 +4294,11 @@
 
     /* substatements */
     ret = parse_sub_module(ctx, &data, mod);
-    YANG_ERR_GOTO(ret, error);
+    LY_CHECK_GOTO(ret, error);
 
     /* read some trailing spaces or new lines */
     ret = get_string(ctx, &data, Y_MAYBE_STR_ARG, &word, &buf, &word_len);
-    YANG_ERR_GOTO(ret, error);
+    LY_CHECK_GOTO(ret, error);
 
     if (word) {
         LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_SYNTAX, "Invalid character sequence \"%.*s\", expected end-of-file.",