Function yaml_parser_scan


#include <include/yaml.h>

int yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token)


Scan the input stream and produce the next token.

Call the function subsequently to produce a sequence of tokens corresponding to the input stream. The initial token has the type YAML_STREAM_START_TOKEN while the ending token has the type YAML_STREAM_END_TOKEN.

An application is responsible for freeing any buffers associated with the produced token object using the yaml_token_delete function.

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


[ in,out ] parser - A parser object.

[ out ] token - An empty token object.

1 if the function succeeded, 0 on error.
Get the next token.

Public API declarations.

Get the next token.


Lines 742-776 in src/scanner.c. Line 1408 in include/yaml.h.

yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token)
    assert(parser); /* Non-NULL parser object is expected. */
    assert(token);  /* Non-NULL token object is expected. */

    /* Erase the token object. */

    memset(token, 0, sizeof(yaml_token_t));

    /* No tokens after STREAM-END or error. */

    if (parser->stream_end_produced || parser->error) {
        return 1;

    /* Ensure that the tokens queue contains enough tokens. */

    if (!parser->token_available) {
        if (!yaml_parser_fetch_more_tokens(parser))
            return 0;

    /* Fetch the next token from the queue. */

    *token = DEQUEUE(parser, parser->tokens);
    parser->token_available = 0;
    parser->tokens_parsed ++;

    if (token->type == YAML_STREAM_END_TOKEN) {
        parser->stream_end_produced = 1;

    return 1;

Add Discussion as Guest

Log in to DocsForge