Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file parser_yang.c |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief YANG parser |
| 5 | * |
| 6 | * Copyright (c) 2018 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 14 | #include "parser_internal.h" |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 15 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 16 | #include <assert.h> |
| 17 | #include <ctype.h> |
| 18 | #include <errno.h> |
| 19 | #include <stdint.h> |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 24 | #include "common.h" |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 25 | #include "context.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 26 | #include "dict.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 27 | #include "in_internal.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 28 | #include "log.h" |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 29 | #include "parser_schema.h" |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 30 | #include "path.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 31 | #include "set.h" |
| 32 | #include "tree.h" |
| 33 | #include "tree_schema.h" |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 34 | #include "tree_schema_internal.h" |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 35 | |
Radek Krejci | ceaf212 | 2019-01-02 15:03:26 +0100 | [diff] [blame] | 36 | /** |
| 37 | * @brief Insert WORD into the libyang context's dictionary and store as TARGET. |
| 38 | * @param[in] CTX yang parser context to access libyang context. |
| 39 | * @param[in] BUF buffer in case the word is not a constant and can be inserted directly (zero-copy) |
| 40 | * @param[out] TARGET variable where to store the pointer to the inserted value. |
| 41 | * @param[in] WORD string to store. |
| 42 | * @param[in] LEN length of the string in WORD to store. |
| 43 | */ |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 44 | #define INSERT_WORD_RET(CTX, BUF, TARGET, WORD, LEN) \ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 45 | if (BUF) {LY_CHECK_RET(lydict_insert_zc(PARSER_CTX(CTX), WORD, &(TARGET)));}\ |
| 46 | else {LY_CHECK_RET(lydict_insert(PARSER_CTX(CTX), LEN ? WORD : "", LEN, &(TARGET)));} |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 47 | |
Radek Krejci | ceaf212 | 2019-01-02 15:03:26 +0100 | [diff] [blame] | 48 | /** |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 49 | * @brief Read from the IN structure COUNT items. Also updates the indent value in yang parser context |
Radek Krejci | ceaf212 | 2019-01-02 15:03:26 +0100 | [diff] [blame] | 50 | * @param[in] CTX yang parser context to update its indent value. |
Radek Krejci | ceaf212 | 2019-01-02 15:03:26 +0100 | [diff] [blame] | 51 | * @param[in] COUNT number of items for which the DATA pointer is supposed to move on. |
| 52 | */ |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 53 | #define MOVE_INPUT(CTX, COUNT) ly_in_skip((CTX)->in, COUNT);(CTX)->indent+=COUNT |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 54 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 55 | /** |
| 56 | * @brief Loop through all substatements providing, return if there are none. |
| 57 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 58 | * @param[in] CTX yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 59 | * @param[out] KW YANG keyword read. |
| 60 | * @param[out] WORD Pointer to the keyword itself. |
| 61 | * @param[out] WORD_LEN Length of the keyword. |
| 62 | * @param[out] ERR Variable for error storing. |
| 63 | * |
| 64 | * @return In case there are no substatements or a fatal error encountered. |
| 65 | */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 66 | #define YANG_READ_SUBSTMT_FOR(CTX, KW, WORD, WORD_LEN, ERR, CHECKGOTO) \ |
| 67 | LY_CHECK_RET(get_keyword(CTX, &KW, &WORD, &WORD_LEN)); \ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 68 | if (KW == LY_STMT_SYNTAX_SEMICOLON) { \ |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 69 | CHECKGOTO; \ |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 70 | return LY_SUCCESS; \ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 71 | } \ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 72 | if (KW != LY_STMT_SYNTAX_LEFT_BRACE) { \ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 73 | LOGVAL_PARSER(CTX, LYVE_SYNTAX_YANG, "Invalid keyword \"%s\", expected \";\" or \"{\".", ly_stmt2str(KW)); \ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 74 | return LY_EVALID; \ |
| 75 | } \ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 76 | for (ERR = get_keyword(CTX, &KW, &WORD, &WORD_LEN); \ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 77 | !ERR && (KW != LY_STMT_SYNTAX_RIGHT_BRACE); \ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 78 | ERR = get_keyword(CTX, &KW, &WORD, &WORD_LEN)) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 79 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 80 | LY_ERR parse_container(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 81 | struct lysp_node **siblings); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 82 | LY_ERR parse_uses(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings); |
| 83 | LY_ERR parse_choice(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings); |
| 84 | LY_ERR parse_case(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings); |
| 85 | LY_ERR parse_list(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 86 | LY_ERR parse_grouping(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node_grp **groupings); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 87 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 88 | /** |
| 89 | * @brief Add another character to dynamic buffer, a low-level function. |
| 90 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 91 | * Enlarge if needed. Updates \p input as well as \p buf_used. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 92 | * |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 93 | * @param[in] ctx libyang context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 94 | * @param[in,out] in Input structure. |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 95 | * @param[in] len Number of bytes to get from the input string and copy into the buffer. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 96 | * @param[in,out] buf Buffer to use, can be moved by realloc(). |
| 97 | * @param[in,out] buf_len Current size of the buffer. |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 98 | * @param[in,out] buf_used Currently used characters of the buffer. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 99 | * |
| 100 | * @return LY_ERR values. |
| 101 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 102 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 103 | buf_add_char(struct ly_ctx *ctx, struct ly_in *in, size_t len, char **buf, size_t *buf_len, size_t *buf_used) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 104 | { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 105 | #define BUF_STEP 16; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 106 | if (*buf_len <= (*buf_used) + len) { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 107 | *buf_len += BUF_STEP; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 108 | *buf = ly_realloc(*buf, *buf_len); |
| 109 | LY_CHECK_ERR_RET(!*buf, LOGMEM(ctx), LY_EMEM); |
| 110 | } |
Radek Krejci | c091739 | 2019-04-10 13:04:04 +0200 | [diff] [blame] | 111 | if (*buf_used) { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 112 | ly_in_read(in, &(*buf)[*buf_used], len); |
Radek Krejci | c091739 | 2019-04-10 13:04:04 +0200 | [diff] [blame] | 113 | } else { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 114 | ly_in_read(in, *buf, len); |
Radek Krejci | c091739 | 2019-04-10 13:04:04 +0200 | [diff] [blame] | 115 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 116 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 117 | (*buf_used) += len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 118 | return LY_SUCCESS; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 119 | #undef BUF_STEP |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 122 | /** |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 123 | * @brief Store a single UTF8 character. It depends whether in a dynamically-allocated buffer or just as a pointer to the data. |
| 124 | * |
| 125 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 126 | * @param[in] arg Type of the input string to select method of checking character validity. |
| 127 | * @param[in,out] word_p Word pointer. If buffer (\p word_b) was not yet needed, it is just a pointer to the first |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 128 | * stored character. If buffer was needed (\p word_b is non-NULL or \p need_buf is set), it is pointing to the buffer. |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 129 | * @param[in,out] word_len Current length of the word pointed to by \p word_p. |
| 130 | * @param[in,out] word_b Word buffer. Is kept NULL as long as it is not requested (word is a substring of the data). |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 131 | * @param[in,out] buf_len Current length of \p word_b. |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 132 | * @param[in] need_buf Flag if the dynamically allocated buffer is required. |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 133 | * @param[in,out] prefix Storage for internally used flag in case of possible prefixed identifiers: |
| 134 | * 0 - colon not yet found (no prefix) |
| 135 | * 1 - \p c is the colon character |
| 136 | * 2 - prefix already processed, now processing the identifier |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 137 | * |
| 138 | * @return LY_ERR values. |
| 139 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 140 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 141 | buf_store_char(struct lys_yang_parser_ctx *ctx, enum yang_arg arg, char **word_p, size_t *word_len, |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 142 | char **word_b, size_t *buf_len, ly_bool need_buf, uint8_t *prefix) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 143 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 144 | uint32_t c; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 145 | size_t len; |
| 146 | |
Radek Krejci | f29b7c3 | 2019-04-09 16:17:49 +0200 | [diff] [blame] | 147 | /* check valid combination of input paremeters - if need_buf specified, word_b must be provided */ |
| 148 | assert(!need_buf || (need_buf && word_b)); |
| 149 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 150 | /* get UTF8 code point (and number of bytes coding the character) */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 151 | LY_CHECK_ERR_RET(ly_getutf8(&ctx->in->current, &c, &len), |
| 152 | LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, ctx->in->current[-len]), LY_EVALID); |
| 153 | ctx->in->current -= len; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 154 | if (c == '\n') { |
| 155 | ctx->indent = 0; |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 156 | LY_IN_NEW_LINE(ctx->in); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 157 | } else { |
| 158 | /* note - even the multibyte character is count as 1 */ |
| 159 | ++ctx->indent; |
| 160 | } |
| 161 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 162 | /* check character validity */ |
| 163 | switch (arg) { |
| 164 | case Y_IDENTIF_ARG: |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 165 | LY_CHECK_RET(lysp_check_identifierchar((struct lys_parser_ctx *)ctx, c, !(*word_len), NULL)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 166 | break; |
| 167 | case Y_PREF_IDENTIF_ARG: |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 168 | LY_CHECK_RET(lysp_check_identifierchar((struct lys_parser_ctx *)ctx, c, !(*word_len), prefix)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 169 | break; |
| 170 | case Y_STR_ARG: |
| 171 | case Y_MAYBE_STR_ARG: |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 172 | LY_CHECK_RET(lysp_check_stringchar((struct lys_parser_ctx *)ctx, c)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 173 | break; |
| 174 | } |
| 175 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 176 | if (word_b && *word_b) { |
| 177 | /* add another character into buffer */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 178 | if (buf_add_char(PARSER_CTX(ctx), ctx->in, len, word_b, buf_len, word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 179 | return LY_EMEM; |
| 180 | } |
| 181 | |
| 182 | /* in case of realloc */ |
| 183 | *word_p = *word_b; |
Radek Krejci | f29b7c3 | 2019-04-09 16:17:49 +0200 | [diff] [blame] | 184 | } else if (word_b && need_buf) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 185 | /* first time we need a buffer, copy everything read up to now */ |
| 186 | if (*word_len) { |
| 187 | *word_b = malloc(*word_len); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 188 | LY_CHECK_ERR_RET(!*word_b, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 189 | *buf_len = *word_len; |
| 190 | memcpy(*word_b, *word_p, *word_len); |
| 191 | } |
| 192 | |
| 193 | /* add this new character into buffer */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 194 | if (buf_add_char(PARSER_CTX(ctx), ctx->in, len, word_b, buf_len, word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 195 | return LY_EMEM; |
| 196 | } |
| 197 | |
| 198 | /* in case of realloc */ |
| 199 | *word_p = *word_b; |
| 200 | } else { |
| 201 | /* just remember the first character pointer */ |
| 202 | if (!*word_p) { |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 203 | *word_p = (char *)ctx->in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 204 | } |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 205 | /* ... and update the word's length */ |
| 206 | (*word_len) += len; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 207 | ly_in_skip(ctx->in, len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | return LY_SUCCESS; |
| 211 | } |
| 212 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 213 | /** |
| 214 | * @brief Skip YANG comment in data. |
| 215 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 216 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 217 | * @param[in] comment Type of the comment to process: |
| 218 | * 1 for a one-line comment, |
| 219 | * 2 for a block comment. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 220 | * @return LY_ERR values. |
| 221 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 222 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 223 | skip_comment(struct lys_yang_parser_ctx *ctx, uint8_t comment) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 224 | { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 225 | /* internal statuses: */ |
| 226 | #define COMMENT_NO 0 /* comment ended */ |
| 227 | #define COMMENT_LINE 1 /* in line comment */ |
| 228 | #define COMMENT_BLOCK 2 /* in block comment */ |
| 229 | #define COMMENT_BLOCK_END 3 /* in block comment with last read character '*' */ |
| 230 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 231 | while (ctx->in->current[0] && comment) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 232 | switch (comment) { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 233 | case COMMENT_LINE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 234 | if (ctx->in->current[0] == '\n') { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 235 | comment = COMMENT_NO; |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 236 | LY_IN_NEW_LINE(ctx->in); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 237 | } |
| 238 | break; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 239 | case COMMENT_BLOCK: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 240 | if (ctx->in->current[0] == '*') { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 241 | comment = COMMENT_BLOCK_END; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 242 | } else if (ctx->in->current[0] == '\n') { |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 243 | LY_IN_NEW_LINE(ctx->in); |
Radek Krejci | 15c80ca | 2018-10-09 11:01:31 +0200 | [diff] [blame] | 244 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 245 | break; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 246 | case COMMENT_BLOCK_END: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 247 | if (ctx->in->current[0] == '/') { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 248 | comment = COMMENT_NO; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 249 | } else if (ctx->in->current[0] != '*') { |
| 250 | if (ctx->in->current[0] == '\n') { |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 251 | LY_IN_NEW_LINE(ctx->in); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 252 | } |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 253 | comment = COMMENT_BLOCK; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 254 | } |
| 255 | break; |
| 256 | default: |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 257 | LOGINT_RET(PARSER_CTX(ctx)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 260 | if (ctx->in->current[0] == '\n') { |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 261 | ctx->indent = 0; |
| 262 | } else { |
| 263 | ++ctx->indent; |
| 264 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 265 | ++ctx->in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 266 | } |
| 267 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 268 | if (!ctx->in->current[0] && (comment >= COMMENT_BLOCK)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 269 | LOGVAL_PARSER(ctx, LYVE_SYNTAX, "Unexpected end-of-input, non-terminated comment."); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 270 | return LY_EVALID; |
| 271 | } |
| 272 | |
| 273 | return LY_SUCCESS; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 274 | |
| 275 | #undef COMMENT_NO |
| 276 | #undef COMMENT_LINE |
| 277 | #undef COMMENT_BLOCK |
| 278 | #undef COMMENT_BLOCK_END |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 281 | /** |
| 282 | * @brief Read a quoted string from data. |
| 283 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 284 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 285 | * @param[in] arg Type of YANG keyword argument expected. |
| 286 | * @param[out] word_p Pointer to the read quoted string. |
| 287 | * @param[out] word_b Pointer to a dynamically-allocated buffer holding the read quoted string. If not needed, |
| 288 | * set to NULL. Otherwise equal to \p word_p. |
| 289 | * @param[out] word_len Length of the read quoted string. |
| 290 | * @param[out] buf_len Length of the dynamically-allocated buffer \p word_b. |
| 291 | * @param[in] indent Current indent (number of YANG spaces). Needed for correct multi-line string |
| 292 | * indenation in the final quoted string. |
| 293 | * |
| 294 | * @return LY_ERR values. |
| 295 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 296 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 297 | read_qstring(struct lys_yang_parser_ctx *ctx, enum yang_arg arg, char **word_p, char **word_b, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 298 | size_t *word_len, size_t *buf_len) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 299 | { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 300 | /* string parsing status: */ |
| 301 | #define STRING_ENDED 0 /* string ended */ |
| 302 | #define STRING_SINGLE_QUOTED 1 /* string with ' */ |
| 303 | #define STRING_DOUBLE_QUOTED 2 /* string with " */ |
| 304 | #define STRING_DOUBLE_QUOTED_ESCAPED 3 /* string with " with last character \ */ |
| 305 | #define STRING_PAUSED_NEXTSTRING 4 /* string finished, now skipping whitespaces looking for + */ |
| 306 | #define STRING_PAUSED_CONTINUE 5 /* string continues after +, skipping whitespaces */ |
| 307 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 308 | uint8_t string; |
| 309 | uint64_t block_indent = 0, current_indent = 0; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 310 | ly_bool need_buf = 0; |
| 311 | uint8_t prefix = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 312 | const char *c; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 313 | uint64_t trailing_ws = 0; /* current number of stored trailing whitespace characters */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 314 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 315 | if (ctx->in->current[0] == '\"') { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 316 | string = STRING_DOUBLE_QUOTED; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 317 | current_indent = block_indent = ctx->indent + 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 318 | } else { |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 319 | assert(ctx->in->current[0] == '\''); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 320 | string = STRING_SINGLE_QUOTED; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 321 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 322 | MOVE_INPUT(ctx, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 323 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 324 | while (ctx->in->current[0] && string) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 325 | switch (string) { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 326 | case STRING_SINGLE_QUOTED: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 327 | switch (ctx->in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 328 | case '\'': |
| 329 | /* string may be finished, but check for + */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 330 | string = STRING_PAUSED_NEXTSTRING; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 331 | MOVE_INPUT(ctx, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 332 | break; |
| 333 | default: |
| 334 | /* check and store character */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 335 | LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 336 | break; |
| 337 | } |
| 338 | break; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 339 | case STRING_DOUBLE_QUOTED: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 340 | switch (ctx->in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 341 | case '\"': |
| 342 | /* string may be finished, but check for + */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 343 | string = STRING_PAUSED_NEXTSTRING; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 344 | MOVE_INPUT(ctx, 1); |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 345 | trailing_ws = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 346 | break; |
| 347 | case '\\': |
| 348 | /* special character following */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 349 | string = STRING_DOUBLE_QUOTED_ESCAPED; |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 350 | |
| 351 | /* the backslash sequence is substituted, so we will need a buffer to store the result */ |
| 352 | need_buf = 1; |
| 353 | |
| 354 | /* move forward to the escaped character */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 355 | ++ctx->in->current; |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 356 | |
| 357 | /* note that the trailing whitespaces are supposed to be trimmed before substitution of |
| 358 | * backslash-escaped characters (RFC 7950, 6.1.3), so we have to zero the trailing whitespaces counter */ |
| 359 | trailing_ws = 0; |
| 360 | |
| 361 | /* since the backslash-escaped character is handled as first non-whitespace character, stop eating indentation */ |
| 362 | current_indent = block_indent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 363 | break; |
| 364 | case ' ': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 365 | if (current_indent < block_indent) { |
| 366 | ++current_indent; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 367 | MOVE_INPUT(ctx, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 368 | } else { |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 369 | /* check and store whitespace character */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 370 | LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 371 | trailing_ws++; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 372 | } |
| 373 | break; |
| 374 | case '\t': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 375 | if (current_indent < block_indent) { |
| 376 | assert(need_buf); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 377 | current_indent += Y_TAB_SPACES; |
| 378 | ctx->indent += Y_TAB_SPACES; |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 379 | for ( ; current_indent > block_indent; --current_indent, --ctx->indent) { |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 380 | /* store leftover spaces from the tab */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 381 | c = ctx->in->current; |
| 382 | ctx->in->current = " "; |
| 383 | LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
| 384 | ctx->in->current = c; |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 385 | trailing_ws++; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 386 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 387 | ++ctx->in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 388 | } else { |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 389 | /* check and store whitespace character */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 390 | LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 391 | trailing_ws++; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 392 | /* additional characters for indentation - only 1 was count in buf_store_char */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 393 | ctx->indent += Y_TAB_SPACES - 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 394 | } |
| 395 | break; |
| 396 | case '\n': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 397 | if (block_indent) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 398 | /* we will be removing the indents so we need our own buffer */ |
| 399 | need_buf = 1; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 400 | |
| 401 | /* remove trailing tabs and spaces */ |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 402 | (*word_len) = *word_len - trailing_ws; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 403 | |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 404 | /* restart indentation */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 405 | current_indent = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /* check and store character */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 409 | LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 410 | |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 411 | /* reset context indentation counter for possible string after this one */ |
| 412 | ctx->indent = 0; |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 413 | trailing_ws = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 414 | break; |
| 415 | default: |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 416 | /* first non-whitespace character, stop eating indentation */ |
| 417 | current_indent = block_indent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 418 | |
| 419 | /* check and store character */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 420 | LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 421 | trailing_ws = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 422 | break; |
| 423 | } |
| 424 | break; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 425 | case STRING_DOUBLE_QUOTED_ESCAPED: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 426 | /* string encoded characters */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 427 | c = ctx->in->current; |
| 428 | switch (ctx->in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 429 | case 'n': |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 430 | ctx->in->current = "\n"; |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 431 | /* fix false newline count in buf_store_char() */ |
| 432 | ctx->in->line--; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 433 | break; |
| 434 | case 't': |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 435 | ctx->in->current = "\t"; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 436 | break; |
| 437 | case '\"': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 438 | case '\\': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 439 | /* ok as is */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 440 | break; |
| 441 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 442 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Double-quoted string unknown special character '\\%c'.", |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 443 | ctx->in->current[0]); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 444 | return LY_EVALID; |
| 445 | } |
| 446 | |
| 447 | /* check and store character */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 448 | LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 449 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 450 | string = STRING_DOUBLE_QUOTED; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 451 | ctx->in->current = c + 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 452 | break; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 453 | case STRING_PAUSED_NEXTSTRING: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 454 | switch (ctx->in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 455 | case '+': |
| 456 | /* string continues */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 457 | string = STRING_PAUSED_CONTINUE; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 458 | need_buf = 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 459 | break; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 460 | case '\n': |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 461 | LY_IN_NEW_LINE(ctx->in); |
Radek Krejci | cb3e647 | 2021-01-06 08:19:01 +0100 | [diff] [blame] | 462 | /* fall through */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 463 | case ' ': |
| 464 | case '\t': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 465 | /* just skip */ |
| 466 | break; |
| 467 | default: |
| 468 | /* string is finished */ |
| 469 | goto string_end; |
| 470 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 471 | MOVE_INPUT(ctx, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 472 | break; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 473 | case STRING_PAUSED_CONTINUE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 474 | switch (ctx->in->current[0]) { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 475 | case '\n': |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 476 | LY_IN_NEW_LINE(ctx->in); |
Radek Krejci | cb3e647 | 2021-01-06 08:19:01 +0100 | [diff] [blame] | 477 | /* fall through */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 478 | case ' ': |
| 479 | case '\t': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 480 | /* skip */ |
| 481 | break; |
| 482 | case '\'': |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 483 | string = STRING_SINGLE_QUOTED; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 484 | break; |
| 485 | case '\"': |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 486 | string = STRING_DOUBLE_QUOTED; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 487 | break; |
| 488 | default: |
| 489 | /* it must be quoted again */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 490 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Both string parts divided by '+' must be quoted."); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 491 | return LY_EVALID; |
| 492 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 493 | MOVE_INPUT(ctx, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 494 | break; |
| 495 | default: |
| 496 | return LY_EINT; |
| 497 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | string_end: |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 501 | if ((arg <= Y_PREF_IDENTIF_ARG) && !(*word_len)) { |
Radek Krejci | 4e199f5 | 2019-05-28 09:09:28 +0200 | [diff] [blame] | 502 | /* empty identifier */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 503 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Statement argument is required."); |
Radek Krejci | 4e199f5 | 2019-05-28 09:09:28 +0200 | [diff] [blame] | 504 | return LY_EVALID; |
| 505 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 506 | return LY_SUCCESS; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 507 | |
| 508 | #undef STRING_ENDED |
| 509 | #undef STRING_SINGLE_QUOTED |
| 510 | #undef STRING_DOUBLE_QUOTED |
| 511 | #undef STRING_DOUBLE_QUOTED_ESCAPED |
| 512 | #undef STRING_PAUSED_NEXTSTRING |
| 513 | #undef STRING_PAUSED_CONTINUE |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 516 | /** |
| 517 | * @brief Get another YANG string from the raw data. |
| 518 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 519 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 520 | * @param[in] arg Type of YANG keyword argument expected. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 521 | * @param[out] flags optional output argument to get flag of the argument's quoting (LYS_*QOUTED - see [schema node flags](@ref snodeflags)) |
Michal Vasko | 2ca70f5 | 2018-09-27 11:04:51 +0200 | [diff] [blame] | 522 | * @param[out] word_p Pointer to the read string. Can return NULL if \p arg is #Y_MAYBE_STR_ARG. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 523 | * @param[out] word_b Pointer to a dynamically-allocated buffer holding the read string. If not needed, |
| 524 | * set to NULL. Otherwise equal to \p word_p. |
| 525 | * @param[out] word_len Length of the read string. |
| 526 | * |
| 527 | * @return LY_ERR values. |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 528 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 529 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 530 | get_argument(struct lys_yang_parser_ctx *ctx, enum yang_arg arg, uint16_t *flags, char **word_p, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 531 | char **word_b, size_t *word_len) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 532 | { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 533 | size_t buf_len = 0; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 534 | uint8_t prefix = 0; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 535 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 536 | /* word buffer - dynamically allocated */ |
| 537 | *word_b = NULL; |
| 538 | |
| 539 | /* word pointer - just a pointer to data */ |
| 540 | *word_p = NULL; |
| 541 | |
| 542 | *word_len = 0; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 543 | while (ctx->in->current[0]) { |
| 544 | switch (ctx->in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 545 | case '\'': |
| 546 | case '\"': |
| 547 | if (*word_len) { |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 548 | /* invalid - quotes cannot be in unquoted string and only optsep, ; or { can follow it */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 549 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, 1, ctx->in->current, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 550 | "unquoted string character, optsep, semicolon or opening brace"); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 551 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 552 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 553 | if (flags) { |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 554 | (*flags) |= ctx->in->current[0] == '\'' ? LYS_SINGLEQUOTED : LYS_DOUBLEQUOTED; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 555 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 556 | LY_CHECK_RET(read_qstring(ctx, arg, word_p, word_b, word_len, &buf_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 557 | goto str_end; |
| 558 | case '/': |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 559 | if (ctx->in->current[1] == '/') { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 560 | /* one-line comment */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 561 | MOVE_INPUT(ctx, 2); |
| 562 | LY_CHECK_RET(skip_comment(ctx, 1)); |
| 563 | } else if (ctx->in->current[1] == '*') { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 564 | /* block comment */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 565 | MOVE_INPUT(ctx, 2); |
| 566 | LY_CHECK_RET(skip_comment(ctx, 2)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 567 | } else { |
| 568 | /* not a comment after all */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 569 | LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, &buf_len, 0, &prefix)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 570 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 571 | break; |
| 572 | case ' ': |
| 573 | if (*word_len) { |
| 574 | /* word is finished */ |
| 575 | goto str_end; |
| 576 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 577 | MOVE_INPUT(ctx, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 578 | break; |
| 579 | case '\t': |
| 580 | if (*word_len) { |
| 581 | /* word is finished */ |
| 582 | goto str_end; |
| 583 | } |
| 584 | /* tabs count for 8 spaces */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 585 | ctx->indent += Y_TAB_SPACES; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 586 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 587 | ++ctx->in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 588 | break; |
| 589 | case '\n': |
| 590 | if (*word_len) { |
| 591 | /* word is finished */ |
| 592 | goto str_end; |
| 593 | } |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 594 | LY_IN_NEW_LINE(ctx->in); |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 595 | MOVE_INPUT(ctx, 1); |
| 596 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 597 | /* reset indent */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 598 | ctx->indent = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 599 | break; |
| 600 | case ';': |
| 601 | case '{': |
| 602 | if (*word_len || (arg == Y_MAYBE_STR_ARG)) { |
| 603 | /* word is finished */ |
| 604 | goto str_end; |
| 605 | } |
| 606 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 607 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, 1, ctx->in->current, "an argument"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 608 | return LY_EVALID; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 609 | case '}': |
| 610 | /* invalid - braces cannot be in unquoted string (opening braces terminates the string and can follow it) */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 611 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, 1, ctx->in->current, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 612 | "unquoted string character, optsep, semicolon or opening brace"); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 613 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 614 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 615 | LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, &buf_len, 0, &prefix)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 616 | break; |
| 617 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 618 | } |
| 619 | |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 620 | /* unexpected end of loop */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 621 | LOGVAL_PARSER(ctx, LY_VCODE_EOF); |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 622 | return LY_EVALID; |
| 623 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 624 | str_end: |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 625 | /* terminating NULL byte for buf */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 626 | if (*word_b) { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 627 | (*word_b) = ly_realloc(*word_b, (*word_len) + 1); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 628 | LY_CHECK_ERR_RET(!(*word_b), LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 629 | (*word_b)[*word_len] = '\0'; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 630 | *word_p = *word_b; |
| 631 | } |
| 632 | |
| 633 | return LY_SUCCESS; |
| 634 | } |
| 635 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 636 | /** |
| 637 | * @brief Get another YANG keyword from the raw data. |
| 638 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 639 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 640 | * @param[out] kw YANG keyword read. |
| 641 | * @param[out] word_p Pointer to the keyword in the data. Useful for extension instances. |
| 642 | * @param[out] word_len Length of the keyword in the data. Useful for extension instances. |
| 643 | * |
| 644 | * @return LY_ERR values. |
| 645 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 646 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 647 | get_keyword(struct lys_yang_parser_ctx *ctx, enum ly_stmt *kw, char **word_p, size_t *word_len) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 648 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 649 | uint8_t prefix; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 650 | const char *word_start; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 651 | size_t len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 652 | |
| 653 | if (word_p) { |
| 654 | *word_p = NULL; |
| 655 | *word_len = 0; |
| 656 | } |
| 657 | |
| 658 | /* first skip "optsep", comments */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 659 | while (ctx->in->current[0]) { |
| 660 | switch (ctx->in->current[0]) { |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 661 | case '/': |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 662 | if (ctx->in->current[1] == '/') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 663 | /* one-line comment */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 664 | MOVE_INPUT(ctx, 2); |
| 665 | LY_CHECK_RET(skip_comment(ctx, 1)); |
| 666 | } else if (ctx->in->current[1] == '*') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 667 | /* block comment */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 668 | MOVE_INPUT(ctx, 2); |
| 669 | LY_CHECK_RET(skip_comment(ctx, 2)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 670 | } else { |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 671 | /* error - not a comment after all, keyword cannot start with slash */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 672 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Invalid identifier first character '/'."); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 673 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 674 | } |
Radek Krejci | 1302828 | 2019-06-11 14:56:48 +0200 | [diff] [blame] | 675 | continue; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 676 | case '\n': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 677 | /* skip whitespaces (optsep) */ |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 678 | LY_IN_NEW_LINE(ctx->in); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 679 | ctx->indent = 0; |
| 680 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 681 | case ' ': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 682 | /* skip whitespaces (optsep) */ |
| 683 | ++ctx->indent; |
| 684 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 685 | case '\t': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 686 | /* skip whitespaces (optsep) */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 687 | ctx->indent += Y_TAB_SPACES; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 688 | break; |
| 689 | default: |
| 690 | /* either a keyword start or an invalid character */ |
| 691 | goto keyword_start; |
| 692 | } |
| 693 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 694 | ly_in_skip(ctx->in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | keyword_start: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 698 | word_start = ctx->in->current; |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 699 | *kw = lysp_match_kw(ctx->in, &ctx->indent); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 700 | |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 701 | if ((*kw == LY_STMT_SYNTAX_SEMICOLON) || (*kw == LY_STMT_SYNTAX_LEFT_BRACE) || (*kw == LY_STMT_SYNTAX_RIGHT_BRACE)) { |
Radek Krejci | 626df48 | 2018-10-11 15:06:31 +0200 | [diff] [blame] | 702 | goto success; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 703 | } |
| 704 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 705 | if (*kw != LY_STMT_NONE) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 706 | /* make sure we have the whole keyword */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 707 | switch (ctx->in->current[0]) { |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 708 | case '\n': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 709 | case '\t': |
Radek Krejci | abdd806 | 2019-06-11 16:44:19 +0200 | [diff] [blame] | 710 | case ' ': |
| 711 | /* mandatory "sep" is just checked, not eaten so nothing in the context is updated */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 712 | break; |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 713 | case ':': |
| 714 | /* keyword is not actually a keyword, but prefix of an extension. |
| 715 | * To avoid repeated check of the prefix syntax, move to the point where the colon was read |
| 716 | * and we will be checking the keyword (extension instance) itself */ |
| 717 | prefix = 1; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 718 | MOVE_INPUT(ctx, 1); |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 719 | goto extension; |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 720 | case '{': |
| 721 | /* allowed only for input and output statements which can be without arguments */ |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 722 | if ((*kw == LY_STMT_INPUT) || (*kw == LY_STMT_OUTPUT)) { |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 723 | break; |
| 724 | } |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 725 | /* fall through */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 726 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 727 | MOVE_INPUT(ctx, 1); |
| 728 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, (int)(ctx->in->current - word_start), word_start, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 729 | "a keyword followed by a separator"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 730 | return LY_EVALID; |
| 731 | } |
| 732 | } else { |
| 733 | /* still can be an extension */ |
| 734 | prefix = 0; |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 735 | extension: |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 736 | while (ctx->in->current[0] && (ctx->in->current[0] != ' ') && (ctx->in->current[0] != '\t') && |
| 737 | (ctx->in->current[0] != '\n') && (ctx->in->current[0] != '{') && (ctx->in->current[0] != ';')) { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 738 | uint32_t c = 0; |
| 739 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 740 | LY_CHECK_ERR_RET(ly_getutf8(&ctx->in->current, &c, &len), |
| 741 | LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, ctx->in->current[-len]), LY_EVALID); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 742 | ++ctx->indent; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 743 | /* check character validity */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 744 | LY_CHECK_RET(lysp_check_identifierchar((struct lys_parser_ctx *)ctx, c, |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 745 | ctx->in->current - len == word_start ? 1 : 0, &prefix)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 746 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 747 | if (!ctx->in->current[0]) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 748 | LOGVAL_PARSER(ctx, LY_VCODE_EOF); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 749 | return LY_EVALID; |
| 750 | } |
| 751 | |
| 752 | /* prefix is mandatory for extension instances */ |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 753 | if (prefix != 2) { |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 754 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, (int)(ctx->in->current - word_start), word_start, "a keyword"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 755 | return LY_EVALID; |
| 756 | } |
| 757 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 758 | *kw = LY_STMT_EXTENSION_INSTANCE; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 759 | } |
Radek Krejci | 626df48 | 2018-10-11 15:06:31 +0200 | [diff] [blame] | 760 | success: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 761 | if (word_p) { |
| 762 | *word_p = (char *)word_start; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 763 | *word_len = ctx->in->current - word_start; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | return LY_SUCCESS; |
| 767 | } |
| 768 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 769 | /** |
| 770 | * @brief Parse extension instance substatements. |
| 771 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 772 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 773 | * @param[in] kw Statement keyword value matching @p word value. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 774 | * @param[in] word Extension instance substatement name (keyword). |
| 775 | * @param[in] word_len Extension instance substatement name length. |
| 776 | * @param[in,out] child Children of this extension instance to add to. |
| 777 | * |
| 778 | * @return LY_ERR values. |
| 779 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 780 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 781 | parse_ext_substmt(struct lys_yang_parser_ctx *ctx, enum ly_stmt kw, char *word, size_t word_len, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 782 | struct lysp_stmt **child) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 783 | { |
| 784 | char *buf; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 785 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 786 | enum ly_stmt child_kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 787 | struct lysp_stmt *stmt, *par_child; |
| 788 | |
| 789 | stmt = calloc(1, sizeof *stmt); |
| 790 | LY_CHECK_ERR_RET(!stmt, LOGMEM(NULL), LY_EMEM); |
| 791 | |
Radek Krejci | bb9b198 | 2019-04-08 14:24:59 +0200 | [diff] [blame] | 792 | /* insert into parent statements */ |
| 793 | if (!*child) { |
| 794 | *child = stmt; |
| 795 | } else { |
Radek Krejci | 1e008d2 | 2020-08-17 11:37:37 +0200 | [diff] [blame] | 796 | for (par_child = *child; par_child->next; par_child = par_child->next) {} |
Radek Krejci | bb9b198 | 2019-04-08 14:24:59 +0200 | [diff] [blame] | 797 | par_child->next = stmt; |
| 798 | } |
| 799 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 800 | LY_CHECK_RET(lydict_insert(PARSER_CTX(ctx), word, word_len, &stmt->stmt)); |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 801 | stmt->kw = kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 802 | |
| 803 | /* get optional argument */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 804 | LY_CHECK_RET(get_argument(ctx, Y_MAYBE_STR_ARG, &stmt->flags, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 805 | |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 806 | if (word) { |
| 807 | if (buf) { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 808 | LY_CHECK_RET(lydict_insert_zc(PARSER_CTX(ctx), word, &stmt->arg)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 809 | } else { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 810 | LY_CHECK_RET(lydict_insert(PARSER_CTX(ctx), word, word_len, &stmt->arg)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 811 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 812 | } |
| 813 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 814 | YANG_READ_SUBSTMT_FOR(ctx, child_kw, word, word_len, ret, ) { |
| 815 | LY_CHECK_RET(parse_ext_substmt(ctx, child_kw, word, word_len, &stmt->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 816 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 817 | return ret; |
| 818 | } |
| 819 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 820 | /** |
| 821 | * @brief Parse extension instance. |
| 822 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 823 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 824 | * @param[in] ext_name Extension instance substatement name (keyword). |
| 825 | * @param[in] ext_name_len Extension instance substatement name length. |
| 826 | * @param[in] insubstmt Type of the keyword this extension instance is a substatement of. |
| 827 | * @param[in] insubstmt_index Index of the keyword instance this extension instance is a substatement of. |
| 828 | * @param[in,out] exts Extension instances to add to. |
| 829 | * |
| 830 | * @return LY_ERR values. |
| 831 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 832 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 833 | parse_ext(struct lys_yang_parser_ctx *ctx, const char *ext_name, size_t ext_name_len, LYEXT_SUBSTMT insubstmt, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 834 | LY_ARRAY_COUNT_TYPE insubstmt_index, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 835 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 836 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 837 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 838 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 839 | struct lysp_ext_instance *e; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 840 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 841 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 842 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *exts, e, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 843 | |
| 844 | /* store name and insubstmt info */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 845 | LY_CHECK_RET(lydict_insert(PARSER_CTX(ctx), ext_name, ext_name_len, &e->name)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 846 | e->insubstmt = insubstmt; |
| 847 | e->insubstmt_index = insubstmt_index; |
| 848 | |
| 849 | /* get optional argument */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 850 | LY_CHECK_RET(get_argument(ctx, Y_MAYBE_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 851 | |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 852 | if (word) { |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 853 | INSERT_WORD_RET(ctx, buf, e->argument, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 854 | } |
| 855 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 856 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
| 857 | LY_CHECK_RET(parse_ext_substmt(ctx, kw, word, word_len, &e->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 858 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 859 | return ret; |
| 860 | } |
| 861 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 862 | /** |
| 863 | * @brief Parse a generic text field without specific constraints. Those are contact, organization, |
| 864 | * description, etc... |
| 865 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 866 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 867 | * @param[in] substmt Type of this substatement. |
| 868 | * @param[in] substmt_index Index of this substatement. |
| 869 | * @param[in,out] value Place to store the parsed value. |
| 870 | * @param[in] arg Type of the YANG keyword argument (of the value). |
| 871 | * @param[in,out] exts Extension instances to add to. |
| 872 | * |
| 873 | * @return LY_ERR values. |
| 874 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 875 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 876 | parse_text_field(struct lys_yang_parser_ctx *ctx, LYEXT_SUBSTMT substmt, uint32_t substmt_index, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 877 | const char **value, enum yang_arg arg, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 878 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 879 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 880 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 881 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 882 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 883 | |
| 884 | if (*value) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 885 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, lyext_substmt2str(substmt)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 886 | return LY_EVALID; |
| 887 | } |
| 888 | |
| 889 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 890 | LY_CHECK_RET(get_argument(ctx, arg, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 891 | |
| 892 | /* store value and spend buf if allocated */ |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 893 | INSERT_WORD_RET(ctx, buf, *value, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 894 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 895 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 896 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 897 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 898 | LY_CHECK_RET(parse_ext(ctx, word, word_len, substmt, substmt_index, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 899 | break; |
| 900 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 901 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 902 | return LY_EVALID; |
| 903 | } |
| 904 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 905 | return ret; |
| 906 | } |
| 907 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 908 | /** |
| 909 | * @brief Parse the yang-version statement. |
| 910 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 911 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 912 | * @param[out] version Storage for the parsed information. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 913 | * @param[in,out] exts Extension instances to add to. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 914 | * |
| 915 | * @return LY_ERR values. |
| 916 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 917 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 918 | parse_yangversion(struct lys_yang_parser_ctx *ctx, uint8_t *version, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 919 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 920 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 921 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 922 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 923 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 924 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 925 | if (*version) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 926 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "yang-version"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 927 | return LY_EVALID; |
| 928 | } |
| 929 | |
| 930 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 931 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 932 | |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 933 | if ((word_len == 1) && !strncmp(word, "1", word_len)) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 934 | *version = LYS_VERSION_1_0; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 935 | } else if ((word_len == ly_strlen_const("1.1")) && !strncmp(word, "1.1", word_len)) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 936 | *version = LYS_VERSION_1_1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 937 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 938 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "yang-version"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 939 | free(buf); |
| 940 | return LY_EVALID; |
| 941 | } |
| 942 | free(buf); |
| 943 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 944 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 945 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 946 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 947 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_VERSION, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 948 | break; |
| 949 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 950 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "yang-version"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 951 | return LY_EVALID; |
| 952 | } |
| 953 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 954 | return ret; |
| 955 | } |
| 956 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 957 | /** |
| 958 | * @brief Parse the belongs-to statement. |
| 959 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 960 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 961 | * @param[in,out] prefix Place to store the parsed belongs-to prefix value. |
| 962 | * @param[in,out] exts Extension instances to add to. |
| 963 | * |
| 964 | * @return LY_ERR values. |
| 965 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 966 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 967 | parse_belongsto(struct lys_yang_parser_ctx *ctx, const char **prefix, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 968 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 969 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 970 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 971 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 972 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 973 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 974 | if (*prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 975 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "belongs-to"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 976 | return LY_EVALID; |
| 977 | } |
| 978 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 979 | /* get value, it must match the main module */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 980 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 981 | if (ly_strncmp(ctx->parsed_mod->mod->name, word, word_len)) { |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 982 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Submodule \"belongs-to\" value \"%.*s\" does not match its module name \"%s\".", |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 983 | (int)word_len, word, ctx->parsed_mod->mod->name); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 984 | free(buf); |
| 985 | return LY_EVALID; |
| 986 | } |
| 987 | free(buf); |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 988 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 989 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 990 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 991 | case LY_STMT_PREFIX: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 992 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_PREFIX, 0, prefix, Y_IDENTIF_ARG, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 993 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 994 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 995 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_BELONGSTO, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 996 | break; |
| 997 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 998 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "belongs-to"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 999 | return LY_EVALID; |
| 1000 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1001 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 1002 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 1003 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1004 | /* mandatory substatements */ |
| 1005 | if (!*prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1006 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "prefix", "belongs-to"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1007 | return LY_EVALID; |
| 1008 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1009 | return ret; |
| 1010 | } |
| 1011 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1012 | /** |
| 1013 | * @brief Parse the revision-date statement. |
| 1014 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1015 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1016 | * @param[in,out] rev Array to store the parsed value in. |
| 1017 | * @param[in,out] exts Extension instances to add to. |
| 1018 | * |
| 1019 | * @return LY_ERR values. |
| 1020 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1021 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1022 | parse_revisiondate(struct lys_yang_parser_ctx *ctx, char *rev, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1023 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1024 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1025 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1026 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1027 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1028 | |
| 1029 | if (rev[0]) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1030 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "revision-date"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1031 | return LY_EVALID; |
| 1032 | } |
| 1033 | |
| 1034 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1035 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1036 | |
| 1037 | /* check value */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1038 | if (lysp_check_date((struct lys_parser_ctx *)ctx, word, word_len, "revision-date")) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1039 | free(buf); |
| 1040 | return LY_EVALID; |
| 1041 | } |
| 1042 | |
| 1043 | /* store value and spend buf if allocated */ |
| 1044 | strncpy(rev, word, word_len); |
| 1045 | free(buf); |
| 1046 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1047 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1048 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1049 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1050 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_REVISIONDATE, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1051 | break; |
| 1052 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1053 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "revision-date"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1054 | return LY_EVALID; |
| 1055 | } |
| 1056 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1057 | return ret; |
| 1058 | } |
| 1059 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1060 | /** |
| 1061 | * @brief Parse the include statement. |
| 1062 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1063 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1064 | * @param[in] module_name Name of the module to check name collisions. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1065 | * @param[in,out] includes Parsed includes to add to. |
| 1066 | * |
| 1067 | * @return LY_ERR values. |
| 1068 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1069 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1070 | parse_include(struct lys_yang_parser_ctx *ctx, const char *module_name, struct lysp_include **includes) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1071 | { |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 1072 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1073 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1074 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1075 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1076 | struct lysp_include *inc; |
| 1077 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1078 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *includes, inc, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1079 | |
| 1080 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1081 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1082 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1083 | INSERT_WORD_RET(ctx, buf, inc->name, word, word_len); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 1084 | |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 1085 | /* submodules share the namespace with the module names, so there must not be |
| 1086 | * a module of the same name in the context, no need for revision matching */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1087 | if (!strcmp(module_name, inc->name) || ly_ctx_get_module_latest(PARSER_CTX(ctx), inc->name)) { |
Radek Krejci | 854e155 | 2020-12-21 15:05:23 +0100 | [diff] [blame] | 1088 | LOGVAL_PARSER(ctx, LY_VCODE_NAME2_COL, "module", "submodule", inc->name); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 1089 | return LY_EVALID; |
| 1090 | } |
| 1091 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1092 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1093 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1094 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1095 | PARSER_CHECK_STMTVER2_RET(ctx, "description", "include"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1096 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &inc->dsc, Y_STR_ARG, &inc->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1097 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1098 | case LY_STMT_REFERENCE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1099 | PARSER_CHECK_STMTVER2_RET(ctx, "reference", "include"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1100 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &inc->ref, Y_STR_ARG, &inc->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1101 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1102 | case LY_STMT_REVISION_DATE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1103 | LY_CHECK_RET(parse_revisiondate(ctx, inc->rev, &inc->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1104 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1105 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1106 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &inc->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1107 | break; |
| 1108 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1109 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "include"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1110 | return LY_EVALID; |
| 1111 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1112 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1113 | return ret; |
| 1114 | } |
| 1115 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1116 | /** |
| 1117 | * @brief Parse the import statement. |
| 1118 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1119 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1120 | * @param[in] module_prefix Prefix of the module to check prefix collisions. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1121 | * @param[in,out] imports Parsed imports to add to. |
| 1122 | * |
| 1123 | * @return LY_ERR values. |
| 1124 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1125 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1126 | parse_import(struct lys_yang_parser_ctx *ctx, const char *module_prefix, struct lysp_import **imports) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1127 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1128 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1129 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1130 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1131 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1132 | struct lysp_import *imp; |
| 1133 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1134 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *imports, imp, LY_EVALID); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1135 | |
| 1136 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1137 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1138 | INSERT_WORD_RET(ctx, buf, imp->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1139 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1140 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1141 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1142 | case LY_STMT_PREFIX: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1143 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_PREFIX, 0, &imp->prefix, Y_IDENTIF_ARG, &imp->exts)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1144 | LY_CHECK_RET(lysp_check_prefix((struct lys_parser_ctx *)ctx, *imports, module_prefix, &imp->prefix), LY_EVALID); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1145 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1146 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1147 | PARSER_CHECK_STMTVER2_RET(ctx, "description", "import"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1148 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &imp->dsc, Y_STR_ARG, &imp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1149 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1150 | case LY_STMT_REFERENCE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1151 | PARSER_CHECK_STMTVER2_RET(ctx, "reference", "import"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1152 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &imp->ref, Y_STR_ARG, &imp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1153 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1154 | case LY_STMT_REVISION_DATE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1155 | LY_CHECK_RET(parse_revisiondate(ctx, imp->rev, &imp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1156 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1157 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1158 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &imp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1159 | break; |
| 1160 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1161 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "import"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1162 | return LY_EVALID; |
| 1163 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1164 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 1165 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 1166 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1167 | /* mandatory substatements */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1168 | LY_CHECK_ERR_RET(!imp->prefix, LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "prefix", "import"), LY_EVALID); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1169 | |
| 1170 | return ret; |
| 1171 | } |
| 1172 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1173 | /** |
| 1174 | * @brief Parse the revision statement. |
| 1175 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1176 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1177 | * @param[in,out] revs Parsed revisions to add to. |
| 1178 | * |
| 1179 | * @return LY_ERR values. |
| 1180 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1181 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1182 | parse_revision(struct lys_yang_parser_ctx *ctx, struct lysp_revision **revs) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1183 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1184 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1185 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1186 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1187 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1188 | struct lysp_revision *rev; |
| 1189 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1190 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *revs, rev, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1191 | |
| 1192 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1193 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1194 | |
| 1195 | /* check value */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1196 | if (lysp_check_date((struct lys_parser_ctx *)ctx, word, word_len, "revision")) { |
David Sedlák | 68ef3dc | 2019-07-22 13:40:19 +0200 | [diff] [blame] | 1197 | free(buf); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1198 | return LY_EVALID; |
| 1199 | } |
| 1200 | |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 1201 | strncpy(rev->date, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1202 | free(buf); |
| 1203 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1204 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1205 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1206 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1207 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &rev->dsc, Y_STR_ARG, &rev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1208 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1209 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1210 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &rev->ref, Y_STR_ARG, &rev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1211 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1212 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1213 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &rev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1214 | break; |
| 1215 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1216 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "revision"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1217 | return LY_EVALID; |
| 1218 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1219 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1220 | return ret; |
| 1221 | } |
| 1222 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1223 | /** |
| 1224 | * @brief Parse a generic text field that can have more instances such as base. |
| 1225 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1226 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1227 | * @param[in] substmt Type of this substatement. |
| 1228 | * @param[in,out] texts Parsed values to add to. |
| 1229 | * @param[in] arg Type of the expected argument. |
| 1230 | * @param[in,out] exts Extension instances to add to. |
| 1231 | * |
| 1232 | * @return LY_ERR values. |
| 1233 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1234 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1235 | parse_text_fields(struct lys_yang_parser_ctx *ctx, LYEXT_SUBSTMT substmt, const char ***texts, enum yang_arg arg, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1236 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1237 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1238 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1239 | char *buf, *word; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 1240 | const char **item; |
| 1241 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1242 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1243 | |
| 1244 | /* allocate new pointer */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1245 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *texts, item, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1246 | |
| 1247 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1248 | LY_CHECK_RET(get_argument(ctx, arg, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1249 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1250 | INSERT_WORD_RET(ctx, buf, *item, word, word_len); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1251 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1252 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1253 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1254 | LY_CHECK_RET(parse_ext(ctx, word, word_len, substmt, LY_ARRAY_COUNT(*texts) - 1, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1255 | break; |
| 1256 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1257 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1258 | return LY_EVALID; |
| 1259 | } |
| 1260 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1261 | return ret; |
| 1262 | } |
| 1263 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1264 | /** |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1265 | * @brief Parse a generic text field that can have more instances such as base. |
| 1266 | * |
| 1267 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1268 | * @param[in] substmt Type of this substatement. |
| 1269 | * @param[in,out] qnames Parsed qnames to add to. |
| 1270 | * @param[in] arg Type of the expected argument. |
| 1271 | * @param[in,out] exts Extension instances to add to. |
| 1272 | * |
| 1273 | * @return LY_ERR values. |
| 1274 | */ |
| 1275 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1276 | parse_qnames(struct lys_yang_parser_ctx *ctx, LYEXT_SUBSTMT substmt, struct lysp_qname **qnames, |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1277 | enum yang_arg arg, struct lysp_ext_instance **exts) |
| 1278 | { |
| 1279 | LY_ERR ret = LY_SUCCESS; |
| 1280 | char *buf, *word; |
| 1281 | struct lysp_qname *item; |
| 1282 | size_t word_len; |
| 1283 | enum ly_stmt kw; |
| 1284 | |
| 1285 | /* allocate new pointer */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1286 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *qnames, item, LY_EMEM); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1287 | |
| 1288 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1289 | LY_CHECK_RET(get_argument(ctx, arg, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1290 | |
| 1291 | INSERT_WORD_RET(ctx, buf, item->str, word, word_len); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1292 | item->mod = ctx->parsed_mod; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1293 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1294 | switch (kw) { |
| 1295 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1296 | LY_CHECK_RET(parse_ext(ctx, word, word_len, substmt, LY_ARRAY_COUNT(*qnames) - 1, exts)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1297 | break; |
| 1298 | default: |
| 1299 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt)); |
| 1300 | return LY_EVALID; |
| 1301 | } |
| 1302 | } |
| 1303 | return ret; |
| 1304 | } |
| 1305 | |
| 1306 | /** |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1307 | * @brief Parse the config statement. |
| 1308 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1309 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1310 | * @param[in,out] flags Flags to add to. |
| 1311 | * @param[in,out] exts Extension instances to add to. |
| 1312 | * |
| 1313 | * @return LY_ERR values. |
| 1314 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1315 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1316 | parse_config(struct lys_yang_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1317 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1318 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1319 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1320 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1321 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1322 | |
| 1323 | if (*flags & LYS_CONFIG_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1324 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "config"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1325 | return LY_EVALID; |
| 1326 | } |
| 1327 | |
| 1328 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1329 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1330 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1331 | if ((word_len == ly_strlen_const("true")) && !strncmp(word, "true", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1332 | *flags |= LYS_CONFIG_W; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1333 | } else if ((word_len == ly_strlen_const("false")) && !strncmp(word, "false", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1334 | *flags |= LYS_CONFIG_R; |
| 1335 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1336 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "config"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1337 | free(buf); |
| 1338 | return LY_EVALID; |
| 1339 | } |
| 1340 | free(buf); |
| 1341 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1342 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1343 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1344 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1345 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_CONFIG, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1346 | break; |
| 1347 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1348 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "config"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1349 | return LY_EVALID; |
| 1350 | } |
| 1351 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1352 | return ret; |
| 1353 | } |
| 1354 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1355 | /** |
| 1356 | * @brief Parse the mandatory statement. |
| 1357 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1358 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1359 | * @param[in,out] flags Flags to add to. |
| 1360 | * @param[in,out] exts Extension instances to add to. |
| 1361 | * |
| 1362 | * @return LY_ERR values. |
| 1363 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1364 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1365 | parse_mandatory(struct lys_yang_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1366 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1367 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1368 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1369 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1370 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1371 | |
| 1372 | if (*flags & LYS_MAND_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1373 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "mandatory"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1374 | return LY_EVALID; |
| 1375 | } |
| 1376 | |
| 1377 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1378 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1379 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1380 | if ((word_len == ly_strlen_const("true")) && !strncmp(word, "true", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1381 | *flags |= LYS_MAND_TRUE; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1382 | } else if ((word_len == ly_strlen_const("false")) && !strncmp(word, "false", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1383 | *flags |= LYS_MAND_FALSE; |
| 1384 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1385 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "mandatory"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1386 | free(buf); |
| 1387 | return LY_EVALID; |
| 1388 | } |
| 1389 | free(buf); |
| 1390 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1391 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1392 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1393 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1394 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_MANDATORY, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1395 | break; |
| 1396 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1397 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "mandatory"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1398 | return LY_EVALID; |
| 1399 | } |
| 1400 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1401 | return ret; |
| 1402 | } |
| 1403 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1404 | /** |
| 1405 | * @brief Parse a restriction such as range or length. |
| 1406 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1407 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1408 | * @param[in] restr_kw Type of this particular restriction. |
| 1409 | * @param[in,out] exts Extension instances to add to. |
| 1410 | * |
| 1411 | * @return LY_ERR values. |
| 1412 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1413 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1414 | parse_restr(struct lys_yang_parser_ctx *ctx, enum ly_stmt restr_kw, struct lysp_restr *restr) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1415 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1416 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1417 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1418 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1419 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1420 | |
| 1421 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1422 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1423 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1424 | CHECK_NONEMPTY(ctx, word_len, ly_stmt2str(restr_kw)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1425 | INSERT_WORD_RET(ctx, buf, restr->arg.str, word, word_len); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1426 | restr->arg.mod = ctx->parsed_mod; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1427 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1428 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1429 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1430 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &restr->dsc, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1431 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1432 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1433 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &restr->ref, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1434 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1435 | case LY_STMT_ERROR_APP_TAG: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1436 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_ERRTAG, 0, &restr->eapptag, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1437 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1438 | case LY_STMT_ERROR_MESSAGE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1439 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_ERRMSG, 0, &restr->emsg, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1440 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1441 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1442 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1443 | break; |
| 1444 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1445 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), ly_stmt2str(restr_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1446 | return LY_EVALID; |
| 1447 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1448 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1449 | return ret; |
| 1450 | } |
| 1451 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1452 | /** |
| 1453 | * @brief Parse a restriction that can have more instances such as must. |
| 1454 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1455 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1456 | * @param[in] restr_kw Type of this particular restriction. |
| 1457 | * @param[in,out] restrs Restrictions to add to. |
| 1458 | * |
| 1459 | * @return LY_ERR values. |
| 1460 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1461 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1462 | parse_restrs(struct lys_yang_parser_ctx *ctx, enum ly_stmt restr_kw, struct lysp_restr **restrs) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1463 | { |
| 1464 | struct lysp_restr *restr; |
| 1465 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1466 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *restrs, restr, LY_EMEM); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1467 | return parse_restr(ctx, restr_kw, restr); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1468 | } |
| 1469 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1470 | /** |
| 1471 | * @brief Parse the status statement. |
| 1472 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1473 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1474 | * @param[in,out] flags Flags to add to. |
| 1475 | * @param[in,out] exts Extension instances to add to. |
| 1476 | * |
| 1477 | * @return LY_ERR values. |
| 1478 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1479 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1480 | parse_status(struct lys_yang_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1481 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1482 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1483 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1484 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1485 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1486 | |
| 1487 | if (*flags & LYS_STATUS_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1488 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "status"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1489 | return LY_EVALID; |
| 1490 | } |
| 1491 | |
| 1492 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1493 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1494 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1495 | if ((word_len == ly_strlen_const("current")) && !strncmp(word, "current", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1496 | *flags |= LYS_STATUS_CURR; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1497 | } else if ((word_len == ly_strlen_const("deprecated")) && !strncmp(word, "deprecated", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1498 | *flags |= LYS_STATUS_DEPRC; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1499 | } else if ((word_len == ly_strlen_const("obsolete")) && !strncmp(word, "obsolete", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1500 | *flags |= LYS_STATUS_OBSLT; |
| 1501 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1502 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "status"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1503 | free(buf); |
| 1504 | return LY_EVALID; |
| 1505 | } |
| 1506 | free(buf); |
| 1507 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1508 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1509 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1510 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1511 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_STATUS, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1512 | break; |
| 1513 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1514 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "status"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1515 | return LY_EVALID; |
| 1516 | } |
| 1517 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1518 | return ret; |
| 1519 | } |
| 1520 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1521 | /** |
| 1522 | * @brief Parse the when statement. |
| 1523 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1524 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1525 | * @param[in,out] when_p When pointer to parse to. |
| 1526 | * |
| 1527 | * @return LY_ERR values. |
| 1528 | */ |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 1529 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1530 | parse_when(struct lys_yang_parser_ctx *ctx, struct lysp_when **when_p) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1531 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1532 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1533 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1534 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1535 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1536 | struct lysp_when *when; |
| 1537 | |
| 1538 | if (*when_p) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1539 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "when"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1540 | return LY_EVALID; |
| 1541 | } |
| 1542 | |
| 1543 | when = calloc(1, sizeof *when); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1544 | LY_CHECK_ERR_RET(!when, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1545 | *when_p = when; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1546 | |
| 1547 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1548 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1549 | CHECK_NONEMPTY(ctx, word_len, "when"); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1550 | INSERT_WORD_RET(ctx, buf, when->cond, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1551 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1552 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1553 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1554 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1555 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &when->dsc, Y_STR_ARG, &when->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1556 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1557 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1558 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &when->ref, Y_STR_ARG, &when->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1559 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1560 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1561 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &when->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1562 | break; |
| 1563 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1564 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "when"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1565 | return LY_EVALID; |
| 1566 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1567 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1568 | return ret; |
| 1569 | } |
| 1570 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1571 | /** |
| 1572 | * @brief Parse the anydata or anyxml statement. |
| 1573 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1574 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1575 | * @param[in] kw Type of this particular keyword. |
| 1576 | * @param[in,out] siblings Siblings to add to. |
| 1577 | * |
| 1578 | * @return LY_ERR values. |
| 1579 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 1580 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1581 | parse_any(struct lys_yang_parser_ctx *ctx, enum ly_stmt kw, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1582 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1583 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1584 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1585 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1586 | struct lysp_node_anydata *any; |
| 1587 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 1588 | /* create new structure and insert into siblings */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1589 | LY_LIST_NEW_RET(PARSER_CTX(ctx), siblings, any, next, LY_EMEM); |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 1590 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1591 | any->nodetype = kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1592 | any->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1593 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1594 | /* get name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1595 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1596 | INSERT_WORD_RET(ctx, buf, any->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1597 | |
| 1598 | /* parse substatements */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1599 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1600 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1601 | case LY_STMT_CONFIG: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1602 | LY_CHECK_RET(parse_config(ctx, &any->flags, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1603 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1604 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1605 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &any->dsc, Y_STR_ARG, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1606 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1607 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1608 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &any->iffeatures, Y_STR_ARG, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1609 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1610 | case LY_STMT_MANDATORY: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1611 | LY_CHECK_RET(parse_mandatory(ctx, &any->flags, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1612 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1613 | case LY_STMT_MUST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1614 | LY_CHECK_RET(parse_restrs(ctx, kw, &any->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1615 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1616 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1617 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &any->ref, Y_STR_ARG, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1618 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1619 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1620 | LY_CHECK_RET(parse_status(ctx, &any->flags, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1621 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1622 | case LY_STMT_WHEN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1623 | LY_CHECK_RET(parse_when(ctx, &any->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1624 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1625 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1626 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1627 | break; |
| 1628 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1629 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1630 | (any->nodetype & LYS_ANYDATA) == LYS_ANYDATA ? ly_stmt2str(LY_STMT_ANYDATA) : ly_stmt2str(LY_STMT_ANYXML)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1631 | return LY_EVALID; |
| 1632 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1633 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1634 | return ret; |
| 1635 | } |
| 1636 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1637 | /** |
| 1638 | * @brief Parse the value or position statement. Substatement of type enum statement. |
| 1639 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1640 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1641 | * @param[in] val_kw Type of this particular keyword. |
| 1642 | * @param[in,out] value Value to write to. |
| 1643 | * @param[in,out] flags Flags to write to. |
| 1644 | * @param[in,out] exts Extension instances to add to. |
| 1645 | * |
| 1646 | * @return LY_ERR values. |
| 1647 | */ |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 1648 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1649 | parse_type_enum_value_pos(struct lys_yang_parser_ctx *ctx, enum ly_stmt val_kw, int64_t *value, uint16_t *flags, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1650 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1651 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1652 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1653 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1654 | size_t word_len; |
Radek Krejci | 4ad42aa | 2019-07-23 16:55:58 +0200 | [diff] [blame] | 1655 | long int num = 0; |
| 1656 | unsigned long int unum = 0; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1657 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1658 | |
| 1659 | if (*flags & LYS_SET_VALUE) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1660 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(val_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1661 | return LY_EVALID; |
| 1662 | } |
| 1663 | *flags |= LYS_SET_VALUE; |
| 1664 | |
| 1665 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1666 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1667 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1668 | if (!word_len || (word[0] == '+') || ((word[0] == '0') && (word_len > 1)) || ((val_kw == LY_STMT_POSITION) && !strncmp(word, "-0", 2))) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1669 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, ly_stmt2str(val_kw)); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1670 | goto error; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | errno = 0; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1674 | if (val_kw == LY_STMT_VALUE) { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1675 | num = strtol(word, &ptr, LY_BASE_DEC); |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1676 | if ((num < INT64_C(-2147483648)) || (num > INT64_C(2147483647))) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1677 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, ly_stmt2str(val_kw)); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1678 | goto error; |
| 1679 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1680 | } else { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1681 | unum = strtoul(word, &ptr, LY_BASE_DEC); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1682 | if (unum > UINT64_C(4294967295)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1683 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, ly_stmt2str(val_kw)); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1684 | goto error; |
| 1685 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1686 | } |
| 1687 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1688 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1689 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, ly_stmt2str(val_kw)); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1690 | goto error; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1691 | } |
| 1692 | if (errno == ERANGE) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1693 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, ly_stmt2str(val_kw)); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1694 | goto error; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1695 | } |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1696 | if (val_kw == LY_STMT_VALUE) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1697 | *value = num; |
| 1698 | } else { |
| 1699 | *value = unum; |
| 1700 | } |
| 1701 | free(buf); |
| 1702 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1703 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1704 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1705 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1706 | LY_CHECK_RET(parse_ext(ctx, word, word_len, val_kw == LY_STMT_VALUE ? LYEXT_SUBSTMT_VALUE : LYEXT_SUBSTMT_POSITION, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1707 | break; |
| 1708 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1709 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), ly_stmt2str(val_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1710 | return LY_EVALID; |
| 1711 | } |
| 1712 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1713 | return ret; |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1714 | |
| 1715 | error: |
| 1716 | free(buf); |
| 1717 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1718 | } |
| 1719 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1720 | /** |
| 1721 | * @brief Parse the enum or bit statement. Substatement of type statement. |
| 1722 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1723 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1724 | * @param[in] enum_kw Type of this particular keyword. |
| 1725 | * @param[in,out] enums Enums or bits to add to. |
| 1726 | * |
| 1727 | * @return LY_ERR values. |
| 1728 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1729 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1730 | parse_type_enum(struct lys_yang_parser_ctx *ctx, enum ly_stmt enum_kw, struct lysp_type_enum **enums) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1731 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1732 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1733 | char *buf, *word; |
David Sedlák | 6544c18 | 2019-07-12 13:17:33 +0200 | [diff] [blame] | 1734 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1735 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1736 | struct lysp_type_enum *enm; |
| 1737 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1738 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *enums, enm, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1739 | |
| 1740 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1741 | LY_CHECK_RET(get_argument(ctx, enum_kw == LY_STMT_ENUM ? Y_STR_ARG : Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1742 | if (enum_kw == LY_STMT_ENUM) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1743 | ret = lysp_check_enum_name((struct lys_parser_ctx *)ctx, (const char *)word, word_len); |
David Sedlák | 6544c18 | 2019-07-12 13:17:33 +0200 | [diff] [blame] | 1744 | LY_CHECK_ERR_RET(ret, free(buf), ret); |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1745 | } /* else nothing specific for YANG_BIT */ |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1746 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1747 | INSERT_WORD_RET(ctx, buf, enm->name, word, word_len); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1748 | CHECK_UNIQUENESS(ctx, *enums, name, ly_stmt2str(enum_kw), enm->name); |
| 1749 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1750 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1751 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1752 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1753 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &enm->dsc, Y_STR_ARG, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1754 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1755 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1756 | PARSER_CHECK_STMTVER2_RET(ctx, "if-feature", ly_stmt2str(enum_kw)); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1757 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &enm->iffeatures, Y_STR_ARG, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1758 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1759 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1760 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &enm->ref, Y_STR_ARG, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1761 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1762 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1763 | LY_CHECK_RET(parse_status(ctx, &enm->flags, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1764 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1765 | case LY_STMT_VALUE: |
| 1766 | LY_CHECK_ERR_RET(enum_kw == LY_STMT_BIT, LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1767 | ly_stmt2str(enum_kw)), LY_EVALID); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1768 | LY_CHECK_RET(parse_type_enum_value_pos(ctx, kw, &enm->value, &enm->flags, &enm->exts)); |
David Sedlák | 9fb515f | 2019-07-11 10:33:58 +0200 | [diff] [blame] | 1769 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1770 | case LY_STMT_POSITION: |
| 1771 | LY_CHECK_ERR_RET(enum_kw == LY_STMT_ENUM, LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1772 | ly_stmt2str(enum_kw)), LY_EVALID); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1773 | LY_CHECK_RET(parse_type_enum_value_pos(ctx, kw, &enm->value, &enm->flags, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1774 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1775 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1776 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1777 | break; |
| 1778 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1779 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), ly_stmt2str(enum_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1780 | return LY_EVALID; |
| 1781 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1782 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1783 | return ret; |
| 1784 | } |
| 1785 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1786 | /** |
| 1787 | * @brief Parse the fraction-digits statement. Substatement of type statement. |
| 1788 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1789 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1790 | * @param[in,out] fracdig Value to write to. |
| 1791 | * @param[in,out] exts Extension instances to add to. |
| 1792 | * |
| 1793 | * @return LY_ERR values. |
| 1794 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1795 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1796 | parse_type_fracdigits(struct lys_yang_parser_ctx *ctx, uint8_t *fracdig, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1797 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1798 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1799 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1800 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1801 | unsigned long int num; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1802 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1803 | |
| 1804 | if (*fracdig) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1805 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1806 | return LY_EVALID; |
| 1807 | } |
| 1808 | |
| 1809 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1810 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1811 | |
| 1812 | if (!word_len || (word[0] == '0') || !isdigit(word[0])) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1813 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1814 | free(buf); |
| 1815 | return LY_EVALID; |
| 1816 | } |
| 1817 | |
| 1818 | errno = 0; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1819 | num = strtoul(word, &ptr, LY_BASE_DEC); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1820 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1821 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1822 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1823 | free(buf); |
| 1824 | return LY_EVALID; |
| 1825 | } |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1826 | if ((errno == ERANGE) || (num > LY_TYPE_DEC64_FD_MAX)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1827 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1828 | free(buf); |
| 1829 | return LY_EVALID; |
| 1830 | } |
| 1831 | *fracdig = num; |
| 1832 | free(buf); |
| 1833 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1834 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1835 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1836 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1837 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_FRACDIGITS, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1838 | break; |
| 1839 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1840 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1841 | return LY_EVALID; |
| 1842 | } |
| 1843 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1844 | return ret; |
| 1845 | } |
| 1846 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1847 | /** |
| 1848 | * @brief Parse the require-instance statement. Substatement of type statement. |
| 1849 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1850 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1851 | * @param[in,out] reqinst Value to write to. |
| 1852 | * @param[in,out] flags Flags to write to. |
| 1853 | * @param[in,out] exts Extension instances to add to. |
| 1854 | * |
| 1855 | * @return LY_ERR values. |
| 1856 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1857 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1858 | parse_type_reqinstance(struct lys_yang_parser_ctx *ctx, uint8_t *reqinst, uint16_t *flags, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1859 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1860 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1861 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1862 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1863 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1864 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1865 | |
| 1866 | if (*flags & LYS_SET_REQINST) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1867 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "require-instance"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1868 | return LY_EVALID; |
| 1869 | } |
| 1870 | *flags |= LYS_SET_REQINST; |
| 1871 | |
| 1872 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1873 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1874 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1875 | if ((word_len == ly_strlen_const("true")) && !strncmp(word, "true", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1876 | *reqinst = 1; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1877 | } else if ((word_len != ly_strlen_const("false")) || strncmp(word, "false", word_len)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1878 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "require-instance"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1879 | free(buf); |
| 1880 | return LY_EVALID; |
| 1881 | } |
| 1882 | free(buf); |
| 1883 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1884 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1885 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1886 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1887 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_REQINSTANCE, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1888 | break; |
| 1889 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1890 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "require-instance"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1891 | return LY_EVALID; |
| 1892 | } |
| 1893 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1894 | return ret; |
| 1895 | } |
| 1896 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1897 | /** |
| 1898 | * @brief Parse the modifier statement. Substatement of type pattern statement. |
| 1899 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1900 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1901 | * @param[in,out] pat Value to write to. |
| 1902 | * @param[in,out] exts Extension instances to add to. |
| 1903 | * |
| 1904 | * @return LY_ERR values. |
| 1905 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1906 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1907 | parse_type_pattern_modifier(struct lys_yang_parser_ctx *ctx, const char **pat, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1908 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1909 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1910 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1911 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1912 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1913 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1914 | if ((*pat)[0] == LYSP_RESTR_PATTERN_NACK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1915 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "modifier"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1916 | return LY_EVALID; |
| 1917 | } |
| 1918 | |
| 1919 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1920 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1921 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1922 | if ((word_len != ly_strlen_const("invert-match")) || strncmp(word, "invert-match", word_len)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1923 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "modifier"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1924 | free(buf); |
| 1925 | return LY_EVALID; |
| 1926 | } |
| 1927 | free(buf); |
| 1928 | |
| 1929 | /* replace the value in the dictionary */ |
| 1930 | buf = malloc(strlen(*pat) + 1); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1931 | LY_CHECK_ERR_RET(!buf, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1932 | strcpy(buf, *pat); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1933 | lydict_remove(PARSER_CTX(ctx), *pat); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1934 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1935 | assert(buf[0] == LYSP_RESTR_PATTERN_ACK); |
| 1936 | buf[0] = LYSP_RESTR_PATTERN_NACK; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1937 | LY_CHECK_RET(lydict_insert_zc(PARSER_CTX(ctx), buf, pat)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1938 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1939 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1940 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1941 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1942 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_MODIFIER, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1943 | break; |
| 1944 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1945 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "modifier"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1946 | return LY_EVALID; |
| 1947 | } |
| 1948 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1949 | return ret; |
| 1950 | } |
| 1951 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1952 | /** |
| 1953 | * @brief Parse the pattern statement. Substatement of type statement. |
| 1954 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1955 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1956 | * @param[in,out] patterns Restrictions to add to. |
| 1957 | * |
| 1958 | * @return LY_ERR values. |
| 1959 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1960 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1961 | parse_type_pattern(struct lys_yang_parser_ctx *ctx, struct lysp_restr **patterns) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1962 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1963 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1964 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1965 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1966 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1967 | struct lysp_restr *restr; |
| 1968 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1969 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *patterns, restr, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1970 | |
| 1971 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1972 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1973 | |
| 1974 | /* add special meaning first byte */ |
| 1975 | if (buf) { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1976 | buf = ly_realloc(buf, word_len + 2); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1977 | word = buf; |
| 1978 | } else { |
| 1979 | buf = malloc(word_len + 2); |
| 1980 | } |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1981 | LY_CHECK_ERR_RET(!buf, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 1982 | memmove(buf + 1, word, word_len); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1983 | buf[0] = LYSP_RESTR_PATTERN_ACK; /* pattern's default regular-match flag */ |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 1984 | buf[word_len + 1] = '\0'; /* terminating NULL byte */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1985 | LY_CHECK_RET(lydict_insert_zc(PARSER_CTX(ctx), buf, &restr->arg.str)); |
| 1986 | restr->arg.mod = ctx->parsed_mod; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1987 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1988 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1989 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1990 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1991 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &restr->dsc, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1992 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1993 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1994 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &restr->ref, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1995 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1996 | case LY_STMT_ERROR_APP_TAG: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 1997 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_ERRTAG, 0, &restr->eapptag, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1998 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1999 | case LY_STMT_ERROR_MESSAGE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2000 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_ERRMSG, 0, &restr->emsg, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2001 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2002 | case LY_STMT_MODIFIER: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2003 | PARSER_CHECK_STMTVER2_RET(ctx, "modifier", "pattern"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2004 | LY_CHECK_RET(parse_type_pattern_modifier(ctx, &restr->arg.str, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2005 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2006 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2007 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2008 | break; |
| 2009 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2010 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "pattern"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2011 | return LY_EVALID; |
| 2012 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2013 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2014 | return ret; |
| 2015 | } |
| 2016 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2017 | /** |
| 2018 | * @brief Parse the type statement. |
| 2019 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2020 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2021 | * @param[in,out] type Type to wrote to. |
| 2022 | * |
| 2023 | * @return LY_ERR values. |
| 2024 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2025 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2026 | parse_type(struct lys_yang_parser_ctx *ctx, struct lysp_type *type) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2027 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2028 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2029 | char *buf, *word; |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 2030 | const char *str_path = NULL; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2031 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2032 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2033 | struct lysp_type *nest_type; |
| 2034 | |
| 2035 | if (type->name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2036 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "type"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2037 | return LY_EVALID; |
| 2038 | } |
| 2039 | |
| 2040 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2041 | LY_CHECK_RET(get_argument(ctx, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2042 | INSERT_WORD_RET(ctx, buf, type->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2043 | |
Michal Vasko | e9c050f | 2020-10-06 14:01:23 +0200 | [diff] [blame] | 2044 | /* set module */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2045 | type->pmod = ctx->parsed_mod; |
Michal Vasko | e9c050f | 2020-10-06 14:01:23 +0200 | [diff] [blame] | 2046 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2047 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2048 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2049 | case LY_STMT_BASE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2050 | LY_CHECK_RET(parse_text_fields(ctx, LYEXT_SUBSTMT_BASE, &type->bases, Y_PREF_IDENTIF_ARG, &type->exts)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2051 | type->flags |= LYS_SET_BASE; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2052 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2053 | case LY_STMT_BIT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2054 | LY_CHECK_RET(parse_type_enum(ctx, kw, &type->bits)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2055 | type->flags |= LYS_SET_BIT; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2056 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2057 | case LY_STMT_ENUM: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2058 | LY_CHECK_RET(parse_type_enum(ctx, kw, &type->enums)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2059 | type->flags |= LYS_SET_ENUM; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2060 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2061 | case LY_STMT_FRACTION_DIGITS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2062 | LY_CHECK_RET(parse_type_fracdigits(ctx, &type->fraction_digits, &type->exts)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2063 | type->flags |= LYS_SET_FRDIGITS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2064 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2065 | case LY_STMT_LENGTH: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2066 | if (type->length) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2067 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2068 | return LY_EVALID; |
| 2069 | } |
| 2070 | type->length = calloc(1, sizeof *type->length); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2071 | LY_CHECK_ERR_RET(!type->length, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2072 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2073 | LY_CHECK_RET(parse_restr(ctx, kw, type->length)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2074 | type->flags |= LYS_SET_LENGTH; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2075 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2076 | case LY_STMT_PATH: |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 2077 | if (type->path) { |
| 2078 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, lyext_substmt2str(LYEXT_SUBSTMT_PATH)); |
| 2079 | return LY_EVALID; |
| 2080 | } |
| 2081 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2082 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_PATH, 0, &str_path, Y_STR_ARG, &type->exts)); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2083 | ret = ly_path_parse(PARSER_CTX(ctx), NULL, str_path, 0, LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2084 | LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &type->path); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2085 | lydict_remove(PARSER_CTX(ctx), str_path); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 2086 | LY_CHECK_RET(ret); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2087 | type->flags |= LYS_SET_PATH; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2088 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2089 | case LY_STMT_PATTERN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2090 | LY_CHECK_RET(parse_type_pattern(ctx, &type->patterns)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2091 | type->flags |= LYS_SET_PATTERN; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2092 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2093 | case LY_STMT_RANGE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2094 | if (type->range) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2095 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2096 | return LY_EVALID; |
| 2097 | } |
| 2098 | type->range = calloc(1, sizeof *type->range); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2099 | LY_CHECK_ERR_RET(!type->range, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2100 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2101 | LY_CHECK_RET(parse_restr(ctx, kw, type->range)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2102 | type->flags |= LYS_SET_RANGE; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2103 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2104 | case LY_STMT_REQUIRE_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2105 | LY_CHECK_RET(parse_type_reqinstance(ctx, &type->require_instance, &type->flags, &type->exts)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2106 | /* LYS_SET_REQINST checked and set inside parse_type_reqinstance() */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2107 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2108 | case LY_STMT_TYPE: |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2109 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), type->types, nest_type, LY_EMEM); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2110 | LY_CHECK_RET(parse_type(ctx, nest_type)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2111 | type->flags |= LYS_SET_TYPE; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2112 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2113 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2114 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &type->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2115 | break; |
| 2116 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2117 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "type"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2118 | return LY_EVALID; |
| 2119 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2120 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2121 | return ret; |
| 2122 | } |
| 2123 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2124 | /** |
| 2125 | * @brief Parse the leaf statement. |
| 2126 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2127 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2128 | * @param[in,out] siblings Siblings to add to. |
| 2129 | * |
| 2130 | * @return LY_ERR values. |
| 2131 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2132 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2133 | parse_leaf(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2134 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2135 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2136 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2137 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2138 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2139 | struct lysp_node_leaf *leaf; |
| 2140 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 2141 | /* create new leaf structure */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2142 | LY_LIST_NEW_RET(PARSER_CTX(ctx), siblings, leaf, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2143 | leaf->nodetype = LYS_LEAF; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2144 | leaf->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2145 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2146 | /* get name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2147 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2148 | INSERT_WORD_RET(ctx, buf, leaf->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2149 | |
| 2150 | /* parse substatements */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2151 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2152 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2153 | case LY_STMT_CONFIG: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2154 | LY_CHECK_RET(parse_config(ctx, &leaf->flags, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2155 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2156 | case LY_STMT_DEFAULT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2157 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DEFAULT, 0, &leaf->dflt.str, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2158 | leaf->dflt.mod = ctx->parsed_mod; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2159 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2160 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2161 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &leaf->dsc, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2162 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2163 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2164 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &leaf->iffeatures, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2165 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2166 | case LY_STMT_MANDATORY: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2167 | LY_CHECK_RET(parse_mandatory(ctx, &leaf->flags, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2168 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2169 | case LY_STMT_MUST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2170 | LY_CHECK_RET(parse_restrs(ctx, kw, &leaf->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2171 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2172 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2173 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &leaf->ref, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2174 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2175 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2176 | LY_CHECK_RET(parse_status(ctx, &leaf->flags, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2177 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2178 | case LY_STMT_TYPE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2179 | LY_CHECK_RET(parse_type(ctx, &leaf->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2180 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2181 | case LY_STMT_UNITS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2182 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_UNITS, 0, &leaf->units, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2183 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2184 | case LY_STMT_WHEN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2185 | LY_CHECK_RET(parse_when(ctx, &leaf->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2186 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2187 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2188 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2189 | break; |
| 2190 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2191 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "leaf"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2192 | return LY_EVALID; |
| 2193 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2194 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 2195 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 2196 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2197 | /* mandatory substatements */ |
| 2198 | if (!leaf->type.name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2199 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "type", "leaf"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2200 | return LY_EVALID; |
| 2201 | } |
| 2202 | |
| 2203 | return ret; |
| 2204 | } |
| 2205 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2206 | /** |
| 2207 | * @brief Parse the max-elements statement. |
| 2208 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2209 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2210 | * @param[in,out] max Value to write to. |
| 2211 | * @param[in,out] flags Flags to write to. |
| 2212 | * @param[in,out] exts Extension instances to add to. |
| 2213 | * |
| 2214 | * @return LY_ERR values. |
| 2215 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2216 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2217 | parse_maxelements(struct lys_yang_parser_ctx *ctx, uint32_t *max, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2218 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2219 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2220 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2221 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2222 | unsigned long int num; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2223 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2224 | |
| 2225 | if (*flags & LYS_SET_MAX) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2226 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2227 | return LY_EVALID; |
| 2228 | } |
| 2229 | *flags |= LYS_SET_MAX; |
| 2230 | |
| 2231 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2232 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2233 | |
| 2234 | if (!word_len || (word[0] == '0') || ((word[0] != 'u') && !isdigit(word[0]))) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2235 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2236 | free(buf); |
| 2237 | return LY_EVALID; |
| 2238 | } |
| 2239 | |
Radek Krejci | 7f9b651 | 2019-09-18 13:11:09 +0200 | [diff] [blame] | 2240 | if (ly_strncmp("unbounded", word, word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2241 | errno = 0; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2242 | num = strtoul(word, &ptr, LY_BASE_DEC); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2243 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2244 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2245 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2246 | free(buf); |
| 2247 | return LY_EVALID; |
| 2248 | } |
| 2249 | if ((errno == ERANGE) || (num > UINT32_MAX)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2250 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2251 | free(buf); |
| 2252 | return LY_EVALID; |
| 2253 | } |
| 2254 | |
| 2255 | *max = num; |
| 2256 | } |
| 2257 | free(buf); |
| 2258 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2259 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2260 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2261 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2262 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_MAX, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2263 | break; |
| 2264 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2265 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2266 | return LY_EVALID; |
| 2267 | } |
| 2268 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2269 | return ret; |
| 2270 | } |
| 2271 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2272 | /** |
| 2273 | * @brief Parse the min-elements statement. |
| 2274 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2275 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2276 | * @param[in,out] min Value to write to. |
| 2277 | * @param[in,out] flags Flags to write to. |
| 2278 | * @param[in,out] exts Extension instances to add to. |
| 2279 | * |
| 2280 | * @return LY_ERR values. |
| 2281 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2282 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2283 | parse_minelements(struct lys_yang_parser_ctx *ctx, uint32_t *min, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2284 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2285 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2286 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2287 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2288 | unsigned long int num; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2289 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2290 | |
| 2291 | if (*flags & LYS_SET_MIN) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2292 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2293 | return LY_EVALID; |
| 2294 | } |
| 2295 | *flags |= LYS_SET_MIN; |
| 2296 | |
| 2297 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2298 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2299 | |
| 2300 | if (!word_len || !isdigit(word[0]) || ((word[0] == '0') && (word_len > 1))) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2301 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2302 | free(buf); |
| 2303 | return LY_EVALID; |
| 2304 | } |
| 2305 | |
| 2306 | errno = 0; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2307 | num = strtoul(word, &ptr, LY_BASE_DEC); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2308 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2309 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2310 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2311 | free(buf); |
| 2312 | return LY_EVALID; |
| 2313 | } |
| 2314 | if ((errno == ERANGE) || (num > UINT32_MAX)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2315 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2316 | free(buf); |
| 2317 | return LY_EVALID; |
| 2318 | } |
| 2319 | *min = num; |
| 2320 | free(buf); |
| 2321 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2322 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2323 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2324 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2325 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_MIN, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2326 | break; |
| 2327 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2328 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2329 | return LY_EVALID; |
| 2330 | } |
| 2331 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2332 | return ret; |
| 2333 | } |
| 2334 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2335 | /** |
| 2336 | * @brief Parse the ordered-by statement. |
| 2337 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2338 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2339 | * @param[in,out] flags Flags to write to. |
| 2340 | * @param[in,out] exts Extension instances to add to. |
| 2341 | * |
| 2342 | * @return LY_ERR values. |
| 2343 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2344 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2345 | parse_orderedby(struct lys_yang_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2346 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2347 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2348 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2349 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2350 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2351 | |
| 2352 | if (*flags & LYS_ORDBY_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2353 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "ordered-by"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2354 | return LY_EVALID; |
| 2355 | } |
| 2356 | |
| 2357 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2358 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2359 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2360 | if ((word_len == ly_strlen_const("system")) && !strncmp(word, "system", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2361 | *flags |= LYS_ORDBY_SYSTEM; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2362 | } else if ((word_len == ly_strlen_const("user")) && !strncmp(word, "user", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2363 | *flags |= LYS_ORDBY_USER; |
| 2364 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2365 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "ordered-by"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2366 | free(buf); |
| 2367 | return LY_EVALID; |
| 2368 | } |
| 2369 | free(buf); |
| 2370 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2371 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2372 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2373 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2374 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_ORDEREDBY, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2375 | break; |
| 2376 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2377 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "ordered-by"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2378 | return LY_EVALID; |
| 2379 | } |
| 2380 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2381 | return ret; |
| 2382 | } |
| 2383 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2384 | /** |
| 2385 | * @brief Parse the leaf-list statement. |
| 2386 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2387 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2388 | * @param[in,out] siblings Siblings to add to. |
| 2389 | * |
| 2390 | * @return LY_ERR values. |
| 2391 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2392 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2393 | parse_leaflist(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2394 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2395 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2396 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2397 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2398 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2399 | struct lysp_node_leaflist *llist; |
| 2400 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 2401 | /* create new leaf-list structure */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2402 | LY_LIST_NEW_RET(PARSER_CTX(ctx), siblings, llist, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2403 | llist->nodetype = LYS_LEAFLIST; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2404 | llist->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2405 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2406 | /* get name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2407 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2408 | INSERT_WORD_RET(ctx, buf, llist->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2409 | |
| 2410 | /* parse substatements */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2411 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2412 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2413 | case LY_STMT_CONFIG: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2414 | LY_CHECK_RET(parse_config(ctx, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2415 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2416 | case LY_STMT_DEFAULT: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2417 | PARSER_CHECK_STMTVER2_RET(ctx, "default", "leaf-list"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2418 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_DEFAULT, &llist->dflts, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2419 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2420 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2421 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &llist->dsc, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2422 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2423 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2424 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &llist->iffeatures, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2425 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2426 | case LY_STMT_MAX_ELEMENTS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2427 | LY_CHECK_RET(parse_maxelements(ctx, &llist->max, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2428 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2429 | case LY_STMT_MIN_ELEMENTS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2430 | LY_CHECK_RET(parse_minelements(ctx, &llist->min, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2431 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2432 | case LY_STMT_MUST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2433 | LY_CHECK_RET(parse_restrs(ctx, kw, &llist->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2434 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2435 | case LY_STMT_ORDERED_BY: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2436 | LY_CHECK_RET(parse_orderedby(ctx, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2437 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2438 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2439 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &llist->ref, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2440 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2441 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2442 | LY_CHECK_RET(parse_status(ctx, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2443 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2444 | case LY_STMT_TYPE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2445 | LY_CHECK_RET(parse_type(ctx, &llist->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2446 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2447 | case LY_STMT_UNITS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2448 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_UNITS, 0, &llist->units, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2449 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2450 | case LY_STMT_WHEN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2451 | LY_CHECK_RET(parse_when(ctx, &llist->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2452 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2453 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2454 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2455 | break; |
| 2456 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2457 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "llist"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2458 | return LY_EVALID; |
| 2459 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2460 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 2461 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 2462 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2463 | /* mandatory substatements */ |
| 2464 | if (!llist->type.name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2465 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "type", "leaf-list"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2466 | return LY_EVALID; |
| 2467 | } |
| 2468 | |
| 2469 | return ret; |
| 2470 | } |
| 2471 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2472 | /** |
| 2473 | * @brief Parse the refine statement. |
| 2474 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2475 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2476 | * @param[in,out] refines Refines to add to. |
| 2477 | * |
| 2478 | * @return LY_ERR values. |
| 2479 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2480 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2481 | parse_refine(struct lys_yang_parser_ctx *ctx, struct lysp_refine **refines) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2482 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2483 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2484 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2485 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2486 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2487 | struct lysp_refine *rf; |
| 2488 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2489 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *refines, rf, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2490 | |
| 2491 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2492 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2493 | CHECK_NONEMPTY(ctx, word_len, "refine"); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2494 | INSERT_WORD_RET(ctx, buf, rf->nodeid, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2495 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2496 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2497 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2498 | case LY_STMT_CONFIG: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2499 | LY_CHECK_RET(parse_config(ctx, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2500 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2501 | case LY_STMT_DEFAULT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2502 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_DEFAULT, &rf->dflts, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2503 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2504 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2505 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &rf->dsc, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2506 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2507 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2508 | PARSER_CHECK_STMTVER2_RET(ctx, "if-feature", "refine"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2509 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &rf->iffeatures, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2510 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2511 | case LY_STMT_MAX_ELEMENTS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2512 | LY_CHECK_RET(parse_maxelements(ctx, &rf->max, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2513 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2514 | case LY_STMT_MIN_ELEMENTS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2515 | LY_CHECK_RET(parse_minelements(ctx, &rf->min, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2516 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2517 | case LY_STMT_MUST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2518 | LY_CHECK_RET(parse_restrs(ctx, kw, &rf->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2519 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2520 | case LY_STMT_MANDATORY: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2521 | LY_CHECK_RET(parse_mandatory(ctx, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2522 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2523 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2524 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &rf->ref, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2525 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2526 | case LY_STMT_PRESENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2527 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_PRESENCE, 0, &rf->presence, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2528 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2529 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2530 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2531 | break; |
| 2532 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2533 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "refine"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2534 | return LY_EVALID; |
| 2535 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2536 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2537 | return ret; |
| 2538 | } |
| 2539 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2540 | /** |
| 2541 | * @brief Parse the typedef statement. |
| 2542 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2543 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2544 | * @param[in,out] typedefs Typedefs to add to. |
| 2545 | * |
| 2546 | * @return LY_ERR values. |
| 2547 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2548 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2549 | parse_typedef(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_tpdf **typedefs) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2550 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2551 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2552 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2553 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2554 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2555 | struct lysp_tpdf *tpdf; |
| 2556 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2557 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *typedefs, tpdf, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2558 | |
| 2559 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2560 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2561 | INSERT_WORD_RET(ctx, buf, tpdf->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2562 | |
| 2563 | /* parse substatements */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2564 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2565 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2566 | case LY_STMT_DEFAULT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2567 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DEFAULT, 0, &tpdf->dflt.str, Y_STR_ARG, &tpdf->exts)); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2568 | tpdf->dflt.mod = ctx->parsed_mod; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2569 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2570 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2571 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &tpdf->dsc, Y_STR_ARG, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2572 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2573 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2574 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &tpdf->ref, Y_STR_ARG, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2575 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2576 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2577 | LY_CHECK_RET(parse_status(ctx, &tpdf->flags, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2578 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2579 | case LY_STMT_TYPE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2580 | LY_CHECK_RET(parse_type(ctx, &tpdf->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2581 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2582 | case LY_STMT_UNITS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2583 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_UNITS, 0, &tpdf->units, Y_STR_ARG, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2584 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2585 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2586 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2587 | break; |
| 2588 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2589 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "typedef"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2590 | return LY_EVALID; |
| 2591 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2592 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 2593 | LY_CHECK_RET(ret); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 2594 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2595 | /* mandatory substatements */ |
| 2596 | if (!tpdf->type.name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2597 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "type", "typedef"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2598 | return LY_EVALID; |
| 2599 | } |
| 2600 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 2601 | /* store data for collision check */ |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2602 | if (parent && !(parent->nodetype & (LYS_GROUPING | LYS_RPC | LYS_ACTION | LYS_INPUT | LYS_OUTPUT | LYS_NOTIF))) { |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 2603 | LY_CHECK_RET(ly_set_add(&ctx->tpdfs_nodes, parent, 0, NULL)); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 2604 | } |
| 2605 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2606 | return ret; |
| 2607 | } |
| 2608 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2609 | /** |
| 2610 | * @brief Parse the input or output statement. |
| 2611 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2612 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2613 | * @param[in] kw Type of this particular keyword |
| 2614 | * @param[in,out] inout_p Input/output pointer to write to. |
| 2615 | * |
| 2616 | * @return LY_ERR values. |
| 2617 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2618 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2619 | parse_inout(struct lys_yang_parser_ctx *ctx, enum ly_stmt inout_kw, struct lysp_node *parent, |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2620 | struct lysp_node_action_inout *inout_p) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2621 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2622 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2623 | char *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2624 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2625 | enum ly_stmt kw; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2626 | ly_bool input = &((struct lysp_node_action *)parent)->input == inout_p ? 1 : 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2627 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2628 | if (inout_p->nodetype) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2629 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(inout_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2630 | return LY_EVALID; |
| 2631 | } |
| 2632 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2633 | /* initiate structure */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2634 | LY_CHECK_RET(lydict_insert(PARSER_CTX(ctx), input ? "input" : "output", 0, &inout_p->name)); |
| 2635 | inout_p->nodetype = input ? LYS_INPUT : LYS_OUTPUT; |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2636 | inout_p->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2637 | |
| 2638 | /* parse substatements */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2639 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2640 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2641 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2642 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", ly_stmt2str(inout_kw)); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2643 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2644 | case LY_STMT_ANYXML: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2645 | LY_CHECK_RET(parse_any(ctx, kw, (struct lysp_node *)inout_p, &inout_p->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2646 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2647 | case LY_STMT_CHOICE: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2648 | LY_CHECK_RET(parse_choice(ctx, (struct lysp_node *)inout_p, &inout_p->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2649 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2650 | case LY_STMT_CONTAINER: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2651 | LY_CHECK_RET(parse_container(ctx, (struct lysp_node *)inout_p, &inout_p->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2652 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2653 | case LY_STMT_LEAF: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2654 | LY_CHECK_RET(parse_leaf(ctx, (struct lysp_node *)inout_p, &inout_p->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2655 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2656 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2657 | LY_CHECK_RET(parse_leaflist(ctx, (struct lysp_node *)inout_p, &inout_p->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2658 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2659 | case LY_STMT_LIST: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2660 | LY_CHECK_RET(parse_list(ctx, (struct lysp_node *)inout_p, &inout_p->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2661 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2662 | case LY_STMT_USES: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2663 | LY_CHECK_RET(parse_uses(ctx, (struct lysp_node *)inout_p, &inout_p->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2664 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2665 | case LY_STMT_TYPEDEF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2666 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)inout_p, &inout_p->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2667 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2668 | case LY_STMT_MUST: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2669 | PARSER_CHECK_STMTVER2_RET(ctx, "must", ly_stmt2str(inout_kw)); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2670 | LY_CHECK_RET(parse_restrs(ctx, kw, &inout_p->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2671 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2672 | case LY_STMT_GROUPING: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2673 | LY_CHECK_RET(parse_grouping(ctx, (struct lysp_node *)inout_p, &inout_p->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2674 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2675 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2676 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &inout_p->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2677 | break; |
| 2678 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2679 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), ly_stmt2str(inout_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2680 | return LY_EVALID; |
| 2681 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2682 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2683 | LY_CHECK_RET(ret); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 2684 | |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2685 | checks: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2686 | if (!inout_p->child) { |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 2687 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "data-def-stmt", ly_stmt2str(inout_kw)); |
| 2688 | return LY_EVALID; |
| 2689 | } |
| 2690 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2691 | return ret; |
| 2692 | } |
| 2693 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2694 | /** |
| 2695 | * @brief Parse the action statement. |
| 2696 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2697 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2698 | * @param[in,out] actions Actions to add to. |
| 2699 | * |
| 2700 | * @return LY_ERR values. |
| 2701 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2702 | LY_ERR |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2703 | parse_action(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node_action **actions) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2704 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2705 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2706 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2707 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2708 | enum ly_stmt kw; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2709 | struct lysp_node_action *act; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2710 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2711 | LY_LIST_NEW_RET(PARSER_CTX(ctx), actions, act, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2712 | |
| 2713 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2714 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2715 | INSERT_WORD_RET(ctx, buf, act->name, word, word_len); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 2716 | act->nodetype = parent ? LYS_ACTION : LYS_RPC; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2717 | act->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2718 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2719 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2720 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2721 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2722 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &act->dsc, Y_STR_ARG, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2723 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2724 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2725 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &act->iffeatures, Y_STR_ARG, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2726 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2727 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2728 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &act->ref, Y_STR_ARG, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2729 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2730 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2731 | LY_CHECK_RET(parse_status(ctx, &act->flags, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2732 | break; |
| 2733 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2734 | case LY_STMT_INPUT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2735 | LY_CHECK_RET(parse_inout(ctx, kw, (struct lysp_node *)act, &act->input)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2736 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2737 | case LY_STMT_OUTPUT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2738 | LY_CHECK_RET(parse_inout(ctx, kw, (struct lysp_node *)act, &act->output)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2739 | break; |
| 2740 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2741 | case LY_STMT_TYPEDEF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2742 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)act, &act->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2743 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2744 | case LY_STMT_GROUPING: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2745 | LY_CHECK_RET(parse_grouping(ctx, (struct lysp_node *)act, &act->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2746 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2747 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2748 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2749 | break; |
| 2750 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2751 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), parent ? "action" : "rpc"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2752 | return LY_EVALID; |
| 2753 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2754 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2755 | LY_CHECK_RET(ret); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2756 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2757 | checks: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2758 | /* always initialize inout, they are technically present (needed for later deviations/refines) */ |
| 2759 | if (!act->input.nodetype) { |
| 2760 | act->input.nodetype = LYS_INPUT; |
| 2761 | act->input.parent = (struct lysp_node *)act; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2762 | LY_CHECK_RET(lydict_insert(PARSER_CTX(ctx), "input", 0, &act->input.name)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2763 | } |
| 2764 | if (!act->output.nodetype) { |
| 2765 | act->output.nodetype = LYS_OUTPUT; |
| 2766 | act->output.parent = (struct lysp_node *)act; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2767 | LY_CHECK_RET(lydict_insert(PARSER_CTX(ctx), "output", 0, &act->output.name)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2768 | } |
| 2769 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2770 | return ret; |
| 2771 | } |
| 2772 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2773 | /** |
| 2774 | * @brief Parse the notification statement. |
| 2775 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2776 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2777 | * @param[in,out] notifs Notifications to add to. |
| 2778 | * |
| 2779 | * @return LY_ERR values. |
| 2780 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2781 | LY_ERR |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2782 | parse_notif(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node_notif **notifs) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2783 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2784 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2785 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2786 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2787 | enum ly_stmt kw; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2788 | struct lysp_node_notif *notif; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2789 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2790 | LY_LIST_NEW_RET(PARSER_CTX(ctx), notifs, notif, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2791 | |
| 2792 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2793 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2794 | INSERT_WORD_RET(ctx, buf, notif->name, word, word_len); |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2795 | notif->nodetype = LYS_NOTIF; |
| 2796 | notif->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2797 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2798 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2799 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2800 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2801 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, ¬if->dsc, Y_STR_ARG, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2802 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2803 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2804 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, ¬if->iffeatures, Y_STR_ARG, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2805 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2806 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2807 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ¬if->ref, Y_STR_ARG, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2808 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2809 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2810 | LY_CHECK_RET(parse_status(ctx, ¬if->flags, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2811 | break; |
| 2812 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2813 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2814 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "notification"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2815 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2816 | case LY_STMT_ANYXML: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2817 | LY_CHECK_RET(parse_any(ctx, kw, (struct lysp_node *)notif, ¬if->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2818 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2819 | case LY_STMT_CHOICE: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2820 | LY_CHECK_RET(parse_case(ctx, (struct lysp_node *)notif, ¬if->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2821 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2822 | case LY_STMT_CONTAINER: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2823 | LY_CHECK_RET(parse_container(ctx, (struct lysp_node *)notif, ¬if->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2824 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2825 | case LY_STMT_LEAF: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2826 | LY_CHECK_RET(parse_leaf(ctx, (struct lysp_node *)notif, ¬if->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2827 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2828 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2829 | LY_CHECK_RET(parse_leaflist(ctx, (struct lysp_node *)notif, ¬if->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2830 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2831 | case LY_STMT_LIST: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2832 | LY_CHECK_RET(parse_list(ctx, (struct lysp_node *)notif, ¬if->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2833 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2834 | case LY_STMT_USES: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2835 | LY_CHECK_RET(parse_uses(ctx, (struct lysp_node *)notif, ¬if->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2836 | break; |
| 2837 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2838 | case LY_STMT_MUST: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2839 | PARSER_CHECK_STMTVER2_RET(ctx, "must", "notification"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2840 | LY_CHECK_RET(parse_restrs(ctx, kw, ¬if->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2841 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2842 | case LY_STMT_TYPEDEF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2843 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)notif, ¬if->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2844 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2845 | case LY_STMT_GROUPING: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2846 | LY_CHECK_RET(parse_grouping(ctx, (struct lysp_node *)notif, ¬if->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2847 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2848 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2849 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2850 | break; |
| 2851 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2852 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "notification"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2853 | return LY_EVALID; |
| 2854 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2855 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2856 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2857 | return ret; |
| 2858 | } |
| 2859 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2860 | /** |
| 2861 | * @brief Parse the grouping statement. |
| 2862 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2863 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2864 | * @param[in,out] groupings Groupings to add to. |
| 2865 | * |
| 2866 | * @return LY_ERR values. |
| 2867 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2868 | LY_ERR |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2869 | parse_grouping(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node_grp **groupings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2870 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2871 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2872 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2873 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2874 | enum ly_stmt kw; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2875 | struct lysp_node_grp *grp; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2876 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2877 | LY_LIST_NEW_RET(PARSER_CTX(ctx), groupings, grp, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2878 | |
| 2879 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2880 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2881 | INSERT_WORD_RET(ctx, buf, grp->name, word, word_len); |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2882 | grp->nodetype = LYS_GROUPING; |
| 2883 | grp->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2884 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2885 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2886 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2887 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2888 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &grp->dsc, Y_STR_ARG, &grp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2889 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2890 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2891 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &grp->ref, Y_STR_ARG, &grp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2892 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2893 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2894 | LY_CHECK_RET(parse_status(ctx, &grp->flags, &grp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2895 | break; |
| 2896 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2897 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2898 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "grouping"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2899 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2900 | case LY_STMT_ANYXML: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2901 | LY_CHECK_RET(parse_any(ctx, kw, &grp->node, &grp->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2902 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2903 | case LY_STMT_CHOICE: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2904 | LY_CHECK_RET(parse_choice(ctx, &grp->node, &grp->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2905 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2906 | case LY_STMT_CONTAINER: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2907 | LY_CHECK_RET(parse_container(ctx, &grp->node, &grp->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2908 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2909 | case LY_STMT_LEAF: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2910 | LY_CHECK_RET(parse_leaf(ctx, &grp->node, &grp->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2911 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2912 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2913 | LY_CHECK_RET(parse_leaflist(ctx, &grp->node, &grp->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2914 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2915 | case LY_STMT_LIST: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2916 | LY_CHECK_RET(parse_list(ctx, &grp->node, &grp->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2917 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2918 | case LY_STMT_USES: |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2919 | LY_CHECK_RET(parse_uses(ctx, &grp->node, &grp->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2920 | break; |
| 2921 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2922 | case LY_STMT_TYPEDEF: |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2923 | LY_CHECK_RET(parse_typedef(ctx, &grp->node, &grp->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2924 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2925 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2926 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "grouping"); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2927 | LY_CHECK_RET(parse_action(ctx, &grp->node, &grp->actions)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2928 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2929 | case LY_STMT_GROUPING: |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2930 | LY_CHECK_RET(parse_grouping(ctx, &grp->node, &grp->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2931 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2932 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2933 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "grouping"); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2934 | LY_CHECK_RET(parse_notif(ctx, &grp->node, &grp->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2935 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2936 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2937 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &grp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2938 | break; |
| 2939 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2940 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "grouping"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2941 | return LY_EVALID; |
| 2942 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2943 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2944 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2945 | return ret; |
| 2946 | } |
| 2947 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2948 | /** |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2949 | * @brief Parse the augment statement. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2950 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2951 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2952 | * @param[in,out] augments Augments to add to. |
| 2953 | * |
| 2954 | * @return LY_ERR values. |
| 2955 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2956 | LY_ERR |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2957 | parse_augment(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node_augment **augments) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2958 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2959 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2960 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2961 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2962 | enum ly_stmt kw; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2963 | struct lysp_node_augment *aug; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2964 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2965 | LY_LIST_NEW_RET(PARSER_CTX(ctx), augments, aug, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2966 | |
| 2967 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2968 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2969 | CHECK_NONEMPTY(ctx, word_len, "augment"); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2970 | INSERT_WORD_RET(ctx, buf, aug->nodeid, word, word_len); |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2971 | aug->nodetype = LYS_AUGMENT; |
| 2972 | aug->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2973 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2974 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2975 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2976 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2977 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &aug->dsc, Y_STR_ARG, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2978 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2979 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2980 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &aug->iffeatures, Y_STR_ARG, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2981 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2982 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2983 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &aug->ref, Y_STR_ARG, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2984 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2985 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2986 | LY_CHECK_RET(parse_status(ctx, &aug->flags, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2987 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2988 | case LY_STMT_WHEN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2989 | LY_CHECK_RET(parse_when(ctx, &aug->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2990 | break; |
| 2991 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2992 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2993 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "augment"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2994 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2995 | case LY_STMT_ANYXML: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2996 | LY_CHECK_RET(parse_any(ctx, kw, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2997 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2998 | case LY_STMT_CASE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 2999 | LY_CHECK_RET(parse_case(ctx, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3000 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3001 | case LY_STMT_CHOICE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3002 | LY_CHECK_RET(parse_choice(ctx, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3003 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3004 | case LY_STMT_CONTAINER: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3005 | LY_CHECK_RET(parse_container(ctx, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3006 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3007 | case LY_STMT_LEAF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3008 | LY_CHECK_RET(parse_leaf(ctx, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3009 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3010 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3011 | LY_CHECK_RET(parse_leaflist(ctx, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3012 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3013 | case LY_STMT_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3014 | LY_CHECK_RET(parse_list(ctx, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3015 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3016 | case LY_STMT_USES: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3017 | LY_CHECK_RET(parse_uses(ctx, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3018 | break; |
| 3019 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3020 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3021 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "augment"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3022 | LY_CHECK_RET(parse_action(ctx, (struct lysp_node *)aug, &aug->actions)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3023 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3024 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3025 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "augment"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3026 | LY_CHECK_RET(parse_notif(ctx, (struct lysp_node *)aug, &aug->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3027 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3028 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3029 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3030 | break; |
| 3031 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3032 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "augment"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3033 | return LY_EVALID; |
| 3034 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3035 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3036 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3037 | return ret; |
| 3038 | } |
| 3039 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3040 | /** |
| 3041 | * @brief Parse the uses statement. |
| 3042 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3043 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3044 | * @param[in,out] siblings Siblings to add to. |
| 3045 | * |
| 3046 | * @return LY_ERR values. |
| 3047 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3048 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3049 | parse_uses(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3050 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3051 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3052 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3053 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3054 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3055 | struct lysp_node_uses *uses; |
| 3056 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3057 | /* create uses structure */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3058 | LY_LIST_NEW_RET(PARSER_CTX(ctx), siblings, uses, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3059 | uses->nodetype = LYS_USES; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3060 | uses->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3061 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3062 | /* get name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3063 | LY_CHECK_RET(get_argument(ctx, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3064 | INSERT_WORD_RET(ctx, buf, uses->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3065 | |
| 3066 | /* parse substatements */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3067 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3068 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3069 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3070 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &uses->dsc, Y_STR_ARG, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3071 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3072 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3073 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &uses->iffeatures, Y_STR_ARG, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3074 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3075 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3076 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &uses->ref, Y_STR_ARG, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3077 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3078 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3079 | LY_CHECK_RET(parse_status(ctx, &uses->flags, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3080 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3081 | case LY_STMT_WHEN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3082 | LY_CHECK_RET(parse_when(ctx, &uses->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3083 | break; |
| 3084 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3085 | case LY_STMT_REFINE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3086 | LY_CHECK_RET(parse_refine(ctx, &uses->refines)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3087 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3088 | case LY_STMT_AUGMENT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3089 | LY_CHECK_RET(parse_augment(ctx, (struct lysp_node *)uses, &uses->augments)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3090 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3091 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3092 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3093 | break; |
| 3094 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3095 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "uses"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3096 | return LY_EVALID; |
| 3097 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3098 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3099 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3100 | return ret; |
| 3101 | } |
| 3102 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3103 | /** |
| 3104 | * @brief Parse the case statement. |
| 3105 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3106 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3107 | * @param[in,out] siblings Siblings to add to. |
| 3108 | * |
| 3109 | * @return LY_ERR values. |
| 3110 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3111 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3112 | parse_case(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3113 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3114 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3115 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3116 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3117 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3118 | struct lysp_node_case *cas; |
| 3119 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3120 | /* create new case structure */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3121 | LY_LIST_NEW_RET(PARSER_CTX(ctx), siblings, cas, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3122 | cas->nodetype = LYS_CASE; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3123 | cas->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3124 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3125 | /* get name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3126 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3127 | INSERT_WORD_RET(ctx, buf, cas->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3128 | |
| 3129 | /* parse substatements */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3130 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3131 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3132 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3133 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &cas->dsc, Y_STR_ARG, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3134 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3135 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3136 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &cas->iffeatures, Y_STR_ARG, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3137 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3138 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3139 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &cas->ref, Y_STR_ARG, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3140 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3141 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3142 | LY_CHECK_RET(parse_status(ctx, &cas->flags, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3143 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3144 | case LY_STMT_WHEN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3145 | LY_CHECK_RET(parse_when(ctx, &cas->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3146 | break; |
| 3147 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3148 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3149 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "case"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3150 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3151 | case LY_STMT_ANYXML: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3152 | LY_CHECK_RET(parse_any(ctx, kw, (struct lysp_node *)cas, &cas->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3153 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3154 | case LY_STMT_CHOICE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3155 | LY_CHECK_RET(parse_choice(ctx, (struct lysp_node *)cas, &cas->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3156 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3157 | case LY_STMT_CONTAINER: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3158 | LY_CHECK_RET(parse_container(ctx, (struct lysp_node *)cas, &cas->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3159 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3160 | case LY_STMT_LEAF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3161 | LY_CHECK_RET(parse_leaf(ctx, (struct lysp_node *)cas, &cas->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3162 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3163 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3164 | LY_CHECK_RET(parse_leaflist(ctx, (struct lysp_node *)cas, &cas->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3165 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3166 | case LY_STMT_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3167 | LY_CHECK_RET(parse_list(ctx, (struct lysp_node *)cas, &cas->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3168 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3169 | case LY_STMT_USES: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3170 | LY_CHECK_RET(parse_uses(ctx, (struct lysp_node *)cas, &cas->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3171 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3172 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3173 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3174 | break; |
| 3175 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3176 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "case"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3177 | return LY_EVALID; |
| 3178 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3179 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3180 | return ret; |
| 3181 | } |
| 3182 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3183 | /** |
| 3184 | * @brief Parse the choice statement. |
| 3185 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3186 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3187 | * @param[in,out] siblings Siblings to add to. |
| 3188 | * |
| 3189 | * @return LY_ERR values. |
| 3190 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3191 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3192 | parse_choice(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3193 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3194 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3195 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3196 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3197 | enum ly_stmt kw; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3198 | struct lysp_node_choice *choice; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3199 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3200 | /* create new choice structure */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3201 | LY_LIST_NEW_RET(PARSER_CTX(ctx), siblings, choice, next, LY_EMEM); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3202 | choice->nodetype = LYS_CHOICE; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3203 | choice->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3204 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3205 | /* get name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3206 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3207 | INSERT_WORD_RET(ctx, buf, choice->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3208 | |
| 3209 | /* parse substatements */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3210 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3211 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3212 | case LY_STMT_CONFIG: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3213 | LY_CHECK_RET(parse_config(ctx, &choice->flags, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3214 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3215 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3216 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &choice->dsc, Y_STR_ARG, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3217 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3218 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3219 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &choice->iffeatures, Y_STR_ARG, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3220 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3221 | case LY_STMT_MANDATORY: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3222 | LY_CHECK_RET(parse_mandatory(ctx, &choice->flags, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3223 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3224 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3225 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &choice->ref, Y_STR_ARG, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3226 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3227 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3228 | LY_CHECK_RET(parse_status(ctx, &choice->flags, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3229 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3230 | case LY_STMT_WHEN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3231 | LY_CHECK_RET(parse_when(ctx, &choice->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3232 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3233 | case LY_STMT_DEFAULT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3234 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DEFAULT, 0, &choice->dflt.str, Y_PREF_IDENTIF_ARG, |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3235 | &choice->exts)); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3236 | choice->dflt.mod = ctx->parsed_mod; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3237 | break; |
| 3238 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3239 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3240 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "choice"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3241 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3242 | case LY_STMT_ANYXML: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3243 | LY_CHECK_RET(parse_any(ctx, kw, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3244 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3245 | case LY_STMT_CASE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3246 | LY_CHECK_RET(parse_case(ctx, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3247 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3248 | case LY_STMT_CHOICE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3249 | PARSER_CHECK_STMTVER2_RET(ctx, "choice", "choice"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3250 | LY_CHECK_RET(parse_choice(ctx, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3251 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3252 | case LY_STMT_CONTAINER: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3253 | LY_CHECK_RET(parse_container(ctx, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3254 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3255 | case LY_STMT_LEAF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3256 | LY_CHECK_RET(parse_leaf(ctx, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3257 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3258 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3259 | LY_CHECK_RET(parse_leaflist(ctx, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3260 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3261 | case LY_STMT_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3262 | LY_CHECK_RET(parse_list(ctx, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3263 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3264 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3265 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3266 | break; |
| 3267 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3268 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "choice"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3269 | return LY_EVALID; |
| 3270 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3271 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3272 | return ret; |
| 3273 | } |
| 3274 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3275 | /** |
| 3276 | * @brief Parse the container statement. |
| 3277 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3278 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3279 | * @param[in,out] siblings Siblings to add to. |
| 3280 | * |
| 3281 | * @return LY_ERR values. |
| 3282 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3283 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3284 | parse_container(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3285 | { |
| 3286 | LY_ERR ret = 0; |
| 3287 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3288 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3289 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3290 | struct lysp_node_container *cont; |
| 3291 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3292 | /* create new container structure */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3293 | LY_LIST_NEW_RET(PARSER_CTX(ctx), siblings, cont, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3294 | cont->nodetype = LYS_CONTAINER; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3295 | cont->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3296 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3297 | /* get name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3298 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3299 | INSERT_WORD_RET(ctx, buf, cont->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3300 | |
| 3301 | /* parse substatements */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3302 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3303 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3304 | case LY_STMT_CONFIG: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3305 | LY_CHECK_RET(parse_config(ctx, &cont->flags, &cont->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3306 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3307 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3308 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &cont->dsc, Y_STR_ARG, &cont->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3309 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3310 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3311 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &cont->iffeatures, Y_STR_ARG, &cont->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3312 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3313 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3314 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &cont->ref, Y_STR_ARG, &cont->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3315 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3316 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3317 | LY_CHECK_RET(parse_status(ctx, &cont->flags, &cont->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3318 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3319 | case LY_STMT_WHEN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3320 | LY_CHECK_RET(parse_when(ctx, &cont->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3321 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3322 | case LY_STMT_PRESENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3323 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_PRESENCE, 0, &cont->presence, Y_STR_ARG, &cont->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3324 | break; |
| 3325 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3326 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3327 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "container"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3328 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3329 | case LY_STMT_ANYXML: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3330 | LY_CHECK_RET(parse_any(ctx, kw, (struct lysp_node *)cont, &cont->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3331 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3332 | case LY_STMT_CHOICE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3333 | LY_CHECK_RET(parse_choice(ctx, (struct lysp_node *)cont, &cont->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3334 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3335 | case LY_STMT_CONTAINER: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3336 | LY_CHECK_RET(parse_container(ctx, (struct lysp_node *)cont, &cont->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3337 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3338 | case LY_STMT_LEAF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3339 | LY_CHECK_RET(parse_leaf(ctx, (struct lysp_node *)cont, &cont->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3340 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3341 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3342 | LY_CHECK_RET(parse_leaflist(ctx, (struct lysp_node *)cont, &cont->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3343 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3344 | case LY_STMT_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3345 | LY_CHECK_RET(parse_list(ctx, (struct lysp_node *)cont, &cont->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3346 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3347 | case LY_STMT_USES: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3348 | LY_CHECK_RET(parse_uses(ctx, (struct lysp_node *)cont, &cont->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3349 | break; |
| 3350 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3351 | case LY_STMT_TYPEDEF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3352 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)cont, &cont->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3353 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3354 | case LY_STMT_MUST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3355 | LY_CHECK_RET(parse_restrs(ctx, kw, &cont->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3356 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3357 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3358 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "container"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3359 | LY_CHECK_RET(parse_action(ctx, (struct lysp_node *)cont, &cont->actions)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3360 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3361 | case LY_STMT_GROUPING: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3362 | LY_CHECK_RET(parse_grouping(ctx, (struct lysp_node *)cont, &cont->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3363 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3364 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3365 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "container"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3366 | LY_CHECK_RET(parse_notif(ctx, (struct lysp_node *)cont, &cont->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3367 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3368 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3369 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &cont->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3370 | break; |
| 3371 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3372 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "container"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3373 | return LY_EVALID; |
| 3374 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3375 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3376 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3377 | return ret; |
| 3378 | } |
| 3379 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3380 | /** |
| 3381 | * @brief Parse the list statement. |
| 3382 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3383 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3384 | * @param[in,out] siblings Siblings to add to. |
| 3385 | * |
| 3386 | * @return LY_ERR values. |
| 3387 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3388 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3389 | parse_list(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3390 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3391 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3392 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3393 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3394 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3395 | struct lysp_node_list *list; |
| 3396 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3397 | /* create new list structure */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3398 | LY_LIST_NEW_RET(PARSER_CTX(ctx), siblings, list, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3399 | list->nodetype = LYS_LIST; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3400 | list->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3401 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3402 | /* get name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3403 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3404 | INSERT_WORD_RET(ctx, buf, list->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3405 | |
| 3406 | /* parse substatements */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3407 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3408 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3409 | case LY_STMT_CONFIG: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3410 | LY_CHECK_RET(parse_config(ctx, &list->flags, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3411 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3412 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3413 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &list->dsc, Y_STR_ARG, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3414 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3415 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3416 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &list->iffeatures, Y_STR_ARG, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3417 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3418 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3419 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &list->ref, Y_STR_ARG, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3420 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3421 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3422 | LY_CHECK_RET(parse_status(ctx, &list->flags, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3423 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3424 | case LY_STMT_WHEN: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3425 | LY_CHECK_RET(parse_when(ctx, &list->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3426 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3427 | case LY_STMT_KEY: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3428 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_KEY, 0, &list->key, Y_STR_ARG, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3429 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3430 | case LY_STMT_MAX_ELEMENTS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3431 | LY_CHECK_RET(parse_maxelements(ctx, &list->max, &list->flags, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3432 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3433 | case LY_STMT_MIN_ELEMENTS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3434 | LY_CHECK_RET(parse_minelements(ctx, &list->min, &list->flags, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3435 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3436 | case LY_STMT_ORDERED_BY: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3437 | LY_CHECK_RET(parse_orderedby(ctx, &list->flags, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3438 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3439 | case LY_STMT_UNIQUE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3440 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_UNIQUE, &list->uniques, Y_STR_ARG, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3441 | break; |
| 3442 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3443 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3444 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "list"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3445 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3446 | case LY_STMT_ANYXML: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3447 | LY_CHECK_RET(parse_any(ctx, kw, (struct lysp_node *)list, &list->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3448 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3449 | case LY_STMT_CHOICE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3450 | LY_CHECK_RET(parse_choice(ctx, (struct lysp_node *)list, &list->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3451 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3452 | case LY_STMT_CONTAINER: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3453 | LY_CHECK_RET(parse_container(ctx, (struct lysp_node *)list, &list->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3454 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3455 | case LY_STMT_LEAF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3456 | LY_CHECK_RET(parse_leaf(ctx, (struct lysp_node *)list, &list->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3457 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3458 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3459 | LY_CHECK_RET(parse_leaflist(ctx, (struct lysp_node *)list, &list->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3460 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3461 | case LY_STMT_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3462 | LY_CHECK_RET(parse_list(ctx, (struct lysp_node *)list, &list->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3463 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3464 | case LY_STMT_USES: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3465 | LY_CHECK_RET(parse_uses(ctx, (struct lysp_node *)list, &list->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3466 | break; |
| 3467 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3468 | case LY_STMT_TYPEDEF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3469 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)list, &list->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3470 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3471 | case LY_STMT_MUST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3472 | LY_CHECK_RET(parse_restrs(ctx, kw, &list->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3473 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3474 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3475 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "list"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3476 | LY_CHECK_RET(parse_action(ctx, (struct lysp_node *)list, &list->actions)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3477 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3478 | case LY_STMT_GROUPING: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3479 | LY_CHECK_RET(parse_grouping(ctx, (struct lysp_node *)list, &list->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3480 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3481 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3482 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "list"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3483 | LY_CHECK_RET(parse_notif(ctx, (struct lysp_node *)list, &list->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3484 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3485 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3486 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3487 | break; |
| 3488 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3489 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "list"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3490 | return LY_EVALID; |
| 3491 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3492 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3493 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3494 | return ret; |
| 3495 | } |
| 3496 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3497 | /** |
| 3498 | * @brief Parse the yin-element statement. |
| 3499 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3500 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3501 | * @param[in,out] flags Flags to write to. |
| 3502 | * @param[in,out] exts Extension instances to add to. |
| 3503 | * |
| 3504 | * @return LY_ERR values. |
| 3505 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3506 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3507 | parse_yinelement(struct lys_yang_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3508 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3509 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3510 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3511 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3512 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3513 | |
| 3514 | if (*flags & LYS_YINELEM_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3515 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "yin-element"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3516 | return LY_EVALID; |
| 3517 | } |
| 3518 | |
| 3519 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3520 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3521 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3522 | if ((word_len == ly_strlen_const("true")) && !strncmp(word, "true", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3523 | *flags |= LYS_YINELEM_TRUE; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3524 | } else if ((word_len == ly_strlen_const("false")) && !strncmp(word, "false", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3525 | *flags |= LYS_YINELEM_FALSE; |
| 3526 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3527 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "yin-element"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3528 | free(buf); |
| 3529 | return LY_EVALID; |
| 3530 | } |
| 3531 | free(buf); |
| 3532 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3533 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3534 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3535 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3536 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_YINELEM, 0, exts)); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3537 | LY_CHECK_RET(ret); |
| 3538 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3539 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3540 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "yin-element"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3541 | return LY_EVALID; |
| 3542 | } |
| 3543 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3544 | return ret; |
| 3545 | } |
| 3546 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3547 | /** |
David Sedlák | 2444f8f | 2019-07-09 11:02:47 +0200 | [diff] [blame] | 3548 | * @brief Parse the argument statement. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3549 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3550 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3551 | * @param[in,out] argument Value to write to. |
| 3552 | * @param[in,out] flags Flags to write to. |
| 3553 | * @param[in,out] exts Extension instances to add to. |
| 3554 | * |
| 3555 | * @return LY_ERR values. |
| 3556 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3557 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3558 | parse_argument(struct lys_yang_parser_ctx *ctx, const char **argument, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3559 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3560 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3561 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3562 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3563 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3564 | |
| 3565 | if (*argument) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3566 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "argument"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3567 | return LY_EVALID; |
| 3568 | } |
| 3569 | |
| 3570 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3571 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3572 | INSERT_WORD_RET(ctx, buf, *argument, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3573 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3574 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3575 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3576 | case LY_STMT_YIN_ELEMENT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3577 | LY_CHECK_RET(parse_yinelement(ctx, flags, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3578 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3579 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3580 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_ARGUMENT, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3581 | break; |
| 3582 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3583 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "argument"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3584 | return LY_EVALID; |
| 3585 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3586 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3587 | return ret; |
| 3588 | } |
| 3589 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3590 | /** |
| 3591 | * @brief Parse the extension statement. |
| 3592 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3593 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3594 | * @param[in,out] extensions Extensions to add to. |
| 3595 | * |
| 3596 | * @return LY_ERR values. |
| 3597 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3598 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3599 | parse_extension(struct lys_yang_parser_ctx *ctx, struct lysp_ext **extensions) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3600 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3601 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3602 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3603 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3604 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3605 | struct lysp_ext *ex; |
| 3606 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3607 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *extensions, ex, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3608 | |
| 3609 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3610 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3611 | INSERT_WORD_RET(ctx, buf, ex->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3612 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3613 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3614 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3615 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3616 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &ex->dsc, Y_STR_ARG, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3617 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3618 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3619 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &ex->ref, Y_STR_ARG, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3620 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3621 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3622 | LY_CHECK_RET(parse_status(ctx, &ex->flags, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3623 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3624 | case LY_STMT_ARGUMENT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3625 | LY_CHECK_RET(parse_argument(ctx, &ex->argument, &ex->flags, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3626 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3627 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3628 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3629 | break; |
| 3630 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3631 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "extension"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3632 | return LY_EVALID; |
| 3633 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3634 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3635 | return ret; |
| 3636 | } |
| 3637 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3638 | /** |
| 3639 | * @brief Parse the deviate statement. |
| 3640 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3641 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3642 | * @param[in,out] deviates Deviates to add to. |
| 3643 | * |
| 3644 | * @return LY_ERR values. |
| 3645 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3646 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3647 | parse_deviate(struct lys_yang_parser_ctx *ctx, struct lysp_deviate **deviates) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3648 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3649 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3650 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3651 | size_t word_len, dev_mod; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3652 | enum ly_stmt kw; |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3653 | struct lysp_deviate *d; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3654 | struct lysp_deviate_add *d_add = NULL; |
| 3655 | struct lysp_deviate_rpl *d_rpl = NULL; |
| 3656 | struct lysp_deviate_del *d_del = NULL; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3657 | const char **d_units = NULL; |
| 3658 | struct lysp_qname **d_uniques = NULL, **d_dflts = NULL; |
Radek Krejci | 4ad42aa | 2019-07-23 16:55:58 +0200 | [diff] [blame] | 3659 | struct lysp_restr **d_musts = NULL; |
| 3660 | uint16_t *d_flags = 0; |
| 3661 | uint32_t *d_min = 0, *d_max = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3662 | |
| 3663 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3664 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3665 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3666 | if ((word_len == ly_strlen_const("not-supported")) && !strncmp(word, "not-supported", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3667 | dev_mod = LYS_DEV_NOT_SUPPORTED; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3668 | } else if ((word_len == ly_strlen_const("add")) && !strncmp(word, "add", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3669 | dev_mod = LYS_DEV_ADD; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3670 | } else if ((word_len == ly_strlen_const("replace")) && !strncmp(word, "replace", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3671 | dev_mod = LYS_DEV_REPLACE; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3672 | } else if ((word_len == ly_strlen_const("delete")) && !strncmp(word, "delete", word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3673 | dev_mod = LYS_DEV_DELETE; |
| 3674 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3675 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "deviate"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3676 | free(buf); |
| 3677 | return LY_EVALID; |
| 3678 | } |
| 3679 | free(buf); |
| 3680 | |
| 3681 | /* create structure */ |
| 3682 | switch (dev_mod) { |
| 3683 | case LYS_DEV_NOT_SUPPORTED: |
| 3684 | d = calloc(1, sizeof *d); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3685 | LY_CHECK_ERR_RET(!d, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3686 | break; |
| 3687 | case LYS_DEV_ADD: |
| 3688 | d_add = calloc(1, sizeof *d_add); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3689 | LY_CHECK_ERR_RET(!d_add, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3690 | d = (struct lysp_deviate *)d_add; |
| 3691 | d_units = &d_add->units; |
| 3692 | d_uniques = &d_add->uniques; |
| 3693 | d_dflts = &d_add->dflts; |
| 3694 | d_musts = &d_add->musts; |
| 3695 | d_flags = &d_add->flags; |
| 3696 | d_min = &d_add->min; |
| 3697 | d_max = &d_add->max; |
| 3698 | break; |
| 3699 | case LYS_DEV_REPLACE: |
| 3700 | d_rpl = calloc(1, sizeof *d_rpl); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3701 | LY_CHECK_ERR_RET(!d_rpl, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3702 | d = (struct lysp_deviate *)d_rpl; |
| 3703 | d_units = &d_rpl->units; |
| 3704 | d_flags = &d_rpl->flags; |
| 3705 | d_min = &d_rpl->min; |
| 3706 | d_max = &d_rpl->max; |
| 3707 | break; |
| 3708 | case LYS_DEV_DELETE: |
| 3709 | d_del = calloc(1, sizeof *d_del); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3710 | LY_CHECK_ERR_RET(!d_del, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3711 | d = (struct lysp_deviate *)d_del; |
| 3712 | d_units = &d_del->units; |
| 3713 | d_uniques = &d_del->uniques; |
| 3714 | d_dflts = &d_del->dflts; |
| 3715 | d_musts = &d_del->musts; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3716 | break; |
| 3717 | default: |
| 3718 | assert(0); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3719 | LOGINT_RET(PARSER_CTX(ctx)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3720 | } |
| 3721 | d->mod = dev_mod; |
| 3722 | |
| 3723 | /* insert into siblings */ |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3724 | LY_LIST_INSERT(deviates, d, next); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3725 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3726 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3727 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3728 | case LY_STMT_CONFIG: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3729 | switch (dev_mod) { |
| 3730 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3731 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3732 | LOGVAL_PARSER(ctx, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3733 | return LY_EVALID; |
| 3734 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3735 | LY_CHECK_RET(parse_config(ctx, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3736 | break; |
| 3737 | } |
| 3738 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3739 | case LY_STMT_DEFAULT: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3740 | switch (dev_mod) { |
| 3741 | case LYS_DEV_NOT_SUPPORTED: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3742 | LOGVAL_PARSER(ctx, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3743 | return LY_EVALID; |
| 3744 | case LYS_DEV_REPLACE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3745 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DEFAULT, 0, &d_rpl->dflt.str, Y_STR_ARG, &d->exts)); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3746 | d_rpl->dflt.mod = ctx->parsed_mod; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3747 | break; |
| 3748 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3749 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_DEFAULT, d_dflts, Y_STR_ARG, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3750 | break; |
| 3751 | } |
| 3752 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3753 | case LY_STMT_MANDATORY: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3754 | switch (dev_mod) { |
| 3755 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3756 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3757 | LOGVAL_PARSER(ctx, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3758 | return LY_EVALID; |
| 3759 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3760 | LY_CHECK_RET(parse_mandatory(ctx, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3761 | break; |
| 3762 | } |
| 3763 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3764 | case LY_STMT_MAX_ELEMENTS: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3765 | switch (dev_mod) { |
| 3766 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3767 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3768 | LOGVAL_PARSER(ctx, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3769 | return LY_EVALID; |
| 3770 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3771 | LY_CHECK_RET(parse_maxelements(ctx, d_max, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3772 | break; |
| 3773 | } |
| 3774 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3775 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3776 | switch (dev_mod) { |
| 3777 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3778 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3779 | LOGVAL_PARSER(ctx, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3780 | return LY_EVALID; |
| 3781 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3782 | LY_CHECK_RET(parse_minelements(ctx, d_min, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3783 | break; |
| 3784 | } |
| 3785 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3786 | case LY_STMT_MUST: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3787 | switch (dev_mod) { |
| 3788 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3789 | case LYS_DEV_REPLACE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3790 | LOGVAL_PARSER(ctx, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3791 | return LY_EVALID; |
| 3792 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3793 | LY_CHECK_RET(parse_restrs(ctx, kw, d_musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3794 | break; |
| 3795 | } |
| 3796 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3797 | case LY_STMT_TYPE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3798 | switch (dev_mod) { |
| 3799 | case LYS_DEV_NOT_SUPPORTED: |
| 3800 | case LYS_DEV_ADD: |
| 3801 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3802 | LOGVAL_PARSER(ctx, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3803 | return LY_EVALID; |
| 3804 | default: |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 3805 | if (d_rpl->type) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3806 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(kw)); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 3807 | return LY_EVALID; |
| 3808 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3809 | d_rpl->type = calloc(1, sizeof *d_rpl->type); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3810 | LY_CHECK_ERR_RET(!d_rpl->type, LOGMEM(PARSER_CTX(ctx)), LY_EMEM); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3811 | LY_CHECK_RET(parse_type(ctx, d_rpl->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3812 | break; |
| 3813 | } |
| 3814 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3815 | case LY_STMT_UNIQUE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3816 | switch (dev_mod) { |
| 3817 | case LYS_DEV_NOT_SUPPORTED: |
| 3818 | case LYS_DEV_REPLACE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3819 | LOGVAL_PARSER(ctx, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3820 | return LY_EVALID; |
| 3821 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3822 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_UNIQUE, d_uniques, Y_STR_ARG, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3823 | break; |
| 3824 | } |
| 3825 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3826 | case LY_STMT_UNITS: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3827 | switch (dev_mod) { |
| 3828 | case LYS_DEV_NOT_SUPPORTED: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3829 | LOGVAL_PARSER(ctx, LY_VCODE_INDEV, ly_devmod2str(dev_mod), ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3830 | return LY_EVALID; |
| 3831 | default: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3832 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_UNITS, 0, d_units, Y_STR_ARG, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3833 | break; |
| 3834 | } |
| 3835 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3836 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3837 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3838 | break; |
| 3839 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3840 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "deviate"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3841 | return LY_EVALID; |
| 3842 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3843 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3844 | return ret; |
| 3845 | } |
| 3846 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3847 | /** |
| 3848 | * @brief Parse the deviation statement. |
| 3849 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3850 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3851 | * @param[in,out] deviations Deviations to add to. |
| 3852 | * |
| 3853 | * @return LY_ERR values. |
| 3854 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3855 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3856 | parse_deviation(struct lys_yang_parser_ctx *ctx, struct lysp_deviation **deviations) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3857 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3858 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3859 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3860 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3861 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3862 | struct lysp_deviation *dev; |
| 3863 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3864 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *deviations, dev, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3865 | |
| 3866 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3867 | LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3868 | CHECK_NONEMPTY(ctx, word_len, "deviation"); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3869 | INSERT_WORD_RET(ctx, buf, dev->nodeid, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3870 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3871 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3872 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3873 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3874 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &dev->dsc, Y_STR_ARG, &dev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3875 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3876 | case LY_STMT_DEVIATE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3877 | LY_CHECK_RET(parse_deviate(ctx, &dev->deviates)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3878 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3879 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3880 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &dev->ref, Y_STR_ARG, &dev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3881 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3882 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3883 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &dev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3884 | break; |
| 3885 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3886 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "deviation"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3887 | return LY_EVALID; |
| 3888 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3889 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 3890 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 3891 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3892 | /* mandatory substatements */ |
| 3893 | if (!dev->deviates) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3894 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "deviate", "deviation"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3895 | return LY_EVALID; |
| 3896 | } |
| 3897 | |
| 3898 | return ret; |
| 3899 | } |
| 3900 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3901 | /** |
| 3902 | * @brief Parse the feature statement. |
| 3903 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3904 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3905 | * @param[in,out] features Features to add to. |
| 3906 | * |
| 3907 | * @return LY_ERR values. |
| 3908 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3909 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3910 | parse_feature(struct lys_yang_parser_ctx *ctx, struct lysp_feature **features) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3911 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3912 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3913 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3914 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3915 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3916 | struct lysp_feature *feat; |
| 3917 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3918 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *features, feat, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3919 | |
| 3920 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3921 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3922 | INSERT_WORD_RET(ctx, buf, feat->name, word, word_len); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 3923 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3924 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3925 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3926 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3927 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &feat->dsc, Y_STR_ARG, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3928 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3929 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3930 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &feat->iffeatures, Y_STR_ARG, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3931 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3932 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3933 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &feat->ref, Y_STR_ARG, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3934 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3935 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3936 | LY_CHECK_RET(parse_status(ctx, &feat->flags, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3937 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3938 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3939 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3940 | break; |
| 3941 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3942 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "feature"); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 3943 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3944 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3945 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3946 | return ret; |
| 3947 | } |
| 3948 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3949 | /** |
| 3950 | * @brief Parse the identity statement. |
| 3951 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3952 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3953 | * @param[in,out] identities Identities to add to. |
| 3954 | * |
| 3955 | * @return LY_ERR values. |
| 3956 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3957 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3958 | parse_identity(struct lys_yang_parser_ctx *ctx, struct lysp_ident **identities) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3959 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3960 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3961 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3962 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3963 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3964 | struct lysp_ident *ident; |
| 3965 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3966 | LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *identities, ident, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3967 | |
| 3968 | /* get value */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3969 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3970 | INSERT_WORD_RET(ctx, buf, ident->name, word, word_len); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 3971 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3972 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3973 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3974 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3975 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &ident->dsc, Y_STR_ARG, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3976 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3977 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3978 | PARSER_CHECK_STMTVER2_RET(ctx, "if-feature", "identity"); |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3979 | LY_CHECK_RET(parse_qnames(ctx, LYEXT_SUBSTMT_IFFEATURE, &ident->iffeatures, Y_STR_ARG, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3980 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3981 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3982 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &ident->ref, Y_STR_ARG, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3983 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3984 | case LY_STMT_STATUS: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3985 | LY_CHECK_RET(parse_status(ctx, &ident->flags, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3986 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3987 | case LY_STMT_BASE: |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3988 | if (ident->bases && (ctx->parsed_mod->version < LYS_VERSION_1_1)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3989 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Identity can be derived from multiple base identities only in YANG 1.1 modules"); |
Radek Krejci | 1011365 | 2018-11-14 16:56:50 +0100 | [diff] [blame] | 3990 | return LY_EVALID; |
| 3991 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3992 | LY_CHECK_RET(parse_text_fields(ctx, LYEXT_SUBSTMT_BASE, &ident->bases, Y_PREF_IDENTIF_ARG, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3993 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3994 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 3995 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3996 | break; |
| 3997 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3998 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "identity"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3999 | return LY_EVALID; |
| 4000 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4001 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4002 | return ret; |
| 4003 | } |
| 4004 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4005 | /** |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4006 | * @brief Parse module substatements. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4007 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 4008 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4009 | * @param[in,out] mod Module to write to. |
| 4010 | * |
| 4011 | * @return LY_ERR values. |
| 4012 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 4013 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4014 | parse_module(struct lys_yang_parser_ctx *ctx, struct lysp_module *mod) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4015 | { |
| 4016 | LY_ERR ret = 0; |
| 4017 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 4018 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4019 | enum ly_stmt kw, prev_kw = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4020 | enum yang_module_stmt mod_stmt = Y_MOD_MODULE_HEADER; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4021 | struct lysp_submodule *dup; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4022 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4023 | mod->is_submod = 0; |
| 4024 | |
| 4025 | /* module name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4026 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 4027 | INSERT_WORD_RET(ctx, buf, mod->mod->name, word, word_len); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 4028 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4029 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4030 | |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4031 | #define CHECK_ORDER(SECTION) \ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4032 | if (mod_stmt > SECTION) {LOGVAL_PARSER(ctx, LY_VCODE_INORD, ly_stmt2str(kw), ly_stmt2str(prev_kw)); return LY_EVALID;}mod_stmt = SECTION |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4033 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4034 | switch (kw) { |
| 4035 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4036 | case LY_STMT_NAMESPACE: |
| 4037 | case LY_STMT_PREFIX: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4038 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
| 4039 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4040 | case LY_STMT_YANG_VERSION: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4041 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4042 | break; |
| 4043 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4044 | case LY_STMT_INCLUDE: |
| 4045 | case LY_STMT_IMPORT: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4046 | CHECK_ORDER(Y_MOD_LINKAGE); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4047 | break; |
| 4048 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4049 | case LY_STMT_ORGANIZATION: |
| 4050 | case LY_STMT_CONTACT: |
| 4051 | case LY_STMT_DESCRIPTION: |
| 4052 | case LY_STMT_REFERENCE: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4053 | CHECK_ORDER(Y_MOD_META); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4054 | break; |
| 4055 | |
| 4056 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4057 | case LY_STMT_REVISION: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4058 | CHECK_ORDER(Y_MOD_REVISION); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4059 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4060 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4061 | case LY_STMT_ANYDATA: |
| 4062 | case LY_STMT_ANYXML: |
| 4063 | case LY_STMT_AUGMENT: |
| 4064 | case LY_STMT_CHOICE: |
| 4065 | case LY_STMT_CONTAINER: |
| 4066 | case LY_STMT_DEVIATION: |
| 4067 | case LY_STMT_EXTENSION: |
| 4068 | case LY_STMT_FEATURE: |
| 4069 | case LY_STMT_GROUPING: |
| 4070 | case LY_STMT_IDENTITY: |
| 4071 | case LY_STMT_LEAF: |
| 4072 | case LY_STMT_LEAF_LIST: |
| 4073 | case LY_STMT_LIST: |
| 4074 | case LY_STMT_NOTIFICATION: |
| 4075 | case LY_STMT_RPC: |
| 4076 | case LY_STMT_TYPEDEF: |
| 4077 | case LY_STMT_USES: |
| 4078 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4079 | mod_stmt = Y_MOD_BODY; |
| 4080 | break; |
| 4081 | default: |
| 4082 | /* error handled in the next switch */ |
| 4083 | break; |
| 4084 | } |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4085 | #undef CHECK_ORDER |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4086 | |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4087 | prev_kw = kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4088 | switch (kw) { |
| 4089 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4090 | case LY_STMT_YANG_VERSION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4091 | LY_CHECK_RET(parse_yangversion(ctx, &mod->version, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4092 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4093 | case LY_STMT_NAMESPACE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4094 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, &mod->mod->ns, Y_STR_ARG, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4095 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4096 | case LY_STMT_PREFIX: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4097 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_PREFIX, 0, &mod->mod->prefix, Y_IDENTIF_ARG, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4098 | break; |
| 4099 | |
| 4100 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4101 | case LY_STMT_INCLUDE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4102 | LY_CHECK_RET(parse_include(ctx, mod->mod->name, &mod->includes)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4103 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4104 | case LY_STMT_IMPORT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4105 | LY_CHECK_RET(parse_import(ctx, mod->mod->prefix, &mod->imports)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4106 | break; |
| 4107 | |
| 4108 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4109 | case LY_STMT_ORGANIZATION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4110 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, &mod->mod->org, Y_STR_ARG, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4111 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4112 | case LY_STMT_CONTACT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4113 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_CONTACT, 0, &mod->mod->contact, Y_STR_ARG, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4114 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4115 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4116 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &mod->mod->dsc, Y_STR_ARG, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4117 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4118 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4119 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &mod->mod->ref, Y_STR_ARG, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4120 | break; |
| 4121 | |
| 4122 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4123 | case LY_STMT_REVISION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4124 | LY_CHECK_RET(parse_revision(ctx, &mod->revs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4125 | break; |
| 4126 | |
| 4127 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4128 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 4129 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "module"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 4130 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4131 | case LY_STMT_ANYXML: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4132 | LY_CHECK_RET(parse_any(ctx, kw, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4133 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4134 | case LY_STMT_CHOICE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4135 | LY_CHECK_RET(parse_choice(ctx, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4136 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4137 | case LY_STMT_CONTAINER: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4138 | LY_CHECK_RET(parse_container(ctx, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4139 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4140 | case LY_STMT_LEAF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4141 | LY_CHECK_RET(parse_leaf(ctx, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4142 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4143 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4144 | LY_CHECK_RET(parse_leaflist(ctx, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4145 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4146 | case LY_STMT_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4147 | LY_CHECK_RET(parse_list(ctx, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4148 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4149 | case LY_STMT_USES: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4150 | LY_CHECK_RET(parse_uses(ctx, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4151 | break; |
| 4152 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4153 | case LY_STMT_AUGMENT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4154 | LY_CHECK_RET(parse_augment(ctx, NULL, &mod->augments)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4155 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4156 | case LY_STMT_DEVIATION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4157 | LY_CHECK_RET(parse_deviation(ctx, &mod->deviations)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4158 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4159 | case LY_STMT_EXTENSION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4160 | LY_CHECK_RET(parse_extension(ctx, &mod->extensions)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4161 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4162 | case LY_STMT_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4163 | LY_CHECK_RET(parse_feature(ctx, &mod->features)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4164 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4165 | case LY_STMT_GROUPING: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4166 | LY_CHECK_RET(parse_grouping(ctx, NULL, &mod->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4167 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4168 | case LY_STMT_IDENTITY: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4169 | LY_CHECK_RET(parse_identity(ctx, &mod->identities)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4170 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4171 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4172 | LY_CHECK_RET(parse_notif(ctx, NULL, &mod->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4173 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4174 | case LY_STMT_RPC: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4175 | LY_CHECK_RET(parse_action(ctx, NULL, &mod->rpcs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4176 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4177 | case LY_STMT_TYPEDEF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4178 | LY_CHECK_RET(parse_typedef(ctx, NULL, &mod->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4179 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4180 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4181 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4182 | break; |
| 4183 | |
| 4184 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4185 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "module"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4186 | return LY_EVALID; |
| 4187 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4188 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 4189 | LY_CHECK_RET(ret); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 4190 | |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 4191 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4192 | /* mandatory substatements */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4193 | if (!mod->mod->ns) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4194 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "namespace", "module"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4195 | return LY_EVALID; |
| 4196 | } else if (!mod->mod->prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4197 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "prefix", "module"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4198 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4199 | } |
| 4200 | |
Radek Krejci | e9e987e | 2018-10-31 12:50:27 +0100 | [diff] [blame] | 4201 | /* submodules share the namespace with the module names, so there must not be |
| 4202 | * a submodule of the same name in the context, no need for revision matching */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4203 | dup = ly_ctx_get_submodule(PARSER_CTX(ctx), NULL, mod->mod->name, NULL); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4204 | if (dup) { |
Radek Krejci | 854e155 | 2020-12-21 15:05:23 +0100 | [diff] [blame] | 4205 | LOGVAL_PARSER(ctx, LY_VCODE_NAME2_COL, "module", "submodule", mod->mod->name); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4206 | return LY_EVALID; |
| 4207 | } |
| 4208 | |
| 4209 | return ret; |
| 4210 | } |
| 4211 | |
| 4212 | /** |
| 4213 | * @brief Parse submodule substatements. |
| 4214 | * |
| 4215 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4216 | * @param[out] submod Parsed submodule structure. |
| 4217 | * |
| 4218 | * @return LY_ERR values. |
| 4219 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 4220 | LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4221 | parse_submodule(struct lys_yang_parser_ctx *ctx, struct lysp_submodule *submod) |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4222 | { |
| 4223 | LY_ERR ret = 0; |
| 4224 | char *buf, *word; |
| 4225 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4226 | enum ly_stmt kw, prev_kw = 0; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4227 | enum yang_module_stmt mod_stmt = Y_MOD_MODULE_HEADER; |
| 4228 | struct lysp_submodule *dup; |
| 4229 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4230 | submod->is_submod = 1; |
| 4231 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4232 | /* submodule name */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4233 | LY_CHECK_RET(get_argument(ctx, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 4234 | INSERT_WORD_RET(ctx, buf, submod->name, word, word_len); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4235 | |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4236 | YANG_READ_SUBSTMT_FOR(ctx, kw, word, word_len, ret, goto checks) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4237 | |
| 4238 | #define CHECK_ORDER(SECTION) \ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4239 | if (mod_stmt > SECTION) {LOGVAL_PARSER(ctx, LY_VCODE_INORD, ly_stmt2str(kw), ly_stmt2str(prev_kw)); return LY_EVALID;}mod_stmt = SECTION |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4240 | |
| 4241 | switch (kw) { |
| 4242 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4243 | case LY_STMT_BELONGS_TO: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4244 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
| 4245 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4246 | case LY_STMT_YANG_VERSION: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4247 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
| 4248 | break; |
| 4249 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4250 | case LY_STMT_INCLUDE: |
| 4251 | case LY_STMT_IMPORT: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4252 | CHECK_ORDER(Y_MOD_LINKAGE); |
| 4253 | break; |
| 4254 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4255 | case LY_STMT_ORGANIZATION: |
| 4256 | case LY_STMT_CONTACT: |
| 4257 | case LY_STMT_DESCRIPTION: |
| 4258 | case LY_STMT_REFERENCE: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4259 | CHECK_ORDER(Y_MOD_META); |
| 4260 | break; |
| 4261 | |
| 4262 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4263 | case LY_STMT_REVISION: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4264 | CHECK_ORDER(Y_MOD_REVISION); |
| 4265 | break; |
| 4266 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4267 | case LY_STMT_ANYDATA: |
| 4268 | case LY_STMT_ANYXML: |
| 4269 | case LY_STMT_AUGMENT: |
| 4270 | case LY_STMT_CHOICE: |
| 4271 | case LY_STMT_CONTAINER: |
| 4272 | case LY_STMT_DEVIATION: |
| 4273 | case LY_STMT_EXTENSION: |
| 4274 | case LY_STMT_FEATURE: |
| 4275 | case LY_STMT_GROUPING: |
| 4276 | case LY_STMT_IDENTITY: |
| 4277 | case LY_STMT_LEAF: |
| 4278 | case LY_STMT_LEAF_LIST: |
| 4279 | case LY_STMT_LIST: |
| 4280 | case LY_STMT_NOTIFICATION: |
| 4281 | case LY_STMT_RPC: |
| 4282 | case LY_STMT_TYPEDEF: |
| 4283 | case LY_STMT_USES: |
| 4284 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4285 | mod_stmt = Y_MOD_BODY; |
| 4286 | break; |
| 4287 | default: |
| 4288 | /* error handled in the next switch */ |
| 4289 | break; |
| 4290 | } |
| 4291 | #undef CHECK_ORDER |
| 4292 | |
| 4293 | prev_kw = kw; |
| 4294 | switch (kw) { |
| 4295 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4296 | case LY_STMT_YANG_VERSION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4297 | LY_CHECK_RET(parse_yangversion(ctx, &submod->version, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4298 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4299 | case LY_STMT_BELONGS_TO: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4300 | LY_CHECK_RET(parse_belongsto(ctx, &submod->prefix, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4301 | break; |
| 4302 | |
| 4303 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4304 | case LY_STMT_INCLUDE: |
Radek Krejci | eeee95c | 2021-01-19 10:57:22 +0100 | [diff] [blame] | 4305 | if (submod->version == LYS_VERSION_1_1) { |
| 4306 | LOGWRN(PARSER_CTX(ctx), "YANG version 1.1 expects all includes in main module, includes in submodules (%s) are not necessary.", |
| 4307 | submod->name); |
| 4308 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4309 | LY_CHECK_RET(parse_include(ctx, submod->name, &submod->includes)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4310 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4311 | case LY_STMT_IMPORT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4312 | LY_CHECK_RET(parse_import(ctx, submod->prefix, &submod->imports)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4313 | break; |
| 4314 | |
| 4315 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4316 | case LY_STMT_ORGANIZATION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4317 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, &submod->org, Y_STR_ARG, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4318 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4319 | case LY_STMT_CONTACT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4320 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_CONTACT, 0, &submod->contact, Y_STR_ARG, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4321 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4322 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4323 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, &submod->dsc, Y_STR_ARG, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4324 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4325 | case LY_STMT_REFERENCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4326 | LY_CHECK_RET(parse_text_field(ctx, LYEXT_SUBSTMT_REFERENCE, 0, &submod->ref, Y_STR_ARG, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4327 | break; |
| 4328 | |
| 4329 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4330 | case LY_STMT_REVISION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4331 | LY_CHECK_RET(parse_revision(ctx, &submod->revs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4332 | break; |
| 4333 | |
| 4334 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4335 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 4336 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "submodule"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 4337 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4338 | case LY_STMT_ANYXML: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4339 | LY_CHECK_RET(parse_any(ctx, kw, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4340 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4341 | case LY_STMT_CHOICE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4342 | LY_CHECK_RET(parse_choice(ctx, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4343 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4344 | case LY_STMT_CONTAINER: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4345 | LY_CHECK_RET(parse_container(ctx, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4346 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4347 | case LY_STMT_LEAF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4348 | LY_CHECK_RET(parse_leaf(ctx, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4349 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4350 | case LY_STMT_LEAF_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4351 | LY_CHECK_RET(parse_leaflist(ctx, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4352 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4353 | case LY_STMT_LIST: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4354 | LY_CHECK_RET(parse_list(ctx, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4355 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4356 | case LY_STMT_USES: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4357 | LY_CHECK_RET(parse_uses(ctx, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4358 | break; |
| 4359 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4360 | case LY_STMT_AUGMENT: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4361 | LY_CHECK_RET(parse_augment(ctx, NULL, &submod->augments)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4362 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4363 | case LY_STMT_DEVIATION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4364 | LY_CHECK_RET(parse_deviation(ctx, &submod->deviations)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4365 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4366 | case LY_STMT_EXTENSION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4367 | LY_CHECK_RET(parse_extension(ctx, &submod->extensions)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4368 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4369 | case LY_STMT_FEATURE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4370 | LY_CHECK_RET(parse_feature(ctx, &submod->features)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4371 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4372 | case LY_STMT_GROUPING: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4373 | LY_CHECK_RET(parse_grouping(ctx, NULL, &submod->groupings)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4374 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4375 | case LY_STMT_IDENTITY: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4376 | LY_CHECK_RET(parse_identity(ctx, &submod->identities)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4377 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4378 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4379 | LY_CHECK_RET(parse_notif(ctx, NULL, &submod->notifs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4380 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4381 | case LY_STMT_RPC: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4382 | LY_CHECK_RET(parse_action(ctx, NULL, &submod->rpcs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4383 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4384 | case LY_STMT_TYPEDEF: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4385 | LY_CHECK_RET(parse_typedef(ctx, NULL, &submod->typedefs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4386 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4387 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4388 | LY_CHECK_RET(parse_ext(ctx, word, word_len, LYEXT_SUBSTMT_SELF, 0, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4389 | break; |
| 4390 | |
| 4391 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4392 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "submodule"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4393 | return LY_EVALID; |
| 4394 | } |
| 4395 | } |
| 4396 | LY_CHECK_RET(ret); |
| 4397 | |
| 4398 | checks: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4399 | /* mandatory substatements */ |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4400 | if (!submod->prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4401 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "belongs-to", "submodule"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4402 | return LY_EVALID; |
| 4403 | } |
| 4404 | |
| 4405 | /* submodules share the namespace with the module names, so there must not be |
| 4406 | * a submodule of the same name in the context, no need for revision matching */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4407 | dup = ly_ctx_get_submodule(PARSER_CTX(ctx), NULL, submod->name, NULL); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4408 | /* main modules may have different revisions */ |
| 4409 | if (dup && strcmp(dup->mod->name, submod->mod->name)) { |
Radek Krejci | 854e155 | 2020-12-21 15:05:23 +0100 | [diff] [blame] | 4410 | LOGVAL_PARSER(ctx, LY_VCODE_NAME_COL, "submodules", dup->name); |
Radek Krejci | e9e987e | 2018-10-31 12:50:27 +0100 | [diff] [blame] | 4411 | return LY_EVALID; |
| 4412 | } |
| 4413 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4414 | return ret; |
| 4415 | } |
| 4416 | |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4417 | /** |
| 4418 | * @brief Skip any redundant characters, namely whitespaces and comments. |
| 4419 | * |
| 4420 | * @param[in] ctx Yang parser context. |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4421 | * @return LY_SUCCESS on success. |
| 4422 | * @return LY_EVALID on invalid comment. |
| 4423 | */ |
| 4424 | static LY_ERR |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4425 | skip_redundant_chars(struct lys_yang_parser_ctx *ctx) |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4426 | { |
| 4427 | /* read some trailing spaces, new lines, or comments */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4428 | while (ctx->in->current[0]) { |
| 4429 | if (!strncmp(ctx->in->current, "//", 2)) { |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4430 | /* one-line comment */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4431 | ly_in_skip(ctx->in, 2); |
| 4432 | LY_CHECK_RET(skip_comment(ctx, 1)); |
| 4433 | } else if (!strncmp(ctx->in->current, "/*", 2)) { |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4434 | /* block comment */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4435 | ly_in_skip(ctx->in, 2); |
| 4436 | LY_CHECK_RET(skip_comment(ctx, 2)); |
| 4437 | } else if (isspace(ctx->in->current[0])) { |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4438 | /* whitespace */ |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 4439 | if (ctx->in->current[0] == '\n') { |
| 4440 | LY_IN_NEW_LINE(ctx->in); |
| 4441 | } |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4442 | ly_in_skip(ctx->in, 1); |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4443 | } else { |
| 4444 | break; |
| 4445 | } |
| 4446 | } |
| 4447 | |
| 4448 | return LY_SUCCESS; |
| 4449 | } |
| 4450 | |
Radek Krejci | d4557c6 | 2018-09-17 11:42:09 +0200 | [diff] [blame] | 4451 | LY_ERR |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4452 | yang_parse_submodule(struct lys_yang_parser_ctx **context, struct ly_ctx *ly_ctx, struct lys_parser_ctx *main_ctx, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 4453 | struct ly_in *in, struct lysp_submodule **submod) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4454 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 4455 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4456 | char *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 4457 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4458 | enum ly_stmt kw; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4459 | struct lysp_submodule *mod_p = NULL; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4460 | |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4461 | /* create context */ |
| 4462 | *context = calloc(1, sizeof **context); |
| 4463 | LY_CHECK_ERR_RET(!(*context), LOGMEM(ly_ctx), LY_EMEM); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4464 | (*context)->format = LYS_IN_YANG; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 4465 | (*context)->unres = main_ctx->unres; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4466 | (*context)->in = in; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4467 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4468 | mod_p = calloc(1, sizeof *mod_p); |
| 4469 | LY_CHECK_ERR_GOTO(!mod_p, LOGMEM(ly_ctx); ret = LY_EMEM, cleanup); |
| 4470 | mod_p->mod = main_ctx->parsed_mod->mod; |
| 4471 | mod_p->parsing = 1; |
| 4472 | (*context)->parsed_mod = (struct lysp_module *)mod_p; |
| 4473 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 4474 | LOG_LOCINIT(NULL, NULL, NULL, in); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 4475 | |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4476 | /* map the typedefs and groupings list from main context to the submodule's context */ |
| 4477 | memcpy(&(*context)->tpdfs_nodes, &main_ctx->tpdfs_nodes, sizeof main_ctx->tpdfs_nodes); |
| 4478 | memcpy(&(*context)->grps_nodes, &main_ctx->grps_nodes, sizeof main_ctx->grps_nodes); |
| 4479 | |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4480 | /* skip redundant but valid characters at the beginning */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4481 | ret = skip_redundant_chars(*context); |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4482 | LY_CHECK_GOTO(ret, cleanup); |
| 4483 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4484 | /* "module"/"submodule" */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4485 | ret = get_keyword(*context, &kw, &word, &word_len); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4486 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4487 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4488 | if (kw == LY_STMT_MODULE) { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4489 | LOGERR(ly_ctx, LY_EDENIED, "Input data contains module in situation when a submodule is expected."); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4490 | ret = LY_EINVAL; |
| 4491 | goto cleanup; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4492 | } else if (kw != LY_STMT_SUBMODULE) { |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 4493 | LOGVAL_PARSER(*context, LY_VCODE_MOD_SUBOMD, ly_stmt2str(kw)); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 4494 | ret = LY_EVALID; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4495 | goto cleanup; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4496 | } |
| 4497 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4498 | /* substatements */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4499 | ret = parse_submodule(*context, mod_p); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4500 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4501 | |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4502 | /* skip redundant but valid characters at the end */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4503 | ret = skip_redundant_chars(*context); |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4504 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4505 | if (in->current[0]) { |
| 4506 | LOGVAL_PARSER(*context, LY_VCODE_TRAILING_SUBMOD, 15, in->current, strlen(in->current) > 15 ? "..." : ""); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 4507 | ret = LY_EVALID; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4508 | goto cleanup; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4509 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4510 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4511 | mod_p->parsing = 0; |
| 4512 | *submod = mod_p; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4513 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4514 | cleanup: |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 4515 | LOG_LOCBACK(0, 0, 0, 1); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4516 | if (ret) { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4517 | lysp_module_free((struct lysp_module *)mod_p); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4518 | yang_parser_ctx_free(*context); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4519 | *context = NULL; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4520 | } |
| 4521 | |
| 4522 | return ret; |
| 4523 | } |
| 4524 | |
| 4525 | LY_ERR |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 4526 | yang_parse_module(struct lys_yang_parser_ctx **context, struct ly_in *in, struct lys_module *mod, struct lys_glob_unres *unres) |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4527 | { |
| 4528 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4529 | char *word; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4530 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4531 | enum ly_stmt kw; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4532 | struct lysp_module *mod_p = NULL; |
| 4533 | |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4534 | /* create context */ |
| 4535 | *context = calloc(1, sizeof **context); |
| 4536 | LY_CHECK_ERR_RET(!(*context), LOGMEM(mod->ctx), LY_EMEM); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4537 | (*context)->format = LYS_IN_YANG; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 4538 | (*context)->unres = unres; |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4539 | (*context)->in = in; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4540 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4541 | mod_p = calloc(1, sizeof *mod_p); |
| 4542 | LY_CHECK_ERR_GOTO(!mod_p, LOGMEM(mod->ctx), cleanup); |
| 4543 | mod_p->mod = mod; |
| 4544 | mod_p->parsing = 1; |
| 4545 | (*context)->parsed_mod = mod_p; |
| 4546 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 4547 | LOG_LOCINIT(NULL, NULL, NULL, in); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 4548 | |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4549 | /* skip redundant but valid characters at the beginning */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4550 | ret = skip_redundant_chars(*context); |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4551 | LY_CHECK_GOTO(ret, cleanup); |
| 4552 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4553 | /* "module"/"submodule" */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4554 | ret = get_keyword(*context, &kw, &word, &word_len); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4555 | LY_CHECK_GOTO(ret, cleanup); |
| 4556 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4557 | if (kw == LY_STMT_SUBMODULE) { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4558 | LOGERR(mod->ctx, LY_EDENIED, "Input data contains submodule which cannot be parsed directly without its main module."); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4559 | ret = LY_EINVAL; |
| 4560 | goto cleanup; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4561 | } else if (kw != LY_STMT_MODULE) { |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 4562 | LOGVAL_PARSER((*context), LY_VCODE_MOD_SUBOMD, ly_stmt2str(kw)); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 4563 | ret = LY_EVALID; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4564 | goto cleanup; |
| 4565 | } |
| 4566 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4567 | /* substatements */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4568 | ret = parse_module(*context, mod_p); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4569 | LY_CHECK_GOTO(ret, cleanup); |
| 4570 | |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4571 | /* skip redundant but valid characters at the end */ |
Radek Krejci | 33090f9 | 2020-12-17 20:12:46 +0100 | [diff] [blame] | 4572 | ret = skip_redundant_chars(*context); |
Michal Vasko | 69e6bbb | 2020-11-04 17:11:46 +0100 | [diff] [blame] | 4573 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4574 | if (in->current[0]) { |
| 4575 | LOGVAL_PARSER(*context, LY_VCODE_TRAILING_MOD, 15, in->current, strlen(in->current) > 15 ? "..." : ""); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 4576 | ret = LY_EVALID; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4577 | goto cleanup; |
| 4578 | } |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4579 | |
| 4580 | mod_p->parsing = 0; |
| 4581 | mod->parsed = mod_p; |
| 4582 | |
| 4583 | cleanup: |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 4584 | LOG_LOCBACK(0, 0, 0, 1); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4585 | if (ret) { |
| 4586 | lysp_module_free(mod_p); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4587 | yang_parser_ctx_free(*context); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4588 | *context = NULL; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4589 | } |
| 4590 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4591 | return ret; |
| 4592 | } |