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);
struct yaml_token_s::@12::@19 tag_directive
The tag directive (for YAML_TAG_DIRECTIVE_TOKEN).
yaml_strdup(const yaml_char_t *str)
struct yaml_token_s::@12::@15 anchor
The anchor (for YAML_ANCHOR_TOKEN).
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 *)
#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)
struct yaml_token_s::@12::@18 version_directive
The version directive (for YAML_VERSION_DIRECTIVE_TOKEN).
A FLOW-SEQUENCE-START token.
Expect the first key of a block mapping.
Cannot allocate or reallocate a block of memory.
yaml_mark_t end_mark
The end of the token.
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 SEQUENCE_START_EVENT_INIT(event, event_anchor, event_tag,event_implicit, event_style, start_mark, end_mark)
#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.
struct yaml_token_s::@12::@14 alias
The alias (for YAML_ALIAS_TOKEN).
yaml_char_t * prefix
The tag prefix.
union yaml_token_s::@12 data
The token data.
static int yaml_parser_parse_stream_start(yaml_parser_t *parser, yaml_event_t *event)
#define MAPPING_START_EVENT_INIT(event, event_anchor, event_tag,event_implicit, event_style, start_mark, end_mark)
#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.
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)
struct yaml_parser_s::@43 states
The parser states stack.
yaml_char_t * handle
The tag handle.
static int yaml_parser_parse_indentless_sequence_entry(yaml_parser_t *parser, yaml_event_t *event)
struct yaml_parser_s::@44 marks
The stack of marks.
Expect a block mapping value.
static int yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event, int block, int indentless_sequence)
yaml_token_type_t type
The token type.
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)
struct yaml_parser_s::@45 tag_directives
The list of TAG directives.
#define DOCUMENT_START_EVENT_INIT(event, event_version_directive,event_tag_directives_start, event_tag_directives_end, event_implicit, start_mark, end_mark)
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.
struct yaml_token_s::@12::@17 scalar
The scalar value (for YAML_SCALAR_TOKEN).
struct yaml_token_s::@12::@16 tag
The tag (for YAML_TAG_TOKEN).
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.
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.
struct yaml_token_s::@12::@13 stream_start
The stream start (for YAML_STREAM_START_TOKEN).
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)
yaml_mark_t start_mark
The beginning of the token.