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" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 27 | #include "log.h" |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 28 | #include "path.h" |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 29 | #include "parser_schema.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 30 | #include "set.h" |
| 31 | #include "tree.h" |
| 32 | #include "tree_schema.h" |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 33 | #include "tree_schema_internal.h" |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 34 | |
Radek Krejci | ceaf212 | 2019-01-02 15:03:26 +0100 | [diff] [blame] | 35 | /** |
| 36 | * @brief Insert WORD into the libyang context's dictionary and store as TARGET. |
| 37 | * @param[in] CTX yang parser context to access libyang context. |
| 38 | * @param[in] BUF buffer in case the word is not a constant and can be inserted directly (zero-copy) |
| 39 | * @param[out] TARGET variable where to store the pointer to the inserted value. |
| 40 | * @param[in] WORD string to store. |
| 41 | * @param[in] LEN length of the string in WORD to store. |
| 42 | */ |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 43 | #define INSERT_WORD(CTX, BUF, TARGET, WORD, LEN) \ |
| 44 | if (BUF) {(TARGET) = lydict_insert_zc((CTX)->ctx, WORD);}\ |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 45 | else {(TARGET) = lydict_insert((CTX)->ctx, LEN ? WORD : "", LEN);} |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 46 | |
Radek Krejci | ceaf212 | 2019-01-02 15:03:26 +0100 | [diff] [blame] | 47 | /** |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 48 | * @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] | 49 | * @param[in] CTX yang parser context to update its indent value. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 50 | * @param[in,out] IN input structure |
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 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 53 | #define MOVE_INPUT(CTX, IN, COUNT) ly_in_skip(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 | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 59 | * @param[in] IN Input structure to read from. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 60 | * @param[out] KW YANG keyword read. |
| 61 | * @param[out] WORD Pointer to the keyword itself. |
| 62 | * @param[out] WORD_LEN Length of the keyword. |
| 63 | * @param[out] ERR Variable for error storing. |
| 64 | * |
| 65 | * @return In case there are no substatements or a fatal error encountered. |
| 66 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 67 | #define YANG_READ_SUBSTMT_FOR(CTX, IN, KW, WORD, WORD_LEN, ERR, CHECKGOTO) \ |
| 68 | LY_CHECK_RET(get_keyword(CTX, IN, &KW, &WORD, &WORD_LEN)); \ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 69 | if (KW == LY_STMT_SYNTAX_SEMICOLON) { \ |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 70 | CHECKGOTO; \ |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 71 | return LY_SUCCESS; \ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 72 | } \ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 73 | if (KW != LY_STMT_SYNTAX_LEFT_BRACE) { \ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 74 | 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] | 75 | return LY_EVALID; \ |
| 76 | } \ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 77 | for (ERR = get_keyword(CTX, IN, &KW, &WORD, &WORD_LEN); \ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 78 | !ERR && (KW != LY_STMT_SYNTAX_RIGHT_BRACE); \ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 79 | ERR = get_keyword(CTX, IN, &KW, &WORD, &WORD_LEN)) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 80 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 81 | LY_ERR parse_container(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 82 | struct lysp_node **siblings); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 83 | LY_ERR parse_uses(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings); |
| 84 | LY_ERR parse_choice(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings); |
| 85 | LY_ERR parse_case(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings); |
| 86 | LY_ERR parse_list(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings); |
| 87 | LY_ERR parse_grouping(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_grp **groupings); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 88 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 89 | /** |
| 90 | * @brief Add another character to dynamic buffer, a low-level function. |
| 91 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 92 | * Enlarge if needed. Updates \p input as well as \p buf_used. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 93 | * |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 94 | * @param[in] ctx libyang context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 95 | * @param[in,out] in Input structure. |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 96 | * @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] | 97 | * @param[in,out] buf Buffer to use, can be moved by realloc(). |
| 98 | * @param[in,out] buf_len Current size of the buffer. |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 99 | * @param[in,out] buf_used Currently used characters of the buffer. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 100 | * |
| 101 | * @return LY_ERR values. |
| 102 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 103 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 104 | 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] | 105 | { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 106 | if (*buf_len <= (*buf_used) + len) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 107 | *buf_len += 16; |
| 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; |
| 119 | } |
| 120 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 121 | /** |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 122 | * @brief Store a single UTF8 character. It depends whether in a dynamically-allocated buffer or just as a pointer to the data. |
| 123 | * |
| 124 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 125 | * @param[in,out] in Input structure. |
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 |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 141 | buf_store_char(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum yang_arg arg, char **word_p, size_t *word_len, |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 142 | char **word_b, size_t *buf_len, uint8_t 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) */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 151 | LY_CHECK_ERR_RET(ly_getutf8(&in->current, &c, &len), |
| 152 | LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, in->current[-len]), LY_EVALID); |
| 153 | in->current -= len; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 154 | if (c == '\n') { |
| 155 | ctx->indent = 0; |
| 156 | } else { |
| 157 | /* note - even the multibyte character is count as 1 */ |
| 158 | ++ctx->indent; |
| 159 | } |
| 160 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 161 | /* check character validity */ |
| 162 | switch (arg) { |
| 163 | case Y_IDENTIF_ARG: |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 164 | 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] | 165 | break; |
| 166 | case Y_PREF_IDENTIF_ARG: |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 167 | 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] | 168 | break; |
| 169 | case Y_STR_ARG: |
| 170 | case Y_MAYBE_STR_ARG: |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 171 | LY_CHECK_RET(lysp_check_stringchar((struct lys_parser_ctx *)ctx, c)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 172 | break; |
| 173 | } |
| 174 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 175 | if (word_b && *word_b) { |
| 176 | /* add another character into buffer */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 177 | if (buf_add_char(ctx->ctx, in, len, word_b, buf_len, word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 178 | return LY_EMEM; |
| 179 | } |
| 180 | |
| 181 | /* in case of realloc */ |
| 182 | *word_p = *word_b; |
Radek Krejci | f29b7c3 | 2019-04-09 16:17:49 +0200 | [diff] [blame] | 183 | } else if (word_b && need_buf) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 184 | /* first time we need a buffer, copy everything read up to now */ |
| 185 | if (*word_len) { |
| 186 | *word_b = malloc(*word_len); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 187 | LY_CHECK_ERR_RET(!*word_b, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 188 | *buf_len = *word_len; |
| 189 | memcpy(*word_b, *word_p, *word_len); |
| 190 | } |
| 191 | |
| 192 | /* add this new character into buffer */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 193 | if (buf_add_char(ctx->ctx, in, len, word_b, buf_len, word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 194 | return LY_EMEM; |
| 195 | } |
| 196 | |
| 197 | /* in case of realloc */ |
| 198 | *word_p = *word_b; |
| 199 | } else { |
| 200 | /* just remember the first character pointer */ |
| 201 | if (!*word_p) { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 202 | *word_p = (char *)in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 203 | } |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 204 | /* ... and update the word's length */ |
| 205 | (*word_len) += len; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 206 | ly_in_skip(in, len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | return LY_SUCCESS; |
| 210 | } |
| 211 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 212 | /** |
| 213 | * @brief Skip YANG comment in data. |
| 214 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 215 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 216 | * @param[in,out] in Input structure. |
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 | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 223 | skip_comment(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint8_t comment) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 224 | { |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 225 | /* internal statuses: 0 - comment ended, |
| 226 | * 1 - in line comment, |
| 227 | * 2 - in block comment, |
| 228 | * 3 - in block comment with last read character '*' |
| 229 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 230 | while (in->current[0] && comment) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 231 | switch (comment) { |
| 232 | case 1: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 233 | if (in->current[0] == '\n') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 234 | comment = 0; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 235 | ++ctx->line; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 236 | } |
| 237 | break; |
| 238 | case 2: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 239 | if (in->current[0] == '*') { |
Radek Krejci | 15c80ca | 2018-10-09 11:01:31 +0200 | [diff] [blame] | 240 | comment = 3; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 241 | } else if (in->current[0] == '\n') { |
Radek Krejci | 15c80ca | 2018-10-09 11:01:31 +0200 | [diff] [blame] | 242 | ++ctx->line; |
| 243 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 244 | break; |
| 245 | case 3: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 246 | if (in->current[0] == '/') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 247 | comment = 0; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 248 | } else if (in->current[0] != '*') { |
| 249 | if (in->current[0] == '\n') { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 250 | ++ctx->line; |
| 251 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 252 | comment = 2; |
| 253 | } |
| 254 | break; |
| 255 | default: |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 256 | LOGINT_RET(ctx->ctx); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 259 | if (in->current[0] == '\n') { |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 260 | ctx->indent = 0; |
| 261 | } else { |
| 262 | ++ctx->indent; |
| 263 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 264 | ++in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 265 | } |
| 266 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 267 | if (!in->current[0] && (comment > 1)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 268 | LOGVAL_PARSER(ctx, LYVE_SYNTAX, "Unexpected end-of-input, non-terminated comment."); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 269 | return LY_EVALID; |
| 270 | } |
| 271 | |
| 272 | return LY_SUCCESS; |
| 273 | } |
| 274 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 275 | /** |
| 276 | * @brief Read a quoted string from data. |
| 277 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 278 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 279 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 280 | * @param[in] arg Type of YANG keyword argument expected. |
| 281 | * @param[out] word_p Pointer to the read quoted string. |
| 282 | * @param[out] word_b Pointer to a dynamically-allocated buffer holding the read quoted string. If not needed, |
| 283 | * set to NULL. Otherwise equal to \p word_p. |
| 284 | * @param[out] word_len Length of the read quoted string. |
| 285 | * @param[out] buf_len Length of the dynamically-allocated buffer \p word_b. |
| 286 | * @param[in] indent Current indent (number of YANG spaces). Needed for correct multi-line string |
| 287 | * indenation in the final quoted string. |
| 288 | * |
| 289 | * @return LY_ERR values. |
| 290 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 291 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 292 | read_qstring(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum yang_arg arg, char **word_p, char **word_b, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 293 | size_t *word_len, size_t *buf_len) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 294 | { |
| 295 | /* string: 0 - string ended, 1 - string with ', 2 - string with ", 3 - string with " with last character \, |
| 296 | * 4 - string finished, now skipping whitespaces looking for +, |
| 297 | * 5 - string continues after +, skipping whitespaces */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 298 | uint8_t string; |
| 299 | uint64_t block_indent = 0, current_indent = 0; |
| 300 | uint8_t need_buf = 0, prefix = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 301 | const char *c; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 302 | uint64_t trailing_ws = 0; /* current number of stored trailing whitespace characters */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 303 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 304 | if (in->current[0] == '\"') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 305 | string = 2; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 306 | current_indent = block_indent = ctx->indent + 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 307 | } else { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 308 | assert(in->current[0] == '\''); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 309 | string = 1; |
| 310 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 311 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 312 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 313 | while (in->current[0] && string) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 314 | switch (string) { |
| 315 | case 1: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 316 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 317 | case '\'': |
| 318 | /* string may be finished, but check for + */ |
| 319 | string = 4; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 320 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 321 | break; |
| 322 | default: |
| 323 | /* check and store character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 324 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 325 | break; |
| 326 | } |
| 327 | break; |
| 328 | case 2: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 329 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 330 | case '\"': |
| 331 | /* string may be finished, but check for + */ |
| 332 | string = 4; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 333 | MOVE_INPUT(ctx, in, 1); |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 334 | trailing_ws = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 335 | break; |
| 336 | case '\\': |
| 337 | /* special character following */ |
| 338 | string = 3; |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 339 | |
| 340 | /* the backslash sequence is substituted, so we will need a buffer to store the result */ |
| 341 | need_buf = 1; |
| 342 | |
| 343 | /* move forward to the escaped character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 344 | ++in->current; |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 345 | |
| 346 | /* note that the trailing whitespaces are supposed to be trimmed before substitution of |
| 347 | * backslash-escaped characters (RFC 7950, 6.1.3), so we have to zero the trailing whitespaces counter */ |
| 348 | trailing_ws = 0; |
| 349 | |
| 350 | /* since the backslash-escaped character is handled as first non-whitespace character, stop eating indentation */ |
| 351 | current_indent = block_indent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 352 | break; |
| 353 | case ' ': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 354 | if (current_indent < block_indent) { |
| 355 | ++current_indent; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 356 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 357 | } else { |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 358 | /* check and store whitespace character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 359 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 360 | trailing_ws++; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 361 | } |
| 362 | break; |
| 363 | case '\t': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 364 | if (current_indent < block_indent) { |
| 365 | assert(need_buf); |
| 366 | current_indent += 8; |
| 367 | ctx->indent += 8; |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 368 | for ( ; current_indent > block_indent; --current_indent, --ctx->indent) { |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 369 | /* store leftover spaces from the tab */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 370 | c = in->current; |
| 371 | in->current = " "; |
| 372 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
| 373 | in->current = c; |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 374 | trailing_ws++; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 375 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 376 | ++in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 377 | } else { |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 378 | /* check and store whitespace character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 379 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 380 | trailing_ws++; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 381 | /* additional characters for indentation - only 1 was count in buf_store_char */ |
| 382 | ctx->indent += 7; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 383 | } |
| 384 | break; |
| 385 | case '\n': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 386 | if (block_indent) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 387 | /* we will be removing the indents so we need our own buffer */ |
| 388 | need_buf = 1; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 389 | |
| 390 | /* remove trailing tabs and spaces */ |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 391 | (*word_len) = *word_len - trailing_ws; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 392 | |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 393 | /* restart indentation */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 394 | current_indent = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* check and store character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 398 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 399 | |
| 400 | /* maintain line number */ |
| 401 | ++ctx->line; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 402 | |
| 403 | /* reset context indentation counter for possible string after this one */ |
| 404 | ctx->indent = 0; |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 405 | trailing_ws = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 406 | break; |
| 407 | default: |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 408 | /* first non-whitespace character, stop eating indentation */ |
| 409 | current_indent = block_indent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 410 | |
| 411 | /* check and store character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 412 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
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 | } |
| 416 | break; |
| 417 | case 3: |
| 418 | /* string encoded characters */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 419 | c = in->current; |
| 420 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 421 | case 'n': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 422 | in->current = "\n"; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 423 | break; |
| 424 | case 't': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 425 | in->current = "\t"; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 426 | break; |
| 427 | case '\"': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 428 | case '\\': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 429 | /* ok as is */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 430 | break; |
| 431 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 432 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Double-quoted string unknown special character '\\%c'.", |
| 433 | in->current[0]); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 434 | return LY_EVALID; |
| 435 | } |
| 436 | |
| 437 | /* check and store character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 438 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 439 | |
| 440 | string = 2; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 441 | in->current = c + 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 442 | break; |
| 443 | case 4: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 444 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 445 | case '+': |
| 446 | /* string continues */ |
| 447 | string = 5; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 448 | need_buf = 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 449 | break; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 450 | case '\n': |
| 451 | ++ctx->line; |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 452 | /* fallthrough */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 453 | case ' ': |
| 454 | case '\t': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 455 | /* just skip */ |
| 456 | break; |
| 457 | default: |
| 458 | /* string is finished */ |
| 459 | goto string_end; |
| 460 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 461 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 462 | break; |
| 463 | case 5: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 464 | switch (in->current[0]) { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 465 | case '\n': |
| 466 | ++ctx->line; |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 467 | /* fallthrough */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 468 | case ' ': |
| 469 | case '\t': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 470 | /* skip */ |
| 471 | break; |
| 472 | case '\'': |
| 473 | string = 1; |
| 474 | break; |
| 475 | case '\"': |
| 476 | string = 2; |
| 477 | break; |
| 478 | default: |
| 479 | /* it must be quoted again */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 480 | 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] | 481 | return LY_EVALID; |
| 482 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 483 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 484 | break; |
| 485 | default: |
| 486 | return LY_EINT; |
| 487 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | string_end: |
Radek Krejci | 4e199f5 | 2019-05-28 09:09:28 +0200 | [diff] [blame] | 491 | if (arg <= Y_PREF_IDENTIF_ARG && !(*word_len)) { |
| 492 | /* empty identifier */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 493 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Statement argument is required."); |
Radek Krejci | 4e199f5 | 2019-05-28 09:09:28 +0200 | [diff] [blame] | 494 | return LY_EVALID; |
| 495 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 496 | return LY_SUCCESS; |
| 497 | } |
| 498 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 499 | /** |
| 500 | * @brief Get another YANG string from the raw data. |
| 501 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 502 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 503 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 504 | * @param[in] arg Type of YANG keyword argument expected. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 505 | * @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] | 506 | * @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] | 507 | * @param[out] word_b Pointer to a dynamically-allocated buffer holding the read string. If not needed, |
| 508 | * set to NULL. Otherwise equal to \p word_p. |
| 509 | * @param[out] word_len Length of the read string. |
| 510 | * |
| 511 | * @return LY_ERR values. |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 512 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 513 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 514 | get_argument(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum yang_arg arg, uint16_t *flags, char **word_p, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 515 | char **word_b, size_t *word_len) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 516 | { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 517 | size_t buf_len = 0; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 518 | uint8_t prefix = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 519 | /* word buffer - dynamically allocated */ |
| 520 | *word_b = NULL; |
| 521 | |
| 522 | /* word pointer - just a pointer to data */ |
| 523 | *word_p = NULL; |
| 524 | |
| 525 | *word_len = 0; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 526 | while (in->current[0]) { |
| 527 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 528 | case '\'': |
| 529 | case '\"': |
| 530 | if (*word_len) { |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 531 | /* invalid - quotes cannot be in unquoted string and only optsep, ; or { can follow it */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 532 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, 1, in->current, |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 533 | "unquoted string character, optsep, semicolon or opening brace"); |
| 534 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 535 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 536 | if (flags) { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 537 | (*flags) |= in->current[0] == '\'' ? LYS_SINGLEQUOTED : LYS_DOUBLEQUOTED; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 538 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 539 | LY_CHECK_RET(read_qstring(ctx, in, arg, word_p, word_b, word_len, &buf_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 540 | goto str_end; |
| 541 | case '/': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 542 | if (in->current[1] == '/') { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 543 | /* one-line comment */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 544 | MOVE_INPUT(ctx, in, 2); |
| 545 | LY_CHECK_RET(skip_comment(ctx, in, 1)); |
| 546 | } else if (in->current[1] == '*') { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 547 | /* block comment */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 548 | MOVE_INPUT(ctx, in, 2); |
| 549 | LY_CHECK_RET(skip_comment(ctx, in, 2)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 550 | } else { |
| 551 | /* not a comment after all */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 552 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, &buf_len, 0, &prefix)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 553 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 554 | break; |
| 555 | case ' ': |
| 556 | if (*word_len) { |
| 557 | /* word is finished */ |
| 558 | goto str_end; |
| 559 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 560 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 561 | break; |
| 562 | case '\t': |
| 563 | if (*word_len) { |
| 564 | /* word is finished */ |
| 565 | goto str_end; |
| 566 | } |
| 567 | /* tabs count for 8 spaces */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 568 | ctx->indent += 8; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 569 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 570 | ++in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 571 | break; |
| 572 | case '\n': |
| 573 | if (*word_len) { |
| 574 | /* word is finished */ |
| 575 | goto str_end; |
| 576 | } |
| 577 | /* reset indent */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 578 | ctx->indent = 0; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 579 | |
| 580 | /* track line numbers */ |
| 581 | ++ctx->line; |
| 582 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 583 | ++in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 584 | break; |
| 585 | case ';': |
| 586 | case '{': |
| 587 | if (*word_len || (arg == Y_MAYBE_STR_ARG)) { |
| 588 | /* word is finished */ |
| 589 | goto str_end; |
| 590 | } |
| 591 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 592 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, 1, in->current, "an argument"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 593 | return LY_EVALID; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 594 | case '}': |
| 595 | /* invalid - braces cannot be in unquoted string (opening braces terminates the string and can follow it) */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 596 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, 1, in->current, |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 597 | "unquoted string character, optsep, semicolon or opening brace"); |
| 598 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 599 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 600 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, &buf_len, 0, &prefix)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 601 | break; |
| 602 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 603 | } |
| 604 | |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 605 | /* unexpected end of loop */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 606 | LOGVAL_PARSER(ctx, LY_VCODE_EOF); |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 607 | return LY_EVALID; |
| 608 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 609 | str_end: |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 610 | /* terminating NULL byte for buf */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 611 | if (*word_b) { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 612 | (*word_b) = ly_realloc(*word_b, (*word_len) + 1); |
| 613 | LY_CHECK_ERR_RET(!(*word_b), LOGMEM(ctx->ctx), LY_EMEM); |
| 614 | (*word_b)[*word_len] = '\0'; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 615 | *word_p = *word_b; |
| 616 | } |
| 617 | |
| 618 | return LY_SUCCESS; |
| 619 | } |
| 620 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 621 | /** |
| 622 | * @brief Get another YANG keyword from the raw data. |
| 623 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 624 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 625 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 626 | * @param[out] kw YANG keyword read. |
| 627 | * @param[out] word_p Pointer to the keyword in the data. Useful for extension instances. |
| 628 | * @param[out] word_len Length of the keyword in the data. Useful for extension instances. |
| 629 | * |
| 630 | * @return LY_ERR values. |
| 631 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 632 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 633 | get_keyword(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt *kw, char **word_p, size_t *word_len) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 634 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 635 | uint8_t prefix; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 636 | const char *word_start; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 637 | size_t len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 638 | |
| 639 | if (word_p) { |
| 640 | *word_p = NULL; |
| 641 | *word_len = 0; |
| 642 | } |
| 643 | |
| 644 | /* first skip "optsep", comments */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 645 | while (in->current[0]) { |
| 646 | switch (in->current[0]) { |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 647 | case '/': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 648 | if (in->current[1] == '/') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 649 | /* one-line comment */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 650 | MOVE_INPUT(ctx, in, 2); |
| 651 | LY_CHECK_RET(skip_comment(ctx, in, 1)); |
| 652 | } else if (in->current[1] == '*') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 653 | /* block comment */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 654 | MOVE_INPUT(ctx, in, 2); |
| 655 | LY_CHECK_RET(skip_comment(ctx, in, 2)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 656 | } else { |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 657 | /* error - not a comment after all, keyword cannot start with slash */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 658 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Invalid identifier first character '/'."); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 659 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 660 | } |
Radek Krejci | 1302828 | 2019-06-11 14:56:48 +0200 | [diff] [blame] | 661 | continue; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 662 | case '\n': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 663 | /* skip whitespaces (optsep) */ |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 664 | ++ctx->line; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 665 | ctx->indent = 0; |
| 666 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 667 | case ' ': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 668 | /* skip whitespaces (optsep) */ |
| 669 | ++ctx->indent; |
| 670 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 671 | case '\t': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 672 | /* skip whitespaces (optsep) */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 673 | ctx->indent += 8; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 674 | break; |
| 675 | default: |
| 676 | /* either a keyword start or an invalid character */ |
| 677 | goto keyword_start; |
| 678 | } |
| 679 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 680 | ly_in_skip(in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | keyword_start: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 684 | word_start = in->current; |
| 685 | *kw = lysp_match_kw(ctx, in); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 686 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 687 | 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] | 688 | goto success; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 689 | } |
| 690 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 691 | if (*kw != LY_STMT_NONE) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 692 | /* make sure we have the whole keyword */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 693 | switch (in->current[0]) { |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 694 | case '\n': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 695 | case '\t': |
Radek Krejci | abdd806 | 2019-06-11 16:44:19 +0200 | [diff] [blame] | 696 | case ' ': |
| 697 | /* 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] | 698 | break; |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 699 | case ':': |
| 700 | /* keyword is not actually a keyword, but prefix of an extension. |
| 701 | * To avoid repeated check of the prefix syntax, move to the point where the colon was read |
| 702 | * and we will be checking the keyword (extension instance) itself */ |
| 703 | prefix = 1; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 704 | MOVE_INPUT(ctx, in, 1); |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 705 | goto extension; |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 706 | case '{': |
| 707 | /* allowed only for input and output statements which can be without arguments */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 708 | if (*kw == LY_STMT_INPUT || *kw == LY_STMT_OUTPUT) { |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 709 | break; |
| 710 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 711 | /* fallthrough */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 712 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 713 | MOVE_INPUT(ctx, in, 1); |
| 714 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, (int)(in->current - word_start), word_start, |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 715 | "a keyword followed by a separator"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 716 | return LY_EVALID; |
| 717 | } |
| 718 | } else { |
| 719 | /* still can be an extension */ |
| 720 | prefix = 0; |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 721 | extension: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 722 | while (in->current[0] && (in->current[0] != ' ') && (in->current[0] != '\t') && (in->current[0] != '\n') |
| 723 | && (in->current[0] != '{') && (in->current[0] != ';')) { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 724 | uint32_t c = 0; |
| 725 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 726 | LY_CHECK_ERR_RET(ly_getutf8(&in->current, &c, &len), |
| 727 | LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, in->current[-len]), LY_EVALID); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 728 | ++ctx->indent; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 729 | /* check character validity */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 730 | LY_CHECK_RET(lysp_check_identifierchar((struct lys_parser_ctx *)ctx, c, |
| 731 | in->current - len == word_start ? 1 : 0, &prefix)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 732 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 733 | if (!in->current[0]) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 734 | LOGVAL_PARSER(ctx, LY_VCODE_EOF); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 735 | return LY_EVALID; |
| 736 | } |
| 737 | |
| 738 | /* prefix is mandatory for extension instances */ |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 739 | if (prefix != 2) { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 740 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, (int)(in->current - word_start), word_start, "a keyword"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 741 | return LY_EVALID; |
| 742 | } |
| 743 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 744 | *kw = LY_STMT_EXTENSION_INSTANCE; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 745 | } |
Radek Krejci | 626df48 | 2018-10-11 15:06:31 +0200 | [diff] [blame] | 746 | success: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 747 | if (word_p) { |
| 748 | *word_p = (char *)word_start; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 749 | *word_len = in->current - word_start; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | return LY_SUCCESS; |
| 753 | } |
| 754 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 755 | /** |
| 756 | * @brief Parse extension instance substatements. |
| 757 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 758 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 759 | * @param[in,out] in Input structure. |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 760 | * @param[in] kw Statement keyword value matching @p word value. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 761 | * @param[in] word Extension instance substatement name (keyword). |
| 762 | * @param[in] word_len Extension instance substatement name length. |
| 763 | * @param[in,out] child Children of this extension instance to add to. |
| 764 | * |
| 765 | * @return LY_ERR values. |
| 766 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 767 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 768 | parse_ext_substmt(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt kw, char *word, size_t word_len, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 769 | struct lysp_stmt **child) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 770 | { |
| 771 | char *buf; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 772 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 773 | enum ly_stmt child_kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 774 | struct lysp_stmt *stmt, *par_child; |
| 775 | |
| 776 | stmt = calloc(1, sizeof *stmt); |
| 777 | LY_CHECK_ERR_RET(!stmt, LOGMEM(NULL), LY_EMEM); |
| 778 | |
Radek Krejci | bb9b198 | 2019-04-08 14:24:59 +0200 | [diff] [blame] | 779 | /* insert into parent statements */ |
| 780 | if (!*child) { |
| 781 | *child = stmt; |
| 782 | } else { |
Radek Krejci | 1e008d2 | 2020-08-17 11:37:37 +0200 | [diff] [blame] | 783 | for (par_child = *child; par_child->next; par_child = par_child->next) {} |
Radek Krejci | bb9b198 | 2019-04-08 14:24:59 +0200 | [diff] [blame] | 784 | par_child->next = stmt; |
| 785 | } |
| 786 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 787 | stmt->stmt = lydict_insert(ctx->ctx, word, word_len); |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 788 | stmt->kw = kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 789 | |
| 790 | /* get optional argument */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 791 | LY_CHECK_RET(get_argument(ctx, in, Y_MAYBE_STR_ARG, &stmt->flags, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 792 | |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 793 | if (word) { |
| 794 | if (buf) { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 795 | stmt->arg = lydict_insert_zc(ctx->ctx, word); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 796 | } else { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 797 | stmt->arg = lydict_insert(ctx->ctx, word, word_len); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 798 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 799 | } |
| 800 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 801 | YANG_READ_SUBSTMT_FOR(ctx, in, child_kw, word, word_len, ret, ) { |
| 802 | LY_CHECK_RET(parse_ext_substmt(ctx, in, child_kw, word, word_len, &stmt->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 803 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 804 | return ret; |
| 805 | } |
| 806 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 807 | /** |
| 808 | * @brief Parse extension instance. |
| 809 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 810 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 811 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 812 | * @param[in] ext_name Extension instance substatement name (keyword). |
| 813 | * @param[in] ext_name_len Extension instance substatement name length. |
| 814 | * @param[in] insubstmt Type of the keyword this extension instance is a substatement of. |
| 815 | * @param[in] insubstmt_index Index of the keyword instance this extension instance is a substatement of. |
| 816 | * @param[in,out] exts Extension instances to add to. |
| 817 | * |
| 818 | * @return LY_ERR values. |
| 819 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 820 | static LY_ERR |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 821 | parse_ext(struct lys_yang_parser_ctx *ctx, struct ly_in *in, const char *ext_name, size_t ext_name_len, LYEXT_SUBSTMT insubstmt, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 822 | LY_ARRAY_COUNT_TYPE insubstmt_index, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 823 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 824 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 825 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 826 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 827 | struct lysp_ext_instance *e; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 828 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 829 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 830 | LY_ARRAY_NEW_RET(ctx->ctx, *exts, e, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 831 | |
| 832 | /* store name and insubstmt info */ |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 833 | e->name = lydict_insert(ctx->ctx, ext_name, ext_name_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 834 | e->insubstmt = insubstmt; |
| 835 | e->insubstmt_index = insubstmt_index; |
| 836 | |
| 837 | /* get optional argument */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 838 | LY_CHECK_RET(get_argument(ctx, in, Y_MAYBE_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 839 | |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 840 | if (word) { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 841 | INSERT_WORD(ctx, buf, e->argument, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 842 | } |
| 843 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 844 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 845 | LY_CHECK_RET(parse_ext_substmt(ctx, in, kw, word, word_len, &e->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 846 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 847 | return ret; |
| 848 | } |
| 849 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 850 | /** |
| 851 | * @brief Parse a generic text field without specific constraints. Those are contact, organization, |
| 852 | * description, etc... |
| 853 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 854 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 855 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 856 | * @param[in] substmt Type of this substatement. |
| 857 | * @param[in] substmt_index Index of this substatement. |
| 858 | * @param[in,out] value Place to store the parsed value. |
| 859 | * @param[in] arg Type of the YANG keyword argument (of the value). |
| 860 | * @param[in,out] exts Extension instances to add to. |
| 861 | * |
| 862 | * @return LY_ERR values. |
| 863 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 864 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 865 | parse_text_field(struct lys_yang_parser_ctx *ctx, struct ly_in *in, LYEXT_SUBSTMT substmt, uint32_t substmt_index, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 866 | const char **value, enum yang_arg arg, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 867 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 868 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 869 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 870 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 871 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 872 | |
| 873 | if (*value) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 874 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, lyext_substmt2str(substmt)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 875 | return LY_EVALID; |
| 876 | } |
| 877 | |
| 878 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 879 | LY_CHECK_RET(get_argument(ctx, in, arg, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 880 | |
| 881 | /* store value and spend buf if allocated */ |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 882 | INSERT_WORD(ctx, buf, *value, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 883 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 884 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 885 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 886 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 887 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, substmt, substmt_index, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 888 | break; |
| 889 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 890 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 891 | return LY_EVALID; |
| 892 | } |
| 893 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 894 | return ret; |
| 895 | } |
| 896 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 897 | /** |
| 898 | * @brief Parse the yang-version statement. |
| 899 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 900 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 901 | * @param[in,out] in Input structure. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 902 | * @param[out] version Storage for the parsed information. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 903 | * @param[in,out] exts Extension instances to add to. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 904 | * |
| 905 | * @return LY_ERR values. |
| 906 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 907 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 908 | parse_yangversion(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint8_t *version, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 909 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 910 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 911 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 912 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 913 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 914 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 915 | if (*version) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 916 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "yang-version"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 917 | return LY_EVALID; |
| 918 | } |
| 919 | |
| 920 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 921 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 922 | |
| 923 | if ((word_len == 3) && !strncmp(word, "1.0", word_len)) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 924 | *version = LYS_VERSION_1_0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 925 | } else if ((word_len == 3) && !strncmp(word, "1.1", word_len)) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 926 | *version = LYS_VERSION_1_1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 927 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 928 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "yang-version"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 929 | free(buf); |
| 930 | return LY_EVALID; |
| 931 | } |
| 932 | free(buf); |
| 933 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 934 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 935 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 936 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 937 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_VERSION, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 938 | break; |
| 939 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 940 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "yang-version"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 941 | return LY_EVALID; |
| 942 | } |
| 943 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 944 | return ret; |
| 945 | } |
| 946 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 947 | /** |
| 948 | * @brief Parse the belongs-to statement. |
| 949 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 950 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 951 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 952 | * @param[in,out] belongsto Place to store the parsed value. |
| 953 | * @param[in,out] prefix Place to store the parsed belongs-to prefix value. |
| 954 | * @param[in,out] exts Extension instances to add to. |
| 955 | * |
| 956 | * @return LY_ERR values. |
| 957 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 958 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 959 | parse_belongsto(struct lys_yang_parser_ctx *ctx, struct ly_in *in, const char **belongsto, const char **prefix, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 960 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 961 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 962 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 963 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 964 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 965 | |
| 966 | if (*belongsto) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 967 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "belongs-to"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 968 | return LY_EVALID; |
| 969 | } |
| 970 | |
| 971 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 972 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 973 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 974 | INSERT_WORD(ctx, buf, *belongsto, word, word_len); |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 975 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 976 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 977 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 978 | case LY_STMT_PREFIX: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 979 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_PREFIX, 0, prefix, Y_IDENTIF_ARG, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 980 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 981 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 982 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_BELONGSTO, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 983 | break; |
| 984 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 985 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "belongs-to"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 986 | return LY_EVALID; |
| 987 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 988 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 989 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 990 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 991 | /* mandatory substatements */ |
| 992 | if (!*prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 993 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "prefix", "belongs-to"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 994 | return LY_EVALID; |
| 995 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 996 | return ret; |
| 997 | } |
| 998 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 999 | /** |
| 1000 | * @brief Parse the revision-date statement. |
| 1001 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1002 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1003 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1004 | * @param[in,out] rev Array to store the parsed value in. |
| 1005 | * @param[in,out] exts Extension instances to add to. |
| 1006 | * |
| 1007 | * @return LY_ERR values. |
| 1008 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1009 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1010 | parse_revisiondate(struct lys_yang_parser_ctx *ctx, struct ly_in *in, char *rev, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1011 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1012 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1013 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1014 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1015 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1016 | |
| 1017 | if (rev[0]) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1018 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "revision-date"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1019 | return LY_EVALID; |
| 1020 | } |
| 1021 | |
| 1022 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1023 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1024 | |
| 1025 | /* check value */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1026 | 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] | 1027 | free(buf); |
| 1028 | return LY_EVALID; |
| 1029 | } |
| 1030 | |
| 1031 | /* store value and spend buf if allocated */ |
| 1032 | strncpy(rev, word, word_len); |
| 1033 | free(buf); |
| 1034 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1035 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1036 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1037 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1038 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_REVISIONDATE, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1039 | break; |
| 1040 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1041 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "revision-date"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1042 | return LY_EVALID; |
| 1043 | } |
| 1044 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1045 | return ret; |
| 1046 | } |
| 1047 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1048 | /** |
| 1049 | * @brief Parse the include statement. |
| 1050 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1051 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1052 | * @param[in] module_name Name of the module to check name collisions. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1053 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1054 | * @param[in,out] includes Parsed includes to add to. |
| 1055 | * |
| 1056 | * @return LY_ERR values. |
| 1057 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1058 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1059 | parse_include(struct lys_yang_parser_ctx *ctx, const char *module_name, struct ly_in *in, struct lysp_include **includes) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1060 | { |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 1061 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1062 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1063 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1064 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1065 | struct lysp_include *inc; |
| 1066 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1067 | LY_ARRAY_NEW_RET(ctx->ctx, *includes, inc, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1068 | |
| 1069 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1070 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1071 | |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 1072 | INSERT_WORD(ctx, buf, inc->name, word, word_len); |
| 1073 | |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 1074 | /* submodules share the namespace with the module names, so there must not be |
| 1075 | * a module of the same name in the context, no need for revision matching */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1076 | if (!strcmp(module_name, inc->name) || ly_ctx_get_module_latest(ctx->ctx, inc->name)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1077 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Name collision between module and submodule of name \"%s\".", inc->name); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 1078 | return LY_EVALID; |
| 1079 | } |
| 1080 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1081 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1082 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1083 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1084 | PARSER_CHECK_STMTVER2_RET(ctx, "description", "include"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1085 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &inc->dsc, Y_STR_ARG, &inc->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1086 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1087 | case LY_STMT_REFERENCE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1088 | PARSER_CHECK_STMTVER2_RET(ctx, "reference", "include"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1089 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &inc->ref, Y_STR_ARG, &inc->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1090 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1091 | case LY_STMT_REVISION_DATE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1092 | LY_CHECK_RET(parse_revisiondate(ctx, in, inc->rev, &inc->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1093 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1094 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1095 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &inc->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1096 | break; |
| 1097 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1098 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "include"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1099 | return LY_EVALID; |
| 1100 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1101 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1102 | return ret; |
| 1103 | } |
| 1104 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1105 | /** |
| 1106 | * @brief Parse the import statement. |
| 1107 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1108 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1109 | * @param[in] module_prefix Prefix of the module to check prefix collisions. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1110 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1111 | * @param[in,out] imports Parsed imports to add to. |
| 1112 | * |
| 1113 | * @return LY_ERR values. |
| 1114 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1115 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1116 | parse_import(struct lys_yang_parser_ctx *ctx, const char *module_prefix, struct ly_in *in, struct lysp_import **imports) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1117 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1118 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1119 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1120 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1121 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1122 | struct lysp_import *imp; |
| 1123 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1124 | LY_ARRAY_NEW_RET(ctx->ctx, *imports, imp, LY_EVALID); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1125 | |
| 1126 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1127 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1128 | INSERT_WORD(ctx, buf, imp->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1129 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1130 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1131 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1132 | case LY_STMT_PREFIX: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1133 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_PREFIX, 0, &imp->prefix, Y_IDENTIF_ARG, &imp->exts)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1134 | 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] | 1135 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1136 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1137 | PARSER_CHECK_STMTVER2_RET(ctx, "description", "import"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1138 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &imp->dsc, Y_STR_ARG, &imp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1139 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1140 | case LY_STMT_REFERENCE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1141 | PARSER_CHECK_STMTVER2_RET(ctx, "reference", "import"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1142 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &imp->ref, Y_STR_ARG, &imp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1143 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1144 | case LY_STMT_REVISION_DATE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1145 | LY_CHECK_RET(parse_revisiondate(ctx, in, imp->rev, &imp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1146 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1147 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1148 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &imp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1149 | break; |
| 1150 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1151 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "import"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1152 | return LY_EVALID; |
| 1153 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1154 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 1155 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 1156 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1157 | /* mandatory substatements */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1158 | 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] | 1159 | |
| 1160 | return ret; |
| 1161 | } |
| 1162 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1163 | /** |
| 1164 | * @brief Parse the revision statement. |
| 1165 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1166 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1167 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1168 | * @param[in,out] revs Parsed revisions to add to. |
| 1169 | * |
| 1170 | * @return LY_ERR values. |
| 1171 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1172 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1173 | parse_revision(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_revision **revs) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1174 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1175 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1176 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1177 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1178 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1179 | struct lysp_revision *rev; |
| 1180 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1181 | LY_ARRAY_NEW_RET(ctx->ctx, *revs, rev, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1182 | |
| 1183 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1184 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1185 | |
| 1186 | /* check value */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1187 | 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] | 1188 | free(buf); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1189 | return LY_EVALID; |
| 1190 | } |
| 1191 | |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 1192 | strncpy(rev->date, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1193 | free(buf); |
| 1194 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1195 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1196 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1197 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1198 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &rev->dsc, Y_STR_ARG, &rev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1199 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1200 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1201 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &rev->ref, Y_STR_ARG, &rev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1202 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1203 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1204 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &rev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1205 | break; |
| 1206 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1207 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "revision"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1208 | return LY_EVALID; |
| 1209 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1210 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1211 | return ret; |
| 1212 | } |
| 1213 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1214 | /** |
| 1215 | * @brief Parse a generic text field that can have more instances such as base. |
| 1216 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1217 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1218 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1219 | * @param[in] substmt Type of this substatement. |
| 1220 | * @param[in,out] texts Parsed values to add to. |
| 1221 | * @param[in] arg Type of the expected argument. |
| 1222 | * @param[in,out] exts Extension instances to add to. |
| 1223 | * |
| 1224 | * @return LY_ERR values. |
| 1225 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1226 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1227 | parse_text_fields(struct lys_yang_parser_ctx *ctx, struct ly_in *in, LYEXT_SUBSTMT substmt, const char ***texts, enum yang_arg arg, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1228 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1229 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1230 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1231 | char *buf, *word; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 1232 | const char **item; |
| 1233 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1234 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1235 | |
| 1236 | /* allocate new pointer */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1237 | LY_ARRAY_NEW_RET(ctx->ctx, *texts, item, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1238 | |
| 1239 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1240 | LY_CHECK_RET(get_argument(ctx, in, arg, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1241 | |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 1242 | INSERT_WORD(ctx, buf, *item, word, word_len); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1243 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1244 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1245 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1246 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, substmt, LY_ARRAY_COUNT(*texts) - 1, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1247 | break; |
| 1248 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1249 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1250 | return LY_EVALID; |
| 1251 | } |
| 1252 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1253 | return ret; |
| 1254 | } |
| 1255 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1256 | /** |
| 1257 | * @brief Parse the config statement. |
| 1258 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1259 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1260 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1261 | * @param[in,out] flags Flags to add to. |
| 1262 | * @param[in,out] exts Extension instances to add to. |
| 1263 | * |
| 1264 | * @return LY_ERR values. |
| 1265 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1266 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1267 | parse_config(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1268 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1269 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1270 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1271 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1272 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1273 | |
| 1274 | if (*flags & LYS_CONFIG_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1275 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "config"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1276 | return LY_EVALID; |
| 1277 | } |
| 1278 | |
| 1279 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1280 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1281 | |
| 1282 | if ((word_len == 4) && !strncmp(word, "true", word_len)) { |
| 1283 | *flags |= LYS_CONFIG_W; |
| 1284 | } else if ((word_len == 5) && !strncmp(word, "false", word_len)) { |
| 1285 | *flags |= LYS_CONFIG_R; |
| 1286 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1287 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "config"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1288 | free(buf); |
| 1289 | return LY_EVALID; |
| 1290 | } |
| 1291 | free(buf); |
| 1292 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1293 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1294 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1295 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1296 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_CONFIG, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1297 | break; |
| 1298 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1299 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "config"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1300 | return LY_EVALID; |
| 1301 | } |
| 1302 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1303 | return ret; |
| 1304 | } |
| 1305 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1306 | /** |
| 1307 | * @brief Parse the mandatory 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 | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1310 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1311 | * @param[in,out] flags Flags to add to. |
| 1312 | * @param[in,out] exts Extension instances to add to. |
| 1313 | * |
| 1314 | * @return LY_ERR values. |
| 1315 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1316 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1317 | parse_mandatory(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1318 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1319 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1320 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1321 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1322 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1323 | |
| 1324 | if (*flags & LYS_MAND_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1325 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "mandatory"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1326 | return LY_EVALID; |
| 1327 | } |
| 1328 | |
| 1329 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1330 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1331 | |
| 1332 | if ((word_len == 4) && !strncmp(word, "true", word_len)) { |
| 1333 | *flags |= LYS_MAND_TRUE; |
| 1334 | } else if ((word_len == 5) && !strncmp(word, "false", word_len)) { |
| 1335 | *flags |= LYS_MAND_FALSE; |
| 1336 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1337 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "mandatory"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1338 | free(buf); |
| 1339 | return LY_EVALID; |
| 1340 | } |
| 1341 | free(buf); |
| 1342 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1343 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1344 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1345 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1346 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_MANDATORY, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1347 | break; |
| 1348 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1349 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "mandatory"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1350 | return LY_EVALID; |
| 1351 | } |
| 1352 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1353 | return ret; |
| 1354 | } |
| 1355 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1356 | /** |
| 1357 | * @brief Parse a restriction such as range or length. |
| 1358 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1359 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1360 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1361 | * @param[in] restr_kw Type of this particular restriction. |
| 1362 | * @param[in,out] exts Extension instances to add to. |
| 1363 | * |
| 1364 | * @return LY_ERR values. |
| 1365 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1366 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1367 | parse_restr(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt restr_kw, struct lysp_restr *restr) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1368 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1369 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1370 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1371 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1372 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1373 | |
| 1374 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1375 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1376 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1377 | CHECK_NONEMPTY(ctx, word_len, ly_stmt2str(restr_kw)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1378 | INSERT_WORD(ctx, buf, restr->arg, word, word_len); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1379 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1380 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1381 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1382 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &restr->dsc, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1383 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1384 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1385 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &restr->ref, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1386 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1387 | case LY_STMT_ERROR_APP_TAG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1388 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_ERRTAG, 0, &restr->eapptag, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1389 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1390 | case LY_STMT_ERROR_MESSAGE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1391 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_ERRMSG, 0, &restr->emsg, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1392 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1393 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1394 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &restr->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), ly_stmt2str(restr_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1398 | return LY_EVALID; |
| 1399 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 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 that can have more instances such as must. |
| 1406 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1407 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1408 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1409 | * @param[in] restr_kw Type of this particular restriction. |
| 1410 | * @param[in,out] restrs Restrictions to add to. |
| 1411 | * |
| 1412 | * @return LY_ERR values. |
| 1413 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1414 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1415 | parse_restrs(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt restr_kw, struct lysp_restr **restrs) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1416 | { |
| 1417 | struct lysp_restr *restr; |
| 1418 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1419 | LY_ARRAY_NEW_RET(ctx->ctx, *restrs, restr, LY_EMEM); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1420 | return parse_restr(ctx, in, restr_kw, restr); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1421 | } |
| 1422 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1423 | /** |
| 1424 | * @brief Parse the status statement. |
| 1425 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1426 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1427 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1428 | * @param[in,out] flags Flags to add to. |
| 1429 | * @param[in,out] exts Extension instances to add to. |
| 1430 | * |
| 1431 | * @return LY_ERR values. |
| 1432 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1433 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1434 | parse_status(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1435 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1436 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1437 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1438 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1439 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1440 | |
| 1441 | if (*flags & LYS_STATUS_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1442 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "status"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1443 | return LY_EVALID; |
| 1444 | } |
| 1445 | |
| 1446 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1447 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1448 | |
| 1449 | if ((word_len == 7) && !strncmp(word, "current", word_len)) { |
| 1450 | *flags |= LYS_STATUS_CURR; |
| 1451 | } else if ((word_len == 10) && !strncmp(word, "deprecated", word_len)) { |
| 1452 | *flags |= LYS_STATUS_DEPRC; |
| 1453 | } else if ((word_len == 8) && !strncmp(word, "obsolete", word_len)) { |
| 1454 | *flags |= LYS_STATUS_OBSLT; |
| 1455 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1456 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "status"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1457 | free(buf); |
| 1458 | return LY_EVALID; |
| 1459 | } |
| 1460 | free(buf); |
| 1461 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1462 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1463 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1464 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1465 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_STATUS, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1466 | break; |
| 1467 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1468 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "status"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1469 | return LY_EVALID; |
| 1470 | } |
| 1471 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1472 | return ret; |
| 1473 | } |
| 1474 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1475 | /** |
| 1476 | * @brief Parse the when statement. |
| 1477 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1478 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1479 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1480 | * @param[in,out] when_p When pointer to parse to. |
| 1481 | * |
| 1482 | * @return LY_ERR values. |
| 1483 | */ |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 1484 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1485 | parse_when(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_when **when_p) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1486 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1487 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1488 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1489 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1490 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1491 | struct lysp_when *when; |
| 1492 | |
| 1493 | if (*when_p) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1494 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "when"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1495 | return LY_EVALID; |
| 1496 | } |
| 1497 | |
| 1498 | when = calloc(1, sizeof *when); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1499 | LY_CHECK_ERR_RET(!when, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1500 | |
| 1501 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1502 | LY_CHECK_ERR_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len), free(when), LY_EMEM); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1503 | CHECK_NONEMPTY(ctx, word_len, "when"); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1504 | INSERT_WORD(ctx, buf, when->cond, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1505 | |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 1506 | *when_p = when; |
| 1507 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1508 | YANG_READ_SUBSTMT_FOR(ctx, in, 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_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1511 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &when->dsc, Y_STR_ARG, &when->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1512 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1513 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1514 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &when->ref, Y_STR_ARG, &when->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1515 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1516 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1517 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &when->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1518 | break; |
| 1519 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1520 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "when"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1521 | return LY_EVALID; |
| 1522 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1523 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1524 | return ret; |
| 1525 | } |
| 1526 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1527 | /** |
| 1528 | * @brief Parse the anydata or anyxml statement. |
| 1529 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1530 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1531 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1532 | * @param[in] kw Type of this particular keyword. |
| 1533 | * @param[in,out] siblings Siblings to add to. |
| 1534 | * |
| 1535 | * @return LY_ERR values. |
| 1536 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 1537 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1538 | parse_any(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt kw, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1539 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1540 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1541 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1542 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1543 | struct lysp_node_anydata *any; |
| 1544 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 1545 | /* create new structure and insert into siblings */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 1546 | LY_LIST_NEW_RET(ctx->ctx, siblings, any, next, LY_EMEM); |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 1547 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1548 | any->nodetype = kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1549 | any->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1550 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1551 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1552 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1553 | INSERT_WORD(ctx, buf, any->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1554 | |
| 1555 | /* parse substatements */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1556 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1557 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1558 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1559 | LY_CHECK_RET(parse_config(ctx, in, &any->flags, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1560 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1561 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1562 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &any->dsc, Y_STR_ARG, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1563 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1564 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1565 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &any->iffeatures, Y_STR_ARG, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1566 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1567 | case LY_STMT_MANDATORY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1568 | LY_CHECK_RET(parse_mandatory(ctx, in, &any->flags, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1569 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1570 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1571 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &any->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1572 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1573 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1574 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &any->ref, Y_STR_ARG, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1575 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1576 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1577 | LY_CHECK_RET(parse_status(ctx, in, &any->flags, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1578 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1579 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1580 | LY_CHECK_RET(parse_when(ctx, in, &any->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1581 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1582 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1583 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1584 | break; |
| 1585 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1586 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1587 | (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] | 1588 | return LY_EVALID; |
| 1589 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1590 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1591 | return ret; |
| 1592 | } |
| 1593 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1594 | /** |
| 1595 | * @brief Parse the value or position statement. Substatement of type enum statement. |
| 1596 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1597 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1598 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1599 | * @param[in] val_kw Type of this particular keyword. |
| 1600 | * @param[in,out] value Value to write to. |
| 1601 | * @param[in,out] flags Flags to write to. |
| 1602 | * @param[in,out] exts Extension instances to add to. |
| 1603 | * |
| 1604 | * @return LY_ERR values. |
| 1605 | */ |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 1606 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1607 | parse_type_enum_value_pos(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt val_kw, int64_t *value, uint16_t *flags, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1608 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1609 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1610 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1611 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1612 | size_t word_len; |
Radek Krejci | 4ad42aa | 2019-07-23 16:55:58 +0200 | [diff] [blame] | 1613 | long int num = 0; |
| 1614 | unsigned long int unum = 0; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1615 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1616 | |
| 1617 | if (*flags & LYS_SET_VALUE) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1618 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(val_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1619 | return LY_EVALID; |
| 1620 | } |
| 1621 | *flags |= LYS_SET_VALUE; |
| 1622 | |
| 1623 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1624 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1625 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1626 | 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] | 1627 | 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] | 1628 | goto error; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | errno = 0; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1632 | if (val_kw == LY_STMT_VALUE) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1633 | num = strtol(word, &ptr, 10); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1634 | if (num < INT64_C(-2147483648) || num > INT64_C(2147483647)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1635 | 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] | 1636 | goto error; |
| 1637 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1638 | } else { |
| 1639 | unum = strtoul(word, &ptr, 10); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1640 | if (unum > UINT64_C(4294967295)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1641 | 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] | 1642 | goto error; |
| 1643 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1644 | } |
| 1645 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1646 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1647 | 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] | 1648 | goto error; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1649 | } |
| 1650 | if (errno == ERANGE) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1651 | 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] | 1652 | goto error; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1653 | } |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1654 | if (val_kw == LY_STMT_VALUE) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1655 | *value = num; |
| 1656 | } else { |
| 1657 | *value = unum; |
| 1658 | } |
| 1659 | free(buf); |
| 1660 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1661 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1662 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1663 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1664 | LY_CHECK_RET(parse_ext(ctx, in, 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] | 1665 | break; |
| 1666 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1667 | 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] | 1668 | return LY_EVALID; |
| 1669 | } |
| 1670 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1671 | return ret; |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1672 | |
| 1673 | error: |
| 1674 | free(buf); |
| 1675 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1676 | } |
| 1677 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1678 | /** |
| 1679 | * @brief Parse the enum or bit statement. Substatement of type statement. |
| 1680 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1681 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1682 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1683 | * @param[in] enum_kw Type of this particular keyword. |
| 1684 | * @param[in,out] enums Enums or bits to add to. |
| 1685 | * |
| 1686 | * @return LY_ERR values. |
| 1687 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1688 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1689 | parse_type_enum(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt enum_kw, struct lysp_type_enum **enums) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1690 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1691 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1692 | char *buf, *word; |
David Sedlák | 6544c18 | 2019-07-12 13:17:33 +0200 | [diff] [blame] | 1693 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1694 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1695 | struct lysp_type_enum *enm; |
| 1696 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1697 | LY_ARRAY_NEW_RET(ctx->ctx, *enums, enm, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1698 | |
| 1699 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1700 | LY_CHECK_RET(get_argument(ctx, in, 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] | 1701 | if (enum_kw == LY_STMT_ENUM) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1702 | 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] | 1703 | LY_CHECK_ERR_RET(ret, free(buf), ret); |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1704 | } /* else nothing specific for YANG_BIT */ |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1705 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1706 | INSERT_WORD(ctx, buf, enm->name, word, word_len); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1707 | CHECK_UNIQUENESS(ctx, *enums, name, ly_stmt2str(enum_kw), enm->name); |
| 1708 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1709 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1710 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1711 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1712 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &enm->dsc, Y_STR_ARG, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1713 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1714 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1715 | PARSER_CHECK_STMTVER2_RET(ctx, "if-feature", ly_stmt2str(enum_kw)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1716 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &enm->iffeatures, Y_STR_ARG, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1717 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1718 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1719 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &enm->ref, Y_STR_ARG, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1720 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1721 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1722 | LY_CHECK_RET(parse_status(ctx, in, &enm->flags, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1723 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1724 | case LY_STMT_VALUE: |
| 1725 | LY_CHECK_ERR_RET(enum_kw == LY_STMT_BIT, LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), |
David Sedlák | 9fb515f | 2019-07-11 10:33:58 +0200 | [diff] [blame] | 1726 | ly_stmt2str(enum_kw)), LY_EVALID); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1727 | LY_CHECK_RET(parse_type_enum_value_pos(ctx, in, kw, &enm->value, &enm->flags, &enm->exts)); |
David Sedlák | 9fb515f | 2019-07-11 10:33:58 +0200 | [diff] [blame] | 1728 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1729 | case LY_STMT_POSITION: |
| 1730 | LY_CHECK_ERR_RET(enum_kw == LY_STMT_ENUM, LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), |
David Sedlák | 9fb515f | 2019-07-11 10:33:58 +0200 | [diff] [blame] | 1731 | ly_stmt2str(enum_kw)), LY_EVALID); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1732 | LY_CHECK_RET(parse_type_enum_value_pos(ctx, in, kw, &enm->value, &enm->flags, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1733 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1734 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1735 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1736 | break; |
| 1737 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1738 | 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] | 1739 | return LY_EVALID; |
| 1740 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1741 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1742 | return ret; |
| 1743 | } |
| 1744 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1745 | /** |
| 1746 | * @brief Parse the fraction-digits statement. Substatement of type statement. |
| 1747 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1748 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1749 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1750 | * @param[in,out] fracdig Value to write to. |
| 1751 | * @param[in,out] exts Extension instances to add to. |
| 1752 | * |
| 1753 | * @return LY_ERR values. |
| 1754 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1755 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1756 | parse_type_fracdigits(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint8_t *fracdig, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1757 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1758 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1759 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1760 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1761 | unsigned long int num; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1762 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1763 | |
| 1764 | if (*fracdig) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1765 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1766 | return LY_EVALID; |
| 1767 | } |
| 1768 | |
| 1769 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1770 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1771 | |
| 1772 | if (!word_len || (word[0] == '0') || !isdigit(word[0])) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1773 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1774 | free(buf); |
| 1775 | return LY_EVALID; |
| 1776 | } |
| 1777 | |
| 1778 | errno = 0; |
| 1779 | num = strtoul(word, &ptr, 10); |
| 1780 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1781 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1782 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1783 | free(buf); |
| 1784 | return LY_EVALID; |
| 1785 | } |
| 1786 | if ((errno == ERANGE) || (num > 18)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1787 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1788 | free(buf); |
| 1789 | return LY_EVALID; |
| 1790 | } |
| 1791 | *fracdig = num; |
| 1792 | free(buf); |
| 1793 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1794 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1795 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1796 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1797 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_FRACDIGITS, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1798 | break; |
| 1799 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1800 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1801 | return LY_EVALID; |
| 1802 | } |
| 1803 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1804 | return ret; |
| 1805 | } |
| 1806 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1807 | /** |
| 1808 | * @brief Parse the require-instance statement. Substatement of type statement. |
| 1809 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1810 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1811 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1812 | * @param[in,out] reqinst Value to write to. |
| 1813 | * @param[in,out] flags Flags to write to. |
| 1814 | * @param[in,out] exts Extension instances to add to. |
| 1815 | * |
| 1816 | * @return LY_ERR values. |
| 1817 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1818 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1819 | parse_type_reqinstance(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint8_t *reqinst, uint16_t *flags, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1820 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1821 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1822 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1823 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1824 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1825 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1826 | |
| 1827 | if (*flags & LYS_SET_REQINST) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1828 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "require-instance"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1829 | return LY_EVALID; |
| 1830 | } |
| 1831 | *flags |= LYS_SET_REQINST; |
| 1832 | |
| 1833 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1834 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1835 | |
| 1836 | if ((word_len == 4) && !strncmp(word, "true", word_len)) { |
| 1837 | *reqinst = 1; |
| 1838 | } else if ((word_len != 5) || strncmp(word, "false", word_len)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1839 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "require-instance"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1840 | free(buf); |
| 1841 | return LY_EVALID; |
| 1842 | } |
| 1843 | free(buf); |
| 1844 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1845 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1846 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1847 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1848 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_REQINSTANCE, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1849 | break; |
| 1850 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1851 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "require-instance"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1852 | return LY_EVALID; |
| 1853 | } |
| 1854 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1855 | return ret; |
| 1856 | } |
| 1857 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1858 | /** |
| 1859 | * @brief Parse the modifier statement. Substatement of type pattern statement. |
| 1860 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1861 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1862 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1863 | * @param[in,out] pat Value to write to. |
| 1864 | * @param[in,out] exts Extension instances to add to. |
| 1865 | * |
| 1866 | * @return LY_ERR values. |
| 1867 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1868 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1869 | parse_type_pattern_modifier(struct lys_yang_parser_ctx *ctx, struct ly_in *in, const char **pat, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1870 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1871 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1872 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1873 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1874 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1875 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1876 | |
| 1877 | if ((*pat)[0] == 0x15) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1878 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "modifier"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1879 | return LY_EVALID; |
| 1880 | } |
| 1881 | |
| 1882 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1883 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1884 | |
| 1885 | if ((word_len != 12) || strncmp(word, "invert-match", word_len)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1886 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "modifier"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1887 | free(buf); |
| 1888 | return LY_EVALID; |
| 1889 | } |
| 1890 | free(buf); |
| 1891 | |
| 1892 | /* replace the value in the dictionary */ |
| 1893 | buf = malloc(strlen(*pat) + 1); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1894 | LY_CHECK_ERR_RET(!buf, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1895 | strcpy(buf, *pat); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1896 | lydict_remove(ctx->ctx, *pat); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1897 | |
| 1898 | assert(buf[0] == 0x06); |
| 1899 | buf[0] = 0x15; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1900 | *pat = lydict_insert_zc(ctx->ctx, buf); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1901 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1902 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1903 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1904 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1905 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_MODIFIER, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1906 | break; |
| 1907 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1908 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "modifier"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1909 | return LY_EVALID; |
| 1910 | } |
| 1911 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1912 | return ret; |
| 1913 | } |
| 1914 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1915 | /** |
| 1916 | * @brief Parse the pattern statement. Substatement of type statement. |
| 1917 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1918 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1919 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1920 | * @param[in,out] patterns Restrictions to add to. |
| 1921 | * |
| 1922 | * @return LY_ERR values. |
| 1923 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1924 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1925 | parse_type_pattern(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_restr **patterns) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1926 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1927 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1928 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1929 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1930 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1931 | struct lysp_restr *restr; |
| 1932 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1933 | LY_ARRAY_NEW_RET(ctx->ctx, *patterns, restr, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1934 | |
| 1935 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1936 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1937 | |
| 1938 | /* add special meaning first byte */ |
| 1939 | if (buf) { |
| 1940 | buf = realloc(buf, word_len + 2); |
| 1941 | word = buf; |
| 1942 | } else { |
| 1943 | buf = malloc(word_len + 2); |
| 1944 | } |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1945 | LY_CHECK_ERR_RET(!buf, LOGMEM(ctx->ctx), LY_EMEM); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 1946 | memmove(buf + 1, word, word_len); |
| 1947 | buf[0] = 0x06; /* pattern's default regular-match flag */ |
| 1948 | buf[word_len + 1] = '\0'; /* terminating NULL byte */ |
| 1949 | restr->arg = lydict_insert_zc(ctx->ctx, buf); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1950 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1951 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1952 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1953 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1954 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &restr->dsc, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1955 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1956 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1957 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &restr->ref, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1958 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1959 | case LY_STMT_ERROR_APP_TAG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1960 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_ERRTAG, 0, &restr->eapptag, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1961 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1962 | case LY_STMT_ERROR_MESSAGE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1963 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_ERRMSG, 0, &restr->emsg, Y_STR_ARG, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1964 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1965 | case LY_STMT_MODIFIER: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1966 | PARSER_CHECK_STMTVER2_RET(ctx, "modifier", "pattern"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1967 | LY_CHECK_RET(parse_type_pattern_modifier(ctx, in, &restr->arg, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1968 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1969 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1970 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1971 | break; |
| 1972 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1973 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "pattern"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1974 | return LY_EVALID; |
| 1975 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1976 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1977 | return ret; |
| 1978 | } |
| 1979 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1980 | /** |
| 1981 | * @brief Parse the type statement. |
| 1982 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1983 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1984 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1985 | * @param[in,out] type Type to wrote to. |
| 1986 | * |
| 1987 | * @return LY_ERR values. |
| 1988 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1989 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1990 | parse_type(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_type *type) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1991 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1992 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1993 | char *buf, *word; |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 1994 | const char *str_path = NULL; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1995 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1996 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1997 | struct lysp_type *nest_type; |
| 1998 | |
| 1999 | if (type->name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2000 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "type"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2001 | return LY_EVALID; |
| 2002 | } |
| 2003 | |
| 2004 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2005 | LY_CHECK_RET(get_argument(ctx, in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2006 | INSERT_WORD(ctx, buf, type->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2007 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2008 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2009 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2010 | case LY_STMT_BASE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2011 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_BASE, &type->bases, Y_PREF_IDENTIF_ARG, &type->exts)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2012 | type->flags |= LYS_SET_BASE; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2013 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2014 | case LY_STMT_BIT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2015 | LY_CHECK_RET(parse_type_enum(ctx, in, kw, &type->bits)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2016 | type->flags |= LYS_SET_BIT; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2017 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2018 | case LY_STMT_ENUM: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2019 | LY_CHECK_RET(parse_type_enum(ctx, in, kw, &type->enums)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2020 | type->flags |= LYS_SET_ENUM; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2021 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2022 | case LY_STMT_FRACTION_DIGITS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2023 | LY_CHECK_RET(parse_type_fracdigits(ctx, in, &type->fraction_digits, &type->exts)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2024 | type->flags |= LYS_SET_FRDIGITS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2025 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2026 | case LY_STMT_LENGTH: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2027 | if (type->length) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2028 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2029 | return LY_EVALID; |
| 2030 | } |
| 2031 | type->length = calloc(1, sizeof *type->length); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2032 | LY_CHECK_ERR_RET(!type->length, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2033 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2034 | LY_CHECK_RET(parse_restr(ctx, in, kw, type->length)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2035 | type->flags |= LYS_SET_LENGTH; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2036 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2037 | case LY_STMT_PATH: |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 2038 | if (type->path) { |
| 2039 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, lyext_substmt2str(LYEXT_SUBSTMT_PATH)); |
| 2040 | return LY_EVALID; |
| 2041 | } |
| 2042 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2043 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_PATH, 0, &str_path, Y_STR_ARG, &type->exts)); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 2044 | ret = ly_path_parse(ctx->ctx, NULL, str_path, 0, LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE, |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 2045 | LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &type->path); |
| 2046 | lydict_remove(ctx->ctx, str_path); |
| 2047 | LY_CHECK_RET(ret); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2048 | type->flags |= LYS_SET_PATH; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2049 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2050 | case LY_STMT_PATTERN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2051 | LY_CHECK_RET(parse_type_pattern(ctx, in, &type->patterns)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2052 | type->flags |= LYS_SET_PATTERN; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2053 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2054 | case LY_STMT_RANGE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2055 | if (type->range) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2056 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2057 | return LY_EVALID; |
| 2058 | } |
| 2059 | type->range = calloc(1, sizeof *type->range); |
David Sedlák | 7a8b247 | 2019-07-11 15:08:34 +0200 | [diff] [blame] | 2060 | LY_CHECK_ERR_RET(!type->range, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2061 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2062 | LY_CHECK_RET(parse_restr(ctx, in, kw, type->range)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2063 | type->flags |= LYS_SET_RANGE; |
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_REQUIRE_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2066 | LY_CHECK_RET(parse_type_reqinstance(ctx, in, &type->require_instance, &type->flags, &type->exts)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2067 | /* LYS_SET_REQINST checked and set inside parse_type_reqinstance() */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2068 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2069 | case LY_STMT_TYPE: |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2070 | LY_ARRAY_NEW_RET(ctx->ctx, type->types, nest_type, LY_EMEM); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2071 | LY_CHECK_RET(parse_type(ctx, in, nest_type)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2072 | type->flags |= LYS_SET_TYPE; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2073 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2074 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2075 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &type->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2076 | break; |
| 2077 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2078 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "type"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2079 | return LY_EVALID; |
| 2080 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2081 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2082 | return ret; |
| 2083 | } |
| 2084 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2085 | /** |
| 2086 | * @brief Parse the leaf statement. |
| 2087 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2088 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2089 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2090 | * @param[in,out] siblings Siblings to add to. |
| 2091 | * |
| 2092 | * @return LY_ERR values. |
| 2093 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2094 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2095 | parse_leaf(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2096 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2097 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2098 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2099 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2100 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2101 | struct lysp_node_leaf *leaf; |
| 2102 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 2103 | /* create new leaf structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 2104 | LY_LIST_NEW_RET(ctx->ctx, siblings, leaf, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2105 | leaf->nodetype = LYS_LEAF; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2106 | leaf->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2107 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2108 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2109 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2110 | INSERT_WORD(ctx, buf, leaf->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2111 | |
| 2112 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2113 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2114 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2115 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2116 | LY_CHECK_RET(parse_config(ctx, in, &leaf->flags, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2117 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2118 | case LY_STMT_DEFAULT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2119 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DEFAULT, 0, &leaf->dflt, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2120 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2121 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2122 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &leaf->dsc, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2123 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2124 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2125 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &leaf->iffeatures, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2126 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2127 | case LY_STMT_MANDATORY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2128 | LY_CHECK_RET(parse_mandatory(ctx, in, &leaf->flags, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2129 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2130 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2131 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &leaf->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2132 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2133 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2134 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &leaf->ref, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2135 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2136 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2137 | LY_CHECK_RET(parse_status(ctx, in, &leaf->flags, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2138 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2139 | case LY_STMT_TYPE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2140 | LY_CHECK_RET(parse_type(ctx, in, &leaf->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2141 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2142 | case LY_STMT_UNITS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2143 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_UNITS, 0, &leaf->units, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2144 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2145 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2146 | LY_CHECK_RET(parse_when(ctx, in, &leaf->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2147 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2148 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2149 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2150 | break; |
| 2151 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2152 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "leaf"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2153 | return LY_EVALID; |
| 2154 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2155 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 2156 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 2157 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2158 | /* mandatory substatements */ |
| 2159 | if (!leaf->type.name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2160 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "type", "leaf"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2161 | return LY_EVALID; |
| 2162 | } |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 2163 | if ((leaf->flags & LYS_MAND_TRUE) && (leaf->dflt)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2164 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMSCOMB, "mandatory", "default", "leaf"); |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 2165 | return LY_EVALID; |
| 2166 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2167 | |
| 2168 | return ret; |
| 2169 | } |
| 2170 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2171 | /** |
| 2172 | * @brief Parse the max-elements statement. |
| 2173 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2174 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2175 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2176 | * @param[in,out] max Value to write to. |
| 2177 | * @param[in,out] flags Flags to write to. |
| 2178 | * @param[in,out] exts Extension instances to add to. |
| 2179 | * |
| 2180 | * @return LY_ERR values. |
| 2181 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2182 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2183 | parse_maxelements(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint32_t *max, uint16_t *flags, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2184 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2185 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2186 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2187 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2188 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2189 | unsigned long int num; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2190 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2191 | |
| 2192 | if (*flags & LYS_SET_MAX) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2193 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2194 | return LY_EVALID; |
| 2195 | } |
| 2196 | *flags |= LYS_SET_MAX; |
| 2197 | |
| 2198 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2199 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2200 | |
| 2201 | 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] | 2202 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2203 | free(buf); |
| 2204 | return LY_EVALID; |
| 2205 | } |
| 2206 | |
Radek Krejci | 7f9b651 | 2019-09-18 13:11:09 +0200 | [diff] [blame] | 2207 | if (ly_strncmp("unbounded", word, word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2208 | errno = 0; |
| 2209 | num = strtoul(word, &ptr, 10); |
| 2210 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2211 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2212 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2213 | free(buf); |
| 2214 | return LY_EVALID; |
| 2215 | } |
| 2216 | if ((errno == ERANGE) || (num > UINT32_MAX)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2217 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2218 | free(buf); |
| 2219 | return LY_EVALID; |
| 2220 | } |
| 2221 | |
| 2222 | *max = num; |
| 2223 | } |
| 2224 | free(buf); |
| 2225 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2226 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2227 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2228 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2229 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_MAX, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2230 | break; |
| 2231 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2232 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2233 | return LY_EVALID; |
| 2234 | } |
| 2235 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2236 | return ret; |
| 2237 | } |
| 2238 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2239 | /** |
| 2240 | * @brief Parse the min-elements statement. |
| 2241 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2242 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2243 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2244 | * @param[in,out] min Value to write to. |
| 2245 | * @param[in,out] flags Flags to write to. |
| 2246 | * @param[in,out] exts Extension instances to add to. |
| 2247 | * |
| 2248 | * @return LY_ERR values. |
| 2249 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2250 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2251 | parse_minelements(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint32_t *min, uint16_t *flags, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2252 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2253 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2254 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2255 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2256 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2257 | unsigned long int num; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2258 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2259 | |
| 2260 | if (*flags & LYS_SET_MIN) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2261 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2262 | return LY_EVALID; |
| 2263 | } |
| 2264 | *flags |= LYS_SET_MIN; |
| 2265 | |
| 2266 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2267 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2268 | |
| 2269 | 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] | 2270 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2271 | free(buf); |
| 2272 | return LY_EVALID; |
| 2273 | } |
| 2274 | |
| 2275 | errno = 0; |
| 2276 | num = strtoul(word, &ptr, 10); |
| 2277 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2278 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2279 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2280 | free(buf); |
| 2281 | return LY_EVALID; |
| 2282 | } |
| 2283 | if ((errno == ERANGE) || (num > UINT32_MAX)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2284 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2285 | free(buf); |
| 2286 | return LY_EVALID; |
| 2287 | } |
| 2288 | *min = num; |
| 2289 | free(buf); |
| 2290 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2291 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2292 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2293 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2294 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_MIN, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2295 | break; |
| 2296 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2297 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2298 | return LY_EVALID; |
| 2299 | } |
| 2300 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2301 | return ret; |
| 2302 | } |
| 2303 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2304 | /** |
| 2305 | * @brief Parse the ordered-by statement. |
| 2306 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2307 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2308 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2309 | * @param[in,out] flags Flags to write to. |
| 2310 | * @param[in,out] exts Extension instances to add to. |
| 2311 | * |
| 2312 | * @return LY_ERR values. |
| 2313 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2314 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2315 | parse_orderedby(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2316 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2317 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2318 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2319 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2320 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2321 | |
| 2322 | if (*flags & LYS_ORDBY_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2323 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "ordered-by"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2324 | return LY_EVALID; |
| 2325 | } |
| 2326 | |
| 2327 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2328 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2329 | |
| 2330 | if ((word_len == 6) && !strncmp(word, "system", word_len)) { |
| 2331 | *flags |= LYS_ORDBY_SYSTEM; |
| 2332 | } else if ((word_len == 4) && !strncmp(word, "user", word_len)) { |
| 2333 | *flags |= LYS_ORDBY_USER; |
| 2334 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2335 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "ordered-by"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2336 | free(buf); |
| 2337 | return LY_EVALID; |
| 2338 | } |
| 2339 | free(buf); |
| 2340 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2341 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2342 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2343 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2344 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_ORDEREDBY, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2345 | break; |
| 2346 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2347 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "ordered-by"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2348 | return LY_EVALID; |
| 2349 | } |
| 2350 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2351 | return ret; |
| 2352 | } |
| 2353 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2354 | /** |
| 2355 | * @brief Parse the leaf-list statement. |
| 2356 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2357 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2358 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2359 | * @param[in,out] siblings Siblings to add to. |
| 2360 | * |
| 2361 | * @return LY_ERR values. |
| 2362 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2363 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2364 | parse_leaflist(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2365 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2366 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2367 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2368 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2369 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2370 | struct lysp_node_leaflist *llist; |
| 2371 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 2372 | /* create new leaf-list structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 2373 | LY_LIST_NEW_RET(ctx->ctx, siblings, llist, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2374 | llist->nodetype = LYS_LEAFLIST; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2375 | llist->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2376 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2377 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2378 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2379 | INSERT_WORD(ctx, buf, llist->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2380 | |
| 2381 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2382 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2383 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2384 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2385 | LY_CHECK_RET(parse_config(ctx, in, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2386 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2387 | case LY_STMT_DEFAULT: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2388 | PARSER_CHECK_STMTVER2_RET(ctx, "default", "leaf-list"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2389 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_DEFAULT, &llist->dflts, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2390 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2391 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2392 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &llist->dsc, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2393 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2394 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2395 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &llist->iffeatures, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2396 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2397 | case LY_STMT_MAX_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2398 | LY_CHECK_RET(parse_maxelements(ctx, in, &llist->max, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2399 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2400 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2401 | LY_CHECK_RET(parse_minelements(ctx, in, &llist->min, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2402 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2403 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2404 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &llist->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2405 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2406 | case LY_STMT_ORDERED_BY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2407 | LY_CHECK_RET(parse_orderedby(ctx, in, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2408 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2409 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2410 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &llist->ref, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2411 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2412 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2413 | LY_CHECK_RET(parse_status(ctx, in, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2414 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2415 | case LY_STMT_TYPE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2416 | LY_CHECK_RET(parse_type(ctx, in, &llist->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2417 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2418 | case LY_STMT_UNITS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2419 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_UNITS, 0, &llist->units, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2420 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2421 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2422 | LY_CHECK_RET(parse_when(ctx, in, &llist->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2423 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2424 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2425 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2426 | break; |
| 2427 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2428 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "llist"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2429 | return LY_EVALID; |
| 2430 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2431 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 2432 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 2433 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2434 | /* mandatory substatements */ |
| 2435 | if (!llist->type.name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2436 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "type", "leaf-list"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2437 | return LY_EVALID; |
| 2438 | } |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 2439 | if ((llist->min) && (llist->dflts)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2440 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMSCOMB, "min-elements", "default", "leaf-list"); |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 2441 | return LY_EVALID; |
| 2442 | } |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 2443 | if (llist->max && llist->min > llist->max) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2444 | LOGVAL_PARSER(ctx, LYVE_SEMANTICS, |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 2445 | "Invalid combination of min-elements and max-elements: min value %u is bigger than the max value %u.", |
| 2446 | llist->min, llist->max); |
| 2447 | return LY_EVALID; |
| 2448 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2449 | |
| 2450 | return ret; |
| 2451 | } |
| 2452 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2453 | /** |
| 2454 | * @brief Parse the refine statement. |
| 2455 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2456 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2457 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2458 | * @param[in,out] refines Refines to add to. |
| 2459 | * |
| 2460 | * @return LY_ERR values. |
| 2461 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2462 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2463 | parse_refine(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_refine **refines) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2464 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2465 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2466 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2467 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2468 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2469 | struct lysp_refine *rf; |
| 2470 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2471 | LY_ARRAY_NEW_RET(ctx->ctx, *refines, rf, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2472 | |
| 2473 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2474 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2475 | CHECK_NONEMPTY(ctx, word_len, "refine"); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2476 | INSERT_WORD(ctx, buf, rf->nodeid, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2477 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2478 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2479 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2480 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2481 | LY_CHECK_RET(parse_config(ctx, in, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2482 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2483 | case LY_STMT_DEFAULT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2484 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_DEFAULT, &rf->dflts, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2485 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2486 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2487 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &rf->dsc, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2488 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2489 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2490 | PARSER_CHECK_STMTVER2_RET(ctx, "if-feature", "refine"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2491 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &rf->iffeatures, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2492 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2493 | case LY_STMT_MAX_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2494 | LY_CHECK_RET(parse_maxelements(ctx, in, &rf->max, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2495 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2496 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2497 | LY_CHECK_RET(parse_minelements(ctx, in, &rf->min, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2498 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2499 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2500 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &rf->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2501 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2502 | case LY_STMT_MANDATORY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2503 | LY_CHECK_RET(parse_mandatory(ctx, in, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2504 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2505 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2506 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &rf->ref, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2507 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2508 | case LY_STMT_PRESENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2509 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_PRESENCE, 0, &rf->presence, 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_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2512 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2513 | break; |
| 2514 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2515 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "refine"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2516 | return LY_EVALID; |
| 2517 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2518 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2519 | return ret; |
| 2520 | } |
| 2521 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2522 | /** |
| 2523 | * @brief Parse the typedef statement. |
| 2524 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2525 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2526 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2527 | * @param[in,out] typedefs Typedefs to add to. |
| 2528 | * |
| 2529 | * @return LY_ERR values. |
| 2530 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2531 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2532 | parse_typedef(struct lys_yang_parser_ctx *ctx, struct lysp_node *parent, struct ly_in *in, struct lysp_tpdf **typedefs) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2533 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2534 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2535 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2536 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2537 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2538 | struct lysp_tpdf *tpdf; |
| 2539 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2540 | LY_ARRAY_NEW_RET(ctx->ctx, *typedefs, tpdf, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2541 | |
| 2542 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2543 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2544 | INSERT_WORD(ctx, buf, tpdf->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2545 | |
| 2546 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2547 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2548 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2549 | case LY_STMT_DEFAULT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2550 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DEFAULT, 0, &tpdf->dflt, Y_STR_ARG, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2551 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2552 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2553 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &tpdf->dsc, Y_STR_ARG, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2554 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2555 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2556 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &tpdf->ref, Y_STR_ARG, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2557 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2558 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2559 | LY_CHECK_RET(parse_status(ctx, in, &tpdf->flags, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2560 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2561 | case LY_STMT_TYPE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2562 | LY_CHECK_RET(parse_type(ctx, in, &tpdf->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2563 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2564 | case LY_STMT_UNITS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2565 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_UNITS, 0, &tpdf->units, Y_STR_ARG, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2566 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2567 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2568 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2569 | break; |
| 2570 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2571 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "typedef"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2572 | return LY_EVALID; |
| 2573 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2574 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 2575 | LY_CHECK_RET(ret); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 2576 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2577 | /* mandatory substatements */ |
| 2578 | if (!tpdf->type.name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2579 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "type", "typedef"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2580 | return LY_EVALID; |
| 2581 | } |
| 2582 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 2583 | /* store data for collision check */ |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 2584 | if (parent && !(parent->nodetype & (LYS_GROUPING | LYS_RPC | LYS_ACTION | LYS_INOUT | LYS_NOTIF))) { |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 2585 | LY_CHECK_RET(ly_set_add(&ctx->tpdfs_nodes, parent, 0, NULL)); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 2586 | } |
| 2587 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2588 | return ret; |
| 2589 | } |
| 2590 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2591 | /** |
| 2592 | * @brief Parse the input or output statement. |
| 2593 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2594 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2595 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2596 | * @param[in] kw Type of this particular keyword |
| 2597 | * @param[in,out] inout_p Input/output pointer to write to. |
| 2598 | * |
| 2599 | * @return LY_ERR values. |
| 2600 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2601 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2602 | parse_inout(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt inout_kw, struct lysp_node *parent, struct lysp_action_inout *inout_p) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2603 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2604 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2605 | char *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2606 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2607 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2608 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2609 | if (inout_p->nodetype) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2610 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(inout_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2611 | return LY_EVALID; |
| 2612 | } |
| 2613 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2614 | /* initiate structure */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2615 | inout_p->nodetype = &((struct lysp_action *)parent)->input == inout_p ? LYS_INPUT : LYS_OUTPUT; |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2616 | inout_p->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2617 | |
| 2618 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2619 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2620 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2621 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2622 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", ly_stmt2str(inout_kw)); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2623 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2624 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2625 | LY_CHECK_RET(parse_any(ctx, in, kw, (struct lysp_node *)inout_p, &inout_p->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2626 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2627 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2628 | LY_CHECK_RET(parse_choice(ctx, in, (struct lysp_node *)inout_p, &inout_p->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2629 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2630 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2631 | LY_CHECK_RET(parse_container(ctx, in, (struct lysp_node *)inout_p, &inout_p->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2632 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2633 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2634 | LY_CHECK_RET(parse_leaf(ctx, in, (struct lysp_node *)inout_p, &inout_p->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2635 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2636 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2637 | LY_CHECK_RET(parse_leaflist(ctx, in, (struct lysp_node *)inout_p, &inout_p->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2638 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2639 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2640 | LY_CHECK_RET(parse_list(ctx, in, (struct lysp_node *)inout_p, &inout_p->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2641 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2642 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2643 | LY_CHECK_RET(parse_uses(ctx, in, (struct lysp_node *)inout_p, &inout_p->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2644 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2645 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2646 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)inout_p, in, &inout_p->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2647 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2648 | case LY_STMT_MUST: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2649 | PARSER_CHECK_STMTVER2_RET(ctx, "must", ly_stmt2str(inout_kw)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2650 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &inout_p->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2651 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2652 | case LY_STMT_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2653 | LY_CHECK_RET(parse_grouping(ctx, in, (struct lysp_node *)inout_p, &inout_p->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2654 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2655 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2656 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &inout_p->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2657 | break; |
| 2658 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2659 | 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] | 2660 | return LY_EVALID; |
| 2661 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2662 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2663 | LY_CHECK_RET(ret); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 2664 | |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2665 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2666 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2667 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, inout_p->groupings, NULL, NULL, NULL)); |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2668 | |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 2669 | if (!inout_p->data) { |
| 2670 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "data-def-stmt", ly_stmt2str(inout_kw)); |
| 2671 | return LY_EVALID; |
| 2672 | } |
| 2673 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2674 | return ret; |
| 2675 | } |
| 2676 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2677 | /** |
| 2678 | * @brief Parse the action statement. |
| 2679 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2680 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2681 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2682 | * @param[in,out] actions Actions to add to. |
| 2683 | * |
| 2684 | * @return LY_ERR values. |
| 2685 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2686 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2687 | parse_action(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_action **actions) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2688 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2689 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2690 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2691 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2692 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2693 | struct lysp_action *act; |
| 2694 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2695 | LY_ARRAY_NEW_RET(ctx->ctx, *actions, act, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2696 | |
| 2697 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2698 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2699 | INSERT_WORD(ctx, buf, act->name, word, word_len); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 2700 | act->nodetype = parent ? LYS_ACTION : LYS_RPC; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2701 | act->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2702 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2703 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2704 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2705 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2706 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &act->dsc, Y_STR_ARG, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2707 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2708 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2709 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &act->iffeatures, Y_STR_ARG, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2710 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2711 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2712 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &act->ref, Y_STR_ARG, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2713 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2714 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2715 | LY_CHECK_RET(parse_status(ctx, in, &act->flags, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2716 | break; |
| 2717 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2718 | case LY_STMT_INPUT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2719 | LY_CHECK_RET(parse_inout(ctx, in, kw, (struct lysp_node *)act, &act->input)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2720 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2721 | case LY_STMT_OUTPUT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2722 | LY_CHECK_RET(parse_inout(ctx, in, kw, (struct lysp_node *)act, &act->output)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2723 | break; |
| 2724 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2725 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2726 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)act, in, &act->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2727 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2728 | case LY_STMT_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2729 | LY_CHECK_RET(parse_grouping(ctx, in, (struct lysp_node *)act, &act->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2730 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2731 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2732 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2733 | break; |
| 2734 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2735 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), parent ? "action" : "rpc"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2736 | return LY_EVALID; |
| 2737 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2738 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2739 | LY_CHECK_RET(ret); |
| 2740 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2741 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2742 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, act->groupings, NULL, NULL, NULL)); |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2743 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2744 | return ret; |
| 2745 | } |
| 2746 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2747 | /** |
| 2748 | * @brief Parse the notification statement. |
| 2749 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2750 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2751 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2752 | * @param[in,out] notifs Notifications to add to. |
| 2753 | * |
| 2754 | * @return LY_ERR values. |
| 2755 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2756 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2757 | parse_notif(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_notif **notifs) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2758 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2759 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2760 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2761 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2762 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2763 | struct lysp_notif *notif; |
| 2764 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2765 | LY_ARRAY_NEW_RET(ctx->ctx, *notifs, notif, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2766 | |
| 2767 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2768 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2769 | INSERT_WORD(ctx, buf, notif->name, word, word_len); |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2770 | notif->nodetype = LYS_NOTIF; |
| 2771 | notif->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2772 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2773 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2774 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2775 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2776 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, ¬if->dsc, Y_STR_ARG, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2777 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2778 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2779 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, ¬if->iffeatures, Y_STR_ARG, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2780 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2781 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2782 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, ¬if->ref, Y_STR_ARG, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2783 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2784 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2785 | LY_CHECK_RET(parse_status(ctx, in, ¬if->flags, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2786 | break; |
| 2787 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2788 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2789 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "notification"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2790 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2791 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2792 | LY_CHECK_RET(parse_any(ctx, in, kw, (struct lysp_node *)notif, ¬if->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2793 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2794 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2795 | LY_CHECK_RET(parse_case(ctx, in, (struct lysp_node *)notif, ¬if->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2796 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2797 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2798 | LY_CHECK_RET(parse_container(ctx, in, (struct lysp_node *)notif, ¬if->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2799 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2800 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2801 | LY_CHECK_RET(parse_leaf(ctx, in, (struct lysp_node *)notif, ¬if->data)); |
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_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2804 | LY_CHECK_RET(parse_leaflist(ctx, in, (struct lysp_node *)notif, ¬if->data)); |
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_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2807 | LY_CHECK_RET(parse_list(ctx, in, (struct lysp_node *)notif, ¬if->data)); |
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_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2810 | LY_CHECK_RET(parse_uses(ctx, in, (struct lysp_node *)notif, ¬if->data)); |
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_MUST: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2814 | PARSER_CHECK_STMTVER2_RET(ctx, "must", "notification"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2815 | LY_CHECK_RET(parse_restrs(ctx, in, kw, ¬if->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2816 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2817 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2818 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)notif, in, ¬if->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2819 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2820 | case LY_STMT_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2821 | LY_CHECK_RET(parse_grouping(ctx, in, (struct lysp_node *)notif, ¬if->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2822 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2823 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2824 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2825 | break; |
| 2826 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2827 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "notification"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2828 | return LY_EVALID; |
| 2829 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2830 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2831 | LY_CHECK_RET(ret); |
| 2832 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2833 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2834 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, notif->groupings, NULL, NULL, NULL)); |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2835 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2836 | return ret; |
| 2837 | } |
| 2838 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2839 | /** |
| 2840 | * @brief Parse the grouping statement. |
| 2841 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2842 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2843 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2844 | * @param[in,out] groupings Groupings to add to. |
| 2845 | * |
| 2846 | * @return LY_ERR values. |
| 2847 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2848 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2849 | parse_grouping(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_grp **groupings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2850 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2851 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2852 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2853 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2854 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2855 | struct lysp_grp *grp; |
| 2856 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2857 | LY_ARRAY_NEW_RET(ctx->ctx, *groupings, grp, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2858 | |
| 2859 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2860 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2861 | INSERT_WORD(ctx, buf, grp->name, word, word_len); |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2862 | grp->nodetype = LYS_GROUPING; |
| 2863 | grp->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2864 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2865 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2866 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2867 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2868 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &grp->dsc, Y_STR_ARG, &grp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2869 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2870 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2871 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &grp->ref, Y_STR_ARG, &grp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2872 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2873 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2874 | LY_CHECK_RET(parse_status(ctx, in, &grp->flags, &grp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2875 | break; |
| 2876 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2877 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2878 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "grouping"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2879 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2880 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2881 | LY_CHECK_RET(parse_any(ctx, in, kw, (struct lysp_node *)grp, &grp->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2882 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2883 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2884 | LY_CHECK_RET(parse_choice(ctx, in, (struct lysp_node *)grp, &grp->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2885 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2886 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2887 | LY_CHECK_RET(parse_container(ctx, in, (struct lysp_node *)grp, &grp->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2888 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2889 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2890 | LY_CHECK_RET(parse_leaf(ctx, in, (struct lysp_node *)grp, &grp->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2891 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2892 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2893 | LY_CHECK_RET(parse_leaflist(ctx, in, (struct lysp_node *)grp, &grp->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2894 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2895 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2896 | LY_CHECK_RET(parse_list(ctx, in, (struct lysp_node *)grp, &grp->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2897 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2898 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2899 | LY_CHECK_RET(parse_uses(ctx, in, (struct lysp_node *)grp, &grp->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2900 | break; |
| 2901 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2902 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2903 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)grp, in, &grp->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2904 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2905 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2906 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "grouping"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2907 | LY_CHECK_RET(parse_action(ctx, in, (struct lysp_node *)grp, &grp->actions)); |
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_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2910 | LY_CHECK_RET(parse_grouping(ctx, in, (struct lysp_node *)grp, &grp->groupings)); |
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_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2913 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "grouping"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2914 | LY_CHECK_RET(parse_notif(ctx, in, (struct lysp_node *)grp, &grp->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2915 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2916 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2917 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &grp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2918 | break; |
| 2919 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2920 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "grouping"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2921 | return LY_EVALID; |
| 2922 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2923 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2924 | LY_CHECK_RET(ret); |
| 2925 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2926 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2927 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, grp->groupings, NULL, grp->actions, grp->notifs)); |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2928 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2929 | return ret; |
| 2930 | } |
| 2931 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2932 | /** |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2933 | * @brief Parse the augment statement. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2934 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2935 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2936 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2937 | * @param[in,out] augments Augments to add to. |
| 2938 | * |
| 2939 | * @return LY_ERR values. |
| 2940 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2941 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2942 | parse_augment(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_augment **augments) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2943 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2944 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2945 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2946 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2947 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2948 | struct lysp_augment *aug; |
| 2949 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2950 | LY_ARRAY_NEW_RET(ctx->ctx, *augments, aug, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2951 | |
| 2952 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2953 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2954 | CHECK_NONEMPTY(ctx, word_len, "augment"); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2955 | INSERT_WORD(ctx, buf, aug->nodeid, word, word_len); |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2956 | aug->nodetype = LYS_AUGMENT; |
| 2957 | aug->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2958 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2959 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2960 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2961 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2962 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &aug->dsc, Y_STR_ARG, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2963 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2964 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2965 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &aug->iffeatures, Y_STR_ARG, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2966 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2967 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2968 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &aug->ref, Y_STR_ARG, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2969 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2970 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2971 | LY_CHECK_RET(parse_status(ctx, in, &aug->flags, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2972 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2973 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2974 | LY_CHECK_RET(parse_when(ctx, in, &aug->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2975 | break; |
| 2976 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2977 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2978 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "augment"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2979 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2980 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2981 | LY_CHECK_RET(parse_any(ctx, in, kw, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2982 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2983 | case LY_STMT_CASE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2984 | LY_CHECK_RET(parse_case(ctx, in, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2985 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2986 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2987 | LY_CHECK_RET(parse_choice(ctx, in, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2988 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2989 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2990 | LY_CHECK_RET(parse_container(ctx, in, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2991 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2992 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2993 | LY_CHECK_RET(parse_leaf(ctx, in, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2994 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2995 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2996 | LY_CHECK_RET(parse_leaflist(ctx, in, (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_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2999 | LY_CHECK_RET(parse_list(ctx, in, (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_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3002 | LY_CHECK_RET(parse_uses(ctx, in, (struct lysp_node *)aug, &aug->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3003 | break; |
| 3004 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3005 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3006 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "augment"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3007 | LY_CHECK_RET(parse_action(ctx, in, (struct lysp_node *)aug, &aug->actions)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3008 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3009 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3010 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "augment"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3011 | LY_CHECK_RET(parse_notif(ctx, in, (struct lysp_node *)aug, &aug->notifs)); |
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_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3014 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3015 | break; |
| 3016 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3017 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "augment"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3018 | return LY_EVALID; |
| 3019 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3020 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3021 | LY_CHECK_RET(ret); |
| 3022 | checks: |
| 3023 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3024 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, NULL, NULL, aug->actions, aug->notifs)); |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3025 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3026 | return ret; |
| 3027 | } |
| 3028 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3029 | /** |
| 3030 | * @brief Parse the uses statement. |
| 3031 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3032 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3033 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3034 | * @param[in,out] siblings Siblings to add to. |
| 3035 | * |
| 3036 | * @return LY_ERR values. |
| 3037 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3038 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3039 | parse_uses(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3040 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3041 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3042 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3043 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3044 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3045 | struct lysp_node_uses *uses; |
| 3046 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3047 | /* create uses structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3048 | LY_LIST_NEW_RET(ctx->ctx, siblings, uses, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3049 | uses->nodetype = LYS_USES; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3050 | uses->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3051 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3052 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3053 | LY_CHECK_RET(get_argument(ctx, in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3054 | INSERT_WORD(ctx, buf, uses->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3055 | |
| 3056 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3057 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3058 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3059 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3060 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &uses->dsc, Y_STR_ARG, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3061 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3062 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3063 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &uses->iffeatures, Y_STR_ARG, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3064 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3065 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3066 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &uses->ref, Y_STR_ARG, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3067 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3068 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3069 | LY_CHECK_RET(parse_status(ctx, in, &uses->flags, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3070 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3071 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3072 | LY_CHECK_RET(parse_when(ctx, in, &uses->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3073 | break; |
| 3074 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3075 | case LY_STMT_REFINE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3076 | LY_CHECK_RET(parse_refine(ctx, in, &uses->refines)); |
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_AUGMENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3079 | LY_CHECK_RET(parse_augment(ctx, in, (struct lysp_node *)uses, &uses->augments)); |
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_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3082 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3083 | break; |
| 3084 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3085 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "uses"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3086 | return LY_EVALID; |
| 3087 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3088 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3089 | checks: |
| 3090 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3091 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, NULL, uses->augments, NULL, NULL)); |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3092 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3093 | return ret; |
| 3094 | } |
| 3095 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3096 | /** |
| 3097 | * @brief Parse the case statement. |
| 3098 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3099 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3100 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3101 | * @param[in,out] siblings Siblings to add to. |
| 3102 | * |
| 3103 | * @return LY_ERR values. |
| 3104 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3105 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3106 | parse_case(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3107 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3108 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3109 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3110 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3111 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3112 | struct lysp_node_case *cas; |
| 3113 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3114 | /* create new case structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3115 | LY_LIST_NEW_RET(ctx->ctx, siblings, cas, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3116 | cas->nodetype = LYS_CASE; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3117 | cas->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3118 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3119 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3120 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3121 | INSERT_WORD(ctx, buf, cas->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3122 | |
| 3123 | /* parse substatements */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3124 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3125 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3126 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3127 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &cas->dsc, Y_STR_ARG, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3128 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3129 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3130 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &cas->iffeatures, Y_STR_ARG, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3131 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3132 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3133 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &cas->ref, 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_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3136 | LY_CHECK_RET(parse_status(ctx, in, &cas->flags, &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_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3139 | LY_CHECK_RET(parse_when(ctx, in, &cas->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3140 | break; |
| 3141 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3142 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3143 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "case"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3144 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3145 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3146 | LY_CHECK_RET(parse_any(ctx, in, kw, (struct lysp_node *)cas, &cas->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3147 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3148 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3149 | LY_CHECK_RET(parse_choice(ctx, in, (struct lysp_node *)cas, &cas->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3150 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3151 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3152 | LY_CHECK_RET(parse_container(ctx, in, (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_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3155 | LY_CHECK_RET(parse_leaf(ctx, in, (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_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3158 | LY_CHECK_RET(parse_leaflist(ctx, in, (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_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3161 | LY_CHECK_RET(parse_list(ctx, in, (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_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3164 | LY_CHECK_RET(parse_uses(ctx, in, (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_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3167 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3168 | break; |
| 3169 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3170 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "case"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3171 | return LY_EVALID; |
| 3172 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3173 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3174 | return ret; |
| 3175 | } |
| 3176 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3177 | /** |
| 3178 | * @brief Parse the choice statement. |
| 3179 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3180 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3181 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3182 | * @param[in,out] siblings Siblings to add to. |
| 3183 | * |
| 3184 | * @return LY_ERR values. |
| 3185 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3186 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3187 | parse_choice(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3188 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3189 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3190 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3191 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3192 | enum ly_stmt kw; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3193 | struct lysp_node_choice *choice; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3194 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3195 | /* create new choice structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3196 | LY_LIST_NEW_RET(ctx->ctx, siblings, choice, next, LY_EMEM); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3197 | choice->nodetype = LYS_CHOICE; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3198 | choice->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3199 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3200 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3201 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3202 | INSERT_WORD(ctx, buf, choice->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3203 | |
| 3204 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3205 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3206 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3207 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3208 | LY_CHECK_RET(parse_config(ctx, in, &choice->flags, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3209 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3210 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3211 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &choice->dsc, Y_STR_ARG, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3212 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3213 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3214 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &choice->iffeatures, Y_STR_ARG, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3215 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3216 | case LY_STMT_MANDATORY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3217 | LY_CHECK_RET(parse_mandatory(ctx, in, &choice->flags, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3218 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3219 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3220 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &choice->ref, Y_STR_ARG, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3221 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3222 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3223 | LY_CHECK_RET(parse_status(ctx, in, &choice->flags, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3224 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3225 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3226 | LY_CHECK_RET(parse_when(ctx, in, &choice->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3227 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3228 | case LY_STMT_DEFAULT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3229 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DEFAULT, 0, &choice->dflt, Y_PREF_IDENTIF_ARG, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3230 | break; |
| 3231 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3232 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3233 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "choice"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3234 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3235 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3236 | LY_CHECK_RET(parse_any(ctx, in, kw, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3237 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3238 | case LY_STMT_CASE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3239 | LY_CHECK_RET(parse_case(ctx, in, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3240 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3241 | case LY_STMT_CHOICE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3242 | PARSER_CHECK_STMTVER2_RET(ctx, "choice", "choice"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3243 | LY_CHECK_RET(parse_choice(ctx, in, (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_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3246 | LY_CHECK_RET(parse_container(ctx, in, (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_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3249 | LY_CHECK_RET(parse_leaf(ctx, in, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3250 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3251 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3252 | LY_CHECK_RET(parse_leaflist(ctx, in, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3253 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3254 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3255 | LY_CHECK_RET(parse_list(ctx, in, (struct lysp_node *)choice, &choice->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3256 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3257 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3258 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3259 | break; |
| 3260 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3261 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "choice"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3262 | return LY_EVALID; |
| 3263 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3264 | } |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 3265 | LY_CHECK_RET(ret); |
| 3266 | checks: |
| 3267 | if ((choice->flags & LYS_MAND_TRUE) && choice->dflt) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3268 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMSCOMB, "mandatory", "default", "choice"); |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 3269 | return LY_EVALID; |
| 3270 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3271 | return ret; |
| 3272 | } |
| 3273 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3274 | /** |
| 3275 | * @brief Parse the container statement. |
| 3276 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3277 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3278 | * @param[in,out] in Input structure. |
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 |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3284 | parse_container(struct lys_yang_parser_ctx *ctx, struct ly_in *in, 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 */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3293 | LY_LIST_NEW_RET(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 */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3298 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3299 | INSERT_WORD(ctx, buf, cont->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3300 | |
| 3301 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3302 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
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: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3305 | LY_CHECK_RET(parse_config(ctx, in, &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: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3308 | LY_CHECK_RET(parse_text_field(ctx, in, 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: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3311 | LY_CHECK_RET(parse_text_fields(ctx, in, 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: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3314 | LY_CHECK_RET(parse_text_field(ctx, in, 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: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3317 | LY_CHECK_RET(parse_status(ctx, in, &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: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3320 | LY_CHECK_RET(parse_when(ctx, in, &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: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3323 | LY_CHECK_RET(parse_text_field(ctx, in, 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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3330 | LY_CHECK_RET(parse_any(ctx, in, 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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3333 | LY_CHECK_RET(parse_choice(ctx, in, (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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3336 | LY_CHECK_RET(parse_container(ctx, in, (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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3339 | LY_CHECK_RET(parse_leaf(ctx, in, (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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3342 | LY_CHECK_RET(parse_leaflist(ctx, in, (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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3345 | LY_CHECK_RET(parse_list(ctx, in, (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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3348 | LY_CHECK_RET(parse_uses(ctx, in, (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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3352 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)cont, in, &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: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3355 | LY_CHECK_RET(parse_restrs(ctx, in, 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"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3359 | LY_CHECK_RET(parse_action(ctx, in, (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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3362 | LY_CHECK_RET(parse_grouping(ctx, in, (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"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3366 | LY_CHECK_RET(parse_notif(ctx, in, (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: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3369 | LY_CHECK_RET(parse_ext(ctx, in, 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 | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3376 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 3377 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3378 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, cont->groupings, NULL, cont->actions, cont->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3379 | return ret; |
| 3380 | } |
| 3381 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3382 | /** |
| 3383 | * @brief Parse the list statement. |
| 3384 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3385 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3386 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3387 | * @param[in,out] siblings Siblings to add to. |
| 3388 | * |
| 3389 | * @return LY_ERR values. |
| 3390 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3391 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3392 | parse_list(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3393 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3394 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3395 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3396 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3397 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3398 | struct lysp_node_list *list; |
| 3399 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3400 | /* create new list structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3401 | LY_LIST_NEW_RET(ctx->ctx, siblings, list, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3402 | list->nodetype = LYS_LIST; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3403 | list->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3404 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3405 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3406 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3407 | INSERT_WORD(ctx, buf, list->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3408 | |
| 3409 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3410 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3411 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3412 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3413 | LY_CHECK_RET(parse_config(ctx, in, &list->flags, &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_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3416 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &list->dsc, 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_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3419 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &list->iffeatures, 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_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3422 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &list->ref, Y_STR_ARG, &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_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3425 | LY_CHECK_RET(parse_status(ctx, in, &list->flags, &list->exts)); |
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_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3428 | LY_CHECK_RET(parse_when(ctx, in, &list->when)); |
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_KEY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3431 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_KEY, 0, &list->key, Y_STR_ARG, &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_MAX_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3434 | LY_CHECK_RET(parse_maxelements(ctx, in, &list->max, &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_MIN_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3437 | LY_CHECK_RET(parse_minelements(ctx, in, &list->min, &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_ORDERED_BY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3440 | LY_CHECK_RET(parse_orderedby(ctx, in, &list->flags, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3441 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3442 | case LY_STMT_UNIQUE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3443 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_UNIQUE, &list->uniques, Y_STR_ARG, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3444 | break; |
| 3445 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3446 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3447 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "list"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3448 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3449 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3450 | LY_CHECK_RET(parse_any(ctx, in, kw, (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_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3453 | LY_CHECK_RET(parse_choice(ctx, in, (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_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3456 | LY_CHECK_RET(parse_container(ctx, in, (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: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3459 | LY_CHECK_RET(parse_leaf(ctx, in, (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_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3462 | LY_CHECK_RET(parse_leaflist(ctx, in, (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_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3465 | LY_CHECK_RET(parse_list(ctx, in, (struct lysp_node *)list, &list->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3466 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3467 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3468 | LY_CHECK_RET(parse_uses(ctx, in, (struct lysp_node *)list, &list->child)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3469 | break; |
| 3470 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3471 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3472 | LY_CHECK_RET(parse_typedef(ctx, (struct lysp_node *)list, in, &list->typedefs)); |
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_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3475 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &list->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3476 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3477 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3478 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "list"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3479 | LY_CHECK_RET(parse_action(ctx, in, (struct lysp_node *)list, &list->actions)); |
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_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3482 | LY_CHECK_RET(parse_grouping(ctx, in, (struct lysp_node *)list, &list->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3483 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3484 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3485 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "list"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3486 | LY_CHECK_RET(parse_notif(ctx, in, (struct lysp_node *)list, &list->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3487 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3488 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3489 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3490 | break; |
| 3491 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3492 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "list"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3493 | return LY_EVALID; |
| 3494 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3495 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 3496 | LY_CHECK_RET(ret); |
| 3497 | checks: |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3498 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3499 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, list->groupings, NULL, list->actions, list->notifs)); |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3500 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 3501 | if (list->max && list->min > list->max) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3502 | LOGVAL_PARSER(ctx, LYVE_SEMANTICS, |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 3503 | "Invalid combination of min-elements and max-elements: min value %u is bigger than the max value %u.", |
| 3504 | list->min, list->max); |
| 3505 | return LY_EVALID; |
| 3506 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3507 | |
| 3508 | return ret; |
| 3509 | } |
| 3510 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3511 | /** |
| 3512 | * @brief Parse the yin-element statement. |
| 3513 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3514 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3515 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3516 | * @param[in,out] flags Flags to write to. |
| 3517 | * @param[in,out] exts Extension instances to add to. |
| 3518 | * |
| 3519 | * @return LY_ERR values. |
| 3520 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3521 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3522 | parse_yinelement(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3523 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3524 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3525 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3526 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3527 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3528 | |
| 3529 | if (*flags & LYS_YINELEM_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3530 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "yin-element"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3531 | return LY_EVALID; |
| 3532 | } |
| 3533 | |
| 3534 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3535 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3536 | |
| 3537 | if ((word_len == 4) && !strncmp(word, "true", word_len)) { |
| 3538 | *flags |= LYS_YINELEM_TRUE; |
| 3539 | } else if ((word_len == 5) && !strncmp(word, "false", word_len)) { |
| 3540 | *flags |= LYS_YINELEM_FALSE; |
| 3541 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3542 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "yin-element"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3543 | free(buf); |
| 3544 | return LY_EVALID; |
| 3545 | } |
| 3546 | free(buf); |
| 3547 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3548 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3549 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3550 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3551 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_YINELEM, 0, exts)); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3552 | LY_CHECK_RET(ret); |
| 3553 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3554 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3555 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "yin-element"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3556 | return LY_EVALID; |
| 3557 | } |
| 3558 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3559 | return ret; |
| 3560 | } |
| 3561 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3562 | /** |
David Sedlák | 2444f8f | 2019-07-09 11:02:47 +0200 | [diff] [blame] | 3563 | * @brief Parse the argument statement. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3564 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3565 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3566 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3567 | * @param[in,out] argument Value to write to. |
| 3568 | * @param[in,out] flags Flags to write to. |
| 3569 | * @param[in,out] exts Extension instances to add to. |
| 3570 | * |
| 3571 | * @return LY_ERR values. |
| 3572 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3573 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3574 | parse_argument(struct lys_yang_parser_ctx *ctx, struct ly_in *in, const char **argument, uint16_t *flags, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3575 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3576 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3577 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3578 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3579 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3580 | |
| 3581 | if (*argument) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3582 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "argument"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3583 | return LY_EVALID; |
| 3584 | } |
| 3585 | |
| 3586 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3587 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3588 | INSERT_WORD(ctx, buf, *argument, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3589 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3590 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3591 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3592 | case LY_STMT_YIN_ELEMENT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3593 | LY_CHECK_RET(parse_yinelement(ctx, in, flags, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3594 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3595 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3596 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_ARGUMENT, 0, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3597 | break; |
| 3598 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3599 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "argument"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3600 | return LY_EVALID; |
| 3601 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3602 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3603 | return ret; |
| 3604 | } |
| 3605 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3606 | /** |
| 3607 | * @brief Parse the extension statement. |
| 3608 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3609 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3610 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3611 | * @param[in,out] extensions Extensions to add to. |
| 3612 | * |
| 3613 | * @return LY_ERR values. |
| 3614 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3615 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3616 | parse_extension(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_ext **extensions) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3617 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3618 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3619 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3620 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3621 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3622 | struct lysp_ext *ex; |
| 3623 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 3624 | LY_ARRAY_NEW_RET(ctx->ctx, *extensions, ex, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3625 | |
| 3626 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3627 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3628 | INSERT_WORD(ctx, buf, ex->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3629 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3630 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3631 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3632 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3633 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &ex->dsc, Y_STR_ARG, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3634 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3635 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3636 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &ex->ref, Y_STR_ARG, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3637 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3638 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3639 | LY_CHECK_RET(parse_status(ctx, in, &ex->flags, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3640 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3641 | case LY_STMT_ARGUMENT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3642 | LY_CHECK_RET(parse_argument(ctx, in, &ex->argument, &ex->flags, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3643 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3644 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3645 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3646 | break; |
| 3647 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3648 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "extension"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3649 | return LY_EVALID; |
| 3650 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3651 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3652 | return ret; |
| 3653 | } |
| 3654 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3655 | /** |
| 3656 | * @brief Parse the deviate statement. |
| 3657 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3658 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3659 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3660 | * @param[in,out] deviates Deviates to add to. |
| 3661 | * |
| 3662 | * @return LY_ERR values. |
| 3663 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3664 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3665 | parse_deviate(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_deviate **deviates) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3666 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3667 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3668 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3669 | size_t word_len, dev_mod; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3670 | enum ly_stmt kw; |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3671 | struct lysp_deviate *d; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3672 | struct lysp_deviate_add *d_add = NULL; |
| 3673 | struct lysp_deviate_rpl *d_rpl = NULL; |
| 3674 | struct lysp_deviate_del *d_del = NULL; |
Radek Krejci | 4ad42aa | 2019-07-23 16:55:58 +0200 | [diff] [blame] | 3675 | const char **d_units = NULL, ***d_uniques = NULL, ***d_dflts = NULL; |
| 3676 | struct lysp_restr **d_musts = NULL; |
| 3677 | uint16_t *d_flags = 0; |
| 3678 | uint32_t *d_min = 0, *d_max = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3679 | |
| 3680 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3681 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3682 | |
| 3683 | if ((word_len == 13) && !strncmp(word, "not-supported", word_len)) { |
| 3684 | dev_mod = LYS_DEV_NOT_SUPPORTED; |
| 3685 | } else if ((word_len == 3) && !strncmp(word, "add", word_len)) { |
| 3686 | dev_mod = LYS_DEV_ADD; |
| 3687 | } else if ((word_len == 7) && !strncmp(word, "replace", word_len)) { |
| 3688 | dev_mod = LYS_DEV_REPLACE; |
| 3689 | } else if ((word_len == 6) && !strncmp(word, "delete", word_len)) { |
| 3690 | dev_mod = LYS_DEV_DELETE; |
| 3691 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3692 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "deviate"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3693 | free(buf); |
| 3694 | return LY_EVALID; |
| 3695 | } |
| 3696 | free(buf); |
| 3697 | |
| 3698 | /* create structure */ |
| 3699 | switch (dev_mod) { |
| 3700 | case LYS_DEV_NOT_SUPPORTED: |
| 3701 | d = calloc(1, sizeof *d); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3702 | LY_CHECK_ERR_RET(!d, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3703 | break; |
| 3704 | case LYS_DEV_ADD: |
| 3705 | d_add = calloc(1, sizeof *d_add); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3706 | LY_CHECK_ERR_RET(!d_add, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3707 | d = (struct lysp_deviate *)d_add; |
| 3708 | d_units = &d_add->units; |
| 3709 | d_uniques = &d_add->uniques; |
| 3710 | d_dflts = &d_add->dflts; |
| 3711 | d_musts = &d_add->musts; |
| 3712 | d_flags = &d_add->flags; |
| 3713 | d_min = &d_add->min; |
| 3714 | d_max = &d_add->max; |
| 3715 | break; |
| 3716 | case LYS_DEV_REPLACE: |
| 3717 | d_rpl = calloc(1, sizeof *d_rpl); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3718 | LY_CHECK_ERR_RET(!d_rpl, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3719 | d = (struct lysp_deviate *)d_rpl; |
| 3720 | d_units = &d_rpl->units; |
| 3721 | d_flags = &d_rpl->flags; |
| 3722 | d_min = &d_rpl->min; |
| 3723 | d_max = &d_rpl->max; |
| 3724 | break; |
| 3725 | case LYS_DEV_DELETE: |
| 3726 | d_del = calloc(1, sizeof *d_del); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3727 | LY_CHECK_ERR_RET(!d_del, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3728 | d = (struct lysp_deviate *)d_del; |
| 3729 | d_units = &d_del->units; |
| 3730 | d_uniques = &d_del->uniques; |
| 3731 | d_dflts = &d_del->dflts; |
| 3732 | d_musts = &d_del->musts; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3733 | break; |
| 3734 | default: |
| 3735 | assert(0); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3736 | LOGINT_RET(ctx->ctx); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3737 | } |
| 3738 | d->mod = dev_mod; |
| 3739 | |
| 3740 | /* insert into siblings */ |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3741 | LY_LIST_INSERT(deviates, d, next); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3742 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3743 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3744 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3745 | case LY_STMT_CONFIG: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3746 | switch (dev_mod) { |
| 3747 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3748 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3749 | 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] | 3750 | return LY_EVALID; |
| 3751 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3752 | LY_CHECK_RET(parse_config(ctx, in, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3753 | break; |
| 3754 | } |
| 3755 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3756 | case LY_STMT_DEFAULT: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3757 | switch (dev_mod) { |
| 3758 | case LYS_DEV_NOT_SUPPORTED: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3759 | 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] | 3760 | return LY_EVALID; |
| 3761 | case LYS_DEV_REPLACE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3762 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DEFAULT, 0, &d_rpl->dflt, Y_STR_ARG, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3763 | break; |
| 3764 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3765 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_DEFAULT, d_dflts, Y_STR_ARG, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3766 | break; |
| 3767 | } |
| 3768 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3769 | case LY_STMT_MANDATORY: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3770 | switch (dev_mod) { |
| 3771 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3772 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3773 | 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] | 3774 | return LY_EVALID; |
| 3775 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3776 | LY_CHECK_RET(parse_mandatory(ctx, in, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3777 | break; |
| 3778 | } |
| 3779 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3780 | case LY_STMT_MAX_ELEMENTS: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3781 | switch (dev_mod) { |
| 3782 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3783 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3784 | 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] | 3785 | return LY_EVALID; |
| 3786 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3787 | LY_CHECK_RET(parse_maxelements(ctx, in, d_max, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3788 | break; |
| 3789 | } |
| 3790 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3791 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3792 | switch (dev_mod) { |
| 3793 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3794 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3795 | 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] | 3796 | return LY_EVALID; |
| 3797 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3798 | LY_CHECK_RET(parse_minelements(ctx, in, d_min, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3799 | break; |
| 3800 | } |
| 3801 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3802 | case LY_STMT_MUST: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3803 | switch (dev_mod) { |
| 3804 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3805 | case LYS_DEV_REPLACE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3806 | 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] | 3807 | return LY_EVALID; |
| 3808 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3809 | LY_CHECK_RET(parse_restrs(ctx, in, kw, d_musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3810 | break; |
| 3811 | } |
| 3812 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3813 | case LY_STMT_TYPE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3814 | switch (dev_mod) { |
| 3815 | case LYS_DEV_NOT_SUPPORTED: |
| 3816 | case LYS_DEV_ADD: |
| 3817 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3818 | 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] | 3819 | return LY_EVALID; |
| 3820 | default: |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 3821 | if (d_rpl->type) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3822 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(kw)); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 3823 | return LY_EVALID; |
| 3824 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3825 | d_rpl->type = calloc(1, sizeof *d_rpl->type); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3826 | LY_CHECK_ERR_RET(!d_rpl->type, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3827 | LY_CHECK_RET(parse_type(ctx, in, d_rpl->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3828 | break; |
| 3829 | } |
| 3830 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3831 | case LY_STMT_UNIQUE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3832 | switch (dev_mod) { |
| 3833 | case LYS_DEV_NOT_SUPPORTED: |
| 3834 | case LYS_DEV_REPLACE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3835 | 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] | 3836 | return LY_EVALID; |
| 3837 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3838 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_UNIQUE, d_uniques, Y_STR_ARG, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3839 | break; |
| 3840 | } |
| 3841 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3842 | case LY_STMT_UNITS: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3843 | switch (dev_mod) { |
| 3844 | case LYS_DEV_NOT_SUPPORTED: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3845 | 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] | 3846 | return LY_EVALID; |
| 3847 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3848 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_UNITS, 0, d_units, Y_STR_ARG, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3849 | break; |
| 3850 | } |
| 3851 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3852 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3853 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3854 | break; |
| 3855 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3856 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "deviate"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3857 | return LY_EVALID; |
| 3858 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3859 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3860 | return ret; |
| 3861 | } |
| 3862 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3863 | /** |
| 3864 | * @brief Parse the deviation statement. |
| 3865 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3866 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3867 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3868 | * @param[in,out] deviations Deviations to add to. |
| 3869 | * |
| 3870 | * @return LY_ERR values. |
| 3871 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3872 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3873 | parse_deviation(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_deviation **deviations) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3874 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3875 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3876 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3877 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3878 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3879 | struct lysp_deviation *dev; |
| 3880 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 3881 | LY_ARRAY_NEW_RET(ctx->ctx, *deviations, dev, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3882 | |
| 3883 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3884 | LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3885 | CHECK_NONEMPTY(ctx, word_len, "deviation"); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3886 | INSERT_WORD(ctx, buf, dev->nodeid, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3887 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3888 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3889 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3890 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3891 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &dev->dsc, Y_STR_ARG, &dev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3892 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3893 | case LY_STMT_DEVIATE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3894 | LY_CHECK_RET(parse_deviate(ctx, in, &dev->deviates)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3895 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3896 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3897 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &dev->ref, Y_STR_ARG, &dev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3898 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3899 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3900 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &dev->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3901 | break; |
| 3902 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3903 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "deviation"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3904 | return LY_EVALID; |
| 3905 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3906 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 3907 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 3908 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3909 | /* mandatory substatements */ |
| 3910 | if (!dev->deviates) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3911 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "deviate", "deviation"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3912 | return LY_EVALID; |
| 3913 | } |
| 3914 | |
| 3915 | return ret; |
| 3916 | } |
| 3917 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3918 | /** |
| 3919 | * @brief Parse the feature statement. |
| 3920 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3921 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3922 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3923 | * @param[in,out] features Features to add to. |
| 3924 | * |
| 3925 | * @return LY_ERR values. |
| 3926 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3927 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3928 | parse_feature(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_feature **features) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3929 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3930 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3931 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3932 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3933 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3934 | struct lysp_feature *feat; |
| 3935 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 3936 | LY_ARRAY_NEW_RET(ctx->ctx, *features, feat, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3937 | |
| 3938 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3939 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3940 | INSERT_WORD(ctx, buf, feat->name, word, word_len); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 3941 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3942 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3943 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3944 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3945 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &feat->dsc, Y_STR_ARG, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3946 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3947 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3948 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &feat->iffeatures, Y_STR_ARG, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3949 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3950 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3951 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &feat->ref, Y_STR_ARG, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3952 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3953 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3954 | LY_CHECK_RET(parse_status(ctx, in, &feat->flags, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3955 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3956 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3957 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3958 | break; |
| 3959 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3960 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "feature"); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 3961 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3962 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3963 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3964 | return ret; |
| 3965 | } |
| 3966 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3967 | /** |
| 3968 | * @brief Parse the identity statement. |
| 3969 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3970 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3971 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3972 | * @param[in,out] identities Identities to add to. |
| 3973 | * |
| 3974 | * @return LY_ERR values. |
| 3975 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3976 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3977 | parse_identity(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_ident **identities) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3978 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3979 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3980 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3981 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3982 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3983 | struct lysp_ident *ident; |
| 3984 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 3985 | LY_ARRAY_NEW_RET(ctx->ctx, *identities, ident, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3986 | |
| 3987 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3988 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3989 | INSERT_WORD(ctx, buf, ident->name, word, word_len); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 3990 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3991 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3992 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3993 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3994 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &ident->dsc, Y_STR_ARG, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3995 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3996 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3997 | PARSER_CHECK_STMTVER2_RET(ctx, "if-feature", "identity"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3998 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &ident->iffeatures, Y_STR_ARG, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3999 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4000 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4001 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &ident->ref, Y_STR_ARG, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4002 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4003 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4004 | LY_CHECK_RET(parse_status(ctx, in, &ident->flags, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4005 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4006 | case LY_STMT_BASE: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4007 | if (ident->bases && ctx->mod_version < 2) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4008 | 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] | 4009 | return LY_EVALID; |
| 4010 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4011 | LY_CHECK_RET(parse_text_fields(ctx, in, LYEXT_SUBSTMT_BASE, &ident->bases, Y_PREF_IDENTIF_ARG, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4012 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4013 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4014 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4015 | break; |
| 4016 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4017 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "identity"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4018 | return LY_EVALID; |
| 4019 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4020 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4021 | return ret; |
| 4022 | } |
| 4023 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4024 | /** |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4025 | * @brief Parse module substatements. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4026 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 4027 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4028 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4029 | * @param[in,out] mod Module to write to. |
| 4030 | * |
| 4031 | * @return LY_ERR values. |
| 4032 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 4033 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4034 | parse_module(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_module *mod) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4035 | { |
| 4036 | LY_ERR ret = 0; |
| 4037 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 4038 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4039 | enum ly_stmt kw, prev_kw = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4040 | enum yang_module_stmt mod_stmt = Y_MOD_MODULE_HEADER; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4041 | struct lysp_submodule *dup; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4042 | |
| 4043 | /* (sub)module name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4044 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4045 | INSERT_WORD(ctx, buf, mod->mod->name, word, word_len); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 4046 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4047 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4048 | |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4049 | #define CHECK_ORDER(SECTION) \ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4050 | 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] | 4051 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4052 | switch (kw) { |
| 4053 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4054 | case LY_STMT_NAMESPACE: |
| 4055 | case LY_STMT_PREFIX: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4056 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
| 4057 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4058 | case LY_STMT_YANG_VERSION: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4059 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4060 | break; |
| 4061 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4062 | case LY_STMT_INCLUDE: |
| 4063 | case LY_STMT_IMPORT: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4064 | CHECK_ORDER(Y_MOD_LINKAGE); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4065 | break; |
| 4066 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4067 | case LY_STMT_ORGANIZATION: |
| 4068 | case LY_STMT_CONTACT: |
| 4069 | case LY_STMT_DESCRIPTION: |
| 4070 | case LY_STMT_REFERENCE: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4071 | CHECK_ORDER(Y_MOD_META); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4072 | break; |
| 4073 | |
| 4074 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4075 | case LY_STMT_REVISION: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4076 | CHECK_ORDER(Y_MOD_REVISION); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4077 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4078 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4079 | case LY_STMT_ANYDATA: |
| 4080 | case LY_STMT_ANYXML: |
| 4081 | case LY_STMT_AUGMENT: |
| 4082 | case LY_STMT_CHOICE: |
| 4083 | case LY_STMT_CONTAINER: |
| 4084 | case LY_STMT_DEVIATION: |
| 4085 | case LY_STMT_EXTENSION: |
| 4086 | case LY_STMT_FEATURE: |
| 4087 | case LY_STMT_GROUPING: |
| 4088 | case LY_STMT_IDENTITY: |
| 4089 | case LY_STMT_LEAF: |
| 4090 | case LY_STMT_LEAF_LIST: |
| 4091 | case LY_STMT_LIST: |
| 4092 | case LY_STMT_NOTIFICATION: |
| 4093 | case LY_STMT_RPC: |
| 4094 | case LY_STMT_TYPEDEF: |
| 4095 | case LY_STMT_USES: |
| 4096 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4097 | mod_stmt = Y_MOD_BODY; |
| 4098 | break; |
| 4099 | default: |
| 4100 | /* error handled in the next switch */ |
| 4101 | break; |
| 4102 | } |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4103 | #undef CHECK_ORDER |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4104 | |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4105 | prev_kw = kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4106 | switch (kw) { |
| 4107 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4108 | case LY_STMT_YANG_VERSION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4109 | LY_CHECK_RET(parse_yangversion(ctx, in, &mod->mod->version, &mod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4110 | ctx->mod_version = mod->mod->version; |
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_NAMESPACE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4113 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_NAMESPACE, 0, &mod->mod->ns, 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_PREFIX: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4116 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_PREFIX, 0, &mod->mod->prefix, Y_IDENTIF_ARG, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4117 | break; |
| 4118 | |
| 4119 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4120 | case LY_STMT_INCLUDE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4121 | LY_CHECK_RET(parse_include(ctx, mod->mod->name, in, &mod->includes)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4122 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4123 | case LY_STMT_IMPORT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4124 | LY_CHECK_RET(parse_import(ctx, mod->mod->prefix, in, &mod->imports)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4125 | break; |
| 4126 | |
| 4127 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4128 | case LY_STMT_ORGANIZATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4129 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_ORGANIZATION, 0, &mod->mod->org, Y_STR_ARG, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4130 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4131 | case LY_STMT_CONTACT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4132 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_CONTACT, 0, &mod->mod->contact, Y_STR_ARG, &mod->exts)); |
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_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4135 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &mod->mod->dsc, Y_STR_ARG, &mod->exts)); |
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_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4138 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &mod->mod->ref, Y_STR_ARG, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4139 | break; |
| 4140 | |
| 4141 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4142 | case LY_STMT_REVISION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4143 | LY_CHECK_RET(parse_revision(ctx, in, &mod->revs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4144 | break; |
| 4145 | |
| 4146 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4147 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 4148 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "module"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 4149 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4150 | case LY_STMT_ANYXML: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4151 | LY_CHECK_RET(parse_any(ctx, in, kw, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4152 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4153 | case LY_STMT_CHOICE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4154 | LY_CHECK_RET(parse_choice(ctx, in, NULL, &mod->data)); |
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_CONTAINER: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4157 | LY_CHECK_RET(parse_container(ctx, in, NULL, &mod->data)); |
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_LEAF: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4160 | LY_CHECK_RET(parse_leaf(ctx, in, NULL, &mod->data)); |
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_LEAF_LIST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4163 | LY_CHECK_RET(parse_leaflist(ctx, in, NULL, &mod->data)); |
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_LIST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4166 | LY_CHECK_RET(parse_list(ctx, in, NULL, &mod->data)); |
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_USES: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4169 | LY_CHECK_RET(parse_uses(ctx, in, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4170 | break; |
| 4171 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4172 | case LY_STMT_AUGMENT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4173 | LY_CHECK_RET(parse_augment(ctx, in, NULL, &mod->augments)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4174 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4175 | case LY_STMT_DEVIATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4176 | LY_CHECK_RET(parse_deviation(ctx, in, &mod->deviations)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4177 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4178 | case LY_STMT_EXTENSION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4179 | LY_CHECK_RET(parse_extension(ctx, in, &mod->extensions)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4180 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4181 | case LY_STMT_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4182 | LY_CHECK_RET(parse_feature(ctx, in, &mod->features)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4183 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4184 | case LY_STMT_GROUPING: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4185 | LY_CHECK_RET(parse_grouping(ctx, in, NULL, &mod->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4186 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4187 | case LY_STMT_IDENTITY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4188 | LY_CHECK_RET(parse_identity(ctx, in, &mod->identities)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4189 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4190 | case LY_STMT_NOTIFICATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4191 | LY_CHECK_RET(parse_notif(ctx, in, NULL, &mod->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4192 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4193 | case LY_STMT_RPC: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4194 | LY_CHECK_RET(parse_action(ctx, in, NULL, &mod->rpcs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4195 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4196 | case LY_STMT_TYPEDEF: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4197 | LY_CHECK_RET(parse_typedef(ctx, NULL, in, &mod->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4198 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4199 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4200 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &mod->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4201 | break; |
| 4202 | |
| 4203 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4204 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "module"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4205 | return LY_EVALID; |
| 4206 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4207 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 4208 | LY_CHECK_RET(ret); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 4209 | |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 4210 | checks: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4211 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4212 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, mod->groupings, mod->augments, mod->rpcs, mod->notifs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4213 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4214 | /* mandatory substatements */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4215 | if (!mod->mod->ns) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4216 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "namespace", "module"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4217 | return LY_EVALID; |
| 4218 | } else if (!mod->mod->prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4219 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "prefix", "module"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4220 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4221 | } |
| 4222 | |
Radek Krejci | e9e987e | 2018-10-31 12:50:27 +0100 | [diff] [blame] | 4223 | /* submodules share the namespace with the module names, so there must not be |
| 4224 | * a submodule of the same name in the context, no need for revision matching */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4225 | dup = ly_ctx_get_submodule(ctx->ctx, NULL, mod->mod->name, NULL); |
| 4226 | if (dup) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4227 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Name collision between module and submodule of name \"%s\".", mod->mod->name); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4228 | return LY_EVALID; |
| 4229 | } |
| 4230 | |
| 4231 | return ret; |
| 4232 | } |
| 4233 | |
| 4234 | /** |
| 4235 | * @brief Parse submodule substatements. |
| 4236 | * |
| 4237 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4238 | * @param[in,out] in Input structure. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4239 | * @param[out] submod Parsed submodule structure. |
| 4240 | * |
| 4241 | * @return LY_ERR values. |
| 4242 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 4243 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4244 | parse_submodule(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_submodule *submod) |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4245 | { |
| 4246 | LY_ERR ret = 0; |
| 4247 | char *buf, *word; |
| 4248 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4249 | enum ly_stmt kw, prev_kw = 0; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4250 | enum yang_module_stmt mod_stmt = Y_MOD_MODULE_HEADER; |
| 4251 | struct lysp_submodule *dup; |
| 4252 | |
| 4253 | /* submodule name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4254 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4255 | INSERT_WORD(ctx, buf, submod->name, word, word_len); |
| 4256 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4257 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, goto checks) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4258 | |
| 4259 | #define CHECK_ORDER(SECTION) \ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4260 | 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] | 4261 | |
| 4262 | switch (kw) { |
| 4263 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4264 | case LY_STMT_BELONGS_TO: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4265 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
| 4266 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4267 | case LY_STMT_YANG_VERSION: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4268 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
| 4269 | break; |
| 4270 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4271 | case LY_STMT_INCLUDE: |
| 4272 | case LY_STMT_IMPORT: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4273 | CHECK_ORDER(Y_MOD_LINKAGE); |
| 4274 | break; |
| 4275 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4276 | case LY_STMT_ORGANIZATION: |
| 4277 | case LY_STMT_CONTACT: |
| 4278 | case LY_STMT_DESCRIPTION: |
| 4279 | case LY_STMT_REFERENCE: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4280 | CHECK_ORDER(Y_MOD_META); |
| 4281 | break; |
| 4282 | |
| 4283 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4284 | case LY_STMT_REVISION: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4285 | CHECK_ORDER(Y_MOD_REVISION); |
| 4286 | break; |
| 4287 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4288 | case LY_STMT_ANYDATA: |
| 4289 | case LY_STMT_ANYXML: |
| 4290 | case LY_STMT_AUGMENT: |
| 4291 | case LY_STMT_CHOICE: |
| 4292 | case LY_STMT_CONTAINER: |
| 4293 | case LY_STMT_DEVIATION: |
| 4294 | case LY_STMT_EXTENSION: |
| 4295 | case LY_STMT_FEATURE: |
| 4296 | case LY_STMT_GROUPING: |
| 4297 | case LY_STMT_IDENTITY: |
| 4298 | case LY_STMT_LEAF: |
| 4299 | case LY_STMT_LEAF_LIST: |
| 4300 | case LY_STMT_LIST: |
| 4301 | case LY_STMT_NOTIFICATION: |
| 4302 | case LY_STMT_RPC: |
| 4303 | case LY_STMT_TYPEDEF: |
| 4304 | case LY_STMT_USES: |
| 4305 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4306 | mod_stmt = Y_MOD_BODY; |
| 4307 | break; |
| 4308 | default: |
| 4309 | /* error handled in the next switch */ |
| 4310 | break; |
| 4311 | } |
| 4312 | #undef CHECK_ORDER |
| 4313 | |
| 4314 | prev_kw = kw; |
| 4315 | switch (kw) { |
| 4316 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4317 | case LY_STMT_YANG_VERSION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4318 | LY_CHECK_RET(parse_yangversion(ctx, in, &submod->version, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4319 | ctx->mod_version = submod->version; |
| 4320 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4321 | case LY_STMT_BELONGS_TO: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4322 | LY_CHECK_RET(parse_belongsto(ctx, in, &submod->belongsto, &submod->prefix, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4323 | break; |
| 4324 | |
| 4325 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4326 | case LY_STMT_INCLUDE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4327 | LY_CHECK_RET(parse_include(ctx, submod->name, in, &submod->includes)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4328 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4329 | case LY_STMT_IMPORT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4330 | LY_CHECK_RET(parse_import(ctx, submod->prefix, in, &submod->imports)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4331 | break; |
| 4332 | |
| 4333 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4334 | case LY_STMT_ORGANIZATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4335 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_ORGANIZATION, 0, &submod->org, Y_STR_ARG, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4336 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4337 | case LY_STMT_CONTACT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4338 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_CONTACT, 0, &submod->contact, Y_STR_ARG, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4339 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4340 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4341 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DESCRIPTION, 0, &submod->dsc, Y_STR_ARG, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4342 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4343 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4344 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_REFERENCE, 0, &submod->ref, Y_STR_ARG, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4345 | break; |
| 4346 | |
| 4347 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4348 | case LY_STMT_REVISION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4349 | LY_CHECK_RET(parse_revision(ctx, in, &submod->revs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4350 | break; |
| 4351 | |
| 4352 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4353 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 4354 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "submodule"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 4355 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4356 | case LY_STMT_ANYXML: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4357 | LY_CHECK_RET(parse_any(ctx, in, kw, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4358 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4359 | case LY_STMT_CHOICE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4360 | LY_CHECK_RET(parse_choice(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4361 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4362 | case LY_STMT_CONTAINER: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4363 | LY_CHECK_RET(parse_container(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4364 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4365 | case LY_STMT_LEAF: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4366 | LY_CHECK_RET(parse_leaf(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4367 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4368 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4369 | LY_CHECK_RET(parse_leaflist(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4370 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4371 | case LY_STMT_LIST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4372 | LY_CHECK_RET(parse_list(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4373 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4374 | case LY_STMT_USES: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4375 | LY_CHECK_RET(parse_uses(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4376 | break; |
| 4377 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4378 | case LY_STMT_AUGMENT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4379 | LY_CHECK_RET(parse_augment(ctx, in, NULL, &submod->augments)); |
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_DEVIATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4382 | LY_CHECK_RET(parse_deviation(ctx, in, &submod->deviations)); |
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_EXTENSION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4385 | LY_CHECK_RET(parse_extension(ctx, in, &submod->extensions)); |
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_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4388 | LY_CHECK_RET(parse_feature(ctx, in, &submod->features)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4389 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4390 | case LY_STMT_GROUPING: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4391 | LY_CHECK_RET(parse_grouping(ctx, in, NULL, &submod->groupings)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4392 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4393 | case LY_STMT_IDENTITY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4394 | LY_CHECK_RET(parse_identity(ctx, in, &submod->identities)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4395 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4396 | case LY_STMT_NOTIFICATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4397 | LY_CHECK_RET(parse_notif(ctx, in, NULL, &submod->notifs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4398 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4399 | case LY_STMT_RPC: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4400 | LY_CHECK_RET(parse_action(ctx, in, NULL, &submod->rpcs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4401 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4402 | case LY_STMT_TYPEDEF: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4403 | LY_CHECK_RET(parse_typedef(ctx, NULL, in, &submod->typedefs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4404 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4405 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4406 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, LYEXT_SUBSTMT_SELF, 0, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4407 | break; |
| 4408 | |
| 4409 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4410 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "submodule"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4411 | return LY_EVALID; |
| 4412 | } |
| 4413 | } |
| 4414 | LY_CHECK_RET(ret); |
| 4415 | |
| 4416 | checks: |
| 4417 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4418 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, submod->groupings, submod->augments, |
| 4419 | submod->rpcs, submod->notifs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4420 | |
| 4421 | /* mandatory substatements */ |
| 4422 | if (!submod->belongsto) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4423 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "belongs-to", "submodule"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4424 | return LY_EVALID; |
| 4425 | } |
| 4426 | |
| 4427 | /* submodules share the namespace with the module names, so there must not be |
| 4428 | * a submodule of the same name in the context, no need for revision matching */ |
| 4429 | dup = ly_ctx_get_submodule(ctx->ctx, NULL, submod->name, NULL); |
| 4430 | if (dup && strcmp(dup->belongsto, submod->belongsto)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4431 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Name collision between submodules of name \"%s\".", dup->name); |
Radek Krejci | e9e987e | 2018-10-31 12:50:27 +0100 | [diff] [blame] | 4432 | return LY_EVALID; |
| 4433 | } |
| 4434 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4435 | return ret; |
| 4436 | } |
| 4437 | |
Radek Krejci | d4557c6 | 2018-09-17 11:42:09 +0200 | [diff] [blame] | 4438 | LY_ERR |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4439 | 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] | 4440 | struct ly_in *in, struct lysp_submodule **submod) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4441 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 4442 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4443 | char *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 4444 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4445 | enum ly_stmt kw; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4446 | struct lysp_submodule *mod_p = NULL; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4447 | |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4448 | /* create context */ |
| 4449 | *context = calloc(1, sizeof **context); |
| 4450 | LY_CHECK_ERR_RET(!(*context), LOGMEM(ly_ctx), LY_EMEM); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4451 | (*context)->format = LYS_IN_YANG; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 4452 | (*context)->main_mod = main_ctx->main_mod; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4453 | (*context)->ctx = ly_ctx; |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 4454 | (*context)->pos_type = LY_VLOG_LINE; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4455 | (*context)->line = 1; |
| 4456 | |
| 4457 | /* map the typedefs and groupings list from main context to the submodule's context */ |
| 4458 | memcpy(&(*context)->tpdfs_nodes, &main_ctx->tpdfs_nodes, sizeof main_ctx->tpdfs_nodes); |
| 4459 | memcpy(&(*context)->grps_nodes, &main_ctx->grps_nodes, sizeof main_ctx->grps_nodes); |
| 4460 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4461 | /* "module"/"submodule" */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4462 | ret = get_keyword(*context, in, &kw, &word, &word_len); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4463 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4464 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4465 | if (kw == LY_STMT_MODULE) { |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4466 | LOGERR((*context)->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] | 4467 | ret = LY_EINVAL; |
| 4468 | goto cleanup; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4469 | } else if (kw != LY_STMT_SUBMODULE) { |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 4470 | LOGVAL_PARSER(*context, LY_VCODE_MOD_SUBOMD, ly_stmt2str(kw)); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 4471 | ret = LY_EVALID; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4472 | goto cleanup; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4473 | } |
| 4474 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4475 | mod_p = calloc(1, sizeof *mod_p); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4476 | LY_CHECK_ERR_GOTO(!mod_p, LOGMEM((*context)->ctx), cleanup); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4477 | mod_p->parsing = 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4478 | |
| 4479 | /* substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4480 | ret = parse_submodule(*context, in, mod_p); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4481 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4482 | |
| 4483 | /* read some trailing spaces or new lines */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4484 | while (isspace(in->current[0])) { |
| 4485 | ++in->current; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4486 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4487 | if (in->current[0]) { |
| 4488 | 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] | 4489 | ret = LY_EVALID; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4490 | goto cleanup; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4491 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4492 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4493 | mod_p->parsing = 0; |
| 4494 | *submod = mod_p; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4495 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4496 | cleanup: |
| 4497 | if (ret) { |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4498 | lysp_submodule_free((*context)->ctx, mod_p); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4499 | yang_parser_ctx_free(*context); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4500 | *context = NULL; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4501 | } |
| 4502 | |
| 4503 | return ret; |
| 4504 | } |
| 4505 | |
| 4506 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4507 | yang_parse_module(struct lys_yang_parser_ctx **context, struct ly_in *in, struct lys_module *mod) |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4508 | { |
| 4509 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4510 | char *word; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4511 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4512 | enum ly_stmt kw; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4513 | struct lysp_module *mod_p = NULL; |
| 4514 | |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4515 | /* create context */ |
| 4516 | *context = calloc(1, sizeof **context); |
| 4517 | LY_CHECK_ERR_RET(!(*context), LOGMEM(mod->ctx), LY_EMEM); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4518 | (*context)->format = LYS_IN_YANG; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 4519 | (*context)->main_mod = mod; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4520 | (*context)->ctx = mod->ctx; |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 4521 | (*context)->pos_type = LY_VLOG_LINE; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4522 | (*context)->line = 1; |
| 4523 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4524 | /* "module"/"submodule" */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4525 | ret = get_keyword(*context, in, &kw, &word, &word_len); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4526 | LY_CHECK_GOTO(ret, cleanup); |
| 4527 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4528 | if (kw == LY_STMT_SUBMODULE) { |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4529 | LOGERR((*context)->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] | 4530 | ret = LY_EINVAL; |
| 4531 | goto cleanup; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4532 | } else if (kw != LY_STMT_MODULE) { |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 4533 | LOGVAL_PARSER((*context), LY_VCODE_MOD_SUBOMD, ly_stmt2str(kw)); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 4534 | ret = LY_EVALID; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4535 | goto cleanup; |
| 4536 | } |
| 4537 | |
| 4538 | mod_p = calloc(1, sizeof *mod_p); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4539 | LY_CHECK_ERR_GOTO(!mod_p, LOGMEM((*context)->ctx), cleanup); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4540 | mod_p->mod = mod; |
| 4541 | mod_p->parsing = 1; |
| 4542 | |
| 4543 | /* substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4544 | ret = parse_module(*context, in, mod_p); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4545 | LY_CHECK_GOTO(ret, cleanup); |
| 4546 | |
| 4547 | /* read some trailing spaces or new lines */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4548 | while (isspace(in->current[0])) { |
| 4549 | ++in->current; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4550 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4551 | if (in->current[0]) { |
| 4552 | 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] | 4553 | ret = LY_EVALID; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4554 | goto cleanup; |
| 4555 | } |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4556 | |
| 4557 | mod_p->parsing = 0; |
| 4558 | mod->parsed = mod_p; |
| 4559 | |
| 4560 | cleanup: |
| 4561 | if (ret) { |
| 4562 | lysp_module_free(mod_p); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4563 | yang_parser_ctx_free(*context); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4564 | *context = NULL; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4565 | } |
| 4566 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4567 | return ret; |
| 4568 | } |