summaryrefslogtreecommitdiffstats
path: root/src/parser_yang.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser_yang.c')
-rw-r--r--src/parser_yang.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 8511d26..57b5f9b 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -596,6 +596,7 @@ get_argument(struct lysp_yang_ctx *ctx, enum yang_arg arg, uint16_t *flags, char
size_t buf_len = 0;
uint8_t prefix = 0;
ly_bool str_end = 0;
+ int comment;
/* word buffer - dynamically allocated */
*word_b = NULL;
@@ -627,18 +628,30 @@ get_argument(struct lysp_yang_ctx *ctx, enum yang_arg arg, uint16_t *flags, char
str_end = 1;
break;
case '/':
+ comment = 0;
if (ctx->in->current[1] == '/') {
/* one-line comment */
- MOVE_INPUT(ctx, 2);
- LY_CHECK_GOTO(ret = skip_comment(ctx, 1), error);
+ comment = 1;
} else if (ctx->in->current[1] == '*') {
/* block comment */
- MOVE_INPUT(ctx, 2);
- LY_CHECK_GOTO(ret = skip_comment(ctx, 2), error);
+ comment = 2;
} else {
/* not a comment after all */
LY_CHECK_GOTO(ret = buf_store_char(ctx, arg, word_p, word_len, word_b, &buf_len, 0, &prefix), error);
}
+
+ if (comment) {
+ if (*word_len) {
+ /* invalid comment sequence (RFC 7950 sec. 6.1.3.) */
+ LOGVAL_PARSER(ctx, LYVE_SYNTAX, "Invalid comment sequence \"%.2s\" in an unquoted string.", ctx->in->current);
+ ret = LY_EVALID;
+ goto error;
+ }
+
+ /* skip the comment */
+ MOVE_INPUT(ctx, 2);
+ LY_CHECK_GOTO(ret = skip_comment(ctx, comment), error);
+ }
break;
case ' ':
if (*word_len) {
@@ -838,6 +851,8 @@ keyword_start:
/* fall through */
default:
MOVE_INPUT(ctx, 1);
+ /* fall through */
+ case '\0':
LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, (int)(ctx->in->current - word_start), word_start,
"a keyword followed by a separator");
return LY_EVALID;
@@ -982,8 +997,16 @@ parse_ext(struct lysp_yang_ctx *ctx, const char *ext_name, size_t ext_name_len,
e->parent_stmt_index = parent_stmt_index;
YANG_READ_SUBSTMT_FOR_GOTO(ctx, kw, word, word_len, ret, cleanup) {
- LY_CHECK_GOTO(ret = parse_ext_substmt(ctx, kw, word, word_len, &e->child), cleanup)
- YANG_READ_SUBSTMT_NEXT_ITER(ctx, kw, word, word_len, NULL, ret, cleanup);
+ switch (kw) {
+ case LY_STMT_EXTENSION_INSTANCE:
+ LY_CHECK_GOTO(parse_ext(ctx, word, word_len, e, LY_STMT_EXTENSION_INSTANCE, 0, &e->exts), cleanup);
+ break;
+ default:
+ /* just store all the statements */
+ LY_CHECK_GOTO(ret = parse_ext_substmt(ctx, kw, word, word_len, &e->child), cleanup)
+ break;
+ }
+ YANG_READ_SUBSTMT_NEXT_ITER(ctx, kw, word, word_len, e->exts, ret, cleanup);
}
cleanup: