Function yaml_parser_load

Synopsis

#include <include/yaml.h>

int yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document)

Description

Parse the input stream and produce the next YAML document.

Call this function subsequently to produce a sequence of documents constituting the input stream.

If the produced document has no root node, it means that the document end has been reached.

An application is responsible for freeing any data associated with the produced document object using the yaml_document_delete() function.

An application must not alternate the calls of yaml_parser_load() with the calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break the parser.

Parameters:

[ in,out ] parser - A parser object.

[ out ] document - An empty document object.

Return
1 if the function succeeded, 0 on error.
Load the next document of the stream.

API functions.

Load the next document of the stream.

Source

Lines 86-132 in src/loader.c. Line 1457 in include/yaml.h.

YAML_DECLARE(int)
yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document)
{
    yaml_event_t event;

    assert(parser);     /* Non-NULL parser object is expected. */
    assert(document);   /* Non-NULL document object is expected. */

    memset(document, 0, sizeof(yaml_document_t));
    if (!STACK_INIT(parser, document->nodes, yaml_node_t*))
        goto error;

    if (!parser->stream_start_produced) {
        if (!yaml_parser_parse(parser, &event)) goto error;
        assert(event.type == YAML_STREAM_START_EVENT);
                        /* STREAM-START is expected. */
    }

    if (parser->stream_end_produced) {
        return 1;
    }

    if (!yaml_parser_parse(parser, &event)) goto error;
    if (event.type == YAML_STREAM_END_EVENT) {
        return 1;
    }

    if (!STACK_INIT(parser, parser->aliases, yaml_alias_data_t*))
        goto error;

    parser->document = document;

    if (!yaml_parser_load_document(parser, &event)) goto error;

    yaml_parser_delete_aliases(parser);
    parser->document = NULL;

    return 1;

error:

    yaml_parser_delete_aliases(parser);
    yaml_document_delete(document);
    parser->document = NULL;

    return 0;
}





Add Discussion as Guest

Log in to DocsForge