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;
388 start_mark =
token->start_mark;
390 &tag_directives.start, &tag_directives.end))
393 if (!
token)
goto error;
396 "did not find expected <document start>",
token->start_mark);
402 end_mark =
token->end_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;
479 start_mark = end_mark =
token->start_mark;
482 end_mark =
token->end_mark;
530 int block,
int indentless_sequence)
541 if (!
token)
return 0;
554 start_mark = end_mark =
token->start_mark;
558 anchor =
token->data.anchor.value;
559 start_mark =
token->start_mark;
560 end_mark =
token->end_mark;
563 if (!
token)
goto error;
566 tag_handle =
token->data.tag.handle;
567 tag_suffix =
token->data.tag.suffix;
568 tag_mark =
token->start_mark;
569 end_mark =
token->end_mark;
572 if (!
token)
goto error;
577 tag_handle =
token->data.tag.handle;
578 tag_suffix =
token->data.tag.suffix;
579 start_mark = tag_mark =
token->start_mark;
580 end_mark =
token->end_mark;
583 if (!
token)
goto error;
586 anchor =
token->data.anchor.value;
587 end_mark =
token->end_mark;
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);
633 end_mark =
token->end_mark;
641 int plain_implicit = 0;
642 int quoted_implicit = 0;
643 end_mark =
token->end_mark;
645 || (tag && strcmp((
char *)tag,
"!") == 0)) {
653 token->data.scalar.value,
token->data.scalar.length,
654 plain_implicit, quoted_implicit,
655 token->data.scalar.style, start_mark, end_mark);
660 end_mark =
token->end_mark;
667 end_mark =
token->end_mark;
674 end_mark =
token->end_mark;
681 end_mark =
token->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;
1252 if (!
token)
goto error;
1258 if (version_directive) {
1260 "found duplicate %YAML directive",
token->start_mark);
1263 if (
token->data.version_directive.major != 1
1264 ||
token->data.version_directive.minor != 1) {
1266 "found incompatible YAML document",
token->start_mark);
1270 if (!version_directive) {
1274 version_directive->
major =
token->data.version_directive.major;
1275 version_directive->
minor =
token->data.version_directive.minor;
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);
#define MAPPING_START_EVENT_INIT(event, event_anchor, event_tag, event_implicit, event_style, start_mark, end_mark)
yaml_strdup(const yaml_char_t *str)
Expect an entry of a flow sequence.
A BLOCK-SEQUENCE-START token.
yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event)
Parse the input stream and produce the next parsing event.
#define STREAM_END_EVENT_INIT(event, start_mark, end_mark)
size_t strlen(const char *)
A FLOW-SEQUENCE-START token.
Expect the first key of a block mapping.
Cannot allocate or reallocate a block of memory.
static int yaml_parser_parse_flow_mapping_value(yaml_parser_t *parser, yaml_event_t *event, int empty)
static int yaml_parser_parse_flow_sequence_entry_mapping_value(yaml_parser_t *parser, yaml_event_t *event)
A BLOCK-SEQUENCE-END token.
static int yaml_parser_parse_flow_sequence_entry_mapping_key(yaml_parser_t *parser, yaml_event_t *event)
#define STREAM_START_EVENT_INIT(event, event_encoding, start_mark, end_mark)
yaml_parser_state_t state
The current parser state.
#define PEEK_TOKEN(parser)
#define INITIAL_STACK_SIZE
unsigned char yaml_char_t
The character type (UTF-8 octet).
const unsigned char * start
The string start pointer.
The version directive data.
const char * context
The error context.
static int yaml_parser_append_tag_directive(yaml_parser_t *parser, yaml_tag_directive_t value, int allow_duplicates, yaml_mark_t mark)
Expect a key of an ordered mapping.
yaml_char_t * prefix
The tag prefix.
static int yaml_parser_parse_stream_start(yaml_parser_t *parser, yaml_event_t *event)
#define SEQUENCE_END_EVENT_INIT(event, start_mark, end_mark)
Expect the beginning of an implicit document.
A FLOW-SEQUENCE-END token.
#define STACK_EMPTY(context, stack)
Expect the content of a document.
static int yaml_parser_process_empty_scalar(yaml_parser_t *parser, yaml_event_t *event, yaml_mark_t mark)
static int yaml_parser_parse_flow_sequence_entry_mapping_end(yaml_parser_t *parser, yaml_event_t *event)
static int yaml_parser_parse_block_sequence_entry(yaml_parser_t *parser, yaml_event_t *event, int first)
int * top
The top of the stack.
struct yaml_parser_s::@75 states
The parser states stack.
struct yaml_parser_s::@77 tag_directives
The list of TAG directives.
A VERSION-DIRECTIVE token.
static int yaml_parser_parse_document_end(yaml_parser_t *parser, yaml_event_t *event)
int major
The major version number.
Expect an entry of a block sequence.
static int yaml_parser_process_directives(yaml_parser_t *parser, yaml_version_directive_t **version_directive_ref, yaml_tag_directive_t **tag_directives_start_ref, yaml_tag_directive_t **tag_directives_end_ref)
#define ALIAS_EVENT_INIT(event, event_anchor, start_mark, end_mark)
static int yaml_parser_parse_document_start(yaml_parser_t *parser, yaml_event_t *event, int implicit)
#define YAML_DECLARE(type)
The public API declaration.
A FLOW-MAPPING-START token.
#define STACK_DEL(context, stack)
yaml_error_type_t error
Error type.
#define DOCUMENT_END_EVENT_INIT(event, event_implicit, start_mark, end_mark)
#define MAPPING_END_EVENT_INIT(event, start_mark, end_mark)
static int yaml_parser_set_parser_error(yaml_parser_t *parser, const char *problem, yaml_mark_t problem_mark)
#define SEQUENCE_START_EVENT_INIT(event, event_anchor, event_tag, event_implicit, event_style, start_mark, end_mark)
yaml_char_t * handle
The tag handle.
static int yaml_parser_parse_indentless_sequence_entry(yaml_parser_t *parser, yaml_event_t *event)
Expect a block mapping value.
static int yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event, int block, int indentless_sequence)
struct yaml_parser_s::@76 marks
The stack of marks.
Cannot parse the input stream.
Expect an empty value of a flow mapping.
yaml_mark_t context_mark
The context position.
static int yaml_parser_set_parser_error_context(yaml_parser_t *parser, const char *context, yaml_mark_t context_mark, const char *problem, yaml_mark_t problem_mark)
A FLOW-MAPPING-END token.
static int yaml_parser_parse_block_mapping_value(yaml_parser_t *parser, yaml_event_t *event)
yaml_mark_t problem_mark
The problem position.
static int yaml_parser_state_machine(yaml_parser_t *parser, yaml_event_t *event)
Expect the and of an ordered mapping entry.
static int yaml_parser_parse_flow_mapping_key(yaml_parser_t *parser, yaml_event_t *event, int first)
Expect an entry of an indentless sequence.
Expect a block node or indentless sequence.
int minor
The minor version number.
Expect the first entry of a flow sequence.
#define POP(context, stack)
Expect the first entry of a block sequence.
static VALUE mark(VALUE self)
Expect a value of a flow mapping.
#define DOCUMENT_START_EVENT_INIT(event, event_version_directive, event_tag_directives_start, event_tag_directives_end, event_implicit, start_mark, end_mark)
Expect a key of a flow mapping.
#define assert(condition)
Expect the first key of a flow mapping.
const char * problem
Error description.
#define SKIP_TOKEN(parser)
#define STACK_INIT(context, stack, size)
Expect a value of an ordered mapping.
#define SCALAR_EVENT_INIT(event, event_anchor, event_tag, event_value, event_length, event_plain_implicit, event_quoted_implicit, event_style, start_mark, end_mark)
Expect a block mapping key.
static int yaml_parser_parse_block_mapping_key(yaml_parser_t *parser, yaml_event_t *event, int first)
static int yaml_parser_parse_document_content(yaml_parser_t *parser, yaml_event_t *event)
The block sequence style.
static int yaml_parser_parse_flow_sequence_entry(yaml_parser_t *parser, yaml_event_t *event, int first)