48 #define PEEK_TOKEN(parser) \
49 ((parser->token_available || yaml_parser_fetch_more_tokens(parser)) ? \
50 parser->tokens.head : NULL)
56 #define SKIP_TOKEN(parser) \
57 (parser->token_available = 0, \
58 parser->tokens_parsed ++, \
59 parser->stream_end_produced = \
60 (parser->tokens.head->type == YAML_STREAM_END_TOKEN), \
61 parser->tokens.head ++)
105 int block,
int indentless_sequence);
181 if (parser->stream_end_produced || parser->error ||
228 switch (parser->
state)
318 if (!token)
return 0;
322 "did not find expected <stream-start>", token->
start_mark);
353 if (!token)
return 0;
362 if (!token)
return 0;
390 &tag_directives.start, &tag_directives.end))
393 if (!token)
goto error;
396 "did not find expected <document start>", token->
start_mark);
404 tag_directives.start, tag_directives.end, 0,
405 start_mark, end_mark);
407 version_directive =
NULL;
408 tag_directives.start = tag_directives.end =
NULL;
424 while (tag_directives.start != tag_directives.end) {
425 yaml_free(tag_directives.end[-1].handle);
426 yaml_free(tag_directives.end[-1].prefix);
427 tag_directives.end --;
445 if (!token)
return 0;
477 if (!token)
return 0;
530 int block,
int indentless_sequence)
541 if (!token)
return 0;
563 if (!token)
goto error;
566 tag_handle = token->
data.
tag.handle;
567 tag_suffix = token->
data.
tag.suffix;
572 if (!token)
goto error;
577 tag_handle = token->
data.
tag.handle;
578 tag_suffix = token->
data.
tag.suffix;
583 if (!token)
goto error;
590 if (!token)
goto error;
598 tag_handle = tag_suffix =
NULL;
605 if (strcmp((
char *)tag_directive->
handle, (
char *)tag_handle) == 0) {
606 size_t prefix_len =
strlen((
char *)tag_directive->
prefix);
607 size_t suffix_len =
strlen((
char *)tag_suffix);
613 memcpy(tag, tag_directive->
prefix, prefix_len);
614 memcpy(tag+prefix_len, tag_suffix, suffix_len);
615 tag[prefix_len+suffix_len] =
'\0';
618 tag_handle = tag_suffix =
NULL;
624 "while parsing a node", start_mark,
625 "found undefined tag handle", tag_mark);
631 implicit = (!tag || !*tag);
641 int plain_implicit = 0;
642 int quoted_implicit = 0;
645 || (tag && strcmp((
char *)tag,
"!") == 0)) {
654 plain_implicit, quoted_implicit,
655 token->
data.
scalar.style, start_mark, end_mark);
687 else if (anchor || tag) {
697 start_mark, end_mark);
702 (block ?
"while parsing a block node"
703 :
"while parsing a flow node"), start_mark,
704 "did not find expected node content", token->
start_mark);
739 if (!token)
return 0;
746 if (!token)
return 0;
772 "while parsing a block collection",
POP(parser, parser->
marks),
773 "did not find expected '-' indicator", token->
start_mark);
790 if (!token)
return 0;
797 if (!token)
return 0;
847 if (!token)
return 0;
854 if (!token)
return 0;
881 "while parsing a block mapping",
POP(parser, parser->
marks),
882 "did not find expected key", token->
start_mark);
905 if (!token)
return 0;
912 if (!token)
return 0;
962 if (!token)
return 0;
970 if (!token)
return 0;
974 "while parsing a flow sequence",
POP(parser, parser->
marks),
975 "did not find expected ',' or ']'", token->
start_mark);
1016 if (!token)
return 0;
1046 if (!token)
return 0;
1051 if (!token)
return 0;
1077 if (!token)
return 0;
1113 if (!token)
return 0;
1121 if (!token)
return 0;
1125 "while parsing a flow mapping",
POP(parser, parser->
marks),
1126 "did not find expected ',' or '}'", token->
start_mark);
1133 if (!token)
return 0;
1176 if (!token)
return 0;
1187 if (!token)
return 0;
1245 } tag_directives = {
NULL,
NULL, NULL };
1252 if (!token)
goto error;
1258 if (version_directive) {
1260 "found duplicate %YAML directive", token->
start_mark);
1266 "found incompatible YAML document", token->
start_mark);
1270 if (!version_directive) {
1286 if (!
PUSH(parser, tag_directives, value))
1292 if (!token)
goto error;
1295 for (default_tag_directive = default_tag_directives;
1296 default_tag_directive->
handle; default_tag_directive++) {
1302 if (version_directive_ref) {
1303 *version_directive_ref = version_directive;
1305 if (tag_directives_start_ref) {
1307 *tag_directives_start_ref = *tag_directives_end_ref =
NULL;
1311 *tag_directives_start_ref = tag_directives.start;
1312 *tag_directives_end_ref = tag_directives.top;
1345 if (strcmp((
char *)value.
handle, (
char *)tag_directive->
handle) == 0) {
1346 if (allow_duplicates)
1349 "found duplicate %TAG directive", mark);