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;
764 dummy_mark =
POP(parser, parser->
marks);
773 "while parsing a block collection",
POP(parser, parser->
marks),
774 "did not find expected '-' indicator", token->
start_mark);
791 if (!token)
return 0;
798 if (!token)
return 0;
848 if (!token)
return 0;
855 if (!token)
return 0;
874 dummy_mark =
POP(parser, parser->
marks);
883 "while parsing a block mapping",
POP(parser, parser->
marks),
884 "did not find expected key", token->
start_mark);
907 if (!token)
return 0;
914 if (!token)
return 0;
965 if (!token)
return 0;
973 if (!token)
return 0;
977 "while parsing a flow sequence",
POP(parser, parser->
marks),
978 "did not find expected ',' or ']'", token->
start_mark);
1000 dummy_mark =
POP(parser, parser->
marks);
1019 if (!token)
return 0;
1049 if (!token)
return 0;
1054 if (!token)
return 0;
1080 if (!token)
return 0;
1117 if (!token)
return 0;
1125 if (!token)
return 0;
1129 "while parsing a flow mapping",
POP(parser, parser->
marks),
1130 "did not find expected ',' or '}'", token->
start_mark);
1137 if (!token)
return 0;
1161 dummy_mark =
POP(parser, parser->
marks);
1180 if (!token)
return 0;
1191 if (!token)
return 0;
1249 } tag_directives = {
NULL,
NULL, NULL };
1256 if (!token)
goto error;
1262 if (version_directive) {
1264 "found duplicate %YAML directive", token->
start_mark);
1270 "found incompatible YAML document", token->
start_mark);
1274 if (!version_directive) {
1290 if (!
PUSH(parser, tag_directives, value))
1296 if (!token)
goto error;
1299 for (default_tag_directive = default_tag_directives;
1300 default_tag_directive->
handle; default_tag_directive++) {
1306 if (version_directive_ref) {
1307 *version_directive_ref = version_directive;
1309 if (tag_directives_start_ref) {
1311 *tag_directives_start_ref = *tag_directives_end_ref =
NULL;
1315 *tag_directives_start_ref = tag_directives.start;
1316 *tag_directives_end_ref = tag_directives.top;
1349 if (strcmp((
char *)value.
handle, (
char *)tag_directive->
handle) == 0) {
1350 if (allow_duplicates)
1353 "found duplicate %TAG directive", mark);