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" |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 28 | #include "parser_schema.h" |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 29 | #include "path.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 | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 43 | #define INSERT_WORD_RET(CTX, BUF, TARGET, WORD, LEN) \ |
| 44 | if (BUF) {LY_CHECK_RET(lydict_insert_zc((CTX)->ctx, WORD, &(TARGET)));}\ |
| 45 | else {LY_CHECK_RET(lydict_insert((CTX)->ctx, LEN ? WORD : "", LEN, &(TARGET)));} |
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 | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 142 | char **word_b, size_t *buf_len, ly_bool need_buf, uint8_t *prefix) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 143 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 144 | uint32_t c; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 145 | size_t len; |
| 146 | |
Radek Krejci | f29b7c3 | 2019-04-09 16:17:49 +0200 | [diff] [blame] | 147 | /* check valid combination of input paremeters - if need_buf specified, word_b must be provided */ |
| 148 | assert(!need_buf || (need_buf && word_b)); |
| 149 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 150 | /* get UTF8 code point (and number of bytes coding the character) */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 151 | LY_CHECK_ERR_RET(ly_getutf8(&in->current, &c, &len), |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 152 | LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, in->current[-len]), LY_EVALID); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 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; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 300 | ly_bool need_buf = 0; |
| 301 | uint8_t prefix = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 302 | const char *c; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 303 | uint64_t trailing_ws = 0; /* current number of stored trailing whitespace characters */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 304 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 305 | if (in->current[0] == '\"') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 306 | string = 2; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 307 | current_indent = block_indent = ctx->indent + 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 308 | } else { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 309 | assert(in->current[0] == '\''); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 310 | string = 1; |
| 311 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 312 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 313 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 314 | while (in->current[0] && string) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 315 | switch (string) { |
| 316 | case 1: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 317 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 318 | case '\'': |
| 319 | /* string may be finished, but check for + */ |
| 320 | string = 4; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 321 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 322 | break; |
| 323 | default: |
| 324 | /* check and store character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 325 | 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] | 326 | break; |
| 327 | } |
| 328 | break; |
| 329 | case 2: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 330 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 331 | case '\"': |
| 332 | /* string may be finished, but check for + */ |
| 333 | string = 4; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 334 | MOVE_INPUT(ctx, in, 1); |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 335 | trailing_ws = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 336 | break; |
| 337 | case '\\': |
| 338 | /* special character following */ |
| 339 | string = 3; |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 340 | |
| 341 | /* the backslash sequence is substituted, so we will need a buffer to store the result */ |
| 342 | need_buf = 1; |
| 343 | |
| 344 | /* move forward to the escaped character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 345 | ++in->current; |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 346 | |
| 347 | /* note that the trailing whitespaces are supposed to be trimmed before substitution of |
| 348 | * backslash-escaped characters (RFC 7950, 6.1.3), so we have to zero the trailing whitespaces counter */ |
| 349 | trailing_ws = 0; |
| 350 | |
| 351 | /* since the backslash-escaped character is handled as first non-whitespace character, stop eating indentation */ |
| 352 | current_indent = block_indent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 353 | break; |
| 354 | case ' ': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 355 | if (current_indent < block_indent) { |
| 356 | ++current_indent; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 357 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 358 | } else { |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 359 | /* check and store whitespace character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 360 | 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] | 361 | trailing_ws++; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 362 | } |
| 363 | break; |
| 364 | case '\t': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 365 | if (current_indent < block_indent) { |
| 366 | assert(need_buf); |
| 367 | current_indent += 8; |
| 368 | ctx->indent += 8; |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 369 | for ( ; current_indent > block_indent; --current_indent, --ctx->indent) { |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 370 | /* store leftover spaces from the tab */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 371 | c = in->current; |
| 372 | in->current = " "; |
| 373 | LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix)); |
| 374 | in->current = c; |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 375 | trailing_ws++; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 376 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 377 | ++in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 378 | } else { |
Michal Vasko | 90edde4 | 2019-11-25 15:25:07 +0100 | [diff] [blame] | 379 | /* check and store whitespace character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 380 | 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] | 381 | trailing_ws++; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 382 | /* additional characters for indentation - only 1 was count in buf_store_char */ |
| 383 | ctx->indent += 7; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 384 | } |
| 385 | break; |
| 386 | case '\n': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 387 | if (block_indent) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 388 | /* we will be removing the indents so we need our own buffer */ |
| 389 | need_buf = 1; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 390 | |
| 391 | /* remove trailing tabs and spaces */ |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 392 | (*word_len) = *word_len - trailing_ws; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 393 | |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 394 | /* restart indentation */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 395 | current_indent = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* check and store character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 399 | 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] | 400 | |
| 401 | /* maintain line number */ |
| 402 | ++ctx->line; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 403 | |
| 404 | /* reset context indentation counter for possible string after this one */ |
| 405 | ctx->indent = 0; |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 406 | trailing_ws = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 407 | break; |
| 408 | default: |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 409 | /* first non-whitespace character, stop eating indentation */ |
| 410 | current_indent = block_indent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 411 | |
| 412 | /* check and store character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 413 | 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] | 414 | trailing_ws = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 415 | break; |
| 416 | } |
| 417 | break; |
| 418 | case 3: |
| 419 | /* string encoded characters */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 420 | c = in->current; |
| 421 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 422 | case 'n': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 423 | in->current = "\n"; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 424 | break; |
| 425 | case 't': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 426 | in->current = "\t"; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 427 | break; |
| 428 | case '\"': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 429 | case '\\': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 430 | /* ok as is */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 431 | break; |
| 432 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 433 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Double-quoted string unknown special character '\\%c'.", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 434 | in->current[0]); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 435 | return LY_EVALID; |
| 436 | } |
| 437 | |
| 438 | /* check and store character */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 439 | 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] | 440 | |
| 441 | string = 2; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 442 | in->current = c + 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 443 | break; |
| 444 | case 4: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 445 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 446 | case '+': |
| 447 | /* string continues */ |
| 448 | string = 5; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 449 | need_buf = 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 450 | break; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 451 | case '\n': |
| 452 | ++ctx->line; |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 453 | /* fallthrough */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 454 | case ' ': |
| 455 | case '\t': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 456 | /* just skip */ |
| 457 | break; |
| 458 | default: |
| 459 | /* string is finished */ |
| 460 | goto string_end; |
| 461 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 462 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 463 | break; |
| 464 | case 5: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 465 | switch (in->current[0]) { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 466 | case '\n': |
| 467 | ++ctx->line; |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 468 | /* fallthrough */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 469 | case ' ': |
| 470 | case '\t': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 471 | /* skip */ |
| 472 | break; |
| 473 | case '\'': |
| 474 | string = 1; |
| 475 | break; |
| 476 | case '\"': |
| 477 | string = 2; |
| 478 | break; |
| 479 | default: |
| 480 | /* it must be quoted again */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 481 | 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] | 482 | return LY_EVALID; |
| 483 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 484 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 485 | break; |
| 486 | default: |
| 487 | return LY_EINT; |
| 488 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | string_end: |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 492 | if ((arg <= Y_PREF_IDENTIF_ARG) && !(*word_len)) { |
Radek Krejci | 4e199f5 | 2019-05-28 09:09:28 +0200 | [diff] [blame] | 493 | /* empty identifier */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 494 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Statement argument is required."); |
Radek Krejci | 4e199f5 | 2019-05-28 09:09:28 +0200 | [diff] [blame] | 495 | return LY_EVALID; |
| 496 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 497 | return LY_SUCCESS; |
| 498 | } |
| 499 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 500 | /** |
| 501 | * @brief Get another YANG string from the raw data. |
| 502 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 503 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 504 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 505 | * @param[in] arg Type of YANG keyword argument expected. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 506 | * @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] | 507 | * @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] | 508 | * @param[out] word_b Pointer to a dynamically-allocated buffer holding the read string. If not needed, |
| 509 | * set to NULL. Otherwise equal to \p word_p. |
| 510 | * @param[out] word_len Length of the read string. |
| 511 | * |
| 512 | * @return LY_ERR values. |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 513 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 514 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 515 | 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] | 516 | char **word_b, size_t *word_len) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 517 | { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 518 | size_t buf_len = 0; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 519 | uint8_t prefix = 0; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 520 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 521 | /* word buffer - dynamically allocated */ |
| 522 | *word_b = NULL; |
| 523 | |
| 524 | /* word pointer - just a pointer to data */ |
| 525 | *word_p = NULL; |
| 526 | |
| 527 | *word_len = 0; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 528 | while (in->current[0]) { |
| 529 | switch (in->current[0]) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 530 | case '\'': |
| 531 | case '\"': |
| 532 | if (*word_len) { |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 533 | /* 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] | 534 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, 1, in->current, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 535 | "unquoted string character, optsep, semicolon or opening brace"); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 536 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 537 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 538 | if (flags) { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 539 | (*flags) |= in->current[0] == '\'' ? LYS_SINGLEQUOTED : LYS_DOUBLEQUOTED; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 540 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 541 | 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] | 542 | goto str_end; |
| 543 | case '/': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 544 | if (in->current[1] == '/') { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 545 | /* one-line comment */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 546 | MOVE_INPUT(ctx, in, 2); |
| 547 | LY_CHECK_RET(skip_comment(ctx, in, 1)); |
| 548 | } else if (in->current[1] == '*') { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 549 | /* block comment */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 550 | MOVE_INPUT(ctx, in, 2); |
| 551 | LY_CHECK_RET(skip_comment(ctx, in, 2)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 552 | } else { |
| 553 | /* not a comment after all */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 554 | 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] | 555 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 556 | break; |
| 557 | case ' ': |
| 558 | if (*word_len) { |
| 559 | /* word is finished */ |
| 560 | goto str_end; |
| 561 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 562 | MOVE_INPUT(ctx, in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 563 | break; |
| 564 | case '\t': |
| 565 | if (*word_len) { |
| 566 | /* word is finished */ |
| 567 | goto str_end; |
| 568 | } |
| 569 | /* tabs count for 8 spaces */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 570 | ctx->indent += 8; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 571 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 572 | ++in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 573 | break; |
| 574 | case '\n': |
| 575 | if (*word_len) { |
| 576 | /* word is finished */ |
| 577 | goto str_end; |
| 578 | } |
| 579 | /* reset indent */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 580 | ctx->indent = 0; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 581 | |
| 582 | /* track line numbers */ |
| 583 | ++ctx->line; |
| 584 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 585 | ++in->current; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 586 | break; |
| 587 | case ';': |
| 588 | case '{': |
| 589 | if (*word_len || (arg == Y_MAYBE_STR_ARG)) { |
| 590 | /* word is finished */ |
| 591 | goto str_end; |
| 592 | } |
| 593 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 594 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, 1, in->current, "an argument"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 595 | return LY_EVALID; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 596 | case '}': |
| 597 | /* 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] | 598 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, 1, in->current, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 599 | "unquoted string character, optsep, semicolon or opening brace"); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 600 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 601 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 602 | 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] | 603 | break; |
| 604 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 605 | } |
| 606 | |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 607 | /* unexpected end of loop */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 608 | LOGVAL_PARSER(ctx, LY_VCODE_EOF); |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 609 | return LY_EVALID; |
| 610 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 611 | str_end: |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 612 | /* terminating NULL byte for buf */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 613 | if (*word_b) { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 614 | (*word_b) = ly_realloc(*word_b, (*word_len) + 1); |
| 615 | LY_CHECK_ERR_RET(!(*word_b), LOGMEM(ctx->ctx), LY_EMEM); |
| 616 | (*word_b)[*word_len] = '\0'; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 617 | *word_p = *word_b; |
| 618 | } |
| 619 | |
| 620 | return LY_SUCCESS; |
| 621 | } |
| 622 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 623 | /** |
| 624 | * @brief Get another YANG keyword from the raw data. |
| 625 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 626 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 627 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 628 | * @param[out] kw YANG keyword read. |
| 629 | * @param[out] word_p Pointer to the keyword in the data. Useful for extension instances. |
| 630 | * @param[out] word_len Length of the keyword in the data. Useful for extension instances. |
| 631 | * |
| 632 | * @return LY_ERR values. |
| 633 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 634 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 635 | 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] | 636 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 637 | uint8_t prefix; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 638 | const char *word_start; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 639 | size_t len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 640 | |
| 641 | if (word_p) { |
| 642 | *word_p = NULL; |
| 643 | *word_len = 0; |
| 644 | } |
| 645 | |
| 646 | /* first skip "optsep", comments */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 647 | while (in->current[0]) { |
| 648 | switch (in->current[0]) { |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 649 | case '/': |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 650 | if (in->current[1] == '/') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 651 | /* one-line comment */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 652 | MOVE_INPUT(ctx, in, 2); |
| 653 | LY_CHECK_RET(skip_comment(ctx, in, 1)); |
| 654 | } else if (in->current[1] == '*') { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 655 | /* block comment */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 656 | MOVE_INPUT(ctx, in, 2); |
| 657 | LY_CHECK_RET(skip_comment(ctx, in, 2)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 658 | } else { |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 659 | /* error - not a comment after all, keyword cannot start with slash */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 660 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Invalid identifier first character '/'."); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 661 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 662 | } |
Radek Krejci | 1302828 | 2019-06-11 14:56:48 +0200 | [diff] [blame] | 663 | continue; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 664 | case '\n': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 665 | /* skip whitespaces (optsep) */ |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 666 | ++ctx->line; |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 667 | ctx->indent = 0; |
| 668 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 669 | case ' ': |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 670 | /* skip whitespaces (optsep) */ |
| 671 | ++ctx->indent; |
| 672 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 673 | case '\t': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 674 | /* skip whitespaces (optsep) */ |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 675 | ctx->indent += 8; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 676 | break; |
| 677 | default: |
| 678 | /* either a keyword start or an invalid character */ |
| 679 | goto keyword_start; |
| 680 | } |
| 681 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 682 | ly_in_skip(in, 1); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | keyword_start: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 686 | word_start = in->current; |
| 687 | *kw = lysp_match_kw(ctx, in); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 688 | |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 689 | 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] | 690 | goto success; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 691 | } |
| 692 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 693 | if (*kw != LY_STMT_NONE) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 694 | /* make sure we have the whole keyword */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 695 | switch (in->current[0]) { |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 696 | case '\n': |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 697 | case '\t': |
Radek Krejci | abdd806 | 2019-06-11 16:44:19 +0200 | [diff] [blame] | 698 | case ' ': |
| 699 | /* 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] | 700 | break; |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 701 | case ':': |
| 702 | /* keyword is not actually a keyword, but prefix of an extension. |
| 703 | * To avoid repeated check of the prefix syntax, move to the point where the colon was read |
| 704 | * and we will be checking the keyword (extension instance) itself */ |
| 705 | prefix = 1; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 706 | MOVE_INPUT(ctx, in, 1); |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 707 | goto extension; |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 708 | case '{': |
| 709 | /* allowed only for input and output statements which can be without arguments */ |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 710 | if ((*kw == LY_STMT_INPUT) || (*kw == LY_STMT_OUTPUT)) { |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 711 | break; |
| 712 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 713 | /* fallthrough */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 714 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 715 | MOVE_INPUT(ctx, in, 1); |
| 716 | LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, (int)(in->current - word_start), word_start, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 717 | "a keyword followed by a separator"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 718 | return LY_EVALID; |
| 719 | } |
| 720 | } else { |
| 721 | /* still can be an extension */ |
| 722 | prefix = 0; |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 723 | extension: |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 724 | while (in->current[0] && (in->current[0] != ' ') && (in->current[0] != '\t') && (in->current[0] != '\n') && |
| 725 | (in->current[0] != '{') && (in->current[0] != ';')) { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 726 | uint32_t c = 0; |
| 727 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 728 | LY_CHECK_ERR_RET(ly_getutf8(&in->current, &c, &len), |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 729 | LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, in->current[-len]), LY_EVALID); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 730 | ++ctx->indent; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 731 | /* check character validity */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 732 | LY_CHECK_RET(lysp_check_identifierchar((struct lys_parser_ctx *)ctx, c, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 733 | in->current - len == word_start ? 1 : 0, &prefix)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 734 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 735 | if (!in->current[0]) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 736 | LOGVAL_PARSER(ctx, LY_VCODE_EOF); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 737 | return LY_EVALID; |
| 738 | } |
| 739 | |
| 740 | /* prefix is mandatory for extension instances */ |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 741 | if (prefix != 2) { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 742 | 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] | 743 | return LY_EVALID; |
| 744 | } |
| 745 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 746 | *kw = LY_STMT_EXTENSION_INSTANCE; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 747 | } |
Radek Krejci | 626df48 | 2018-10-11 15:06:31 +0200 | [diff] [blame] | 748 | success: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 749 | if (word_p) { |
| 750 | *word_p = (char *)word_start; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 751 | *word_len = in->current - word_start; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | return LY_SUCCESS; |
| 755 | } |
| 756 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 757 | /** |
| 758 | * @brief Parse extension instance substatements. |
| 759 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 760 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 761 | * @param[in,out] in Input structure. |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 762 | * @param[in] kw Statement keyword value matching @p word value. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 763 | * @param[in] word Extension instance substatement name (keyword). |
| 764 | * @param[in] word_len Extension instance substatement name length. |
| 765 | * @param[in,out] child Children of this extension instance to add to. |
| 766 | * |
| 767 | * @return LY_ERR values. |
| 768 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 769 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 770 | 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] | 771 | struct lysp_stmt **child) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 772 | { |
| 773 | char *buf; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 774 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 775 | enum ly_stmt child_kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 776 | struct lysp_stmt *stmt, *par_child; |
| 777 | |
| 778 | stmt = calloc(1, sizeof *stmt); |
| 779 | LY_CHECK_ERR_RET(!stmt, LOGMEM(NULL), LY_EMEM); |
| 780 | |
Radek Krejci | bb9b198 | 2019-04-08 14:24:59 +0200 | [diff] [blame] | 781 | /* insert into parent statements */ |
| 782 | if (!*child) { |
| 783 | *child = stmt; |
| 784 | } else { |
Radek Krejci | 1e008d2 | 2020-08-17 11:37:37 +0200 | [diff] [blame] | 785 | for (par_child = *child; par_child->next; par_child = par_child->next) {} |
Radek Krejci | bb9b198 | 2019-04-08 14:24:59 +0200 | [diff] [blame] | 786 | par_child->next = stmt; |
| 787 | } |
| 788 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 789 | LY_CHECK_RET(lydict_insert(ctx->ctx, word, word_len, &stmt->stmt)); |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 790 | stmt->kw = kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 791 | |
| 792 | /* get optional argument */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 793 | 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] | 794 | |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 795 | if (word) { |
| 796 | if (buf) { |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 797 | LY_CHECK_RET(lydict_insert_zc(ctx->ctx, word, &stmt->arg)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 798 | } else { |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 799 | LY_CHECK_RET(lydict_insert(ctx->ctx, word, word_len, &stmt->arg)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 800 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 801 | } |
| 802 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 803 | YANG_READ_SUBSTMT_FOR(ctx, in, child_kw, word, word_len, ret, ) { |
| 804 | 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] | 805 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 806 | return ret; |
| 807 | } |
| 808 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 809 | /** |
| 810 | * @brief Parse extension instance. |
| 811 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 812 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 813 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 814 | * @param[in] ext_name Extension instance substatement name (keyword). |
| 815 | * @param[in] ext_name_len Extension instance substatement name length. |
| 816 | * @param[in] insubstmt Type of the keyword this extension instance is a substatement of. |
| 817 | * @param[in] insubstmt_index Index of the keyword instance this extension instance is a substatement of. |
| 818 | * @param[in,out] exts Extension instances to add to. |
| 819 | * |
| 820 | * @return LY_ERR values. |
| 821 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 822 | static LY_ERR |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 823 | 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] | 824 | LY_ARRAY_COUNT_TYPE insubstmt_index, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 825 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 826 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 827 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 828 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 829 | struct lysp_ext_instance *e; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 830 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 831 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 832 | LY_ARRAY_NEW_RET(ctx->ctx, *exts, e, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 833 | |
| 834 | /* store name and insubstmt info */ |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 835 | LY_CHECK_RET(lydict_insert(ctx->ctx, ext_name, ext_name_len, &e->name)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 836 | e->insubstmt = insubstmt; |
| 837 | e->insubstmt_index = insubstmt_index; |
| 838 | |
| 839 | /* get optional argument */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 840 | 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] | 841 | |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 842 | if (word) { |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 843 | INSERT_WORD_RET(ctx, buf, e->argument, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 844 | } |
| 845 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 846 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 847 | 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] | 848 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 849 | return ret; |
| 850 | } |
| 851 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 852 | /** |
| 853 | * @brief Parse a generic text field without specific constraints. Those are contact, organization, |
| 854 | * description, etc... |
| 855 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 856 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 857 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 858 | * @param[in] substmt Type of this substatement. |
| 859 | * @param[in] substmt_index Index of this substatement. |
| 860 | * @param[in,out] value Place to store the parsed value. |
| 861 | * @param[in] arg Type of the YANG keyword argument (of the value). |
| 862 | * @param[in,out] exts Extension instances to add to. |
| 863 | * |
| 864 | * @return LY_ERR values. |
| 865 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 866 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 867 | 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] | 868 | const char **value, enum yang_arg arg, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 869 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 870 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 871 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 872 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 873 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 874 | |
| 875 | if (*value) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 876 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, lyext_substmt2str(substmt)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 877 | return LY_EVALID; |
| 878 | } |
| 879 | |
| 880 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 881 | 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] | 882 | |
| 883 | /* store value and spend buf if allocated */ |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 884 | INSERT_WORD_RET(ctx, buf, *value, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 885 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 886 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 887 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 888 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 889 | 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] | 890 | break; |
| 891 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 892 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 893 | return LY_EVALID; |
| 894 | } |
| 895 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 896 | return ret; |
| 897 | } |
| 898 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 899 | /** |
| 900 | * @brief Parse the yang-version statement. |
| 901 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 902 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 903 | * @param[in,out] in Input structure. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 904 | * @param[out] version Storage for the parsed information. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 905 | * @param[in,out] exts Extension instances to add to. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 906 | * |
| 907 | * @return LY_ERR values. |
| 908 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 909 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 910 | 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] | 911 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 912 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 913 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 914 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 915 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 916 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 917 | if (*version) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 918 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "yang-version"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 919 | return LY_EVALID; |
| 920 | } |
| 921 | |
| 922 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 923 | 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] | 924 | |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 925 | if ((word_len == 1) && !strncmp(word, "1", word_len)) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 926 | *version = LYS_VERSION_1_0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 927 | } else if ((word_len == 3) && !strncmp(word, "1.1", word_len)) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 928 | *version = LYS_VERSION_1_1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 929 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 930 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "yang-version"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 931 | free(buf); |
| 932 | return LY_EVALID; |
| 933 | } |
| 934 | free(buf); |
| 935 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 936 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 937 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 938 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 939 | 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] | 940 | break; |
| 941 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 942 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "yang-version"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 943 | return LY_EVALID; |
| 944 | } |
| 945 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 946 | return ret; |
| 947 | } |
| 948 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 949 | /** |
| 950 | * @brief Parse the belongs-to statement. |
| 951 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 952 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 953 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 954 | * @param[in,out] prefix Place to store the parsed belongs-to prefix value. |
| 955 | * @param[in,out] exts Extension instances to add to. |
| 956 | * |
| 957 | * @return LY_ERR values. |
| 958 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 959 | static LY_ERR |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 960 | parse_belongsto(struct lys_yang_parser_ctx *ctx, struct ly_in *in, const char **prefix, struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 961 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 962 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 963 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 964 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 965 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 966 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 967 | if (*prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 968 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "belongs-to"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 969 | return LY_EVALID; |
| 970 | } |
| 971 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 972 | /* get value, it must match the main module */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 973 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 974 | if (ly_strncmp(ctx->main_mod->name, word, word_len)) { |
| 975 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Submodule \"belongs-to\" value \"%.*s\" does not match its module name \"%s\".", |
| 976 | (int)word_len, word, ctx->main_mod->name); |
| 977 | free(buf); |
| 978 | return LY_EVALID; |
| 979 | } |
| 980 | free(buf); |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 981 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 982 | 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] | 983 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 984 | case LY_STMT_PREFIX: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 985 | 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] | 986 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 987 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 988 | 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] | 989 | break; |
| 990 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 991 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "belongs-to"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 992 | return LY_EVALID; |
| 993 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 994 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 995 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 996 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 997 | /* mandatory substatements */ |
| 998 | if (!*prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 999 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "prefix", "belongs-to"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1000 | return LY_EVALID; |
| 1001 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1002 | return ret; |
| 1003 | } |
| 1004 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1005 | /** |
| 1006 | * @brief Parse the revision-date statement. |
| 1007 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1008 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1009 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1010 | * @param[in,out] rev Array to store the parsed value in. |
| 1011 | * @param[in,out] exts Extension instances to add to. |
| 1012 | * |
| 1013 | * @return LY_ERR values. |
| 1014 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1015 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1016 | 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] | 1017 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1018 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1019 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1020 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1021 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1022 | |
| 1023 | if (rev[0]) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1024 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "revision-date"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1025 | return LY_EVALID; |
| 1026 | } |
| 1027 | |
| 1028 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1029 | 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] | 1030 | |
| 1031 | /* check value */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1032 | 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] | 1033 | free(buf); |
| 1034 | return LY_EVALID; |
| 1035 | } |
| 1036 | |
| 1037 | /* store value and spend buf if allocated */ |
| 1038 | strncpy(rev, word, word_len); |
| 1039 | free(buf); |
| 1040 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1041 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1042 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1043 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1044 | 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] | 1045 | break; |
| 1046 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1047 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "revision-date"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1048 | return LY_EVALID; |
| 1049 | } |
| 1050 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1051 | return ret; |
| 1052 | } |
| 1053 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1054 | /** |
| 1055 | * @brief Parse the include statement. |
| 1056 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1057 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1058 | * @param[in] module_name Name of the module to check name collisions. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1059 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1060 | * @param[in,out] includes Parsed includes to add to. |
| 1061 | * |
| 1062 | * @return LY_ERR values. |
| 1063 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1064 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1065 | 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] | 1066 | { |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 1067 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1068 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1069 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1070 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1071 | struct lysp_include *inc; |
| 1072 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1073 | LY_ARRAY_NEW_RET(ctx->ctx, *includes, inc, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1074 | |
| 1075 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1076 | 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] | 1077 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1078 | INSERT_WORD_RET(ctx, buf, inc->name, word, word_len); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 1079 | |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 1080 | /* submodules share the namespace with the module names, so there must not be |
| 1081 | * 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] | 1082 | 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] | 1083 | 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] | 1084 | return LY_EVALID; |
| 1085 | } |
| 1086 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1087 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1088 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1089 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1090 | PARSER_CHECK_STMTVER2_RET(ctx, "description", "include"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1091 | 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] | 1092 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1093 | case LY_STMT_REFERENCE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1094 | PARSER_CHECK_STMTVER2_RET(ctx, "reference", "include"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1095 | 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] | 1096 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1097 | case LY_STMT_REVISION_DATE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1098 | LY_CHECK_RET(parse_revisiondate(ctx, in, inc->rev, &inc->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1099 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1100 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1101 | 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] | 1102 | break; |
| 1103 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1104 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "include"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1105 | return LY_EVALID; |
| 1106 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1107 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1108 | return ret; |
| 1109 | } |
| 1110 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1111 | /** |
| 1112 | * @brief Parse the import statement. |
| 1113 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1114 | * @param[in] ctx yang parser context for logging. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1115 | * @param[in] module_prefix Prefix of the module to check prefix collisions. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1116 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1117 | * @param[in,out] imports Parsed imports to add to. |
| 1118 | * |
| 1119 | * @return LY_ERR values. |
| 1120 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1121 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1122 | 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] | 1123 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1124 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1125 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1126 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1127 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1128 | struct lysp_import *imp; |
| 1129 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1130 | LY_ARRAY_NEW_RET(ctx->ctx, *imports, imp, LY_EVALID); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1131 | |
| 1132 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1133 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1134 | INSERT_WORD_RET(ctx, buf, imp->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1135 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1136 | 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] | 1137 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1138 | case LY_STMT_PREFIX: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1139 | 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] | 1140 | 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] | 1141 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1142 | case LY_STMT_DESCRIPTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1143 | PARSER_CHECK_STMTVER2_RET(ctx, "description", "import"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1144 | 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] | 1145 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1146 | case LY_STMT_REFERENCE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1147 | PARSER_CHECK_STMTVER2_RET(ctx, "reference", "import"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1148 | 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] | 1149 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1150 | case LY_STMT_REVISION_DATE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1151 | LY_CHECK_RET(parse_revisiondate(ctx, in, imp->rev, &imp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1152 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1153 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1154 | 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] | 1155 | break; |
| 1156 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1157 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "import"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1158 | return LY_EVALID; |
| 1159 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1160 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 1161 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 1162 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1163 | /* mandatory substatements */ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1164 | 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] | 1165 | |
| 1166 | return ret; |
| 1167 | } |
| 1168 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1169 | /** |
| 1170 | * @brief Parse the revision statement. |
| 1171 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1172 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1173 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1174 | * @param[in,out] revs Parsed revisions to add to. |
| 1175 | * |
| 1176 | * @return LY_ERR values. |
| 1177 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1178 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1179 | 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] | 1180 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1181 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1182 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1183 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1184 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1185 | struct lysp_revision *rev; |
| 1186 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1187 | LY_ARRAY_NEW_RET(ctx->ctx, *revs, rev, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1188 | |
| 1189 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1190 | 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] | 1191 | |
| 1192 | /* check value */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1193 | 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] | 1194 | free(buf); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1195 | return LY_EVALID; |
| 1196 | } |
| 1197 | |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 1198 | strncpy(rev->date, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1199 | free(buf); |
| 1200 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1201 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1202 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1203 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1204 | 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] | 1205 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1206 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1207 | 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] | 1208 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1209 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1210 | 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] | 1211 | break; |
| 1212 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1213 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "revision"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1214 | return LY_EVALID; |
| 1215 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1216 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1217 | return ret; |
| 1218 | } |
| 1219 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1220 | /** |
| 1221 | * @brief Parse a generic text field that can have more instances such as base. |
| 1222 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1223 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1224 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1225 | * @param[in] substmt Type of this substatement. |
| 1226 | * @param[in,out] texts Parsed values to add to. |
| 1227 | * @param[in] arg Type of the expected argument. |
| 1228 | * @param[in,out] exts Extension instances to add to. |
| 1229 | * |
| 1230 | * @return LY_ERR values. |
| 1231 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1232 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1233 | 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] | 1234 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1235 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1236 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1237 | char *buf, *word; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 1238 | const char **item; |
| 1239 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1240 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1241 | |
| 1242 | /* allocate new pointer */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1243 | LY_ARRAY_NEW_RET(ctx->ctx, *texts, item, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1244 | |
| 1245 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1246 | 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] | 1247 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1248 | INSERT_WORD_RET(ctx, buf, *item, word, word_len); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1249 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1250 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1251 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1252 | 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] | 1253 | break; |
| 1254 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1255 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1256 | return LY_EVALID; |
| 1257 | } |
| 1258 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1259 | return ret; |
| 1260 | } |
| 1261 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1262 | /** |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1263 | * @brief Parse a generic text field that can have more instances such as base. |
| 1264 | * |
| 1265 | * @param[in] ctx yang parser context for logging. |
| 1266 | * @param[in,out] in Input structure. |
| 1267 | * @param[in] substmt Type of this substatement. |
| 1268 | * @param[in,out] qnames Parsed qnames to add to. |
| 1269 | * @param[in] arg Type of the expected argument. |
| 1270 | * @param[in,out] exts Extension instances to add to. |
| 1271 | * |
| 1272 | * @return LY_ERR values. |
| 1273 | */ |
| 1274 | static LY_ERR |
| 1275 | parse_qnames(struct lys_yang_parser_ctx *ctx, struct ly_in *in, LYEXT_SUBSTMT substmt, struct lysp_qname **qnames, |
| 1276 | enum yang_arg arg, struct lysp_ext_instance **exts) |
| 1277 | { |
| 1278 | LY_ERR ret = LY_SUCCESS; |
| 1279 | char *buf, *word; |
| 1280 | struct lysp_qname *item; |
| 1281 | size_t word_len; |
| 1282 | enum ly_stmt kw; |
| 1283 | |
| 1284 | /* allocate new pointer */ |
| 1285 | LY_ARRAY_NEW_RET(ctx->ctx, *qnames, item, LY_EMEM); |
| 1286 | |
| 1287 | /* get value */ |
| 1288 | LY_CHECK_RET(get_argument(ctx, in, arg, NULL, &word, &buf, &word_len)); |
| 1289 | |
| 1290 | INSERT_WORD_RET(ctx, buf, item->str, word, word_len); |
| 1291 | item->mod = ctx->main_mod; |
| 1292 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
| 1293 | switch (kw) { |
| 1294 | case LY_STMT_EXTENSION_INSTANCE: |
| 1295 | LY_CHECK_RET(parse_ext(ctx, in, word, word_len, substmt, LY_ARRAY_COUNT(*qnames) - 1, exts)); |
| 1296 | break; |
| 1297 | default: |
| 1298 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), lyext_substmt2str(substmt)); |
| 1299 | return LY_EVALID; |
| 1300 | } |
| 1301 | } |
| 1302 | return ret; |
| 1303 | } |
| 1304 | |
| 1305 | /** |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1306 | * @brief Parse the config statement. |
| 1307 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1308 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1309 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1310 | * @param[in,out] flags Flags to add to. |
| 1311 | * @param[in,out] exts Extension instances to add to. |
| 1312 | * |
| 1313 | * @return LY_ERR values. |
| 1314 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1315 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1316 | 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] | 1317 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1318 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1319 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1320 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1321 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1322 | |
| 1323 | if (*flags & LYS_CONFIG_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1324 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "config"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1325 | return LY_EVALID; |
| 1326 | } |
| 1327 | |
| 1328 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1329 | 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] | 1330 | |
| 1331 | if ((word_len == 4) && !strncmp(word, "true", word_len)) { |
| 1332 | *flags |= LYS_CONFIG_W; |
| 1333 | } else if ((word_len == 5) && !strncmp(word, "false", word_len)) { |
| 1334 | *flags |= LYS_CONFIG_R; |
| 1335 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1336 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "config"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1337 | free(buf); |
| 1338 | return LY_EVALID; |
| 1339 | } |
| 1340 | free(buf); |
| 1341 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1342 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1343 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1344 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1345 | 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] | 1346 | break; |
| 1347 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1348 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "config"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1349 | return LY_EVALID; |
| 1350 | } |
| 1351 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1352 | return ret; |
| 1353 | } |
| 1354 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1355 | /** |
| 1356 | * @brief Parse the mandatory statement. |
| 1357 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1358 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1359 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1360 | * @param[in,out] flags Flags to add to. |
| 1361 | * @param[in,out] exts Extension instances to add to. |
| 1362 | * |
| 1363 | * @return LY_ERR values. |
| 1364 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1365 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1366 | 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] | 1367 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1368 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1369 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1370 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1371 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1372 | |
| 1373 | if (*flags & LYS_MAND_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1374 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "mandatory"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1375 | return LY_EVALID; |
| 1376 | } |
| 1377 | |
| 1378 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1379 | 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] | 1380 | |
| 1381 | if ((word_len == 4) && !strncmp(word, "true", word_len)) { |
| 1382 | *flags |= LYS_MAND_TRUE; |
| 1383 | } else if ((word_len == 5) && !strncmp(word, "false", word_len)) { |
| 1384 | *flags |= LYS_MAND_FALSE; |
| 1385 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1386 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "mandatory"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1387 | free(buf); |
| 1388 | return LY_EVALID; |
| 1389 | } |
| 1390 | free(buf); |
| 1391 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1392 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1393 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1394 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1395 | 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] | 1396 | break; |
| 1397 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1398 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "mandatory"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1399 | return LY_EVALID; |
| 1400 | } |
| 1401 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1402 | return ret; |
| 1403 | } |
| 1404 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1405 | /** |
| 1406 | * @brief Parse a restriction such as range or length. |
| 1407 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1408 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1409 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1410 | * @param[in] restr_kw Type of this particular restriction. |
| 1411 | * @param[in,out] exts Extension instances to add to. |
| 1412 | * |
| 1413 | * @return LY_ERR values. |
| 1414 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1415 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1416 | 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] | 1417 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1418 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1419 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1420 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1421 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1422 | |
| 1423 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1424 | 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] | 1425 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1426 | CHECK_NONEMPTY(ctx, word_len, ly_stmt2str(restr_kw)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1427 | INSERT_WORD_RET(ctx, buf, restr->arg.str, word, word_len); |
| 1428 | restr->arg.mod = ctx->main_mod; |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1429 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1430 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1431 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1432 | 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] | 1433 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1434 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1435 | 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] | 1436 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1437 | case LY_STMT_ERROR_APP_TAG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1438 | 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] | 1439 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1440 | case LY_STMT_ERROR_MESSAGE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1441 | 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] | 1442 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1443 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1444 | 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] | 1445 | break; |
| 1446 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1447 | 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] | 1448 | return LY_EVALID; |
| 1449 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1450 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1451 | return ret; |
| 1452 | } |
| 1453 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1454 | /** |
| 1455 | * @brief Parse a restriction that can have more instances such as must. |
| 1456 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1457 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1458 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1459 | * @param[in] restr_kw Type of this particular restriction. |
| 1460 | * @param[in,out] restrs Restrictions to add to. |
| 1461 | * |
| 1462 | * @return LY_ERR values. |
| 1463 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1464 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1465 | 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] | 1466 | { |
| 1467 | struct lysp_restr *restr; |
| 1468 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1469 | LY_ARRAY_NEW_RET(ctx->ctx, *restrs, restr, LY_EMEM); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1470 | return parse_restr(ctx, in, restr_kw, restr); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1471 | } |
| 1472 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1473 | /** |
| 1474 | * @brief Parse the status statement. |
| 1475 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1476 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1477 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1478 | * @param[in,out] flags Flags to add to. |
| 1479 | * @param[in,out] exts Extension instances to add to. |
| 1480 | * |
| 1481 | * @return LY_ERR values. |
| 1482 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1483 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1484 | 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] | 1485 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1486 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1487 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1488 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1489 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1490 | |
| 1491 | if (*flags & LYS_STATUS_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1492 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "status"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1493 | return LY_EVALID; |
| 1494 | } |
| 1495 | |
| 1496 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1497 | 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] | 1498 | |
| 1499 | if ((word_len == 7) && !strncmp(word, "current", word_len)) { |
| 1500 | *flags |= LYS_STATUS_CURR; |
| 1501 | } else if ((word_len == 10) && !strncmp(word, "deprecated", word_len)) { |
| 1502 | *flags |= LYS_STATUS_DEPRC; |
| 1503 | } else if ((word_len == 8) && !strncmp(word, "obsolete", word_len)) { |
| 1504 | *flags |= LYS_STATUS_OBSLT; |
| 1505 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1506 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "status"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1507 | free(buf); |
| 1508 | return LY_EVALID; |
| 1509 | } |
| 1510 | free(buf); |
| 1511 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1512 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1513 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1514 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1515 | 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] | 1516 | break; |
| 1517 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1518 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "status"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1519 | return LY_EVALID; |
| 1520 | } |
| 1521 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1522 | return ret; |
| 1523 | } |
| 1524 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1525 | /** |
| 1526 | * @brief Parse the when statement. |
| 1527 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1528 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1529 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1530 | * @param[in,out] when_p When pointer to parse to. |
| 1531 | * |
| 1532 | * @return LY_ERR values. |
| 1533 | */ |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 1534 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1535 | 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] | 1536 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1537 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1538 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1539 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1540 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1541 | struct lysp_when *when; |
| 1542 | |
| 1543 | if (*when_p) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1544 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "when"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1545 | return LY_EVALID; |
| 1546 | } |
| 1547 | |
| 1548 | when = calloc(1, sizeof *when); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1549 | LY_CHECK_ERR_RET(!when, LOGMEM(ctx->ctx), LY_EMEM); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1550 | *when_p = when; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1551 | |
| 1552 | /* get value */ |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1553 | 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] | 1554 | CHECK_NONEMPTY(ctx, word_len, "when"); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1555 | INSERT_WORD_RET(ctx, buf, when->cond, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1556 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1557 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1558 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1559 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1560 | 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] | 1561 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1562 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1563 | 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] | 1564 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1565 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1566 | 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] | 1567 | break; |
| 1568 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1569 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "when"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1570 | return LY_EVALID; |
| 1571 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1572 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1573 | return ret; |
| 1574 | } |
| 1575 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1576 | /** |
| 1577 | * @brief Parse the anydata or anyxml statement. |
| 1578 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1579 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1580 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1581 | * @param[in] kw Type of this particular keyword. |
| 1582 | * @param[in,out] siblings Siblings to add to. |
| 1583 | * |
| 1584 | * @return LY_ERR values. |
| 1585 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 1586 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1587 | 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] | 1588 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1589 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1590 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1591 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1592 | struct lysp_node_anydata *any; |
| 1593 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 1594 | /* create new structure and insert into siblings */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 1595 | LY_LIST_NEW_RET(ctx->ctx, siblings, any, next, LY_EMEM); |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 1596 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1597 | any->nodetype = kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1598 | any->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1599 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1600 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1601 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1602 | INSERT_WORD_RET(ctx, buf, any->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1603 | |
| 1604 | /* parse substatements */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1605 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1606 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1607 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1608 | LY_CHECK_RET(parse_config(ctx, in, &any->flags, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1609 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1610 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1611 | 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] | 1612 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1613 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1614 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &any->iffeatures, Y_STR_ARG, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1615 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1616 | case LY_STMT_MANDATORY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1617 | LY_CHECK_RET(parse_mandatory(ctx, in, &any->flags, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1618 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1619 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1620 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &any->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1621 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1622 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1623 | 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] | 1624 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1625 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1626 | LY_CHECK_RET(parse_status(ctx, in, &any->flags, &any->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1627 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1628 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1629 | LY_CHECK_RET(parse_when(ctx, in, &any->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1630 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1631 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1632 | 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] | 1633 | break; |
| 1634 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1635 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1636 | (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] | 1637 | return LY_EVALID; |
| 1638 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1639 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1640 | return ret; |
| 1641 | } |
| 1642 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1643 | /** |
| 1644 | * @brief Parse the value or position statement. Substatement of type enum statement. |
| 1645 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1646 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1647 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1648 | * @param[in] val_kw Type of this particular keyword. |
| 1649 | * @param[in,out] value Value to write to. |
| 1650 | * @param[in,out] flags Flags to write to. |
| 1651 | * @param[in,out] exts Extension instances to add to. |
| 1652 | * |
| 1653 | * @return LY_ERR values. |
| 1654 | */ |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 1655 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1656 | 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] | 1657 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1658 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1659 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1660 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1661 | size_t word_len; |
Radek Krejci | 4ad42aa | 2019-07-23 16:55:58 +0200 | [diff] [blame] | 1662 | long int num = 0; |
| 1663 | unsigned long int unum = 0; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1664 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1665 | |
| 1666 | if (*flags & LYS_SET_VALUE) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1667 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(val_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1668 | return LY_EVALID; |
| 1669 | } |
| 1670 | *flags |= LYS_SET_VALUE; |
| 1671 | |
| 1672 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1673 | 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] | 1674 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1675 | 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] | 1676 | 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] | 1677 | goto error; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | errno = 0; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1681 | if (val_kw == LY_STMT_VALUE) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1682 | num = strtol(word, &ptr, 10); |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 1683 | if ((num < INT64_C(-2147483648)) || (num > INT64_C(2147483647))) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1684 | 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] | 1685 | goto error; |
| 1686 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1687 | } else { |
| 1688 | unum = strtoul(word, &ptr, 10); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1689 | if (unum > UINT64_C(4294967295)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1690 | 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] | 1691 | goto error; |
| 1692 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1693 | } |
| 1694 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1695 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1696 | 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] | 1697 | goto error; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1698 | } |
| 1699 | if (errno == ERANGE) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1700 | 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] | 1701 | goto error; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1702 | } |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1703 | if (val_kw == LY_STMT_VALUE) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1704 | *value = num; |
| 1705 | } else { |
| 1706 | *value = unum; |
| 1707 | } |
| 1708 | free(buf); |
| 1709 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1710 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1711 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1712 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1713 | 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] | 1714 | break; |
| 1715 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1716 | 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] | 1717 | return LY_EVALID; |
| 1718 | } |
| 1719 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1720 | return ret; |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1721 | |
| 1722 | error: |
| 1723 | free(buf); |
| 1724 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1725 | } |
| 1726 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1727 | /** |
| 1728 | * @brief Parse the enum or bit statement. Substatement of type statement. |
| 1729 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1730 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1731 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1732 | * @param[in] enum_kw Type of this particular keyword. |
| 1733 | * @param[in,out] enums Enums or bits to add to. |
| 1734 | * |
| 1735 | * @return LY_ERR values. |
| 1736 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1737 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1738 | 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] | 1739 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1740 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1741 | char *buf, *word; |
David Sedlák | 6544c18 | 2019-07-12 13:17:33 +0200 | [diff] [blame] | 1742 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1743 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1744 | struct lysp_type_enum *enm; |
| 1745 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1746 | LY_ARRAY_NEW_RET(ctx->ctx, *enums, enm, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1747 | |
| 1748 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1749 | 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] | 1750 | if (enum_kw == LY_STMT_ENUM) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1751 | 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] | 1752 | LY_CHECK_ERR_RET(ret, free(buf), ret); |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1753 | } /* else nothing specific for YANG_BIT */ |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1754 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1755 | INSERT_WORD_RET(ctx, buf, enm->name, word, word_len); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1756 | CHECK_UNIQUENESS(ctx, *enums, name, ly_stmt2str(enum_kw), enm->name); |
| 1757 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1758 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1759 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1760 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1761 | 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] | 1762 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1763 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 1764 | PARSER_CHECK_STMTVER2_RET(ctx, "if-feature", ly_stmt2str(enum_kw)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1765 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &enm->iffeatures, Y_STR_ARG, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1766 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1767 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1768 | 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] | 1769 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1770 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1771 | LY_CHECK_RET(parse_status(ctx, in, &enm->flags, &enm->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1772 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1773 | case LY_STMT_VALUE: |
| 1774 | LY_CHECK_ERR_RET(enum_kw == LY_STMT_BIT, LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 1775 | ly_stmt2str(enum_kw)), LY_EVALID); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1776 | 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] | 1777 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1778 | case LY_STMT_POSITION: |
| 1779 | LY_CHECK_ERR_RET(enum_kw == LY_STMT_ENUM, LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 1780 | ly_stmt2str(enum_kw)), LY_EVALID); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1781 | 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] | 1782 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1783 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1784 | 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] | 1785 | break; |
| 1786 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1787 | 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] | 1788 | return LY_EVALID; |
| 1789 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1790 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1791 | return ret; |
| 1792 | } |
| 1793 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1794 | /** |
| 1795 | * @brief Parse the fraction-digits statement. Substatement of type statement. |
| 1796 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1797 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1798 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1799 | * @param[in,out] fracdig Value to write to. |
| 1800 | * @param[in,out] exts Extension instances to add to. |
| 1801 | * |
| 1802 | * @return LY_ERR values. |
| 1803 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1804 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1805 | 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] | 1806 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1807 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1808 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1809 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1810 | unsigned long int num; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1811 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1812 | |
| 1813 | if (*fracdig) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1814 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1815 | return LY_EVALID; |
| 1816 | } |
| 1817 | |
| 1818 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1819 | 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] | 1820 | |
| 1821 | if (!word_len || (word[0] == '0') || !isdigit(word[0])) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1822 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1823 | free(buf); |
| 1824 | return LY_EVALID; |
| 1825 | } |
| 1826 | |
| 1827 | errno = 0; |
| 1828 | num = strtoul(word, &ptr, 10); |
| 1829 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1830 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1831 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1832 | free(buf); |
| 1833 | return LY_EVALID; |
| 1834 | } |
| 1835 | if ((errno == ERANGE) || (num > 18)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1836 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1837 | free(buf); |
| 1838 | return LY_EVALID; |
| 1839 | } |
| 1840 | *fracdig = num; |
| 1841 | free(buf); |
| 1842 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1843 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1844 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1845 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1846 | 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] | 1847 | break; |
| 1848 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1849 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "fraction-digits"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1850 | return LY_EVALID; |
| 1851 | } |
| 1852 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1853 | return ret; |
| 1854 | } |
| 1855 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1856 | /** |
| 1857 | * @brief Parse the require-instance statement. Substatement of type statement. |
| 1858 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1859 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1860 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1861 | * @param[in,out] reqinst Value to write to. |
| 1862 | * @param[in,out] flags Flags to write to. |
| 1863 | * @param[in,out] exts Extension instances to add to. |
| 1864 | * |
| 1865 | * @return LY_ERR values. |
| 1866 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1867 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1868 | 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] | 1869 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1870 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1871 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1872 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1873 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1874 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1875 | |
| 1876 | if (*flags & LYS_SET_REQINST) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1877 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "require-instance"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1878 | return LY_EVALID; |
| 1879 | } |
| 1880 | *flags |= LYS_SET_REQINST; |
| 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 == 4) && !strncmp(word, "true", word_len)) { |
| 1886 | *reqinst = 1; |
| 1887 | } else if ((word_len != 5) || strncmp(word, "false", word_len)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1888 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "require-instance"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1889 | free(buf); |
| 1890 | return LY_EVALID; |
| 1891 | } |
| 1892 | free(buf); |
| 1893 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1894 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1895 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1896 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1897 | 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] | 1898 | break; |
| 1899 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1900 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "require-instance"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1901 | return LY_EVALID; |
| 1902 | } |
| 1903 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1904 | return ret; |
| 1905 | } |
| 1906 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1907 | /** |
| 1908 | * @brief Parse the modifier statement. Substatement of type pattern statement. |
| 1909 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1910 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1911 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1912 | * @param[in,out] pat Value to write to. |
| 1913 | * @param[in,out] exts Extension instances to add to. |
| 1914 | * |
| 1915 | * @return LY_ERR values. |
| 1916 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1917 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1918 | 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] | 1919 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1920 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1921 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1922 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1923 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1924 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1925 | |
| 1926 | if ((*pat)[0] == 0x15) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1927 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "modifier"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1928 | return LY_EVALID; |
| 1929 | } |
| 1930 | |
| 1931 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1932 | 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] | 1933 | |
| 1934 | if ((word_len != 12) || strncmp(word, "invert-match", word_len)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1935 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "modifier"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1936 | free(buf); |
| 1937 | return LY_EVALID; |
| 1938 | } |
| 1939 | free(buf); |
| 1940 | |
| 1941 | /* replace the value in the dictionary */ |
| 1942 | buf = malloc(strlen(*pat) + 1); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1943 | LY_CHECK_ERR_RET(!buf, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1944 | strcpy(buf, *pat); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1945 | lydict_remove(ctx->ctx, *pat); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1946 | |
| 1947 | assert(buf[0] == 0x06); |
| 1948 | buf[0] = 0x15; |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1949 | LY_CHECK_RET(lydict_insert_zc(ctx->ctx, buf, pat)); |
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_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1954 | 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] | 1955 | break; |
| 1956 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 1957 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "modifier"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1958 | return LY_EVALID; |
| 1959 | } |
| 1960 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1961 | return ret; |
| 1962 | } |
| 1963 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1964 | /** |
| 1965 | * @brief Parse the pattern statement. Substatement of type statement. |
| 1966 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1967 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1968 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 1969 | * @param[in,out] patterns Restrictions to add to. |
| 1970 | * |
| 1971 | * @return LY_ERR values. |
| 1972 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1973 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1974 | 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] | 1975 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 1976 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1977 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1978 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1979 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1980 | struct lysp_restr *restr; |
| 1981 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1982 | LY_ARRAY_NEW_RET(ctx->ctx, *patterns, restr, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 1983 | |
| 1984 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1985 | 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] | 1986 | |
| 1987 | /* add special meaning first byte */ |
| 1988 | if (buf) { |
| 1989 | buf = realloc(buf, word_len + 2); |
| 1990 | word = buf; |
| 1991 | } else { |
| 1992 | buf = malloc(word_len + 2); |
| 1993 | } |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1994 | LY_CHECK_ERR_RET(!buf, LOGMEM(ctx->ctx), LY_EMEM); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 1995 | memmove(buf + 1, word, word_len); |
| 1996 | buf[0] = 0x06; /* pattern's default regular-match flag */ |
| 1997 | buf[word_len + 1] = '\0'; /* terminating NULL byte */ |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1998 | LY_CHECK_RET(lydict_insert_zc(ctx->ctx, buf, &restr->arg.str)); |
| 1999 | restr->arg.mod = ctx->main_mod; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2000 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2001 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2002 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2003 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2004 | 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] | 2005 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2006 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2007 | 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] | 2008 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2009 | case LY_STMT_ERROR_APP_TAG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2010 | 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] | 2011 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2012 | case LY_STMT_ERROR_MESSAGE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2013 | 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] | 2014 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2015 | case LY_STMT_MODIFIER: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2016 | PARSER_CHECK_STMTVER2_RET(ctx, "modifier", "pattern"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2017 | LY_CHECK_RET(parse_type_pattern_modifier(ctx, in, &restr->arg.str, &restr->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2018 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2019 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2020 | 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] | 2021 | break; |
| 2022 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2023 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "pattern"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2024 | return LY_EVALID; |
| 2025 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2026 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2027 | return ret; |
| 2028 | } |
| 2029 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2030 | /** |
| 2031 | * @brief Parse the type statement. |
| 2032 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2033 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2034 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2035 | * @param[in,out] type Type to wrote to. |
| 2036 | * |
| 2037 | * @return LY_ERR values. |
| 2038 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2039 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2040 | 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] | 2041 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2042 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2043 | char *buf, *word; |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 2044 | const char *str_path = NULL; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2045 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2046 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2047 | struct lysp_type *nest_type; |
| 2048 | |
| 2049 | if (type->name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2050 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "type"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2051 | return LY_EVALID; |
| 2052 | } |
| 2053 | |
| 2054 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2055 | LY_CHECK_RET(get_argument(ctx, in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2056 | INSERT_WORD_RET(ctx, buf, type->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2057 | |
Michal Vasko | e9c050f | 2020-10-06 14:01:23 +0200 | [diff] [blame] | 2058 | /* set module */ |
| 2059 | type->mod = ctx->main_mod; |
| 2060 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2061 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2062 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2063 | case LY_STMT_BASE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2064 | 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] | 2065 | type->flags |= LYS_SET_BASE; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2066 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2067 | case LY_STMT_BIT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2068 | LY_CHECK_RET(parse_type_enum(ctx, in, kw, &type->bits)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2069 | type->flags |= LYS_SET_BIT; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2070 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2071 | case LY_STMT_ENUM: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2072 | LY_CHECK_RET(parse_type_enum(ctx, in, kw, &type->enums)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2073 | type->flags |= LYS_SET_ENUM; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2074 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2075 | case LY_STMT_FRACTION_DIGITS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2076 | 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] | 2077 | type->flags |= LYS_SET_FRDIGITS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2078 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2079 | case LY_STMT_LENGTH: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2080 | if (type->length) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2081 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2082 | return LY_EVALID; |
| 2083 | } |
| 2084 | type->length = calloc(1, sizeof *type->length); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2085 | LY_CHECK_ERR_RET(!type->length, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2086 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2087 | LY_CHECK_RET(parse_restr(ctx, in, kw, type->length)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2088 | type->flags |= LYS_SET_LENGTH; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2089 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2090 | case LY_STMT_PATH: |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 2091 | if (type->path) { |
| 2092 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, lyext_substmt2str(LYEXT_SUBSTMT_PATH)); |
| 2093 | return LY_EVALID; |
| 2094 | } |
| 2095 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2096 | 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] | 2097 | ret = ly_path_parse(ctx->ctx, NULL, str_path, 0, LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 2098 | LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &type->path); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 2099 | lydict_remove(ctx->ctx, str_path); |
| 2100 | LY_CHECK_RET(ret); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2101 | type->flags |= LYS_SET_PATH; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2102 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2103 | case LY_STMT_PATTERN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2104 | LY_CHECK_RET(parse_type_pattern(ctx, in, &type->patterns)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2105 | type->flags |= LYS_SET_PATTERN; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2106 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2107 | case LY_STMT_RANGE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2108 | if (type->range) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2109 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2110 | return LY_EVALID; |
| 2111 | } |
| 2112 | type->range = calloc(1, sizeof *type->range); |
David Sedlák | 7a8b247 | 2019-07-11 15:08:34 +0200 | [diff] [blame] | 2113 | LY_CHECK_ERR_RET(!type->range, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2114 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2115 | LY_CHECK_RET(parse_restr(ctx, in, kw, type->range)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2116 | type->flags |= LYS_SET_RANGE; |
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_REQUIRE_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2119 | 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] | 2120 | /* LYS_SET_REQINST checked and set inside parse_type_reqinstance() */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2121 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2122 | case LY_STMT_TYPE: |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2123 | LY_ARRAY_NEW_RET(ctx->ctx, type->types, nest_type, LY_EMEM); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2124 | LY_CHECK_RET(parse_type(ctx, in, nest_type)); |
Radek Krejci | d505e3d | 2018-11-13 09:04:17 +0100 | [diff] [blame] | 2125 | type->flags |= LYS_SET_TYPE; |
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_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2128 | 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] | 2129 | break; |
| 2130 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2131 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "type"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2132 | return LY_EVALID; |
| 2133 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2134 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2135 | return ret; |
| 2136 | } |
| 2137 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2138 | /** |
| 2139 | * @brief Parse the leaf statement. |
| 2140 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2141 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2142 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2143 | * @param[in,out] siblings Siblings to add to. |
| 2144 | * |
| 2145 | * @return LY_ERR values. |
| 2146 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2147 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2148 | 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] | 2149 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2150 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2151 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2152 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2153 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2154 | struct lysp_node_leaf *leaf; |
| 2155 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 2156 | /* create new leaf structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 2157 | LY_LIST_NEW_RET(ctx->ctx, siblings, leaf, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2158 | leaf->nodetype = LYS_LEAF; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2159 | leaf->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2160 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2161 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2162 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2163 | INSERT_WORD_RET(ctx, buf, leaf->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2164 | |
| 2165 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2166 | 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] | 2167 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2168 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2169 | LY_CHECK_RET(parse_config(ctx, in, &leaf->flags, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2170 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2171 | case LY_STMT_DEFAULT: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2172 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DEFAULT, 0, &leaf->dflt.str, Y_STR_ARG, &leaf->exts)); |
| 2173 | leaf->dflt.mod = ctx->main_mod; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2174 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2175 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2176 | 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] | 2177 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2178 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2179 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &leaf->iffeatures, Y_STR_ARG, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2180 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2181 | case LY_STMT_MANDATORY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2182 | LY_CHECK_RET(parse_mandatory(ctx, in, &leaf->flags, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2183 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2184 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2185 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &leaf->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2186 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2187 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2188 | 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] | 2189 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2190 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2191 | LY_CHECK_RET(parse_status(ctx, in, &leaf->flags, &leaf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2192 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2193 | case LY_STMT_TYPE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2194 | LY_CHECK_RET(parse_type(ctx, in, &leaf->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2195 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2196 | case LY_STMT_UNITS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2197 | 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] | 2198 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2199 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2200 | LY_CHECK_RET(parse_when(ctx, in, &leaf->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2201 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2202 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2203 | 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] | 2204 | break; |
| 2205 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2206 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "leaf"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2207 | return LY_EVALID; |
| 2208 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2209 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 2210 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 2211 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2212 | /* mandatory substatements */ |
| 2213 | if (!leaf->type.name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2214 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "type", "leaf"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2215 | return LY_EVALID; |
| 2216 | } |
| 2217 | |
| 2218 | return ret; |
| 2219 | } |
| 2220 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2221 | /** |
| 2222 | * @brief Parse the max-elements statement. |
| 2223 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2224 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2225 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2226 | * @param[in,out] max Value to write to. |
| 2227 | * @param[in,out] flags Flags to write to. |
| 2228 | * @param[in,out] exts Extension instances to add to. |
| 2229 | * |
| 2230 | * @return LY_ERR values. |
| 2231 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2232 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2233 | 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] | 2234 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2235 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2236 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2237 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2238 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2239 | unsigned long int num; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2240 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2241 | |
| 2242 | if (*flags & LYS_SET_MAX) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2243 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2244 | return LY_EVALID; |
| 2245 | } |
| 2246 | *flags |= LYS_SET_MAX; |
| 2247 | |
| 2248 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2249 | 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] | 2250 | |
| 2251 | 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] | 2252 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2253 | free(buf); |
| 2254 | return LY_EVALID; |
| 2255 | } |
| 2256 | |
Radek Krejci | 7f9b651 | 2019-09-18 13:11:09 +0200 | [diff] [blame] | 2257 | if (ly_strncmp("unbounded", word, word_len)) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2258 | errno = 0; |
| 2259 | num = strtoul(word, &ptr, 10); |
| 2260 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2261 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2262 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2263 | free(buf); |
| 2264 | return LY_EVALID; |
| 2265 | } |
| 2266 | if ((errno == ERANGE) || (num > UINT32_MAX)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2267 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2268 | free(buf); |
| 2269 | return LY_EVALID; |
| 2270 | } |
| 2271 | |
| 2272 | *max = num; |
| 2273 | } |
| 2274 | free(buf); |
| 2275 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2276 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2277 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2278 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2279 | 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] | 2280 | break; |
| 2281 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2282 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "max-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2283 | return LY_EVALID; |
| 2284 | } |
| 2285 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2286 | return ret; |
| 2287 | } |
| 2288 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2289 | /** |
| 2290 | * @brief Parse the min-elements statement. |
| 2291 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2292 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2293 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2294 | * @param[in,out] min Value to write to. |
| 2295 | * @param[in,out] flags Flags to write to. |
| 2296 | * @param[in,out] exts Extension instances to add to. |
| 2297 | * |
| 2298 | * @return LY_ERR values. |
| 2299 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2300 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2301 | 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] | 2302 | struct lysp_ext_instance **exts) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2303 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2304 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2305 | char *buf, *word, *ptr; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2306 | size_t word_len; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2307 | unsigned long int num; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2308 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2309 | |
| 2310 | if (*flags & LYS_SET_MIN) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2311 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2312 | return LY_EVALID; |
| 2313 | } |
| 2314 | *flags |= LYS_SET_MIN; |
| 2315 | |
| 2316 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2317 | 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] | 2318 | |
| 2319 | 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] | 2320 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2321 | free(buf); |
| 2322 | return LY_EVALID; |
| 2323 | } |
| 2324 | |
| 2325 | errno = 0; |
| 2326 | num = strtoul(word, &ptr, 10); |
| 2327 | /* we have not parsed the whole argument */ |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2328 | if ((size_t)(ptr - word) != word_len) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2329 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2330 | free(buf); |
| 2331 | return LY_EVALID; |
| 2332 | } |
| 2333 | if ((errno == ERANGE) || (num > UINT32_MAX)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2334 | LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "min-elements"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2335 | free(buf); |
| 2336 | return LY_EVALID; |
| 2337 | } |
| 2338 | *min = num; |
| 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_MIN, 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), "min-elements"); |
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 ordered-by 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] flags Flags to write to. |
| 2360 | * @param[in,out] exts Extension instances to add to. |
| 2361 | * |
| 2362 | * @return LY_ERR values. |
| 2363 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2364 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2365 | 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] | 2366 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2367 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2368 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2369 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2370 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2371 | |
| 2372 | if (*flags & LYS_ORDBY_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2373 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "ordered-by"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2374 | return LY_EVALID; |
| 2375 | } |
| 2376 | |
| 2377 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2378 | 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] | 2379 | |
| 2380 | if ((word_len == 6) && !strncmp(word, "system", word_len)) { |
| 2381 | *flags |= LYS_ORDBY_SYSTEM; |
| 2382 | } else if ((word_len == 4) && !strncmp(word, "user", word_len)) { |
| 2383 | *flags |= LYS_ORDBY_USER; |
| 2384 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2385 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "ordered-by"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2386 | free(buf); |
| 2387 | return LY_EVALID; |
| 2388 | } |
| 2389 | free(buf); |
| 2390 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2391 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2392 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2393 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2394 | 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] | 2395 | break; |
| 2396 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2397 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "ordered-by"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2398 | return LY_EVALID; |
| 2399 | } |
| 2400 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2401 | return ret; |
| 2402 | } |
| 2403 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2404 | /** |
| 2405 | * @brief Parse the leaf-list statement. |
| 2406 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2407 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2408 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2409 | * @param[in,out] siblings Siblings to add to. |
| 2410 | * |
| 2411 | * @return LY_ERR values. |
| 2412 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2413 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2414 | 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] | 2415 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2416 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2417 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2418 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2419 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2420 | struct lysp_node_leaflist *llist; |
| 2421 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 2422 | /* create new leaf-list structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 2423 | LY_LIST_NEW_RET(ctx->ctx, siblings, llist, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2424 | llist->nodetype = LYS_LEAFLIST; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2425 | llist->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2426 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2427 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2428 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2429 | INSERT_WORD_RET(ctx, buf, llist->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2430 | |
| 2431 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2432 | 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] | 2433 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2434 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2435 | LY_CHECK_RET(parse_config(ctx, in, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2436 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2437 | case LY_STMT_DEFAULT: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2438 | PARSER_CHECK_STMTVER2_RET(ctx, "default", "leaf-list"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2439 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_DEFAULT, &llist->dflts, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2440 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2441 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2442 | 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] | 2443 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2444 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2445 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &llist->iffeatures, Y_STR_ARG, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2446 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2447 | case LY_STMT_MAX_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2448 | 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] | 2449 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2450 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2451 | 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] | 2452 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2453 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2454 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &llist->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2455 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2456 | case LY_STMT_ORDERED_BY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2457 | LY_CHECK_RET(parse_orderedby(ctx, in, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2458 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2459 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2460 | 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] | 2461 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2462 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2463 | LY_CHECK_RET(parse_status(ctx, in, &llist->flags, &llist->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2464 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2465 | case LY_STMT_TYPE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2466 | LY_CHECK_RET(parse_type(ctx, in, &llist->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2467 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2468 | case LY_STMT_UNITS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2469 | 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] | 2470 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2471 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2472 | LY_CHECK_RET(parse_when(ctx, in, &llist->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2473 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2474 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2475 | 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] | 2476 | break; |
| 2477 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2478 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "llist"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2479 | return LY_EVALID; |
| 2480 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2481 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 2482 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 2483 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2484 | /* mandatory substatements */ |
| 2485 | if (!llist->type.name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2486 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "type", "leaf-list"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2487 | return LY_EVALID; |
| 2488 | } |
| 2489 | |
| 2490 | return ret; |
| 2491 | } |
| 2492 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2493 | /** |
| 2494 | * @brief Parse the refine statement. |
| 2495 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2496 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2497 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2498 | * @param[in,out] refines Refines to add to. |
| 2499 | * |
| 2500 | * @return LY_ERR values. |
| 2501 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2502 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2503 | 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] | 2504 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2505 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2506 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2507 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2508 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2509 | struct lysp_refine *rf; |
| 2510 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2511 | LY_ARRAY_NEW_RET(ctx->ctx, *refines, rf, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2512 | |
| 2513 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2514 | 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] | 2515 | CHECK_NONEMPTY(ctx, word_len, "refine"); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2516 | INSERT_WORD_RET(ctx, buf, rf->nodeid, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2517 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 2518 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2519 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2520 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2521 | LY_CHECK_RET(parse_config(ctx, in, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2522 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2523 | case LY_STMT_DEFAULT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2524 | 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] | 2525 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2526 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2527 | 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] | 2528 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2529 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2530 | PARSER_CHECK_STMTVER2_RET(ctx, "if-feature", "refine"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2531 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &rf->iffeatures, Y_STR_ARG, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2532 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2533 | case LY_STMT_MAX_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2534 | 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] | 2535 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2536 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2537 | 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] | 2538 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2539 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2540 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &rf->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2541 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2542 | case LY_STMT_MANDATORY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2543 | LY_CHECK_RET(parse_mandatory(ctx, in, &rf->flags, &rf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2544 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2545 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2546 | 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] | 2547 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2548 | case LY_STMT_PRESENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2549 | 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] | 2550 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2551 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2552 | 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] | 2553 | break; |
| 2554 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2555 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "refine"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2556 | return LY_EVALID; |
| 2557 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2558 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2559 | return ret; |
| 2560 | } |
| 2561 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2562 | /** |
| 2563 | * @brief Parse the typedef statement. |
| 2564 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2565 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2566 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2567 | * @param[in,out] typedefs Typedefs to add to. |
| 2568 | * |
| 2569 | * @return LY_ERR values. |
| 2570 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2571 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2572 | 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] | 2573 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2574 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2575 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2576 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2577 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2578 | struct lysp_tpdf *tpdf; |
| 2579 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2580 | LY_ARRAY_NEW_RET(ctx->ctx, *typedefs, tpdf, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2581 | |
| 2582 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2583 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2584 | INSERT_WORD_RET(ctx, buf, tpdf->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2585 | |
| 2586 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2587 | 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] | 2588 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2589 | case LY_STMT_DEFAULT: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2590 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DEFAULT, 0, &tpdf->dflt.str, Y_STR_ARG, &tpdf->exts)); |
| 2591 | tpdf->dflt.mod = ctx->main_mod; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2592 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2593 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2594 | 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] | 2595 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2596 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2597 | 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] | 2598 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2599 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2600 | LY_CHECK_RET(parse_status(ctx, in, &tpdf->flags, &tpdf->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2601 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2602 | case LY_STMT_TYPE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2603 | LY_CHECK_RET(parse_type(ctx, in, &tpdf->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2604 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2605 | case LY_STMT_UNITS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2606 | 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] | 2607 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2608 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2609 | 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] | 2610 | break; |
| 2611 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2612 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "typedef"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2613 | return LY_EVALID; |
| 2614 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2615 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 2616 | LY_CHECK_RET(ret); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 2617 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2618 | /* mandatory substatements */ |
| 2619 | if (!tpdf->type.name) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2620 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "type", "typedef"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2621 | return LY_EVALID; |
| 2622 | } |
| 2623 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 2624 | /* store data for collision check */ |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2625 | if (parent && !(parent->nodetype & (LYS_GROUPING | LYS_RPC | LYS_ACTION | LYS_INPUT | LYS_OUTPUT | LYS_NOTIF))) { |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 2626 | LY_CHECK_RET(ly_set_add(&ctx->tpdfs_nodes, parent, 0, NULL)); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 2627 | } |
| 2628 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2629 | return ret; |
| 2630 | } |
| 2631 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2632 | /** |
| 2633 | * @brief Parse the input or output statement. |
| 2634 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2635 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2636 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2637 | * @param[in] kw Type of this particular keyword |
| 2638 | * @param[in,out] inout_p Input/output pointer to write to. |
| 2639 | * |
| 2640 | * @return LY_ERR values. |
| 2641 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2642 | static LY_ERR |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2643 | parse_inout(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt inout_kw, struct lysp_node *parent, |
| 2644 | struct lysp_action_inout *inout_p) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2645 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2646 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2647 | char *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2648 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2649 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2650 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2651 | if (inout_p->nodetype) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2652 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(inout_kw)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2653 | return LY_EVALID; |
| 2654 | } |
| 2655 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2656 | /* initiate structure */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2657 | 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] | 2658 | inout_p->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2659 | |
| 2660 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2661 | 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] | 2662 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2663 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2664 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", ly_stmt2str(inout_kw)); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2665 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2666 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2667 | 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] | 2668 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2669 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2670 | 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] | 2671 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2672 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2673 | 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] | 2674 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2675 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2676 | 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] | 2677 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2678 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2679 | 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] | 2680 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2681 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2682 | 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] | 2683 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2684 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2685 | 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] | 2686 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2687 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2688 | 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] | 2689 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2690 | case LY_STMT_MUST: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2691 | PARSER_CHECK_STMTVER2_RET(ctx, "must", ly_stmt2str(inout_kw)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2692 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &inout_p->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2693 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2694 | case LY_STMT_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2695 | 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] | 2696 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2697 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2698 | 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] | 2699 | break; |
| 2700 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2701 | 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] | 2702 | return LY_EVALID; |
| 2703 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2704 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2705 | LY_CHECK_RET(ret); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 2706 | |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2707 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2708 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2709 | 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] | 2710 | |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 2711 | if (!inout_p->data) { |
| 2712 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "data-def-stmt", ly_stmt2str(inout_kw)); |
| 2713 | return LY_EVALID; |
| 2714 | } |
| 2715 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2716 | return ret; |
| 2717 | } |
| 2718 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2719 | /** |
| 2720 | * @brief Parse the action statement. |
| 2721 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2722 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2723 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2724 | * @param[in,out] actions Actions to add to. |
| 2725 | * |
| 2726 | * @return LY_ERR values. |
| 2727 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2728 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2729 | 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] | 2730 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2731 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2732 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2733 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2734 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2735 | struct lysp_action *act; |
| 2736 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2737 | LY_ARRAY_NEW_RET(ctx->ctx, *actions, act, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2738 | |
| 2739 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2740 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2741 | INSERT_WORD_RET(ctx, buf, act->name, word, word_len); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 2742 | act->nodetype = parent ? LYS_ACTION : LYS_RPC; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2743 | act->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2744 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2745 | 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] | 2746 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2747 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2748 | 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] | 2749 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2750 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2751 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &act->iffeatures, Y_STR_ARG, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2752 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2753 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2754 | 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] | 2755 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2756 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2757 | LY_CHECK_RET(parse_status(ctx, in, &act->flags, &act->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2758 | break; |
| 2759 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2760 | case LY_STMT_INPUT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2761 | 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] | 2762 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2763 | case LY_STMT_OUTPUT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2764 | 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] | 2765 | break; |
| 2766 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2767 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2768 | 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] | 2769 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2770 | case LY_STMT_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2771 | 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] | 2772 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2773 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2774 | 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] | 2775 | break; |
| 2776 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2777 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), parent ? "action" : "rpc"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2778 | return LY_EVALID; |
| 2779 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2780 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2781 | LY_CHECK_RET(ret); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2782 | |
| 2783 | /* always initialize inout, they are technically present (needed for later deviations/refines) */ |
| 2784 | if (!act->input.nodetype) { |
| 2785 | act->input.nodetype = LYS_INPUT; |
| 2786 | act->input.parent = (struct lysp_node *)act; |
| 2787 | } |
| 2788 | if (!act->output.nodetype) { |
| 2789 | act->output.nodetype = LYS_OUTPUT; |
| 2790 | act->output.parent = (struct lysp_node *)act; |
| 2791 | } |
| 2792 | |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2793 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2794 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2795 | 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] | 2796 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2797 | return ret; |
| 2798 | } |
| 2799 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2800 | /** |
| 2801 | * @brief Parse the notification statement. |
| 2802 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2803 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2804 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2805 | * @param[in,out] notifs Notifications to add to. |
| 2806 | * |
| 2807 | * @return LY_ERR values. |
| 2808 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2809 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2810 | 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] | 2811 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2812 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2813 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2814 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2815 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2816 | struct lysp_notif *notif; |
| 2817 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2818 | LY_ARRAY_NEW_RET(ctx->ctx, *notifs, notif, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2819 | |
| 2820 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2821 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2822 | INSERT_WORD_RET(ctx, buf, notif->name, word, word_len); |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2823 | notif->nodetype = LYS_NOTIF; |
| 2824 | notif->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2825 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2826 | 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] | 2827 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2828 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2829 | 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] | 2830 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2831 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2832 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, ¬if->iffeatures, Y_STR_ARG, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2833 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2834 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2835 | 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] | 2836 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2837 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2838 | LY_CHECK_RET(parse_status(ctx, in, ¬if->flags, ¬if->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2839 | break; |
| 2840 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2841 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2842 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "notification"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2843 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2844 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2845 | 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] | 2846 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2847 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2848 | 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] | 2849 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2850 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2851 | 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] | 2852 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2853 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2854 | 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] | 2855 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2856 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2857 | 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] | 2858 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2859 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2860 | 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] | 2861 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2862 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2863 | 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] | 2864 | break; |
| 2865 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2866 | case LY_STMT_MUST: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2867 | PARSER_CHECK_STMTVER2_RET(ctx, "must", "notification"); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2868 | LY_CHECK_RET(parse_restrs(ctx, in, kw, ¬if->musts)); |
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_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2871 | 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] | 2872 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2873 | case LY_STMT_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2874 | 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] | 2875 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2876 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2877 | 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] | 2878 | break; |
| 2879 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2880 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "notification"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2881 | return LY_EVALID; |
| 2882 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2883 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2884 | LY_CHECK_RET(ret); |
| 2885 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2886 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2887 | 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] | 2888 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2889 | return ret; |
| 2890 | } |
| 2891 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2892 | /** |
| 2893 | * @brief Parse the grouping statement. |
| 2894 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2895 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2896 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2897 | * @param[in,out] groupings Groupings to add to. |
| 2898 | * |
| 2899 | * @return LY_ERR values. |
| 2900 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2901 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2902 | 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] | 2903 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2904 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2905 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2906 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2907 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2908 | struct lysp_grp *grp; |
| 2909 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 2910 | LY_ARRAY_NEW_RET(ctx->ctx, *groupings, grp, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2911 | |
| 2912 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2913 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 2914 | INSERT_WORD_RET(ctx, buf, grp->name, word, word_len); |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2915 | grp->nodetype = LYS_GROUPING; |
| 2916 | grp->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2917 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2918 | 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] | 2919 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2920 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2921 | 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] | 2922 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2923 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2924 | 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] | 2925 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2926 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2927 | LY_CHECK_RET(parse_status(ctx, in, &grp->flags, &grp->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2928 | break; |
| 2929 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2930 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2931 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "grouping"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2932 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2933 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2934 | 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] | 2935 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2936 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2937 | 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] | 2938 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2939 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2940 | 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] | 2941 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2942 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2943 | 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] | 2944 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2945 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2946 | 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] | 2947 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2948 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2949 | 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] | 2950 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2951 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2952 | 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] | 2953 | break; |
| 2954 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2955 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2956 | 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] | 2957 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2958 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2959 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "grouping"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2960 | 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] | 2961 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2962 | case LY_STMT_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2963 | 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] | 2964 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2965 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 2966 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "grouping"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2967 | 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] | 2968 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2969 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2970 | 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] | 2971 | break; |
| 2972 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 2973 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "grouping"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2974 | return LY_EVALID; |
| 2975 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2976 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 2977 | LY_CHECK_RET(ret); |
| 2978 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2979 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2980 | 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] | 2981 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2982 | return ret; |
| 2983 | } |
| 2984 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2985 | /** |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2986 | * @brief Parse the augment statement. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2987 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2988 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2989 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 2990 | * @param[in,out] augments Augments to add to. |
| 2991 | * |
| 2992 | * @return LY_ERR values. |
| 2993 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 2994 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 2995 | 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] | 2996 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 2997 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 2998 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2999 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3000 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3001 | struct lysp_augment *aug; |
| 3002 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 3003 | LY_ARRAY_NEW_RET(ctx->ctx, *augments, aug, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3004 | |
| 3005 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3006 | 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] | 3007 | CHECK_NONEMPTY(ctx, word_len, "augment"); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3008 | INSERT_WORD_RET(ctx, buf, aug->nodeid, word, word_len); |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3009 | aug->nodetype = LYS_AUGMENT; |
| 3010 | aug->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3011 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3012 | 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] | 3013 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3014 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3015 | 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] | 3016 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3017 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3018 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &aug->iffeatures, Y_STR_ARG, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3019 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3020 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3021 | 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] | 3022 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3023 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3024 | LY_CHECK_RET(parse_status(ctx, in, &aug->flags, &aug->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3025 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3026 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3027 | LY_CHECK_RET(parse_when(ctx, in, &aug->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3028 | break; |
| 3029 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3030 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3031 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "augment"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3032 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3033 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3034 | 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] | 3035 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3036 | case LY_STMT_CASE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3037 | 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] | 3038 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3039 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3040 | 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] | 3041 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3042 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3043 | 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] | 3044 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3045 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3046 | 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] | 3047 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3048 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3049 | 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] | 3050 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3051 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3052 | 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] | 3053 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3054 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3055 | 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] | 3056 | break; |
| 3057 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3058 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3059 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "augment"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3060 | 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] | 3061 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3062 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3063 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "augment"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3064 | 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] | 3065 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3066 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3067 | 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] | 3068 | break; |
| 3069 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3070 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "augment"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3071 | return LY_EVALID; |
| 3072 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3073 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3074 | LY_CHECK_RET(ret); |
| 3075 | checks: |
| 3076 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3077 | 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] | 3078 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3079 | return ret; |
| 3080 | } |
| 3081 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3082 | /** |
| 3083 | * @brief Parse the uses statement. |
| 3084 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3085 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3086 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3087 | * @param[in,out] siblings Siblings to add to. |
| 3088 | * |
| 3089 | * @return LY_ERR values. |
| 3090 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3091 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3092 | 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] | 3093 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3094 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3095 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3096 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3097 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3098 | struct lysp_node_uses *uses; |
| 3099 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3100 | /* create uses structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3101 | LY_LIST_NEW_RET(ctx->ctx, siblings, uses, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3102 | uses->nodetype = LYS_USES; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3103 | uses->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3104 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3105 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3106 | LY_CHECK_RET(get_argument(ctx, in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3107 | INSERT_WORD_RET(ctx, buf, uses->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3108 | |
| 3109 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3110 | 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] | 3111 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3112 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3113 | 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] | 3114 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3115 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3116 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &uses->iffeatures, Y_STR_ARG, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3117 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3118 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3119 | 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] | 3120 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3121 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3122 | LY_CHECK_RET(parse_status(ctx, in, &uses->flags, &uses->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3123 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3124 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3125 | LY_CHECK_RET(parse_when(ctx, in, &uses->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3126 | break; |
| 3127 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3128 | case LY_STMT_REFINE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3129 | LY_CHECK_RET(parse_refine(ctx, in, &uses->refines)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3130 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3131 | case LY_STMT_AUGMENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3132 | 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] | 3133 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3134 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3135 | 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] | 3136 | break; |
| 3137 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3138 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "uses"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3139 | return LY_EVALID; |
| 3140 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3141 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3142 | checks: |
| 3143 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3144 | 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] | 3145 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3146 | return ret; |
| 3147 | } |
| 3148 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3149 | /** |
| 3150 | * @brief Parse the case statement. |
| 3151 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3152 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3153 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3154 | * @param[in,out] siblings Siblings to add to. |
| 3155 | * |
| 3156 | * @return LY_ERR values. |
| 3157 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3158 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3159 | 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] | 3160 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3161 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3162 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3163 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3164 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3165 | struct lysp_node_case *cas; |
| 3166 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3167 | /* create new case structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3168 | LY_LIST_NEW_RET(ctx->ctx, siblings, cas, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3169 | cas->nodetype = LYS_CASE; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3170 | cas->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3171 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3172 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3173 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3174 | INSERT_WORD_RET(ctx, buf, cas->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3175 | |
| 3176 | /* parse substatements */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3177 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3178 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3179 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3180 | 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] | 3181 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3182 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3183 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &cas->iffeatures, Y_STR_ARG, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3184 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3185 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3186 | 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] | 3187 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3188 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3189 | LY_CHECK_RET(parse_status(ctx, in, &cas->flags, &cas->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3190 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3191 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3192 | LY_CHECK_RET(parse_when(ctx, in, &cas->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3193 | break; |
| 3194 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3195 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3196 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "case"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3197 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3198 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3199 | 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] | 3200 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3201 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3202 | 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] | 3203 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3204 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3205 | 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] | 3206 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3207 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3208 | 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] | 3209 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3210 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3211 | 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] | 3212 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3213 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3214 | 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] | 3215 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3216 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3217 | 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] | 3218 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3219 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3220 | 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] | 3221 | break; |
| 3222 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3223 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "case"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3224 | return LY_EVALID; |
| 3225 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3226 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3227 | return ret; |
| 3228 | } |
| 3229 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3230 | /** |
| 3231 | * @brief Parse the choice statement. |
| 3232 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3233 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3234 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3235 | * @param[in,out] siblings Siblings to add to. |
| 3236 | * |
| 3237 | * @return LY_ERR values. |
| 3238 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3239 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3240 | 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] | 3241 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3242 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3243 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3244 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3245 | enum ly_stmt kw; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3246 | struct lysp_node_choice *choice; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3247 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3248 | /* create new choice structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3249 | LY_LIST_NEW_RET(ctx->ctx, siblings, choice, next, LY_EMEM); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3250 | choice->nodetype = LYS_CHOICE; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3251 | choice->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3252 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3253 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3254 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3255 | INSERT_WORD_RET(ctx, buf, choice->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3256 | |
| 3257 | /* parse substatements */ |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3258 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3259 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3260 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3261 | LY_CHECK_RET(parse_config(ctx, in, &choice->flags, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3262 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3263 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3264 | 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] | 3265 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3266 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3267 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &choice->iffeatures, Y_STR_ARG, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3268 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3269 | case LY_STMT_MANDATORY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3270 | LY_CHECK_RET(parse_mandatory(ctx, in, &choice->flags, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3271 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3272 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3273 | 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] | 3274 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3275 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3276 | LY_CHECK_RET(parse_status(ctx, in, &choice->flags, &choice->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3277 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3278 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3279 | LY_CHECK_RET(parse_when(ctx, in, &choice->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3280 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3281 | case LY_STMT_DEFAULT: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3282 | LY_CHECK_RET(parse_text_field(ctx, in, LYEXT_SUBSTMT_DEFAULT, 0, &choice->dflt.str, Y_PREF_IDENTIF_ARG, |
| 3283 | &choice->exts)); |
| 3284 | choice->dflt.mod = ctx->main_mod; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3285 | break; |
| 3286 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3287 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3288 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "choice"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3289 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3290 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3291 | 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] | 3292 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3293 | case LY_STMT_CASE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3294 | 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] | 3295 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3296 | case LY_STMT_CHOICE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3297 | PARSER_CHECK_STMTVER2_RET(ctx, "choice", "choice"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3298 | 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] | 3299 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3300 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3301 | 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] | 3302 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3303 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3304 | 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] | 3305 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3306 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3307 | 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] | 3308 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3309 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3310 | 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] | 3311 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3312 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3313 | 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] | 3314 | break; |
| 3315 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3316 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "choice"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3317 | return LY_EVALID; |
| 3318 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3319 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3320 | return ret; |
| 3321 | } |
| 3322 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3323 | /** |
| 3324 | * @brief Parse the container statement. |
| 3325 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3326 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3327 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3328 | * @param[in,out] siblings Siblings to add to. |
| 3329 | * |
| 3330 | * @return LY_ERR values. |
| 3331 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3332 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3333 | 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] | 3334 | { |
| 3335 | LY_ERR ret = 0; |
| 3336 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3337 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3338 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3339 | struct lysp_node_container *cont; |
| 3340 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3341 | /* create new container structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3342 | LY_LIST_NEW_RET(ctx->ctx, siblings, cont, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3343 | cont->nodetype = LYS_CONTAINER; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3344 | cont->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3345 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3346 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3347 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3348 | INSERT_WORD_RET(ctx, buf, cont->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3349 | |
| 3350 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3351 | 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] | 3352 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3353 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3354 | LY_CHECK_RET(parse_config(ctx, in, &cont->flags, &cont->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3355 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3356 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3357 | 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] | 3358 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3359 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3360 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &cont->iffeatures, Y_STR_ARG, &cont->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3361 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3362 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3363 | 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] | 3364 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3365 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3366 | LY_CHECK_RET(parse_status(ctx, in, &cont->flags, &cont->exts)); |
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_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3369 | LY_CHECK_RET(parse_when(ctx, in, &cont->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3370 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3371 | case LY_STMT_PRESENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3372 | 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] | 3373 | break; |
| 3374 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3375 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3376 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "container"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3377 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3378 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3379 | 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] | 3380 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3381 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3382 | 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] | 3383 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3384 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3385 | 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] | 3386 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3387 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3388 | 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] | 3389 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3390 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3391 | 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] | 3392 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3393 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3394 | 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] | 3395 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3396 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3397 | 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] | 3398 | break; |
| 3399 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3400 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3401 | 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] | 3402 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3403 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3404 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &cont->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3405 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3406 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3407 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "container"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3408 | 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] | 3409 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3410 | case LY_STMT_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3411 | 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] | 3412 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3413 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3414 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "container"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3415 | 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] | 3416 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3417 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3418 | 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] | 3419 | break; |
| 3420 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3421 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "container"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3422 | return LY_EVALID; |
| 3423 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3424 | } |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3425 | checks: |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 3426 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3427 | 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] | 3428 | return ret; |
| 3429 | } |
| 3430 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3431 | /** |
| 3432 | * @brief Parse the list statement. |
| 3433 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3434 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3435 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3436 | * @param[in,out] siblings Siblings to add to. |
| 3437 | * |
| 3438 | * @return LY_ERR values. |
| 3439 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3440 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3441 | 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] | 3442 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3443 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3444 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3445 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3446 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3447 | struct lysp_node_list *list; |
| 3448 | |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3449 | /* create new list structure */ |
David Sedlák | b9eeb9c | 2019-09-13 11:17:19 +0200 | [diff] [blame] | 3450 | LY_LIST_NEW_RET(ctx->ctx, siblings, list, next, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3451 | list->nodetype = LYS_LIST; |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3452 | list->parent = parent; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3453 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3454 | /* get name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3455 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3456 | INSERT_WORD_RET(ctx, buf, list->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3457 | |
| 3458 | /* parse substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3459 | 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] | 3460 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3461 | case LY_STMT_CONFIG: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3462 | LY_CHECK_RET(parse_config(ctx, in, &list->flags, &list->exts)); |
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_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3465 | 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] | 3466 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3467 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3468 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &list->iffeatures, Y_STR_ARG, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3469 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3470 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3471 | 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] | 3472 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3473 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3474 | LY_CHECK_RET(parse_status(ctx, in, &list->flags, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3475 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3476 | case LY_STMT_WHEN: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3477 | LY_CHECK_RET(parse_when(ctx, in, &list->when)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3478 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3479 | case LY_STMT_KEY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3480 | 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] | 3481 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3482 | case LY_STMT_MAX_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3483 | 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] | 3484 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3485 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3486 | 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] | 3487 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3488 | case LY_STMT_ORDERED_BY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3489 | LY_CHECK_RET(parse_orderedby(ctx, in, &list->flags, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3490 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3491 | case LY_STMT_UNIQUE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3492 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_UNIQUE, &list->uniques, Y_STR_ARG, &list->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3493 | break; |
| 3494 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3495 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3496 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "list"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3497 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3498 | case LY_STMT_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3499 | 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] | 3500 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3501 | case LY_STMT_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3502 | 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] | 3503 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3504 | case LY_STMT_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3505 | 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] | 3506 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3507 | case LY_STMT_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3508 | 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] | 3509 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3510 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3511 | 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] | 3512 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3513 | case LY_STMT_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3514 | 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] | 3515 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3516 | case LY_STMT_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3517 | 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] | 3518 | break; |
| 3519 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3520 | case LY_STMT_TYPEDEF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3521 | 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] | 3522 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3523 | case LY_STMT_MUST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3524 | LY_CHECK_RET(parse_restrs(ctx, in, kw, &list->musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3525 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3526 | case LY_STMT_ACTION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3527 | PARSER_CHECK_STMTVER2_RET(ctx, "action", "list"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3528 | 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] | 3529 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3530 | case LY_STMT_GROUPING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3531 | 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] | 3532 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3533 | case LY_STMT_NOTIFICATION: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 3534 | PARSER_CHECK_STMTVER2_RET(ctx, "notification", "list"); |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 3535 | 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] | 3536 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3537 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3538 | 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] | 3539 | break; |
| 3540 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3541 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "list"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3542 | return LY_EVALID; |
| 3543 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3544 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 3545 | LY_CHECK_RET(ret); |
| 3546 | checks: |
Radek Krejci | 7fc6829 | 2019-06-12 13:51:09 +0200 | [diff] [blame] | 3547 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3548 | 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] | 3549 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3550 | return ret; |
| 3551 | } |
| 3552 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3553 | /** |
| 3554 | * @brief Parse the yin-element statement. |
| 3555 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3556 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3557 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3558 | * @param[in,out] flags Flags to write to. |
| 3559 | * @param[in,out] exts Extension instances to add to. |
| 3560 | * |
| 3561 | * @return LY_ERR values. |
| 3562 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3563 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3564 | 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] | 3565 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3566 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3567 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3568 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3569 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3570 | |
| 3571 | if (*flags & LYS_YINELEM_MASK) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3572 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "yin-element"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3573 | return LY_EVALID; |
| 3574 | } |
| 3575 | |
| 3576 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3577 | 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] | 3578 | |
| 3579 | if ((word_len == 4) && !strncmp(word, "true", word_len)) { |
| 3580 | *flags |= LYS_YINELEM_TRUE; |
| 3581 | } else if ((word_len == 5) && !strncmp(word, "false", word_len)) { |
| 3582 | *flags |= LYS_YINELEM_FALSE; |
| 3583 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3584 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "yin-element"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3585 | free(buf); |
| 3586 | return LY_EVALID; |
| 3587 | } |
| 3588 | free(buf); |
| 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_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3593 | 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] | 3594 | LY_CHECK_RET(ret); |
| 3595 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3596 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3597 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "yin-element"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3598 | return LY_EVALID; |
| 3599 | } |
| 3600 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3601 | return ret; |
| 3602 | } |
| 3603 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3604 | /** |
David Sedlák | 2444f8f | 2019-07-09 11:02:47 +0200 | [diff] [blame] | 3605 | * @brief Parse the argument statement. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3606 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3607 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3608 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3609 | * @param[in,out] argument Value to write to. |
| 3610 | * @param[in,out] flags Flags to write to. |
| 3611 | * @param[in,out] exts Extension instances 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_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] | 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 | |
| 3623 | if (*argument) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3624 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "argument"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3625 | return LY_EVALID; |
| 3626 | } |
| 3627 | |
| 3628 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3629 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3630 | INSERT_WORD_RET(ctx, buf, *argument, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3631 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3632 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3633 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3634 | case LY_STMT_YIN_ELEMENT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3635 | LY_CHECK_RET(parse_yinelement(ctx, in, flags, exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3636 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3637 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3638 | 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] | 3639 | break; |
| 3640 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3641 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "argument"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3642 | return LY_EVALID; |
| 3643 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3644 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3645 | return ret; |
| 3646 | } |
| 3647 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3648 | /** |
| 3649 | * @brief Parse the extension statement. |
| 3650 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3651 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3652 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3653 | * @param[in,out] extensions Extensions to add to. |
| 3654 | * |
| 3655 | * @return LY_ERR values. |
| 3656 | */ |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3657 | static LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3658 | 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] | 3659 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3660 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3661 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3662 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3663 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3664 | struct lysp_ext *ex; |
| 3665 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 3666 | LY_ARRAY_NEW_RET(ctx->ctx, *extensions, ex, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3667 | |
| 3668 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3669 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3670 | INSERT_WORD_RET(ctx, buf, ex->name, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3671 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3672 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3673 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3674 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3675 | 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] | 3676 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3677 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3678 | 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] | 3679 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3680 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3681 | LY_CHECK_RET(parse_status(ctx, in, &ex->flags, &ex->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3682 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3683 | case LY_STMT_ARGUMENT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3684 | 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] | 3685 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3686 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3687 | 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] | 3688 | break; |
| 3689 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3690 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "extension"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3691 | return LY_EVALID; |
| 3692 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3693 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3694 | return ret; |
| 3695 | } |
| 3696 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3697 | /** |
| 3698 | * @brief Parse the deviate statement. |
| 3699 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3700 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3701 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3702 | * @param[in,out] deviates Deviates to add to. |
| 3703 | * |
| 3704 | * @return LY_ERR values. |
| 3705 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3706 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3707 | 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] | 3708 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3709 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3710 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3711 | size_t word_len, dev_mod; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3712 | enum ly_stmt kw; |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3713 | struct lysp_deviate *d; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3714 | struct lysp_deviate_add *d_add = NULL; |
| 3715 | struct lysp_deviate_rpl *d_rpl = NULL; |
| 3716 | struct lysp_deviate_del *d_del = NULL; |
Radek Krejci | 4ad42aa | 2019-07-23 16:55:58 +0200 | [diff] [blame] | 3717 | const char **d_units = NULL, ***d_uniques = NULL, ***d_dflts = NULL; |
| 3718 | struct lysp_restr **d_musts = NULL; |
| 3719 | uint16_t *d_flags = 0; |
| 3720 | uint32_t *d_min = 0, *d_max = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3721 | |
| 3722 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3723 | 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] | 3724 | |
| 3725 | if ((word_len == 13) && !strncmp(word, "not-supported", word_len)) { |
| 3726 | dev_mod = LYS_DEV_NOT_SUPPORTED; |
| 3727 | } else if ((word_len == 3) && !strncmp(word, "add", word_len)) { |
| 3728 | dev_mod = LYS_DEV_ADD; |
| 3729 | } else if ((word_len == 7) && !strncmp(word, "replace", word_len)) { |
| 3730 | dev_mod = LYS_DEV_REPLACE; |
| 3731 | } else if ((word_len == 6) && !strncmp(word, "delete", word_len)) { |
| 3732 | dev_mod = LYS_DEV_DELETE; |
| 3733 | } else { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3734 | LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "deviate"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3735 | free(buf); |
| 3736 | return LY_EVALID; |
| 3737 | } |
| 3738 | free(buf); |
| 3739 | |
| 3740 | /* create structure */ |
| 3741 | switch (dev_mod) { |
| 3742 | case LYS_DEV_NOT_SUPPORTED: |
| 3743 | d = calloc(1, sizeof *d); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3744 | LY_CHECK_ERR_RET(!d, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3745 | break; |
| 3746 | case LYS_DEV_ADD: |
| 3747 | d_add = calloc(1, sizeof *d_add); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3748 | LY_CHECK_ERR_RET(!d_add, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3749 | d = (struct lysp_deviate *)d_add; |
| 3750 | d_units = &d_add->units; |
| 3751 | d_uniques = &d_add->uniques; |
| 3752 | d_dflts = &d_add->dflts; |
| 3753 | d_musts = &d_add->musts; |
| 3754 | d_flags = &d_add->flags; |
| 3755 | d_min = &d_add->min; |
| 3756 | d_max = &d_add->max; |
| 3757 | break; |
| 3758 | case LYS_DEV_REPLACE: |
| 3759 | d_rpl = calloc(1, sizeof *d_rpl); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3760 | LY_CHECK_ERR_RET(!d_rpl, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3761 | d = (struct lysp_deviate *)d_rpl; |
| 3762 | d_units = &d_rpl->units; |
| 3763 | d_flags = &d_rpl->flags; |
| 3764 | d_min = &d_rpl->min; |
| 3765 | d_max = &d_rpl->max; |
| 3766 | break; |
| 3767 | case LYS_DEV_DELETE: |
| 3768 | d_del = calloc(1, sizeof *d_del); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3769 | LY_CHECK_ERR_RET(!d_del, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3770 | d = (struct lysp_deviate *)d_del; |
| 3771 | d_units = &d_del->units; |
| 3772 | d_uniques = &d_del->uniques; |
| 3773 | d_dflts = &d_del->dflts; |
| 3774 | d_musts = &d_del->musts; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3775 | break; |
| 3776 | default: |
| 3777 | assert(0); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3778 | LOGINT_RET(ctx->ctx); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3779 | } |
| 3780 | d->mod = dev_mod; |
| 3781 | |
| 3782 | /* insert into siblings */ |
David Sedlák | 60adc09 | 2019-08-06 15:57:02 +0200 | [diff] [blame] | 3783 | LY_LIST_INSERT(deviates, d, next); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3784 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3785 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3786 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3787 | case LY_STMT_CONFIG: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3788 | switch (dev_mod) { |
| 3789 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3790 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3791 | 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] | 3792 | return LY_EVALID; |
| 3793 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3794 | LY_CHECK_RET(parse_config(ctx, in, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3795 | break; |
| 3796 | } |
| 3797 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3798 | case LY_STMT_DEFAULT: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3799 | switch (dev_mod) { |
| 3800 | case LYS_DEV_NOT_SUPPORTED: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3801 | 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] | 3802 | return LY_EVALID; |
| 3803 | case LYS_DEV_REPLACE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3804 | 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] | 3805 | break; |
| 3806 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3807 | 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] | 3808 | break; |
| 3809 | } |
| 3810 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3811 | case LY_STMT_MANDATORY: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3812 | switch (dev_mod) { |
| 3813 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3814 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3815 | 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] | 3816 | return LY_EVALID; |
| 3817 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3818 | LY_CHECK_RET(parse_mandatory(ctx, in, d_flags, &d->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3819 | break; |
| 3820 | } |
| 3821 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3822 | case LY_STMT_MAX_ELEMENTS: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3823 | switch (dev_mod) { |
| 3824 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3825 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3826 | 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] | 3827 | return LY_EVALID; |
| 3828 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3829 | 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] | 3830 | break; |
| 3831 | } |
| 3832 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3833 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3834 | switch (dev_mod) { |
| 3835 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3836 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3837 | 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] | 3838 | return LY_EVALID; |
| 3839 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3840 | 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] | 3841 | break; |
| 3842 | } |
| 3843 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3844 | case LY_STMT_MUST: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3845 | switch (dev_mod) { |
| 3846 | case LYS_DEV_NOT_SUPPORTED: |
Michal Vasko | 492bec7 | 2018-09-18 13:11:10 +0200 | [diff] [blame] | 3847 | case LYS_DEV_REPLACE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3848 | 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] | 3849 | return LY_EVALID; |
| 3850 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3851 | LY_CHECK_RET(parse_restrs(ctx, in, kw, d_musts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3852 | break; |
| 3853 | } |
| 3854 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3855 | case LY_STMT_TYPE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3856 | switch (dev_mod) { |
| 3857 | case LYS_DEV_NOT_SUPPORTED: |
| 3858 | case LYS_DEV_ADD: |
| 3859 | case LYS_DEV_DELETE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3860 | 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] | 3861 | return LY_EVALID; |
| 3862 | default: |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 3863 | if (d_rpl->type) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3864 | LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, ly_stmt2str(kw)); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 3865 | return LY_EVALID; |
| 3866 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3867 | d_rpl->type = calloc(1, sizeof *d_rpl->type); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3868 | LY_CHECK_ERR_RET(!d_rpl->type, LOGMEM(ctx->ctx), LY_EMEM); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3869 | LY_CHECK_RET(parse_type(ctx, in, d_rpl->type)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3870 | break; |
| 3871 | } |
| 3872 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3873 | case LY_STMT_UNIQUE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3874 | switch (dev_mod) { |
| 3875 | case LYS_DEV_NOT_SUPPORTED: |
| 3876 | case LYS_DEV_REPLACE: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3877 | 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] | 3878 | return LY_EVALID; |
| 3879 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3880 | 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] | 3881 | break; |
| 3882 | } |
| 3883 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3884 | case LY_STMT_UNITS: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3885 | switch (dev_mod) { |
| 3886 | case LYS_DEV_NOT_SUPPORTED: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3887 | 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] | 3888 | return LY_EVALID; |
| 3889 | default: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3890 | 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] | 3891 | break; |
| 3892 | } |
| 3893 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3894 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3895 | 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] | 3896 | break; |
| 3897 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3898 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "deviate"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3899 | return LY_EVALID; |
| 3900 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3901 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3902 | return ret; |
| 3903 | } |
| 3904 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3905 | /** |
| 3906 | * @brief Parse the deviation statement. |
| 3907 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3908 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3909 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3910 | * @param[in,out] deviations Deviations to add to. |
| 3911 | * |
| 3912 | * @return LY_ERR values. |
| 3913 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3914 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3915 | 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] | 3916 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3917 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3918 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3919 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3920 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3921 | struct lysp_deviation *dev; |
| 3922 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 3923 | LY_ARRAY_NEW_RET(ctx->ctx, *deviations, dev, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3924 | |
| 3925 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3926 | 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] | 3927 | CHECK_NONEMPTY(ctx, word_len, "deviation"); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3928 | INSERT_WORD_RET(ctx, buf, dev->nodeid, word, word_len); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3929 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3930 | 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] | 3931 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3932 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3933 | 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] | 3934 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3935 | case LY_STMT_DEVIATE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3936 | LY_CHECK_RET(parse_deviate(ctx, in, &dev->deviates)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3937 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3938 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3939 | 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] | 3940 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3941 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3942 | 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] | 3943 | break; |
| 3944 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3945 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "deviation"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3946 | return LY_EVALID; |
| 3947 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3948 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 3949 | LY_CHECK_RET(ret); |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 3950 | checks: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3951 | /* mandatory substatements */ |
| 3952 | if (!dev->deviates) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 3953 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "deviate", "deviation"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3954 | return LY_EVALID; |
| 3955 | } |
| 3956 | |
| 3957 | return ret; |
| 3958 | } |
| 3959 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3960 | /** |
| 3961 | * @brief Parse the feature statement. |
| 3962 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 3963 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3964 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 3965 | * @param[in,out] features Features to add to. |
| 3966 | * |
| 3967 | * @return LY_ERR values. |
| 3968 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 3969 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3970 | 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] | 3971 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 3972 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3973 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 3974 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3975 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3976 | struct lysp_feature *feat; |
| 3977 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 3978 | LY_ARRAY_NEW_RET(ctx->ctx, *features, feat, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3979 | |
| 3980 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3981 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3982 | INSERT_WORD_RET(ctx, buf, feat->name, word, word_len); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 3983 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 3984 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3985 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3986 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3987 | 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] | 3988 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3989 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3990 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &feat->iffeatures, Y_STR_ARG, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3991 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3992 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3993 | 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] | 3994 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3995 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3996 | LY_CHECK_RET(parse_status(ctx, in, &feat->flags, &feat->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 3997 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3998 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3999 | 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] | 4000 | break; |
| 4001 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4002 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "feature"); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 4003 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4004 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4005 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4006 | return ret; |
| 4007 | } |
| 4008 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4009 | /** |
| 4010 | * @brief Parse the identity statement. |
| 4011 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 4012 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4013 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4014 | * @param[in,out] identities Identities to add to. |
| 4015 | * |
| 4016 | * @return LY_ERR values. |
| 4017 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 4018 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4019 | 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] | 4020 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 4021 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4022 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 4023 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4024 | enum ly_stmt kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4025 | struct lysp_ident *ident; |
| 4026 | |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 4027 | LY_ARRAY_NEW_RET(ctx->ctx, *identities, ident, LY_EMEM); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4028 | |
| 4029 | /* get value */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4030 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 4031 | INSERT_WORD_RET(ctx, buf, ident->name, word, word_len); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 4032 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 4033 | YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) { |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4034 | switch (kw) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4035 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4036 | 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] | 4037 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4038 | case LY_STMT_IF_FEATURE: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 4039 | PARSER_CHECK_STMTVER2_RET(ctx, "if-feature", "identity"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 4040 | LY_CHECK_RET(parse_qnames(ctx, in, LYEXT_SUBSTMT_IFFEATURE, &ident->iffeatures, Y_STR_ARG, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4041 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4042 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4043 | 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] | 4044 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4045 | case LY_STMT_STATUS: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4046 | LY_CHECK_RET(parse_status(ctx, in, &ident->flags, &ident->exts)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4047 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4048 | case LY_STMT_BASE: |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 4049 | if (ident->bases && (ctx->mod_version < 2)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4050 | 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] | 4051 | return LY_EVALID; |
| 4052 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4053 | 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] | 4054 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4055 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4056 | 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] | 4057 | break; |
| 4058 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4059 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "identity"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4060 | return LY_EVALID; |
| 4061 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4062 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4063 | return ret; |
| 4064 | } |
| 4065 | |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4066 | /** |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4067 | * @brief Parse module substatements. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4068 | * |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 4069 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4070 | * @param[in,out] in Input structure. |
Michal Vasko | ea5abea | 2018-09-18 13:10:54 +0200 | [diff] [blame] | 4071 | * @param[in,out] mod Module to write to. |
| 4072 | * |
| 4073 | * @return LY_ERR values. |
| 4074 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 4075 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4076 | 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] | 4077 | { |
| 4078 | LY_ERR ret = 0; |
| 4079 | char *buf, *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 4080 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4081 | enum ly_stmt kw, prev_kw = 0; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4082 | enum yang_module_stmt mod_stmt = Y_MOD_MODULE_HEADER; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4083 | struct lysp_submodule *dup; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4084 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4085 | mod->is_submod = 0; |
| 4086 | |
| 4087 | /* module name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4088 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 4089 | INSERT_WORD_RET(ctx, buf, mod->mod->name, word, word_len); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 4090 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4091 | 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] | 4092 | |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4093 | #define CHECK_ORDER(SECTION) \ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4094 | 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] | 4095 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4096 | switch (kw) { |
| 4097 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4098 | case LY_STMT_NAMESPACE: |
| 4099 | case LY_STMT_PREFIX: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4100 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
| 4101 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4102 | case LY_STMT_YANG_VERSION: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4103 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4104 | break; |
| 4105 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4106 | case LY_STMT_INCLUDE: |
| 4107 | case LY_STMT_IMPORT: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4108 | CHECK_ORDER(Y_MOD_LINKAGE); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4109 | break; |
| 4110 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4111 | case LY_STMT_ORGANIZATION: |
| 4112 | case LY_STMT_CONTACT: |
| 4113 | case LY_STMT_DESCRIPTION: |
| 4114 | case LY_STMT_REFERENCE: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4115 | CHECK_ORDER(Y_MOD_META); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4116 | break; |
| 4117 | |
| 4118 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4119 | case LY_STMT_REVISION: |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4120 | CHECK_ORDER(Y_MOD_REVISION); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4121 | break; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4122 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4123 | case LY_STMT_ANYDATA: |
| 4124 | case LY_STMT_ANYXML: |
| 4125 | case LY_STMT_AUGMENT: |
| 4126 | case LY_STMT_CHOICE: |
| 4127 | case LY_STMT_CONTAINER: |
| 4128 | case LY_STMT_DEVIATION: |
| 4129 | case LY_STMT_EXTENSION: |
| 4130 | case LY_STMT_FEATURE: |
| 4131 | case LY_STMT_GROUPING: |
| 4132 | case LY_STMT_IDENTITY: |
| 4133 | case LY_STMT_LEAF: |
| 4134 | case LY_STMT_LEAF_LIST: |
| 4135 | case LY_STMT_LIST: |
| 4136 | case LY_STMT_NOTIFICATION: |
| 4137 | case LY_STMT_RPC: |
| 4138 | case LY_STMT_TYPEDEF: |
| 4139 | case LY_STMT_USES: |
| 4140 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4141 | mod_stmt = Y_MOD_BODY; |
| 4142 | break; |
| 4143 | default: |
| 4144 | /* error handled in the next switch */ |
| 4145 | break; |
| 4146 | } |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4147 | #undef CHECK_ORDER |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4148 | |
Radek Krejci | e384647 | 2018-10-15 15:24:51 +0200 | [diff] [blame] | 4149 | prev_kw = kw; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4150 | switch (kw) { |
| 4151 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4152 | case LY_STMT_YANG_VERSION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4153 | LY_CHECK_RET(parse_yangversion(ctx, in, &mod->mod->version, &mod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4154 | ctx->mod_version = mod->mod->version; |
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_NAMESPACE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4157 | 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] | 4158 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4159 | case LY_STMT_PREFIX: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4160 | 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] | 4161 | break; |
| 4162 | |
| 4163 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4164 | case LY_STMT_INCLUDE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4165 | LY_CHECK_RET(parse_include(ctx, mod->mod->name, in, &mod->includes)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4166 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4167 | case LY_STMT_IMPORT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4168 | LY_CHECK_RET(parse_import(ctx, mod->mod->prefix, in, &mod->imports)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4169 | break; |
| 4170 | |
| 4171 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4172 | case LY_STMT_ORGANIZATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4173 | 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] | 4174 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4175 | case LY_STMT_CONTACT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4176 | 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] | 4177 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4178 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4179 | 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] | 4180 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4181 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4182 | 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] | 4183 | break; |
| 4184 | |
| 4185 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4186 | case LY_STMT_REVISION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4187 | LY_CHECK_RET(parse_revision(ctx, in, &mod->revs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4188 | break; |
| 4189 | |
| 4190 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4191 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 4192 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "module"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 4193 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4194 | case LY_STMT_ANYXML: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4195 | LY_CHECK_RET(parse_any(ctx, in, kw, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4196 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4197 | case LY_STMT_CHOICE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4198 | LY_CHECK_RET(parse_choice(ctx, in, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4199 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4200 | case LY_STMT_CONTAINER: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4201 | LY_CHECK_RET(parse_container(ctx, in, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4202 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4203 | case LY_STMT_LEAF: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4204 | LY_CHECK_RET(parse_leaf(ctx, in, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4205 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4206 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4207 | LY_CHECK_RET(parse_leaflist(ctx, in, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4208 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4209 | case LY_STMT_LIST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4210 | LY_CHECK_RET(parse_list(ctx, in, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4211 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4212 | case LY_STMT_USES: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4213 | LY_CHECK_RET(parse_uses(ctx, in, NULL, &mod->data)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4214 | break; |
| 4215 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4216 | case LY_STMT_AUGMENT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4217 | LY_CHECK_RET(parse_augment(ctx, in, NULL, &mod->augments)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4218 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4219 | case LY_STMT_DEVIATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4220 | LY_CHECK_RET(parse_deviation(ctx, in, &mod->deviations)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4221 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4222 | case LY_STMT_EXTENSION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4223 | LY_CHECK_RET(parse_extension(ctx, in, &mod->extensions)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4224 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4225 | case LY_STMT_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4226 | LY_CHECK_RET(parse_feature(ctx, in, &mod->features)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4227 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4228 | case LY_STMT_GROUPING: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4229 | LY_CHECK_RET(parse_grouping(ctx, in, NULL, &mod->groupings)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4230 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4231 | case LY_STMT_IDENTITY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4232 | LY_CHECK_RET(parse_identity(ctx, in, &mod->identities)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4233 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4234 | case LY_STMT_NOTIFICATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4235 | LY_CHECK_RET(parse_notif(ctx, in, NULL, &mod->notifs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4236 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4237 | case LY_STMT_RPC: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4238 | LY_CHECK_RET(parse_action(ctx, in, NULL, &mod->rpcs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4239 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4240 | case LY_STMT_TYPEDEF: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4241 | LY_CHECK_RET(parse_typedef(ctx, NULL, in, &mod->typedefs)); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4242 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4243 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4244 | 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] | 4245 | break; |
| 4246 | |
| 4247 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4248 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "module"); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4249 | return LY_EVALID; |
| 4250 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4251 | } |
Radek Krejci | c59bc97 | 2018-09-17 16:13:06 +0200 | [diff] [blame] | 4252 | LY_CHECK_RET(ret); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 4253 | |
Radek Krejci | 6d6556c | 2018-11-08 09:37:45 +0100 | [diff] [blame] | 4254 | checks: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4255 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4256 | 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] | 4257 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4258 | /* mandatory substatements */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4259 | if (!mod->mod->ns) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4260 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "namespace", "module"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4261 | return LY_EVALID; |
| 4262 | } else if (!mod->mod->prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4263 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "prefix", "module"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4264 | return LY_EVALID; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4265 | } |
| 4266 | |
Radek Krejci | e9e987e | 2018-10-31 12:50:27 +0100 | [diff] [blame] | 4267 | /* submodules share the namespace with the module names, so there must not be |
| 4268 | * 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] | 4269 | dup = ly_ctx_get_submodule(ctx->ctx, NULL, mod->mod->name, NULL); |
| 4270 | if (dup) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4271 | 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] | 4272 | return LY_EVALID; |
| 4273 | } |
| 4274 | |
| 4275 | return ret; |
| 4276 | } |
| 4277 | |
| 4278 | /** |
| 4279 | * @brief Parse submodule substatements. |
| 4280 | * |
| 4281 | * @param[in] ctx yang parser context for logging. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4282 | * @param[in,out] in Input structure. |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4283 | * @param[out] submod Parsed submodule structure. |
| 4284 | * |
| 4285 | * @return LY_ERR values. |
| 4286 | */ |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 4287 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4288 | 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] | 4289 | { |
| 4290 | LY_ERR ret = 0; |
| 4291 | char *buf, *word; |
| 4292 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4293 | enum ly_stmt kw, prev_kw = 0; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4294 | enum yang_module_stmt mod_stmt = Y_MOD_MODULE_HEADER; |
| 4295 | struct lysp_submodule *dup; |
| 4296 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4297 | submod->is_submod = 1; |
| 4298 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4299 | /* submodule name */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4300 | LY_CHECK_RET(get_argument(ctx, in, Y_IDENTIF_ARG, NULL, &word, &buf, &word_len)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 4301 | INSERT_WORD_RET(ctx, buf, submod->name, word, word_len); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4302 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4303 | 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] | 4304 | |
| 4305 | #define CHECK_ORDER(SECTION) \ |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4306 | 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] | 4307 | |
| 4308 | switch (kw) { |
| 4309 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4310 | case LY_STMT_BELONGS_TO: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4311 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
| 4312 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4313 | case LY_STMT_YANG_VERSION: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4314 | CHECK_ORDER(Y_MOD_MODULE_HEADER); |
| 4315 | break; |
| 4316 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4317 | case LY_STMT_INCLUDE: |
| 4318 | case LY_STMT_IMPORT: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4319 | CHECK_ORDER(Y_MOD_LINKAGE); |
| 4320 | break; |
| 4321 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4322 | case LY_STMT_ORGANIZATION: |
| 4323 | case LY_STMT_CONTACT: |
| 4324 | case LY_STMT_DESCRIPTION: |
| 4325 | case LY_STMT_REFERENCE: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4326 | CHECK_ORDER(Y_MOD_META); |
| 4327 | break; |
| 4328 | |
| 4329 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4330 | case LY_STMT_REVISION: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4331 | CHECK_ORDER(Y_MOD_REVISION); |
| 4332 | break; |
| 4333 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4334 | case LY_STMT_ANYDATA: |
| 4335 | case LY_STMT_ANYXML: |
| 4336 | case LY_STMT_AUGMENT: |
| 4337 | case LY_STMT_CHOICE: |
| 4338 | case LY_STMT_CONTAINER: |
| 4339 | case LY_STMT_DEVIATION: |
| 4340 | case LY_STMT_EXTENSION: |
| 4341 | case LY_STMT_FEATURE: |
| 4342 | case LY_STMT_GROUPING: |
| 4343 | case LY_STMT_IDENTITY: |
| 4344 | case LY_STMT_LEAF: |
| 4345 | case LY_STMT_LEAF_LIST: |
| 4346 | case LY_STMT_LIST: |
| 4347 | case LY_STMT_NOTIFICATION: |
| 4348 | case LY_STMT_RPC: |
| 4349 | case LY_STMT_TYPEDEF: |
| 4350 | case LY_STMT_USES: |
| 4351 | case LY_STMT_EXTENSION_INSTANCE: |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4352 | mod_stmt = Y_MOD_BODY; |
| 4353 | break; |
| 4354 | default: |
| 4355 | /* error handled in the next switch */ |
| 4356 | break; |
| 4357 | } |
| 4358 | #undef CHECK_ORDER |
| 4359 | |
| 4360 | prev_kw = kw; |
| 4361 | switch (kw) { |
| 4362 | /* module header */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4363 | case LY_STMT_YANG_VERSION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4364 | LY_CHECK_RET(parse_yangversion(ctx, in, &submod->version, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4365 | ctx->mod_version = submod->version; |
| 4366 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4367 | case LY_STMT_BELONGS_TO: |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4368 | LY_CHECK_RET(parse_belongsto(ctx, in, &submod->prefix, &submod->exts)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4369 | break; |
| 4370 | |
| 4371 | /* linkage */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4372 | case LY_STMT_INCLUDE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4373 | LY_CHECK_RET(parse_include(ctx, submod->name, in, &submod->includes)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4374 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4375 | case LY_STMT_IMPORT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4376 | LY_CHECK_RET(parse_import(ctx, submod->prefix, in, &submod->imports)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4377 | break; |
| 4378 | |
| 4379 | /* meta */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4380 | case LY_STMT_ORGANIZATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4381 | 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] | 4382 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4383 | case LY_STMT_CONTACT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4384 | 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] | 4385 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4386 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4387 | 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] | 4388 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4389 | case LY_STMT_REFERENCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4390 | 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] | 4391 | break; |
| 4392 | |
| 4393 | /* revision */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4394 | case LY_STMT_REVISION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4395 | LY_CHECK_RET(parse_revision(ctx, in, &submod->revs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4396 | break; |
| 4397 | |
| 4398 | /* body */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4399 | case LY_STMT_ANYDATA: |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 4400 | PARSER_CHECK_STMTVER2_RET(ctx, "anydata", "submodule"); |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 4401 | /* fall through */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4402 | case LY_STMT_ANYXML: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4403 | LY_CHECK_RET(parse_any(ctx, in, kw, NULL, &submod->data)); |
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_CHOICE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4406 | LY_CHECK_RET(parse_choice(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4407 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4408 | case LY_STMT_CONTAINER: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4409 | LY_CHECK_RET(parse_container(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4410 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4411 | case LY_STMT_LEAF: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4412 | LY_CHECK_RET(parse_leaf(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4413 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4414 | case LY_STMT_LEAF_LIST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4415 | LY_CHECK_RET(parse_leaflist(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4416 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4417 | case LY_STMT_LIST: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4418 | LY_CHECK_RET(parse_list(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4419 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4420 | case LY_STMT_USES: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4421 | LY_CHECK_RET(parse_uses(ctx, in, NULL, &submod->data)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4422 | break; |
| 4423 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4424 | case LY_STMT_AUGMENT: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4425 | LY_CHECK_RET(parse_augment(ctx, in, NULL, &submod->augments)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4426 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4427 | case LY_STMT_DEVIATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4428 | LY_CHECK_RET(parse_deviation(ctx, in, &submod->deviations)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4429 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4430 | case LY_STMT_EXTENSION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4431 | LY_CHECK_RET(parse_extension(ctx, in, &submod->extensions)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4432 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4433 | case LY_STMT_FEATURE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4434 | LY_CHECK_RET(parse_feature(ctx, in, &submod->features)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4435 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4436 | case LY_STMT_GROUPING: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4437 | LY_CHECK_RET(parse_grouping(ctx, in, NULL, &submod->groupings)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4438 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4439 | case LY_STMT_IDENTITY: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4440 | LY_CHECK_RET(parse_identity(ctx, in, &submod->identities)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4441 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4442 | case LY_STMT_NOTIFICATION: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4443 | LY_CHECK_RET(parse_notif(ctx, in, NULL, &submod->notifs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4444 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4445 | case LY_STMT_RPC: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4446 | LY_CHECK_RET(parse_action(ctx, in, NULL, &submod->rpcs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4447 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4448 | case LY_STMT_TYPEDEF: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4449 | LY_CHECK_RET(parse_typedef(ctx, NULL, in, &submod->typedefs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4450 | break; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4451 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4452 | 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] | 4453 | break; |
| 4454 | |
| 4455 | default: |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4456 | LOGVAL_PARSER(ctx, LY_VCODE_INCHILDSTMT, ly_stmt2str(kw), "submodule"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4457 | return LY_EVALID; |
| 4458 | } |
| 4459 | } |
| 4460 | LY_CHECK_RET(ret); |
| 4461 | |
| 4462 | checks: |
| 4463 | /* finalize parent pointers to the reallocated items */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4464 | LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, submod->groupings, submod->augments, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame^] | 4465 | submod->rpcs, submod->notifs)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4466 | |
| 4467 | /* mandatory substatements */ |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4468 | if (!submod->prefix) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4469 | LOGVAL_PARSER(ctx, LY_VCODE_MISSTMT, "belongs-to", "submodule"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4470 | return LY_EVALID; |
| 4471 | } |
| 4472 | |
| 4473 | /* submodules share the namespace with the module names, so there must not be |
| 4474 | * a submodule of the same name in the context, no need for revision matching */ |
| 4475 | dup = ly_ctx_get_submodule(ctx->ctx, NULL, submod->name, NULL); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4476 | /* main modules may have different revisions */ |
| 4477 | if (dup && strcmp(dup->mod->name, submod->mod->name)) { |
David Sedlák | b307719 | 2019-06-19 10:55:37 +0200 | [diff] [blame] | 4478 | 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] | 4479 | return LY_EVALID; |
| 4480 | } |
| 4481 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4482 | return ret; |
| 4483 | } |
| 4484 | |
Radek Krejci | d4557c6 | 2018-09-17 11:42:09 +0200 | [diff] [blame] | 4485 | LY_ERR |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4486 | 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] | 4487 | struct ly_in *in, struct lysp_submodule **submod) |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4488 | { |
Radek Krejci | 6d9b9b5 | 2018-11-02 12:43:39 +0100 | [diff] [blame] | 4489 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4490 | char *word; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 4491 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4492 | enum ly_stmt kw; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4493 | struct lysp_submodule *mod_p = NULL; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4494 | |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4495 | /* create context */ |
| 4496 | *context = calloc(1, sizeof **context); |
| 4497 | LY_CHECK_ERR_RET(!(*context), LOGMEM(ly_ctx), LY_EMEM); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4498 | (*context)->format = LYS_IN_YANG; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 4499 | (*context)->main_mod = main_ctx->main_mod; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4500 | (*context)->ctx = ly_ctx; |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 4501 | (*context)->pos_type = LY_VLOG_LINE; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4502 | (*context)->line = 1; |
| 4503 | |
| 4504 | /* map the typedefs and groupings list from main context to the submodule's context */ |
| 4505 | memcpy(&(*context)->tpdfs_nodes, &main_ctx->tpdfs_nodes, sizeof main_ctx->tpdfs_nodes); |
| 4506 | memcpy(&(*context)->grps_nodes, &main_ctx->grps_nodes, sizeof main_ctx->grps_nodes); |
| 4507 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4508 | /* "module"/"submodule" */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4509 | ret = get_keyword(*context, in, &kw, &word, &word_len); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4510 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4511 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4512 | if (kw == LY_STMT_MODULE) { |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4513 | 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] | 4514 | ret = LY_EINVAL; |
| 4515 | goto cleanup; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4516 | } else if (kw != LY_STMT_SUBMODULE) { |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 4517 | LOGVAL_PARSER(*context, LY_VCODE_MOD_SUBOMD, ly_stmt2str(kw)); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 4518 | ret = LY_EVALID; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4519 | goto cleanup; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4520 | } |
| 4521 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4522 | mod_p = calloc(1, sizeof *mod_p); |
Radek Krejci | f027df7 | 2020-09-15 13:00:28 +0200 | [diff] [blame] | 4523 | LY_CHECK_ERR_GOTO(!mod_p, LOGMEM((*context)->ctx); ret = LY_EMEM, cleanup); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4524 | mod_p->mod = main_ctx->main_mod; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4525 | mod_p->parsing = 1; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4526 | |
| 4527 | /* substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4528 | ret = parse_submodule(*context, in, mod_p); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4529 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4530 | |
| 4531 | /* read some trailing spaces or new lines */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4532 | while (isspace(in->current[0])) { |
| 4533 | ++in->current; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4534 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4535 | if (in->current[0]) { |
| 4536 | 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] | 4537 | ret = LY_EVALID; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4538 | goto cleanup; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4539 | } |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4540 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4541 | mod_p->parsing = 0; |
| 4542 | *submod = mod_p; |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4543 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4544 | cleanup: |
| 4545 | if (ret) { |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4546 | lysp_submodule_free((*context)->ctx, mod_p); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4547 | yang_parser_ctx_free(*context); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4548 | *context = NULL; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | return ret; |
| 4552 | } |
| 4553 | |
| 4554 | LY_ERR |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4555 | 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] | 4556 | { |
| 4557 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4558 | char *word; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4559 | size_t word_len; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4560 | enum ly_stmt kw; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4561 | struct lysp_module *mod_p = NULL; |
| 4562 | |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4563 | /* create context */ |
| 4564 | *context = calloc(1, sizeof **context); |
| 4565 | LY_CHECK_ERR_RET(!(*context), LOGMEM(mod->ctx), LY_EMEM); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4566 | (*context)->format = LYS_IN_YANG; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 4567 | (*context)->main_mod = mod; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4568 | (*context)->ctx = mod->ctx; |
Radek Krejci | 335332a | 2019-09-05 13:03:35 +0200 | [diff] [blame] | 4569 | (*context)->pos_type = LY_VLOG_LINE; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4570 | (*context)->line = 1; |
| 4571 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4572 | /* "module"/"submodule" */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4573 | ret = get_keyword(*context, in, &kw, &word, &word_len); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4574 | LY_CHECK_GOTO(ret, cleanup); |
| 4575 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4576 | if (kw == LY_STMT_SUBMODULE) { |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4577 | 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] | 4578 | ret = LY_EINVAL; |
| 4579 | goto cleanup; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 4580 | } else if (kw != LY_STMT_MODULE) { |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 4581 | LOGVAL_PARSER((*context), LY_VCODE_MOD_SUBOMD, ly_stmt2str(kw)); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 4582 | ret = LY_EVALID; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4583 | goto cleanup; |
| 4584 | } |
| 4585 | |
| 4586 | mod_p = calloc(1, sizeof *mod_p); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4587 | LY_CHECK_ERR_GOTO(!mod_p, LOGMEM((*context)->ctx), cleanup); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4588 | mod_p->mod = mod; |
| 4589 | mod_p->parsing = 1; |
| 4590 | |
| 4591 | /* substatements */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4592 | ret = parse_module(*context, in, mod_p); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4593 | LY_CHECK_GOTO(ret, cleanup); |
| 4594 | |
| 4595 | /* read some trailing spaces or new lines */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4596 | while (isspace(in->current[0])) { |
| 4597 | ++in->current; |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 4598 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4599 | if (in->current[0]) { |
| 4600 | 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] | 4601 | ret = LY_EVALID; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4602 | goto cleanup; |
| 4603 | } |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 4604 | |
| 4605 | mod_p->parsing = 0; |
| 4606 | mod->parsed = mod_p; |
| 4607 | |
| 4608 | cleanup: |
| 4609 | if (ret) { |
| 4610 | lysp_module_free(mod_p); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4611 | yang_parser_ctx_free(*context); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4612 | *context = NULL; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 4613 | } |
| 4614 | |
Michal Vasko | 7fbc816 | 2018-09-17 10:35:16 +0200 | [diff] [blame] | 4615 | return ret; |
| 4616 | } |