LIBFYAML-CORE(3) libfyaml LIBFYAML-CORE(3)

libfyaml-core - libfyaml core API

This is the single top-level include for the entire libfyaml public API. Including it pulls in all subsystem headers:

  • Core YAML parser, document tree, emitter, and diagnostics (libfyaml/libfyaml-core.h)
  • General-purpose utilities and portability macros (libfyaml/libfyaml-util.h)
  • YAML path expression parser and executor (libfyaml/libfyaml-path-exec.h)
  • Document builder: event-stream to tree conversion (libfyaml/libfyaml-docbuild.h)
  • Document iterator: tree traversal and event replay (libfyaml/libfyaml-dociter.h)
  • Composer: callback-driven, path-aware event processing (libfyaml/libfyaml-composer.h)
  • Pluggable memory allocators (libfyaml/libfyaml-allocator.h)
  • Thread pool for parallel work (libfyaml/libfyaml-thread.h)
  • BLAKE3 cryptographic hashing (libfyaml/libfyaml-blake3.h)
  • Alignment macros and helpers (libfyaml/libfyaml-align.h)
  • Portable endian detection (libfyaml/libfyaml-endian.h)
  • Portable atomic operations (libfyaml/libfyaml-atomics.h)
  • Variable-length size encoding (libfyaml/libfyaml-vlsize.h)

For faster compilation you may include only the subsystem headers you need. All public symbols are prefixed with fy_ (functions/types) or FY_ (macros and constants).

This header provides the complete YAML 1.2 / JSON parser, document tree, and emitter API — the core of libfyaml. It is the largest and most frequently used part of the public interface.

Three complementary APIs cover the full lifecycle of a YAML document:

Event-based parsing (fy_parser_*): A streaming interface similar to libyaml’s. The parser produces a sequence of typed events (stream-start, document-start, scalar, sequence-start, …) without building an in-memory tree. Ideal for large documents, filters, and transcoding pipelines.

Document tree (fy_document_*, fy_node_*): Builds a fully navigable in-memory tree from a YAML or JSON source. Nodes can be queried, modified, merged, and serialised. Path-expression helpers (fy_document_scanf(), fy_document_insert_at(), …) provide XPath-like access into the tree.

Emitter (fy_emitter_*): Serialises documents or raw event streams back to YAML or JSON with full control over formatting style, indentation, and quoting. Supports streaming output to files, memory buffers, or user-supplied callbacks.

Diagnostics (fy_diag_*): A structured error-reporting subsystem that attributes messages to precise source locations and integrates with IDE/compiler toolchains via a standard file:line:col: level: text format.

All types are opaque pointers (struct fy_parser *, struct fy_document *, struct fy_node *, …) so the ABI is stable across minor releases.

The YAML version

struct fy_version {
    int major;
    int minor;
}

Major version number
Major version number

The parser fills it according to the %YAML directive found in the document.

Compare two yaml versions
  • va (const struct fy_version*) – The first version, if NULL use default version
  • vb (const struct fy_version*) – The second version, if NULL use default version

Compare the versions

0 if versions are equal, > 0 if version va is higher than vb < 0 if version va is lower than vb

Get the default version of the library
void – no arguments

Return the default version of the library, i.e. the highest stable version that is supported.

The default YAML version of this library

Check if supported version
vers (const struct fy_version*) – The version to check, NULL means default version.

Check if the given YAML version is supported.

true if version supported, false otherwise.

Iterate over the supported YAML versions
prevp (void**) – The previous version iterator

This method iterates over the supported YAML versions of this ibrary. The start of the iteration is signalled by a NULL in *prevp.

The next node in sequence or NULL at the end of the sequence.

Final cleanup before exit
void – no arguments

Some libraries cough*libclang* need explicit cleanup calls at the end of program execution, even if you’ve never called any of their functions.

This method will make sure it calls their cleanup functions so that no memory leaks are reported in valgrind etc.

The YAML tag structure.

struct fy_tag {
    const char *handle;
    const char *prefix;
}

Handle of the tag (i.e. “!!”)
The prefix of the tag (i.e. “tag:yaml.org,2002:”) The parser fills it according to the %TAG directives encountered during parsing.

marker holding information about a location in a struct fy_input

struct fy_mark {
    size_t input_pos;
    int line;
    int column;
}

Position of the mark (from the start of the current input)
Line position (0 index based)
Column position (0 index based)

The supported diagnostic/error types

enum fy_error_type {
    FYET_DEBUG,
    FYET_INFO,
    FYET_NOTICE,
    FYET_WARNING,
    FYET_ERROR,
    FYET_MAX
};

Debug level (disabled if library is not compiled in debug mode)
Informational level
Notice level
Warning level
Error level - error reporting is using this level
Non inclusive maximum fy_error_type value

Module which generated the diagnostic/error

enum fy_error_module {
    FYEM_UNKNOWN,
    FYEM_ATOM,
    FYEM_SCAN,
    FYEM_PARSE,
    FYEM_DOC,
    FYEM_BUILD,
    FYEM_INTERNAL,
    FYEM_SYSTEM,
    FYEM_EMIT,
    FYEM_TYPESET,
    FYEM_DECODE,
    FYEM_ENCODE,
    FYEM_REFLECTION,
    FYEM_MAX
};

Unknown, default if not specific
Atom module, used by atom chunking
Scanner module
Parser module
Document module
Build document module (after tree is constructed)
Internal error/diagnostic module
System error/diagnostic module
Emitter module
Prepare types module (C reflection)
Decode, serialization -> internal form module
Encode, internal form -> serialized form module
Generic reflection module messages
Non inclusive maximum fy_error_module value

Parse configuration flags

enum fy_parse_cfg_flags {
    FYPCF_QUIET,
    FYPCF_COLLECT_DIAG,
    FYPCF_RESOLVE_DOCUMENT,
    FYPCF_DISABLE_MMAP_OPT,
    FYPCF_DISABLE_RECYCLING,
    FYPCF_PARSE_COMMENTS,
    FYPCF_DISABLE_DEPTH_LIMIT,
    FYPCF_DISABLE_ACCELERATORS,
    FYPCF_DISABLE_BUFFERING,
    FYPCF_DEFAULT_VERSION_AUTO,
    FYPCF_DEFAULT_VERSION_1_1,
    FYPCF_DEFAULT_VERSION_1_2,
    FYPCF_DEFAULT_VERSION_1_3,
    FYPCF_SLOPPY_FLOW_INDENTATION,
    FYPCF_PREFER_RECURSIVE,
    FYPCF_JSON_AUTO,
    FYPCF_JSON_NONE,
    FYPCF_JSON_FORCE,
    FYPCF_YPATH_ALIASES,
    FYPCF_ALLOW_DUPLICATE_KEYS
};

Quiet, do not output any information messages
Collect diagnostic/error messages
When producing documents, automatically resolve them
Disable mmap optimization
Disable recycling optimization
Enable parsing of comments (experimental)
Disable depth limit check, use with enlarged stack
Disable use of access accelerators (saves memory)
Disable use of buffering where possible
Automatically use the most recent version the library supports
Default version is YAML 1.1
Default version is YAML 1.2
Default version is YAML 1.3 (experimental)
Allow sloppy indentation in flow mode
Prefer recursive algorighms instead of iterative whenever possible
Automatically enable JSON mode (when extension is .json)
Never enable JSON input mode
Force JSON mode always
Enable YPATH aliases mode
Allow duplicate keys on mappings

These flags control the operation of the parse and the debugging output/error reporting via filling in the fy_parse_cfg->flags member.

parser configuration structure.

struct fy_parse_cfg {
    const char *search_path;
    enum fy_parse_cfg_flags flags;
    void *userdata;
    struct fy_diag *diag;
}

Search path when accessing files, seperate with ‘:’
Configuration flags
Opaque user data pointer
Optional diagnostic interface to use

Argument to the fy_parser_create() method which perform parsing of YAML files.

Event types

enum fy_event_type {
    FYET_NONE,
    FYET_STREAM_START,
    FYET_STREAM_END,
    FYET_DOCUMENT_START,
    FYET_DOCUMENT_END,
    FYET_MAPPING_START,
    FYET_MAPPING_END,
    FYET_SEQUENCE_START,
    FYET_SEQUENCE_END,
    FYET_SCALAR,
    FYET_ALIAS
};

No event
Stream start event
Stream end event
Document start event
Document end event
YAML mapping start event
YAML mapping end event
YAML sequence start event
YAML sequence end event
YAML scalar event
YAML alias event

Return text of an event type
type (enum fy_event_type) – The event type to get text from

A pointer to a text, i.e for FYET_SCALAR “=VAL”.

Collection styles supported by the parser/emitter

enum fy_collection_style {
    FYCS_ANY,
    FYCS_BLOCK,
    FYCS_FLOW,
    FYCS_MAX
};

Any collection style, not generated by the parser. Lets the emitter to choose
Block style (not {}[])
Flow style {}[]
marks end of scalar styles

Scalar styles supported by the parser/emitter

enum fy_scalar_style {
    FYSS_ANY,
    FYSS_PLAIN,
    FYSS_SINGLE_QUOTED,
    FYSS_DOUBLE_QUOTED,
    FYSS_LITERAL,
    FYSS_FOLDED,
    FYSS_MAX
};

Any scalar style, not generated by the parser. Lets the emitter to choose
Plain scalar style
Single quoted style
Double quoted style
YAML literal block style
YAML folded block style
marks end of scalar styles

stream start event data

struct fy_event_stream_start_data {
    struct fy_token *stream_start;
}

The token that started the stream

stream end event data

struct fy_event_stream_end_data {
    struct fy_token *stream_end;
}

The token that ended the stream

doument start event data

struct fy_event_document_start_data {
    struct fy_token *document_start;
    struct fy_document_state *document_state;
    bool implicit;
}

The token that started the document, or NULL if the document was implicitly started.
The state of the document (i.e. information about the YAML version and configured tags)
True if the document started implicitly

doument end event data

struct fy_event_document_end_data {
    struct fy_token *document_end;
    bool implicit;
}

The token that ended the document, or NULL if the document was implicitly ended
True if the document ended implicitly

alias event data

struct fy_event_alias_data {
    struct fy_token *anchor;
}

The anchor token definining this alias.

scalar event data

struct fy_event_scalar_data {
    struct fy_token *anchor;
    struct fy_token *tag;
    struct fy_token *value;
    bool tag_implicit;
}

anchor token or NULL
tag token or NULL
scalar value token (cannot be NULL)
true if the tag was implicit or explicit

sequence start event data

struct fy_event_sequence_start_data {
    struct fy_token *anchor;
    struct fy_token *tag;
    struct fy_token *sequence_start;
}

anchor token or NULL
tag token or NULL
sequence start value token or NULL if the sequence was started implicitly

sequence end event data

struct fy_event_sequence_end_data {
    struct fy_token *sequence_end;
}

The token that ended the sequence, or NULL if the sequence was implicitly ended

mapping start event data

struct fy_event_mapping_start_data {
    struct fy_token *anchor;
    struct fy_token *tag;
    struct fy_token *mapping_start;
}

anchor token or NULL
tag token or NULL
mapping start value token or NULL if the mapping was started implicitly

mapping end event data

struct fy_event_mapping_end_data {
    struct fy_token *mapping_end;
}

The token that ended the mapping, or NULL if the mapping was implicitly ended

Event generated by the parser

struct fy_event {
    enum fy_event_type type;
    union {
        struct fy_event_stream_start_data stream_start;
        struct fy_event_stream_end_data stream_end;
        struct fy_event_document_start_data document_start;
        struct fy_event_document_end_data document_end;
        struct fy_event_alias_data alias;
        struct fy_event_scalar_data scalar;
        struct fy_event_sequence_start_data sequence_start;
        struct fy_event_sequence_end_data sequence_end;
        struct fy_event_mapping_start_data mapping_start;
        struct fy_event_mapping_end_data mapping_end;
    } ;
}

Type of the event, see enum fy_event_type
{unnamed_union}
anonymous
Stream start information, it is valid when fy_event->type is enum FYET_STREAM_START
Stream end information, it is valid when fy_event->type is enum FYET_STREAM_END
Document start information, it is valid when fy_event->type is enum FYET_DOCUMENT_START
Document end information, it is valid when fy_event->type is enum FYET_DOCUMENT_END
Alias information, it is valid when fy_event->type is enum FYET_ALIAS
Scalar information, it is valid when fy_event->type is enum FYET_SCALAR
Sequence start information, it is valid when fy_event->type is enum FYET_SEQUENCE_START
Sequence end information, it is valid when fy_event->type is enum FYET_SEQUENCE_END
Mapping start information, it is valid when fy_event->type is enum FYET_MAPPING_START
Mapping end information, it is valid when fy_event->type is enum FYET_MAPPING_END

This structure is generated by the parser by each call to fy_parser_parse() and release by fy_parser_event_free()

Select part of the event

enum fy_event_part {
    FYEP_VALUE,
    FYEP_TAG,
    FYEP_ANCHOR
};

The value of the event (the main token)
The tag of the event
The anchor of the event

Get the event’s type
fye (const struct fy_event*) – The event

Return the type of the event

The event type, or FYET_NONE when the event is invalid

Get a pointer to the event data
fye (struct fy_event*) – The event

Some languages cough*golang*cough really don’t like unions, and anonymous unions in particular.

You should not have to use this in other language bindings.

A pointer to the event data structure, or NULL if the event is invalid

Return the library version string
void – no arguments

A pointer to a version string of the form <MAJOR>.<MINOR>[[.<PATCH>][-EXTRA-VERSION-INFO]]

Return the error type from a string
str (const char*) – The string to convert to an error type

The error type if greater or equal to zero, FYET_MAX otherwise

Convert an error type to string
type (enum fy_error_type) – The error type to convert

The string value of the error type or the empty string “” on error

Return the error module from a string
str (const char*) – The string to convert to an error module

The error type if greater or equal to zero, FYEM_MAX otherwise

Convert an error module to string
module (enum fy_error_module) – The error module to convert

The string value of the error module or the empty string “” on error

Check whether the given event is an implicit one
fye (struct fy_event*) – A pointer to a struct fy_event to check.

true if the event is an implicit one.

Check whether the given document event is an implicit one
fye (const struct fy_event*) – A pointer to a struct fy_event to check. It must be either a document start or document end event.

true if the event is an implicit one.

Create a parser.
cfg (const struct fy_parse_cfg*) – The configuration for the parser

Creates a parser with its configuration cfg The parser may be destroyed by a corresponding call to fy_parser_destroy().

A pointer to the parser or NULL in case of an error.

Destroy the given parser
fyp (struct fy_parser*) – The parser to destroy

Destroy a parser created earlier via fy_parser_create().

Get the configuration of a parser
fyp (struct fy_parser*) – The parser

The configuration of the parser

Get the diagnostic object of a parser
fyp (struct fy_parser*) – The parser to get the diagnostic object

Return a pointer to the diagnostic object of a parser object. Note that the returned diag object has a reference taken so you should fy_diag_unref() it when you’re done with it.

A pointer to a ref’ed diagnostic object or NULL in case of an error.

Set the diagnostic object of a parser
  • fyp (struct fy_parser*) – The parser to replace the diagnostic object
  • diag (struct fy_diag*) – The parser’s new diagnostic object, NULL for default

Replace the parser’s current diagnostic object with the one given as an argument. The previous diagnostic object will be unref’ed (and freed if its reference gets to 0). Also note that the diag argument shall take a reference too.

0 if everything OK, -1 otherwise

Reset a parser completely
fyp (struct fy_parser*) – The parser to reset

Completely reset a parser, including after an error that caused a parser error to be emitted.

0 if the reset was successful, -1 otherwise

Set the parser to process the given file
  • fyp (struct fy_parser*) – The parser
  • file (const char*) – The file to parse.

Point the parser to the given file for processing. The file is located by honoring the search path of the configuration set by the earlier call to fy_parser_create(). While the parser is in use the file will must be available.

zero on success, -1 on error

Set the parser to process the given string.
  • fyp (struct fy_parser*) – The parser
  • str (const char*) – The YAML string to parse.
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)

Point the parser to the given (NULL terminated) string. Note that while the parser is active the string must not go out of scope.

zero on success, -1 on error

Set the parser to process the given malloced string.
  • fyp (struct fy_parser*) – The parser
  • str (char*) – The YAML string to parse (allocated).
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)

Point the parser to the given (possible NULL terminated) string. Note that the string is expected to be allocated via malloc(3) and ownership is transferred to the created input. When the input is free’ed the memory will be automatically freed.

In case of an error the string is not freed.

zero on success, -1 on error

Set the parser to process the given file
  • fyp (struct fy_parser*) – The parser
  • name (const char*) – The label of the stream
  • fp (FILE*) – The FILE pointer, it must be open in read mode.

Point the parser to use fp for processing.

zero on success, -1 on error

Set the parser to process via a callback
  • fyp (struct fy_parser*) – The parser
  • user (void*) – The user data pointer
  • callback (ssize_t (*)(void *user, void *buf, size_t count)) – The callback method to request data with

Point the parser to use a callback for input.

zero on success, -1 on error

Set the parser to process the given file descriptor
  • fyp (struct fy_parser*) – The parser
  • fd (int) – The file descriptor to use

Point the parser to use fd for processing.

zero on success, -1 on error

Parse and return the next event.
fyp (struct fy_parser*) – The parser

Each call to fy_parser_parse() returns the next event from the configured input of the parser, or NULL at the end of the stream. The returned event must be released via a matching call to fy_parser_event_free().

The next event in the stream or NULL.

Parse and peek at the next event.
fyp (struct fy_parser*) – The parser

It will return the next event that a call to fy_parser_parse would generate, but as read-only.

You must not free this event.

A peek at the next event in the stream or NULL.

Skip the current scalar/collection
fyp (struct fy_parser*) – The parser

Skips the current scalar or collection.

0 on success, -1 on error

Count the sequence items
fyp (struct fy_parser*) – The parser

Counts the number of sequence items. Parser must already be in a sequence state. Note that this uses backtracking so it might not be very efficient.

The number of sequence items on success, -1 on error Note if the number of items exceeds INT_MAX, INT_MAX will be returned.

Count the mapping items
fyp (struct fy_parser*) – The parser

Counts the number of mapping items. Parser must already be in a mapping state. Note that this uses backtracking so it might not be very efficient.

The number of mapping items on success, -1 on error Note if the number of items exceeds INT_MAX, INT_MAX will be returned.

Free an event
  • fyp (struct fy_parser*) – The parser
  • fye (struct fy_event*) – The event to free (may be NULL)

Free a previously returned event from fy_parser_parse().

Check the parser for stream errors
fyp (struct fy_parser*) – The parser

true in case of a stream error, false otherwise.

Get the parser mode
fyp (struct fy_parser*) – The parser

Retrieve the current mode of the parser, which indicates the YAML version or format being parsed (YAML 1.1, 1.2, 1.3, or JSON).

The parser mode

Log using the parsers diagnostics printf style (va_arg)
  • fyp (struct fy_parser*) – The parser
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a log on the parser diagnostic output

Log using the parsers diagnostics printf style
  • fyp (struct fy_parser*) – The parser
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments

Output a report on the parser’s diagnostics

Report using the parsers diagnostics printf style and mark token (va_arg)
  • fyp (struct fy_parser*) – The parser
  • type (enum fy_error_type) – The error type
  • fyt (struct fy_token*) – The token
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a report on the parser and indicate the token’s position

Report using the parsers diagnostics printf style and mark token
  • fyp (struct fy_parser*) – The parser
  • type (enum fy_error_type) – The error type
  • fyt (struct fy_token*) – The token
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments

Output a report on the parser and indicate the token’s position

Get the style of a scalar token
fyt (struct fy_token*) – The scalar token to get it’s style. Note that a NULL token is a enum FYSS_PLAIN.

The scalar style of the token, or FYSS_PLAIN on each other case

Get the style of a collection token
fyt (struct fy_token*) – The collection token to get it’s style. Note that a NULL token is a enum FYCS_ANY.

The collection style of the token, or FYCS_ANY

Test whether the scalar is null (content)
fyt (struct fy_token*) – The scalar token to check for NULLity.

Note that this is different than null of the YAML type system. It is null as in null content. It is also different than an empty scalar.

true if is a null scalar, false otherwise

Get text (and length of it) of a token
  • fyt (struct fy_token*) – The token out of which the text pointer will be returned.
  • lenp (size_t*) – Pointer to a variable that will hold the returned length

This method will return a pointer to the text of a token along with the length of it. Note that this text is not NULL terminated. If you need a NULL terminated pointer use fy_token_get_text0().

In case that the token is ‘simple’ enough (i.e. a plain scalar) or something similar the returned pointer is a direct pointer to the space of the input that contains the token.

That means that the pointer is not guaranteed to be valid after the parser is destroyed.

If the token is ‘complex’ enough, then space shall be allocated, filled and returned.

Note that the concept of ‘simple’ and ‘complex’ is vague, and that’s on purpose.

A pointer to the text representation of the token, while lenp will be assigned the character length of said representation. NULL in case of an error.

Get zero terminated text of a token
fyt (struct fy_token*) – The token out of which the text pointer will be returned.

This method will return a pointer to the text of a token which is zero terminated. It will allocate memory to hold it in the token structure so try to use fy_token_get_text() instead if possible.

A pointer to a zero terminated text representation of the token. NULL in case of an error.

Get length of the text of a token
fyt (struct fy_token*) – The token

This method will return the length of the text representation of a token.

The size of the text representation of a token, -1 in case of an error. Note that the NULL token will return a length of zero.

Comment placement relative to token

enum fy_comment_placement {
    fycp_top,
    fycp_right,
    fycp_bottom
};

Comment on top of token
Comment to the right of the token
Comment to the bottom of the token

Get zero terminated comment of a token
  • fyt (struct fy_token*) – The token out of which the comment text will be returned.
  • which (enum fy_comment_placement) – The comment placement

Get the comment that is attached at a token having the given placement.

A pointer to a zero terminated text representation of the token comment. NULL in case of an error or if the token has no comment.

Get all comments of a token
fyt (struct fy_token*) – The token

Get all the comments that are attached on a token

A pointer to a zero terminated text representation of all the comments. The comments of all the placements are concatenated and returned as one. NULL in case of an error or if the event has no comments.

Attach a comment to a token
  • fyt (struct fy_token*) – The token out of which the comment text will be attached
  • which (enum fy_comment_placement) – The placement
  • text (const char*) – The text of the comment
  • len (size_t) – The length of the comment (FY_NT means the length of text)

Attach the given comment on the token at the specified placement. If another comment is already present it will be overriden. If text is NULL the comment is removed.

0 on success, -1 on failure.

Get all comments of an event
fye (struct fy_event*) – The event

A pointer to a zero terminated text representation of all the comments. The comments of all the placements are concatenated and returned as one. NULL in case of an error or if the event has no comments. The pointer must be free’ed if it’s not NULL via a call to free()

Get comment of a node
  • fyn (struct fy_node*) – The node
  • which (enum fy_comment_placement) – The placement of the comment

A pointer to a zero terminated text representation of the comment. NULL in case of an error or if the event has no such comments.

Get all comments of a node
fyn (struct fy_node*) – The node

A pointer to a zero terminated text representation of all the comments. The comments of all the placements are concatenated and returned as one. NULL in case of an error or if the event has no comments.

An iteration chunk

struct fy_iter_chunk {
    const char *str;
    size_t len;
}

Pointer to the start of the chunk
The size of the chunk

The iterator produces a stream of chunks which cover the whole object.

Create a token iterator
fyt (struct fy_token*) – The token to iterate, or NULL.

Create an iterator for operating on the given token, or a generic iterator for use with fy_token_iter_start(). The iterator must be destroyed with a matching call to fy_token_iter_destroy().

A pointer to the newly created iterator, or NULL in case of an error.

Destroy the iterator
iter (struct fy_token_iter*) – The iterator to destroy.

Destroy the iterator created by fy_token_iter_create().

Start iterating over the contents of a token
  • fyt (struct fy_token*) – The token to iterate over
  • iter (struct fy_token_iter*) – The iterator to prepare.

Prepare an iterator for operating on the given token. The iterator must be created via a previous call to fy_token_iter_create() for user level API access.

Stop iterating over the contents of a token
iter (struct fy_token_iter*) – The iterator.

Stop the iteration operation.

Peek at the next iterator chunk
iter (struct fy_token_iter*) – The iterator.

Peek at the next iterator chunk

A pointer to the next iterator chunk, or NULL in case there’s no other.

Get next iterator chunk
  • iter (struct fy_token_iter*) – The iterator.
  • curr (const struct fy_iter_chunk*) – The current chunk, or NULL for the first one.
  • errp (int*) – Pointer to an error return value or NULL

Get the next iterator chunk in sequence,

A pointer to the next iterator chunk, or NULL in case there’s no other. When the return value is NULL, the errp variable will be filled with 0 for normal end, or -1 in case of an error.

Advance the iterator position
  • iter (struct fy_token_iter*) – The iterator.
  • len (size_t) – Number of bytes to advance the iterator position

Advance the read pointer of the iterator. Note that mixing calls of this with any call of fy_token_iter_ungetc() / fy_token_iter_utf8_unget() in a single iterator sequence leads to undefined behavior.

Read a block from an iterator
  • iter (struct fy_token_iter*) – The iterator.
  • buf (void*) – Pointer to a block of memory to receive the data. Must be at least count bytes long.
  • count (size_t) – Amount of bytes to read.

Read a block from an iterator. Note than mixing calls of this and any of the ungetc methods leads to undefined behavior.

The amount of data read, or -1 in case of an error.

Get a single character from an iterator
iter (struct fy_token_iter*) – The iterator.

Reads a single character from an iterator. If the iterator is finished, it will return -1. If any calls to ungetc have pushed a character in the iterator it shall return that.

The next character in the iterator, or -1 in case of an error, or end of stream.

Ungets a single character from an iterator
  • iter (struct fy_token_iter*) – The iterator.
  • c (int) – The character to push back, or -1 to reset the pushback buffer.

Pushes back a single character to an iterator stream. It will be returned in subsequent calls of fy_token_iter_getc(). Currently only a single character is allowed to be pushed back, and any further calls to ungetc will return an error.

The pushed back character given as argument, or -1 in case of an error. If the pushed back character was -1, then 0 will be returned.

Peeks at single character from an iterator
iter (struct fy_token_iter*) – The iterator.

Peeks at the next character to get from an iterator. If the iterator is finished, it will return -1. If any calls to ungetc have pushed a character in the iterator it shall return that. The character is not removed from the iterator stream.

The next character in the iterator, or -1 in case of an error, or end of stream.

Get a single utf8 character from an iterator
iter (struct fy_token_iter*) – The iterator.

Reads a single utf8 character from an iterator. If the iterator is finished, it will return -1. If any calls to ungetc have pushed a character in the iterator it shall return that.

The next utf8 character in the iterator, or -1 in case of an error, or end of stream.

Ungets a single utf8 character from an iterator
  • iter (struct fy_token_iter*) – The iterator.
  • c (int) – The character to push back, or -1 to reset the pushback buffer.

Pushes back a single utf8 character to an iterator stream. It will be returned in subsequent calls of fy_token_iter_utf8_getc(). Currently only a single character is allowed to be pushed back, and any further calls to ungetc will return an error.

The pushed back utf8 character given as argument, or -1 in case of an error. If the pushed back utf8 character was -1, then 0 will be returned.

Peeks at single utf8 character from an iterator
iter (struct fy_token_iter*) – The iterator.

Peeks at the next utf8 character to get from an iterator. If the iterator is finished, it will return -1. If any calls to ungetc have pushed a character in the iterator it shall return that. The character is not removed from the iterator stream.

The next utf8 character in the iterator, or -1 in case of an error, or end of stream.

Parse the next document from the parser stream
fyp (struct fy_parser*) – The parser

This method performs parsing on a parser stream and returns the next document. This means that for a compound document with multiple documents, each call will return the next document.

The next document from the parser stream.

Destroy a document created by fy_parse_load_document()
  • fyp (struct fy_parser*) – The parser
  • fyd (struct fy_document*) – The document to destroy

Resolve anchors and merge keys
fyd (struct fy_document*) – The document to resolve

This method performs resolution of the given document, by replacing references to anchors with their contents and handling merge keys (<<)

zero on success, -1 on error

Document directive check
fyd (const struct fy_document*) – The document to check for directives existence

Checks whether the given document has any directives, i.e. TAG or VERSION.

true if directives exist, false if not

Explicit document start check
fyd (const struct fy_document*) – The document to check for explicit start marker

Checks whether the given document has an explicit document start marker, i.e. —

true if document has an explicit document start marker, false if not

Explicit document end check
fyd (const struct fy_document*) – The document to check for explicit end marker

Checks whether the given document has an explicit document end marker, i.e. …

true if document has an explicit document end marker, false if not

Retreive the document the node belong to
fyn (struct fy_node*) – The node to retreive it’s document

Returns the document of the node; note that while the node may not be reachable via a path expression, it may still be member of a document.

The document of the node, or NULL in case of an error, or when the node has no document attached.

Type of the emitted output

enum fy_emitter_write_type {
    fyewt_document_indicator,
    fyewt_tag_directive,
    fyewt_version_directive,
    fyewt_indent,
    fyewt_indicator,
    fyewt_whitespace,
    fyewt_plain_scalar,
    fyewt_single_quoted_scalar,
    fyewt_double_quoted_scalar,
    fyewt_literal_scalar,
    fyewt_folded_scalar,
    fyewt_anchor,
    fyewt_tag,
    fyewt_linebreak,
    fyewt_alias,
    fyewt_terminating_zero,
    fyewt_plain_scalar_key,
    fyewt_single_quoted_scalar_key,
    fyewt_double_quoted_scalar_key,
    fyewt_comment,
    fyewt_indicator_question_mark,
    fyewt_indicator_colon,
    fyewt_indicator_dash,
    fyewt_indicator_left_bracket,
    fyewt_indicator_right_bracket,
    fyewt_indicator_left_brace,
    fyewt_indicator_right_brace,
    fyewt_indicator_comma,
    fyewt_indicator_bar,
    fyewt_indicator_greater,
    fyewt_indicator_single_quote_start,
    fyewt_indicator_single_quote_end,
    fyewt_indicator_double_quote_start,
    fyewt_indicator_double_quote_end,
    fyewt_indicator_ambersand,
    fyewt_indicator_star,
    fyewt_indicator_chomp,
    fyewt_indicator_explicit_indent
};

Output chunk is a document indicator
Output chunk is a tag directive
Output chunk is a version directive
Output chunk is a document indicator
Output chunk is an indicator
Output chunk is white space
Output chunk is a plain scalar
Output chunk is a single quoted scalar
Output chunk is a double quoted scalar
Output chunk is a literal block scalar
Output chunk is a folded block scalar
Output chunk is an anchor
Output chunk is a tag
Output chunk is a linebreak
Output chunk is an alias
Output chunk is a terminating zero
Output chunk is an plain scalar key
Output chunk is an single quoted scalar key
Output chunk is an double quoted scalar key
Output chunk is a comment
? indicator
: indicator
indicator
[ indicator
] indicator
{ indicator
} indicator
, indicator
indicator
> indicator
‘ indicator
‘ indicator
“ indicator
“ indicator
& indicator
indicator
chomp indicator (- or +)
explicit indent indicator (0-9)

Describes the kind of emitted output, which makes it possible to colorize the output, or do some other content related filtering.

Emitter configuration flags

enum fy_emitter_cfg_flags {
    FYECF_SORT_KEYS,
    FYECF_OUTPUT_COMMENTS,
    FYECF_STRIP_LABELS,
    FYECF_STRIP_TAGS,
    FYECF_STRIP_DOC,
    FYECF_NO_ENDING_NEWLINE,
    FYECF_STRIP_EMPTY_KV,
    FYECF_EXTENDED_CFG,
    FYECF_INDENT_DEFAULT,
    FYECF_INDENT_1,
    FYECF_INDENT_2,
    FYECF_INDENT_3,
    FYECF_INDENT_4,
    FYECF_INDENT_5,
    FYECF_INDENT_6,
    FYECF_INDENT_7,
    FYECF_INDENT_8,
    FYECF_INDENT_9,
    FYECF_WIDTH_DEFAULT,
    FYECF_WIDTH_80,
    FYECF_WIDTH_132,
    FYECF_WIDTH_INF,
    FYECF_MODE_ORIGINAL,
    FYECF_MODE_BLOCK,
    FYECF_MODE_FLOW,
    FYECF_MODE_FLOW_ONELINE,
    FYECF_MODE_JSON,
    FYECF_MODE_JSON_TP,
    FYECF_MODE_JSON_ONELINE,
    FYECF_MODE_DEJSON,
    FYECF_MODE_PRETTY,
    FYECF_MODE_MANUAL,
    FYECF_MODE_FLOW_COMPACT,
    FYECF_MODE_JSON_COMPACT,
    FYECF_DOC_START_MARK_AUTO,
    FYECF_DOC_START_MARK_OFF,
    FYECF_DOC_START_MARK_ON,
    FYECF_DOC_END_MARK_AUTO,
    FYECF_DOC_END_MARK_OFF,
    FYECF_DOC_END_MARK_ON,
    FYECF_VERSION_DIR_AUTO,
    FYECF_VERSION_DIR_OFF,
    FYECF_VERSION_DIR_ON,
    FYECF_TAG_DIR_AUTO,
    FYECF_TAG_DIR_OFF,
    FYECF_TAG_DIR_ON,
    FYECF_DEFAULT
};

Sort key when emitting
Output comments (experimental)
Strip labels when emitting
Strip tags when emitting
Strip document tags and markers when emitting
Do not output ending new line (useful for single line mode)
Remove all keys with empty values from the output (not available in streaming mode)
Extend configuration, this config structure is embedded in a fy_emitter_xcfg.
Default emit output indent
Output indent is 1
Output indent is 2
Output indent is 3
Output indent is 4
Output indent is 5
Output indent is 6
Output indent is 7
Output indent is 8
Output indent is 9
Default emit output width
Output width is 80
Output width is 132
Output width is infinite
Emit using the same flow mode as the original
Emit using only the block mode
Emit using only the flow mode
Emit using only the flow mode (in one line)
Emit using JSON mode (non type preserving)
Emit using JSON mode (type preserving)
Emit using JSON mode (non type preserving, one line)
Emit YAML trying to pretify JSON
Emit YAML that tries to look good
Emit YAML respecting all manual style hints (reformats if needed)
Emit using only the flow mode in as much as possible compact form
Emit using JSON compact form
Automatically generate document start markers if required
Do not generate document start markers
Always generate document start markers
Automatically generate document end markers if required
Do not generate document end markers
Always generate document end markers
Automatically generate version directive
Never generate version directive
Always generate version directive
Automatically generate tag directives
Never generate tag directives
Always generate tag directives
The default emitter configuration

These flags control the operation of the emitter

emitter configuration structure.

struct fy_emitter_cfg {
    enum fy_emitter_cfg_flags flags;
    int (*output)(struct fy_emitter *emit, enum fy_emitter_write_type type, const char *str, int len, void *userdata);
    void *userdata;
    struct fy_diag *diag;
}

Configuration flags
Pointer to the method that will perform output.
Opaque user data pointer
Diagnostic interface

Argument to the fy_emitter_create() method which is the way to convert a runtime document structure back to YAML.

Emitter extended configuration flags

enum fy_emitter_xcfg_flags {
    FYEXCF_COLOR_AUTO,
    FYEXCF_COLOR_NONE,
    FYEXCF_COLOR_FORCE,
    FYEXCF_OUTPUT_STDOUT,
    FYEXCF_OUTPUT_STDERR,
    FYEXCF_OUTPUT_FILE,
    FYEXCF_OUTPUT_FD,
    FYEXCF_NULL_OUTPUT,
    FYEXCF_OUTPUT_FILENAME,
    FYEXCF_VISIBLE_WS,
    FYEXCF_EXTENDED_INDICATORS,
    FYEXCF_INDENTED_SEQ_IN_MAP,
    FYEXCF_PRESERVE_FLOW_LAYOUT
};

Automatically colorize if on a terminal
Do not colorize output
Force color generation
Output to stdout (default)
Output to stderr, instead of stdout
Output to the fp FILE pointer
Output to the fd file descriptor
No output
Output to the given filename
Make white space visible
Extend the indicators generated
Indent block sequences that are mapping values
Preserve oneline flow collections in streaming mode

These flags control the operation of the emitter. If no extended configuration mode is enabled all the flags are assumed 0.

emitter extended configuration structure.

struct fy_emitter_xcfg {
    struct fy_emitter_cfg cfg;
    enum fy_emitter_xcfg_flags xflags;
    const char *colors[FYEWT_COUNT];
    union {
        FILE *output_fp;
        int output_fd;
        const char *output_filename;
    } ;
}

The standard emitter configuration
Extra configuration flags
ANSI color overrides for the default output method
{unnamed_union}
anonymous
The output FILE *, FYEXCF_FILE_OUTPUT must be set
The output file descriptor, FYEXCF_FD_OUTPUT must be set
The output filename, FYEXCF_FILENAME_OUTPUT must be set

Argument to the fy_emitter create when FYECF_EXTENDED_CFG bit is set.

Create an emitter
cfg (const struct fy_emitter_cfg*) – The emitter configuration

Creates an emitter using the supplied configuration

The newly created emitter or NULL on error.

Destroy an emitter
emit (struct fy_emitter*) – The emitter to destroy

Destroy an emitter previously created by fy_emitter_create()

Get the configuration of an emitter
emit (struct fy_emitter*) – The emitter

The configuration of the emitter

Get the diagnostic object of an emitter
emit (struct fy_emitter*) – The emitter to get the diagnostic object

Return a pointer to the diagnostic object of an emitter object. Note that the returned diag object has a reference taken so you should fy_diag_unref() it when you’re done with it.

A pointer to a ref’ed diagnostic object or NULL in case of an error.

Set the diagnostic object of an emitter
  • emit (struct fy_emitter*) – The emitter to replace the diagnostic object
  • diag (struct fy_diag*) – The emitter’s new diagnostic object, NULL for default

Replace the emitters’s current diagnostic object with the one given as an argument. The previous diagnostic object will be unref’ed (and freed if its reference gets to 0). Also note that the diag argument shall take a reference too.

0 if everything OK, -1 otherwise

Set emitter finalizer
  • emit (struct fy_emitter*) – The emitter to replace the diagnostic object
  • finalizer (void (*)(struct fy_emitter *emit)) – The finalizer callback

Set a method callback to be called when the emitter is disposed of. If finalizer is NULL, then the method is removed.

emitter default output configuration

struct fy_emitter_default_output_data {
    FILE *fp;
    bool colorize;
    bool visible;
}

File where the output is directed to
Use ANSI color sequences to colorize the output
Make whitespace visible (requires a UTF8 capable terminal)

This is the argument to the default output method of the emitter.

The default colorizing output method
  • fye (struct fy_emitter*) – The emitter
  • type (enum fy_emitter_write_type) – Type of the emitted output
  • str (const char*) – Pointer to the string to output
  • len (int) – Length of the string
  • userdata (void*) – Must point to a fy_emitter_default_output_data structure

This is the default colorizing output method. Will be used when the output field of the emitter configuration is NULL.

0 on success, -1 on error

Emit a document to a file, using defaults
  • fyd (struct fy_document*) – The document to emit
  • fp (FILE*) – The file where the output is sent

Simple one shot emitter to a file, using the default emitter output. The output will be colorized if the the file points to a tty.

0 on success, -1 on error

Queue (and possibly emit) an event
  • emit (struct fy_emitter*) – The emitter to use
  • fye (struct fy_event*) – The event to queue for emission

Queue and output using the emitter. This is the streaming output method which does not require creating a document.

0 on success, -1 on error

Queue (and possibly emit) an event using varargs
  • emit (struct fy_emitter*) – The emitter to use
  • type (enum fy_event_type) – The event type to create
  • ap (va_list) – The variable argument list pointer.

Queue and output using the emitter. The format is identical to the one used in fy_emit_event_vcreate().

0 on success, -1 on error

Queue (and possibly emit) an event using variable args
  • emit (struct fy_emitter*) – The emitter to use
  • type (enum fy_event_type) – The event type to create
  • ellipsis (ellipsis) – The optional extra arguments

Queue and output using the emitter. The format is identical to the one used in fy_emit_event_create().

0 on success, -1 on error

Emit a scalar with write semantics
  • fye (struct fy_emitter*) – The emitter to use
  • style (enum fy_scalar_style) – The scalar style to use
  • anchor (const char*) – The anchor or NULL
  • tag (const char*) – The tag or NULL
  • buf (const char*) – Pointer to the buffer
  • count (size_t) – The number of bytes to write

Queue and output using the emitter a scalar using a standard write interface.

0 on success, -1 on error

Emit a scalar with vprintf semantics
  • fye (struct fy_emitter*) – The emitter to use
  • style (enum fy_scalar_style) – The scalar style to use
  • anchor (const char*) – The anchor or NULL
  • tag (const char*) – The tag or NULL
  • fmt (const char*) – The printf like format string
  • ap (va_list) – The argument list

Queue and output using the emitter a scalar using a standard vprintf interface.

0 on success, -1 on error

Emit a scalar with printf semantics
  • fye (struct fy_emitter*) – The emitter to use
  • style (enum fy_scalar_style) – The scalar style to use
  • anchor (const char*) – The anchor or NULL
  • tag (const char*) – The tag or NULL
  • fmt (const char*) – The printf like format string
  • ellipsis (ellipsis) – The extra arguments

Queue and output using the emitter a scalar using a standard printf interface.

0 on success, -1 on error

Queue (and possibly emit) an event generated by the parser.
  • emit (struct fy_emitter*) – The emitter to use
  • fyp (struct fy_parser*) – The parser that generated the event
  • fye (struct fy_event*) – The event to queue for emission

Queue and output using the emitter. This is the streaming output method which does not require creating a document. Similar to fy_emit_event() but it is more efficient.

0 on success, -1 on error

Emit the document using the emitter
  • emit (struct fy_emitter*) – The emitter
  • fyd (struct fy_document*) – The document to emit

Emits a document in YAML format using the emitter.

0 on success, -1 on error

Emit document start using the emitter
  • emit (struct fy_emitter*) – The emitter
  • fyd (struct fy_document*) – The document to use for emitting it’s start
  • fyn (struct fy_node*) – The root (or NULL for using the document’s root)

Emits a document start using the emitter. This is used in case you need finer control over the emitting output.

0 on success, -1 on error

Emit document end using the emitter
emit (struct fy_emitter*) – The emitter

Emits a document end using the emitter. This is used in case you need finer control over the emitting output.

0 on success, -1 on error

Emit a single node using the emitter
  • emit (struct fy_emitter*) – The emitter
  • fyn (struct fy_node*) – The node to emit

Emits a single node using the emitter. This is used in case you need finer control over the emitting output.

0 on success, -1 on error

Emit a single root node using the emitter
  • emit (struct fy_emitter*) – The emitter
  • fyn (struct fy_node*) – The root node to emit

Emits a single root node using the emitter. This is used in case you need finer control over the emitting output.

0 on success, -1 on error

Emit a single body node using the emitter
  • emit (struct fy_emitter*) – The emitter
  • fyn (struct fy_node*) – The body node to emit

Emits a single body node using the emitter. This is used in case you need finer control over the emitting output. No stream and document events will be generated at all.

0 on success, -1 on error

Emit an explicit document end
emit (struct fy_emitter*) – The emitter

Emits an explicit document end, i.e. … . Use this if you you need finer control over the emitting output.

0 on success, -1 on error

Emit a document to an file pointer
  • fyd (struct fy_document*) – The document to emit
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use
  • fp (FILE*) – The file pointer to output to

Emits a document from the root to the given file pointer.

0 on success, -1 on error

Emit a document to file
  • fyd (struct fy_document*) – The document to emit
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use
  • filename (const char*) – The filename to output to, or NULL for stdout

Emits a document from the root to the given file. The file will be fopen’ed using a “wa” mode.

0 on success, -1 on error

Emit a document to a file descriptor
  • fyd (struct fy_document*) – The document to emit
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use
  • fd (int) – The file descriptor to output to

Emits a document from the root to the given file descriptor

0 on success, -1 on error

Emit a document to a buffer
  • fyd (struct fy_document*) – The document to emit
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use
  • buf (char*) – Pointer to the buffer area to fill
  • size (size_t) – Size of the buffer

Emits an document from the root to the given buffer. If the document does not fit, an error will be returned.

A positive number, which is the size of the emitted document on the buffer on success, -1 on error

Emit a document to an allocated string
  • fyd (struct fy_document*) – The document to emit
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use

Emits an document from the root to a string which will be dynamically allocated.

A pointer to the allocated string, or NULL in case of an error

Emit a node (recursively) to a buffer
  • fyn (struct fy_node*) – The node to emit
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use
  • buf (char*) – Pointer to the buffer area to fill
  • size (size_t) – Size of the buffer

Emits a node recursively to the given buffer. If the document does not fit, an error will be returned.

A positive number, which is the size of the emitted node on the buffer on success, -1 on error

Emit a node to an allocated string
  • fyn (struct fy_node*) – The node to emit
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use

Emits a node recursively to a string which will be dynamically allocated.

A pointer to the allocated string, or NULL in case of an error

Create an emitter for buffer output.
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use
  • buf (char*) – Pointer to the buffer area to fill
  • size (size_t) – Size of the buffer

Creates a special purpose emitter for buffer output. Calls to fy_emit_event() populate the buffer. The contents are retreived by a call to fy_emit_to_buffer_collect()

The newly created emitter or NULL on error.

Collect the buffer emitter output
  • emit (struct fy_emitter*) – The emitter
  • sizep (size_t*) – Pointer to the size to be filled

Collects the output of the emitter which was created by fy_emit_to_buffer() and populated using fy_emit_event() calls. The NULL terminated returned buffer is the same as the one used in the fy_emit_to_buffer() call and the sizep argument will be filled with the size of the buffer.

The buffer or NULL in case of an error.

Create an emitter to create a dynamically allocated string.
flags (enum fy_emitter_cfg_flags) – The emitter flags to use

Creates a special purpose emitter for output to a dynamically allocated string. Calls to fy_emit_event() populate the buffer. The contents are retreived by a call to fy_emit_to_string_collect()

The newly created emitter or NULL on error.

Collect the string emitter output
  • emit (struct fy_emitter*) – The emitter
  • sizep (size_t*) – Pointer to the size to be filled

Collects the output of the emitter which was created by fy_emit_to_string() and populated using fy_emit_event() calls. The NULL terminated returned buffer is dynamically allocated and must be freed via a call to free(). The sizep argument will be filled with the size of the buffer.

The dynamically allocated string or NULL in case of an error.

Copy a node, associating the new node with the given document
  • fyd (struct fy_document*) – The document which the resulting node will be associated with
  • fyn_from (struct fy_node*) – The source node to recursively copy

Make a deep copy of a node, associating the copy with the given document. Note that no content copying takes place as the contents of the nodes are reference counted. This means that the operation is relatively inexpensive.

Note that the copy includes all anchors contained in the subtree of the source, so this call will register them with the document.

The copied node on success, NULL on error

Clones a document
fydsrc (struct fy_document*) – The source document to clone

Clone a document, by making a deep copy of the source. Note that no content copying takes place as the contents of the nodes are reference counted. This means that the operation is relatively inexpensive.

The newly created clone document, or NULL in case of an error

Insert a node to the given node
  • fyn_to (struct fy_node*) – The target node
  • fyn_from (struct fy_node*) – The source node

Insert a node to another node. If fyn_from is NULL then this operation will delete the fyn_to node.

from: scalar

to: another-scalar -> scalar to: { key: value } -> scalar to: [ seq0, seq1 ] -> scalar

from: [ seq2 ] to: scalar -> [ seq2 ] to: { key: value } -> [ seq2 ] to: [ seq0, seq1 ] -> [ seq0, seq1, sec2 ]

from: { another-key: another-value } to: scalar -> { another-key: another-value } to: { key: value } -> { key: value, another-key: another-value } to: [ seq0, seq1 ] -> { another-key: another-value }

from: { key: another-value } to: scalar -> { key: another-value } to: { key: value } -> { key: another-value } to: [ seq0, seq1 ] -> { key: another-value }

  • If target node changes type, source ovewrites target.
  • If source or target node are scalars, source it overwrites target.
  • If target and source are sequences the items of the source sequence are appended to the target sequence.
  • If target and source are maps the key, value pairs of the source are appended to the target map. If the target map contains a key-value pair that is present in the source map, it is overwriten by it.

0 on success, -1 on error

Delete a node from a document
fyn (struct fy_node*) – The node to delete.

Delete the given node. If it’s part of a sequence it will be removed from it. If it’s the value of a node key value pair, it will be removed from the mapping.

This is an alias for fy_document_insert_at(fyn, NULL)

Note that it is expected this node is attached to a document. Do not call this to free a node, because if it’s part of a collection it will not be properly removed.

0 on success, -1 on error

Insert a node to the given path in the document
  • fyd (struct fy_document*) – The document
  • path (const char*) – The path where the insert operation will target
  • pathlen (size_t) – The length of the path (or -1 if ‘0’ terminated)
  • fyn (struct fy_node*) – The source node

Insert a node to a given point in the document. If fyn is NULL then this operation will delete the target node.

Please see fy_node_insert for details of operation.

Note that in any case the fyn node will be unref’ed. So if the operation fails, and the reference is 0 the node will be freed. If you want it to stick around take a reference before.

0 on success, -1 on error

Node type

enum fy_node_type {
    FYNT_SCALAR,
    FYNT_SEQUENCE,
    FYNT_MAPPING
};

Node is a scalar
Node is a sequence
Node is a mapping

Each node may be one of the following types

Node style

enum fy_node_style {
    FYNS_ANY,
    FYNS_FLOW,
    FYNS_BLOCK,
    FYNS_PLAIN,
    FYNS_SINGLE_QUOTED,
    FYNS_DOUBLE_QUOTED,
    FYNS_LITERAL,
    FYNS_FOLDED,
    FYNS_ALIAS
};

No hint, let the emitter decide
Prefer flow style (for sequence/mappings)
Prefer block style (for sequence/mappings)
Plain style preferred
Single quoted style preferred
Double quoted style preferred
Literal style preferred (valid in block context)
Folded style preferred (valid in block context)
It’s an alias

A node may contain a hint of how it should be rendered, encoded as a style.

Node walk flags

enum fy_node_walk_flags {
    FYNWF_DONT_FOLLOW,
    FYNWF_FOLLOW,
    FYNWF_PTR_YAML,
    FYNWF_PTR_JSON,
    FYNWF_PTR_RELJSON,
    FYNWF_PTR_YPATH,
    FYNWF_URI_ENCODED,
    FYNWF_MAXDEPTH_DEFAULT,
    FYNWF_MARKER_DEFAULT,
    FYNWF_PTR_DEFAULT
};

Don’t follow aliases during pathwalk
Follow aliases during pathwalk
YAML pointer path walks
JSON pointer path walks
Relative JSON pointer path walks
YPATH pointer path walks
The path is URI encoded
Max follow depth is automatically determined
Default marker to use when scanning
Default path type

Convert from scalar to node style
sstyle (enum fy_scalar_style) – The input scalar style

Convert a scalar style to a node style.

The matching node style

Mapping sorting method function
  • fynp_a (const struct fy_node_pair*) – The first node_pair used in the comparison
  • fynp_b (const struct fy_node_pair*) – The second node_pair used in the comparison
  • arg (void*) – The opaque user provided pointer to the sort operation

<0 if fynp_a is less than fynp_b 0 if fynp_a is equal to fynp_b >0 if fynp_a is greater than fynp_b

Node compare method function for scalars
  • fyn_a (struct fy_node*) – The first scalar node used in the comparison
  • fyn_b (struct fy_node*) – The second scalar node used in the comparison
  • arg (void*) – The opaque user provided pointer to the compare operation

<0 if fyn_a is less than fyn_b 0 if fyn_a is equal to fyn_b >0 if fyn_a is greater than fyn_b

Compare two nodes for equality
  • fyn1 (struct fy_node*) – The first node to use in the comparison
  • fyn2 (struct fy_node*) – The second node to use in the comparison

Compare two nodes for equality. The comparison is ‘deep’, i.e. it recurses in subnodes, and orders the keys of maps using default libc strcmp ordering. For scalar the comparison is performed after any escaping so it’s a true content comparison.

true if the nodes contain the same content, false otherwise

Compare two nodes for equality using user supplied sort and scalar compare methods
  • fyn1 (struct fy_node*) – The first node to use in the comparison
  • fyn2 (struct fy_node*) – The second node to use in the comparison
  • sort_fn (fy_node_mapping_sort_fn) – The method to use for sorting maps, or NULL for the default
  • sort_fn_arg (void*) – The extra user supplied argument to the sort_fn
  • cmp_fn (fy_node_scalar_compare_fn) – The method to use for comparing scalars, or NULL for the default
  • cmp_fn_arg (void*) – The extra user supplied argument to the cmp_fn

Compare two nodes for equality using user supplied sot and scalar compare methods. The comparison is ‘deep’, i.e. it recurses in subnodes, and orders the keys of maps using the supplied mapping sort method for ordering. For scalars the comparison is performed using the supplied scalar node compare methods.

true if the nodes contain the same content, false otherwise

Compare a node for equality with a YAML string
  • fyn (struct fy_node*) – The node to use in the comparison
  • str (const char*) – The YAML string to compare against
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)

Compare a node for equality with a YAML string. The comparison is performed using fy_node_compare() with the first node supplied as an argument and the second being generated by calling fy_document_build_from_string with the YAML string.

true if the node and the string are equal.

Compare a node for equality against a token
  • fyn (struct fy_node*) – The node to use in the comparison
  • fyt (struct fy_token*) – The scalar token

Compare a node for equality with a token. Both the node and the tokens must be a scalars.

true if the node and the token are equal.

Compare a node for equality with a raw C text
  • fyn (struct fy_node*) – The node to use in the comparison
  • text (const char*) – The raw C text to compare against
  • len (size_t) – The length of the text (or -1 if ‘0’ terminated)

Compare a node for equality with a raw C string. The node must be a scalar.

true if the node and the text are equal.

Create an empty document
cfg (const struct fy_parse_cfg*) – The parse configuration to use or NULL for the default.

Create an empty document using the provided parser configuration. If NULL use the default parse configuration.

The created empty document, or NULL on error.

Destroy a document previously created via fy_document_create()
fyd (struct fy_document*) – The document to destroy

Destroy a document (along with all children documents)

Get the configuration of a document
fyd (struct fy_document*) – The document

The configuration of the document

Get the diagnostic object of a document
fyd (struct fy_document*) – The document to get the diagnostic object

Return a pointer to the diagnostic object of a document object. Note that the returned diag object has a reference taken so you should fy_diag_unref() it when you’re done with it.

A pointer to a ref’ed diagnostic object or NULL in case of an error.

Set the diagnostic object of a document
  • fyd (struct fy_document*) – The document to replace the diagnostic object
  • diag (struct fy_diag*) – The document’s new diagnostic object, NULL for default

Replace the documents’s current diagnostic object with the one given as an argument. The previous diagnostic object will be unref’ed (and freed if its reference gets to 0). Also note that the diag argument shall take a reference too.

0 if everything OK, -1 otherwise

Make a document a child of another
  • fyd (struct fy_document*) – The parent document
  • fyd_child (struct fy_document*) – The child document

Set the parent of fyd_child document to be fyd

0 if all OK, -1 on error.

Create a document using the provided YAML source.
  • cfg (const struct fy_parse_cfg*) – The parse configuration to use or NULL for the default.
  • str (const char*) – The YAML source to use.
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)

Create a document parsing the provided string as a YAML source.

The created document, or NULL on error.

Create a document using the provided YAML source which was malloced.
  • cfg (const struct fy_parse_cfg*) – The parse configuration to use or NULL for the default.
  • str (char*) – The YAML source to use.
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)

Create a document parsing the provided string as a YAML source. The string is expected to have been allocated by malloc(3) and when the document is destroyed it will be automatically freed.

The created document, or NULL on error.

Create a document parsing the given file
  • cfg (const struct fy_parse_cfg*) – The parse configuration to use or NULL for the default.
  • file (const char*) – The name of the file to parse

Create a document parsing the provided file as a YAML source.

The created document, or NULL on error.

Create a document parsing the given file pointer
  • cfg (const struct fy_parse_cfg*) – The parse configuration to use or NULL for the default.
  • fp (FILE*) – The file pointer

Create a document parsing the provided file pointer as a YAML source.

The created document, or NULL on error.

Create a document using the provided YAML via vprintf formatting
  • cfg (const struct fy_parse_cfg*) – The parse configuration to use or NULL for the default.
  • fmt (const char*) – The format string creating the YAML source to use.
  • ap (va_list) – The va_list argument pointer

Create a document parsing the provided string as a YAML source. The string is created by applying vprintf formatting.

The created document, or NULL on error.

Create a document using the provided YAML source via printf formatting
  • cfg (const struct fy_parse_cfg*) – The parse configuration to use or NULL for the default.
  • fmt (const char*) – The format string creating the YAML source to use.
  • ellipsis (ellipsis) – The printf arguments

Create a document parsing the provided string as a YAML source. The string is created by applying printf formatting.

The created document, or NULL on error.

Create a document using the provided YAML source.
  • cfg (const struct fy_parse_cfg*) – The parse configuration to use or NULL for the default.
  • str (const char*) – The YAML source to use.
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)
  • consumed (size_t*) – A pointer to the consumed amount

Create a document parsing the provided string as a YAML source.

The document is a flow document, i.e. does not contain any block content and is usually laid out in a single line.

plain-scalar “double-quoted-scalar” ‘single-quoted-scalar’ { foo: bar } [ 0, 1, 2 ]

A flow document is important because parsing stops at the end of it, and so can be placed in other non-yaml content.

The created document, or NULL on error.

Create a document using the provided YAML source.
  • cfg (const struct fy_parse_cfg*) – The parse configuration to use or NULL for the default.
  • str (const char*) – The YAML source to use.
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)
  • consumed (size_t*) – A pointer to the consumed amount

Create a document parsing the provided string as a YAML source.

The document is a block document, and it terminates when indentation appears to do so.

Example of block documents:

this-is-yaml
  foo: bar    <- starts here
  baz: [1, 2]
this-is-yaml-no-more

The created document, or NULL on error.

Return the root node of the document
fyd (struct fy_document*) – The document

Returns the root of the document. If the document is empty NULL will be returned instead.

The root of the document, or NULL if the document is empty.

Set the root of the document
  • fyd (struct fy_document*) – The document
  • fyn (struct fy_node*) – The new root of the document.

Set the root of a document. If the document was not empty the old root will be freed. If fyn is NULL then the document is set to empty.

0 on success, -1 on error

Get the node type
fyn (struct fy_node*) – The node

Retrieve the node type. It is one of FYNT_SCALAR, FYNT_SEQUENCE or FYNT_MAPPING. A NULL node argument is a FYNT_SCALAR.

The node type

Get the node style
fyn (struct fy_node*) – The node

Retrieve the node rendering style. If the node is NULL then the style is FYNS_PLAIN.

The node style

Set the node style
  • fyn (struct fy_node*) – The node
  • style (enum fy_node_style) – The requested node rendering style

Try to set the node rendering style of a node. If the style of node is illegal (for example you can’t set an arbitrary scalar that contains zeroes to plain) then the actual style that was set will be returned.

The final node style

Get the node start token
fyn (struct fy_node*) – The node

Retrieve the node start token.

For scalars, this is the same as the end token.

The node start token

Get the node end token
fyn (struct fy_node*) – The node

Retrieve the node end token.

For scalars, this is the same as the start token.

The node end token

Check whether the node is a scalar
fyn (struct fy_node*) – The node

Convenience method for checking whether a node is a scalar.

true if the node is a scalar, false otherwise

Check whether the node is a sequence
fyn (struct fy_node*) – The node

Convenience method for checking whether a node is a sequence.

true if the node is a sequence, false otherwise

Check whether the node is a mapping
fyn (struct fy_node*) – The node

Convenience method for checking whether a node is a mapping.

true if the node is a mapping, false otherwise

Check whether the node is an alias
fyn (struct fy_node*) – The node

Convenience method for checking whether a node is an alias.

true if the node is an alias, false otherwise

Check whether the node is a NULL
fyn (struct fy_node*) – The node

Convenience method for checking whether a node is a NULL scalar.. Note that a NULL node argument returns true…

true if the node is a NULL scalar, false otherwise

Check whether the node is attached
fyn (struct fy_node*) – The node

Checks whether a node is attached in a document structure. An attached node may not be freed, before being detached. Note that there is no method that explicitly detaches a node, since this is handled internaly by the sequence and mapping removal methods.

true if the node is attached, false otherwise

Gets the tag token of a node (if it exists)
fyn (struct fy_node*) – The node which has the tag token to be returned

Gets the tag token of a node, if it exists

The tag token of the given node, or NULL if the tag does not exist.

Gets the scalar token of a node (if it exists)
fyn (struct fy_node*) – The node which has the scalar token to be returned

Gets the scalar token of a node, if it exists and the node is a valid scalar node. Note that aliases are scalars, so if this call is issued on an alias node the return shall be of an alias token.

The scalar token of the given node, or NULL if the node is not a scalar.

Resolve an alias node
fyn (struct fy_node*) – The alias node to be resolved

Resolve an alias node, following any subsequent aliases until a non alias node has been found. This call performs cycle detection and excessive redirections checks so it’s safe to call in any context.

The resolved alias node, or NULL if either fyn is not an alias, or resolution fails due to a graph cycle.

Dereference a single alias node
fyn (struct fy_node*) – The alias node to be dereferenced

Dereference an alias node. This is different than resolution in that will only perform a single alias follow call and it will fail if the input is not an alias. This call performs cycle detection and excessive redirections checks so it’s safe to call in any context.

The dereferenced alias node, or NULL if either fyn is not an alias, or resolution fails due to a graph cycle.

Free a node
fyn (struct fy_node*) – The node to free

Recursively frees the given node releasing the memory it uses, removing any anchors on the document it contains, and releasing references on the tokens it contains.

This method will return an error if the node is attached, or if not NULL it is not a member of a document.

0 on success, -1 on error.

Create a node using the provided YAML source.
  • fyd (struct fy_document*) – The document
  • str (const char*) – The YAML source to use.
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)

Create a node parsing the provided string as a YAML source. The node created will be associated with the provided document.

The created node, or NULL on error.

Create a node using the provided YAML source which was malloced.
  • fyd (struct fy_document*) – The document
  • str (char*) – The YAML source to use.
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)

Create a node parsing the provided string as a YAML source. The node created will be associated with the provided document. The string is expected to have been allocated by malloc(3) and when the document is destroyed it will be automatically freed.

The created node, or NULL on error.

Create a node using the provided YAML file.
  • fyd (struct fy_document*) – The document
  • file (const char*) – The name of the file to parse

Create a node parsing the provided file as a YAML source. The node created will be associated with the provided document.

The created node, or NULL on error.

Create a node using the provided file pointer.
  • fyd (struct fy_document*) – The document
  • fp (FILE*) – The file pointer

Create a node parsing the provided file pointer as a YAML source. The node created will be associated with the provided document.

The created node, or NULL on error.

Create a node using the provided YAML source via vprintf formatting
  • fyd (struct fy_document*) – The document
  • fmt (const char*) – The format string creating the YAML source to use.
  • ap (va_list) – The va_list argument pointer

Create a node parsing the resulting string as a YAML source. The string is created by applying vprintf formatting.

The created node, or NULL on error.

Create a node using the provided YAML source via printf formatting
  • fyd (struct fy_document*) – The document
  • fmt (const char*) – The format string creating the YAML source to use.
  • ellipsis (ellipsis) – The printf arguments

Create a node parsing the resulting string as a YAML source. The string is created by applying printf formatting.

The created node, or NULL on error.

Retrieve a node using the provided path spec.
  • fyn (struct fy_node*) – The node to use as start of the traversal operation
  • path (const char*) – The path spec to use in the traversal operation
  • len (size_t) – The length of the path (or -1 if ‘0’ terminated)
  • flags (enum fy_node_walk_flags) – The extra path walk flags

This method will retrieve a node relative to the given node using the provided path spec.

Path specs are comprised of keys seperated by slashes ‘/’. Keys are either regular YAML expressions in flow format for traversing mappings, or indexes in brackets for traversing sequences. Path specs may start with ‘/’ which is silently ignored.

A few examples will make this clear:

fyn = { foo: bar } - fy_node_by_path(fyn, "/foo") -> bar
fyn = [ foo, bar ] - fy_node_by_path(fyn, "1") -> bar
fyn = { { foo: bar }: baz } - fy_node_by_path(fyn, "{foo: bar}") -> baz
fyn = [ foo, { bar: baz } } - fy_node_by_path(fyn, "1/bar") -> baz

Note that the special characters /{}[] are not escaped in plain style, so you will not be able to use them as path traversal keys. In that case you can easily use either the single, or double quoted forms:

fyn = { foo/bar: baz } - fy_node_by_path(fyn, "'foo/bar'") -> baz

The retrieved node, or NULL if not possible to be found.

Get the path of this node
fyn (struct fy_node*) – The node

Retrieve the given node’s path address relative to the document root. The address is dynamically allocated and should be freed when you’re done with it.

The node’s address, or NULL if fyn is the root.

Get the parent node of a node
fyn (struct fy_node*) – The node

Get the parent node of a node. The parent of a document’s root is NULL, and so is the parent of the root of a key node’s of a mapping. This is because the nodes of a key may not be addressed using a path expression.

The node’s parent, or NULL if fyn is the root, or the root of a key mapping.

Get the document parent node of a node
fyn (struct fy_node*) – The node

Get the document parent node of a node. The document parent differs than the regular parent in that a key’s root node of a mapping is not NULL, rather it points to the actual node parent.

The node’s document parent, or NULL if fyn is the root

Get the path address of this node’s parent
fyn (struct fy_node*) – The node

Retrieve the given node’s parent path address The address is dynamically allocated and should be freed when you’re done with it.

The parent’s address, or NULL if fyn is the root.

Get a path address of a node relative to one of it’s parents
  • fyn_parent (struct fy_node*) – The node parent/grandparent…
  • fyn (struct fy_node*) – The node

Retrieve the given node’s path address relative to an arbitrary parent in the tree. The address is dynamically allocated and should be freed when you’re done with it.

The relative address from the parent to the node

Get a path address of a node in the shortest path possible
fyn (struct fy_node*) – The node

Retrieve the given nodes short path address relative to the closest anchor (either on this node, or its parent). If no such parent is found then returns the absolute path from the start of the document.

Example:

--- &foo
foo: &bar
    bar
baz
- The short path of /foo is \*foo
- The short path of /foo/bar is \*bar
- The short path of /baz is \*foo/baz

The address is dynamically allocated and should be freed when you’re done with it.

The shortest path describing the node

Get a textual reference to a node
fyn (struct fy_node*) – The node

Retrieve the given node’s textual reference. If the node contains an anchor the expression that references the anchor will be returned, otherwise an absolute path reference relative to the root of the document will be returned.

The address is dynamically allocated and should be freed when you’re done with it.

The node’s text reference.

Create an alias reference node
fyn (struct fy_node*) – The node

Create an alias node reference. If the node contains an anchor the expression that references the alias will use the anchor, otherwise an absolute path reference relative to the root of the document will be created.

An alias node referencing the argument node

Get a textual reference to a node relative to a base node.
  • fyn_base (struct fy_node*) – The base node
  • fyn (struct fy_node*) – The node

Retrieve the given node’s textual reference as generated using another parent (or grand parent) as a base. If the node contains an anchor the expression that references the anchor will be returned. If the base node contains an anchor the reference will be relative to it otherwise an absolute path reference will be returned.

The address is dynamically allocated and should be freed when you’re done with it.

The node’s text reference.

Create an alias reference node
  • fyn_base (struct fy_node*) – The base node
  • fyn (struct fy_node*) – The node

Create a relative alias node reference using another parent (or grand parent) as a base. If the node contains an anchor the alias will reference the anchor. If the base node contains an anchor the alias will be relative to it otherwise an absolute path reference will be created.

An alias node referencing the argument node relative to the base

Create a scalar node.
  • fyd (struct fy_document*) – The document which the resulting node will be associated with
  • data (const char*) – Pointer to the data area
  • size (size_t) – Size of the data area, or (size_t)-1 for ‘0’ terminated data.

Create a scalar node using the provided memory area as input. The input is expected to be regular utf8 encoded. It may contain escaped characters in which case the style of the scalar will be set to double quoted.

Note that the data are not copied, merely a reference is taken, so it must be available while the node is in use.

The created node, or NULL on error.

Create a scalar node copying the data.
  • fyd (struct fy_document*) – The document which the resulting node will be associated with
  • data (const char*) – Pointer to the data area
  • size (size_t) – Size of the data area, or (size_t)-1 for ‘0’ terminated data.

Create a scalar node using the provided memory area as input. The input is expected to be regular utf8 encoded. It may contain escaped characters in which case the style of the scalar will be set to double quoted.

A copy of the data will be made, so it is safe to free the data after the call.

The created node, or NULL on error.

vprintf interface for creating scalars
  • fyd (struct fy_document*) – The document which the resulting node will be associated with
  • fmt (const char*) – The printf based format string
  • ap (va_list) – The va_list containing the arguments

Create a scalar node using a vprintf interface. The input is expected to be regular utf8 encoded. It may contain escaped characters in which case the style of the scalar will be set to double quoted.

The created node, or NULL on error.

printf interface for creating scalars
  • fyd (struct fy_document*) – The document which the resulting node will be associated with
  • fmt (const char*) – The printf based format string
  • ellipsis (ellipsis) – The arguments

Create a scalar node using a printf interface. The input is expected to be regular utf8 encoded. It may contain escaped characters in which case the style of the scalar will be set to double quoted.

The created node, or NULL on error.

Create an empty sequence node.
fyd (struct fy_document*) – The document which the resulting node will be associated with

Create an empty sequence node associated with the given document.

The created node, or NULL on error.

Create an empty mapping node.
fyd (struct fy_document*) – The document which the resulting node will be associated with

Create an empty mapping node associated with the given document.

The created node, or NULL on error.

Set the tag of node
  • fyn (struct fy_node*) – The node to set it’s tag.
  • data (const char*) – Pointer to the tag data.
  • len (size_t) – Size of the tag data, or (size_t)-1 for ‘0’ terminated.

Manually set the tag of a node. The tag must be a valid one for the document the node belongs to.

Note that the data are not copied, merely a reference is taken, so it must be available while the node is in use.

If the node already contains a tag it will be overwriten.

0 on success, -1 on error.

Remove the tag of node
fyn (struct fy_node*) – The node to remove it’s tag.

Remove the tag of a node.

0 on success, -1 on error.

Get the tag of the node
  • fyn (struct fy_node*) – The node
  • lenp (size_t*) – Pointer to a variable that will hold the returned length

This method will return a pointer to the text of a tag along with the length of it. Note that this text is not NULL terminated.

A pointer to the tag of the node, while lenp will be assigned the length of said tag. A NULL will be returned in case of an error.

Get the tag of the node
fyn (struct fy_node*) – The node

This method will return a pointer to the text of a tag, which will be NULL terminated.

A pointer to the null terminated tag of the node. A NULL will be returned in case of an error.

Get the length of the tag of the node
fyn (struct fy_node*) – The tagged node

This method will return the size of the tag of the node. If the node is not tagged it will return 0.

The size of the tag, or 0 if node is not tagged.

Get the scalar content of the node
  • fyn (struct fy_node*) – The scalar node
  • lenp (size_t*) – Pointer to a variable that will hold the returned length

This method will return a pointer to the text of the scalar content of a node along with the length of it. Note that this pointer is not NULL terminated.

A pointer to the scalar content of the node, while lenp will be assigned the length of said content. A NULL will be returned in case of an error, i.e. the node is not a scalar.

Get the scalar content of the node
fyn (struct fy_node*) – The scalar node

This method will return a pointer to the text of the scalar content of a node as a null terminated string. Note that this call will allocate memory to hold the null terminated string so if possible use fy_node_get_scalar()

A pointer to the scalar content of the node or NULL in returned in case of an error.

Get the length of the scalar content
fyn (struct fy_node*) – The scalar node

This method will return the size of the scalar content of the node. If the node is not a scalar it will return 0.

The size of the scalar content, or 0 if node is not scalar.

Get the length of the scalar content in utf8 characters
fyn (struct fy_node*) – The scalar node

This method will return the size of the scalar content of the node in utf8 characters. If the node is not a scalar it will return 0.

The size of the scalar content in utf8 characters, or 0 if node is not scalar.

Iterate over a sequence node
  • fyn (struct fy_node*) – The sequence node
  • prevp (void**) – The previous sequence iterator

This method iterates over all the item nodes in the sequence node. The start of the iteration is signalled by a NULL in *prevp.

The next node in sequence or NULL at the end of the sequence.

Iterate over a sequence node in reverse
  • fyn (struct fy_node*) – The sequence node
  • prevp (void**) – The previous sequence iterator

This method iterates in reverse over all the item nodes in the sequence node. The start of the iteration is signalled by a NULL in *prevp.

The next node in reverse sequence or NULL at the end of the sequence.

Return the item count of the sequence
fyn (struct fy_node*) – The sequence node

Get the item count of the sequence.

The count of items in the sequence or -1 in case of an error.

Check whether the sequence is empty
fyn (struct fy_node*) – The sequence node

Check whether the sequence contains items.

true if the node is a sequence containing items, false otherwise

Return a sequence item by index
  • fyn (struct fy_node*) – The sequence node
  • index (int) – The index of the node to retrieve. - >= 0 counting from the start - < 0 counting from the end

Retrieve a node in the sequence using it’s index. If index is positive or zero the count is from the start of the sequence, while if negative from the end. I.e. -1 returns the last item in the sequence.

The node at the specified index or NULL if no such item exist.

Append a node item to a sequence
  • fyn_seq (struct fy_node*) – The sequence node
  • fyn (struct fy_node*) – The node item to append

Append a node item to a sequence.

0 on success, -1 on error

Append a node item to a sequence
  • fyn_seq (struct fy_node*) – The sequence node
  • fyn (struct fy_node*) – The node item to prepend

Prepend a node item to a sequence.

0 on success, -1 on error

Insert a node item before another
  • fyn_seq (struct fy_node*) – The sequence node
  • fyn_mark (struct fy_node*) – The node item which the node will be inserted before.
  • fyn (struct fy_node*) – The node item to insert in the sequence.

Insert a node item before another in the sequence.

0 on success, -1 on error

Insert a node item after another
  • fyn_seq (struct fy_node*) – The sequence node
  • fyn_mark (struct fy_node*) – The node item which the node will be inserted after.
  • fyn (struct fy_node*) – The node item to insert in the sequence.

Insert a node item after another in the sequence.

0 on success, -1 on error

Remove an item from a sequence
  • fyn_seq (struct fy_node*) – The sequence node
  • fyn (struct fy_node*) – The node item to remove from the sequence.

Remove a node item from a sequence and return it.

The removed node item fyn, or NULL in case of an error.

Sequence sorting method function
  • fyn_a (struct fy_node*) – The first node used in the comparison
  • fyn_b (struct fy_node*) – The second node used in the comparison
  • arg (void*) – The opaque user provided pointer to the sort operation

<0 if fyn_a is less than fyn_b 0 if fyn_a is equal to fyn_b >0 if fyn_a is greater than fyn_b

Sort a sequence’s items
  • fyn_seq (struct fy_node*) – The sequence node to sort
  • cmp (fy_node_sequence_sort_fn) – The comparison method
  • arg (void*) – An opaque user pointer for the comparison method

Sort the items of a sequence node using the given comparison method.

0 on success, -1 on error

Iterate over a mapping node
  • fyn (struct fy_node*) – The mapping node
  • prevp (void**) – The previous sequence iterator

This method iterates over all the node pairs in the mapping node. The start of the iteration is signalled by a NULL in *prevp.

Note that while a mapping is an unordered collection of key/values the order of which they are created is important for presentation purposes.

The next node pair in the mapping or NULL at the end of the mapping.

Iterate over a mapping node in reverse
  • fyn (struct fy_node*) – The mapping node
  • prevp (void**) – The previous sequence iterator

This method iterates in reverse over all the node pairs in the mapping node. The start of the iteration is signalled by a NULL in *prevp.

Note that while a mapping is an unordered collection of key/values the order of which they are created is important for presentation purposes.

The next node pair in reverse sequence in the mapping or NULL at the end of the mapping.

Return the node pair count of the mapping
fyn (struct fy_node*) – The mapping node

Get the count of the node pairs in the mapping.

The count of node pairs in the mapping or -1 in case of an error.

Check whether the mapping is empty
fyn (struct fy_node*) – The mapping node

Check whether the mapping contains any node pairs.

true if the node is a mapping containing node pairs, false otherwise

Return a node pair by index
  • fyn (struct fy_node*) – The mapping node
  • index (int) – The index of the node pair to retrieve. - >= 0 counting from the start - < 0 counting from the end

Retrieve a node pair in the mapping using its index. If index is positive or zero the count is from the start of the sequence, while if negative from the end. I.e. -1 returns the last node pair in the mapping.

The node pair at the specified index or NULL if no such item exist.

Lookup a node pair in mapping by string
  • fyn (struct fy_node*) – The mapping node
  • key (const char*) – The YAML source to use as key
  • len (size_t) – The length of the key (or -1 if ‘0’ terminated)

This method will return the node pair that contains the same key from the YAML node created from the key argument. The comparison of the node is using fy_node_compare()

The value matching the given key, or NULL if not found.

Lookup a node value in mapping by string
  • fyn (struct fy_node*) – The mapping node
  • key (const char*) – The YAML source to use as key
  • len (size_t) – The length of the key (or -1 if ‘0’ terminated)

This method will return the value of node pair that contains the same key from the YAML node created from the key argument. The comparison of the node is using fy_node_compare()

The value matching the given key, or NULL if not found.

Lookup a node value in mapping by string
  • fyn (struct fy_node*) – The mapping node
  • key (const char*) – The YAML source to use as key
  • len (size_t) – The length of the key (or -1 if ‘0’ terminated)

This method will return the value of node pair that contains the same key from the YAML node created from the key argument. The comparison of the node is using fy_node_compare()

It is synonymous with fy_node_mapping_lookup_by_string().

The value matching the given key, or NULL if not found.

Lookup a node key in mapping by string
  • fyn (struct fy_node*) – The mapping node
  • key (const char*) – The YAML source to use as key
  • len (size_t) – The length of the key (or -1 if ‘0’ terminated)

This method will return the key of node pair that contains the same key from the YAML node created from the key argument. The comparison of the node is using fy_node_compare()

The key matching the given key, or NULL if not found.

Lookup a node pair in mapping by simple string
  • fyn (struct fy_node*) – The mapping node
  • key (const char*) – The string to use as key
  • len (size_t) – The length of the key (or -1 if ‘0’ terminated)

This method will return the node pair that contains the same key from the YAML node created from the key argument. The comparison of the node is using by comparing the strings for identity.

The node pair matching the given key, or NULL if not found.

Lookup a node value in mapping by simple string
  • fyn (struct fy_node*) – The mapping node
  • key (const char*) – The string to use as key
  • len (size_t) – The length of the key (or -1 if ‘0’ terminated)

This method will return the value of node pair that contains the same key from the YAML node created from the key argument. The comparison of the node is using by comparing the strings for identity.

The value matching the given key, or NULL if not found.

Lookup a node pair in mapping that has a NULL key
fyn (struct fy_node*) – The mapping node

This method will return the node pair that has a NULL key. Note this method is not using the mapping accelerator and arguably NULL keys should not exist. Alas…

The node pair with a NULL key, NULL otherwise

Lookup a node value with a NULL key.
fyn (struct fy_node*) – The mapping node

Return the value of a node pair that has a NULL key.

The value matching the null key, NULL otherwise. Note that the value may be NULL too, but for that pathological case use the node pair method instead.

Lookup a scalar in mapping by simple string
  • fyn (struct fy_node*) – The mapping node
  • lenp (size_t*) – Pointer to a variable that will hold the returned length
  • key (const char*) – The string to use as key
  • keylen (size_t) – The length of the key (or -1 if ‘0’ terminated)

This method will return the scalar contents that contains the same key from the YAML node created from the key argument. The comparison of the node is using by comparing the strings for identity.

The scalar contents matching the given key, or NULL if not found.

Lookup a scalar in mapping by simple string returning a ‘0’ terminated scalar
  • fyn (struct fy_node*) – The mapping node
  • key (const char*) – The string to use as key
  • keylen (size_t) – The length of the key (or -1 if ‘0’ terminated)

This method will return the NUL terminated scalar contents that contains the same key from the YAML node created from the key argument. The comparison of the node is using by comparing the strings for identity.

The NUL terminated scalar contents matching the given key, or NULL if not found.

Lookup a node pair matching the provided key
  • fyn (struct fy_node*) – The mapping node
  • fyn_key (struct fy_node*) – The node to use as key

This method will return the node pair that matches the provided fyn_key

The node pair matching the given key, or NULL if not found.

Lookup a node pair’s value matching the provided key
  • fyn (struct fy_node*) – The mapping node
  • fyn_key (struct fy_node*) – The node to use as key

This method will return the node pair that matches the provided fyn_key The key may be collection and a content match check is performed recursively in order to find the right key.

The node value matching the given key, or NULL if not found.

Lookup a node pair’s key matching the provided key
  • fyn (struct fy_node*) – The mapping node
  • fyn_key (struct fy_node*) – The node to use as key

This method will return the node pair that matches the provided fyn_key The key may be collection and a content match check is performed recursively in order to find the right key.

The node key matching the given key, or NULL if not found.

Return the node pair index in the mapping
  • fyn (struct fy_node*) – The mapping node
  • fynp (const struct fy_node_pair*) – The node pair

This method will return the node pair index in the mapping of the given node pair argument.

The index of the node pair in the mapping or -1 in case of an error.

Return the key of a node pair
fynp (struct fy_node_pair*) – The node pair

This method will return the node pair’s key. Note that this may be NULL, which is returned also in case the node pair argument is NULL, so you should protect against such a case.

The node pair key

Return the value of a node pair
fynp (struct fy_node_pair*) – The node pair

This method will return the node pair’s value. Note that this may be NULL, which is returned also in case the node pair argument is NULL, so you should protect against such a case.

The node pair value

Sets the key of a node pair
  • fynp (struct fy_node_pair*) – The node pair
  • fyn (struct fy_node*) – The key node

This method will set the key part of the node pair. It will ovewrite any previous key.

Note that no checks for duplicate keys are going to be performed.

0 on success, -1 on error

Sets the value of a node pair
  • fynp (struct fy_node_pair*) – The node pair
  • fyn (struct fy_node*) – The value node

This method will set the value part of the node pair. It will ovewrite any previous value.

0 on success, -1 on error

Append a node item to a mapping
  • fyn_map (struct fy_node*) – The mapping node
  • fyn_key (struct fy_node*) – The node pair’s key
  • fyn_value (struct fy_node*) – The node pair’s value

Append a node pair to a mapping.

0 on success, -1 on error

Prepend a node item to a mapping
  • fyn_map (struct fy_node*) – The mapping node
  • fyn_key (struct fy_node*) – The node pair’s key
  • fyn_value (struct fy_node*) – The node pair’s value

Prepend a node pair to a mapping.

0 on success, -1 on error

Remove a node pair from a mapping
  • fyn_map (struct fy_node*) – The mapping node
  • fynp (struct fy_node_pair*) – The node pair to remove

Remove node pair from a mapping.

0 on success, -1 on failure.

Sort a single mapping’s keys
  • fyn_map (struct fy_node*) – The mapping node to sort
  • key_cmp (fy_node_mapping_sort_fn) – The comparison method
  • arg (void*) – An opaque user pointer for the comparison method

Sort the keys of a single mapping node using the given comparison method (if NULL use the default one). Unlike fy_node_sort(), this does not recurse into child nodes.

0 on success, -1 on error

Remove a node pair from a mapping returning the value
  • fyn_map (struct fy_node*) – The mapping node
  • fyn_key (struct fy_node*) – The node pair’s key

Remove node pair from a mapping using the supplied key.

The value part of removed node pair, or NULL in case of an error.

Recursively sort node
  • fyn (struct fy_node*) – The node to sort
  • key_cmp (fy_node_mapping_sort_fn) – The comparison method
  • arg (void*) – An opaque user pointer for the comparison method

Recursively sort all mappings of the given node, using the given comparison method (if NULL use the default one).

0 on success, -1 on error

Retrieve data via vscanf
  • fyn (struct fy_node*) – The node to use as a pathspec root
  • fmt (const char*) – The scanf based format string
  • ap (va_list) – The va_list containing the arguments

This method easily retrieves data using a familiar vscanf interface. The format string is a regular scanf format string with the following format.

“pathspec opt pathspec opt…”

Each pathspec is separated with space from the scanf option

For example

fyn = { foo: 3 } -> fy_node_scanf(fyn, “/foo d“, struct var) -> var = 3

The number of scanned arguments, or -1 on error.

Retrieve data via scanf
  • fyn (struct fy_node*) – The node to use as a pathspec root
  • fmt (const char*) – The scanf based format string
  • ellipsis (ellipsis) – The arguments

This method easily retrieves data using a familiar vscanf interface. The format string is a regular scanf format string with the following format.

“pathspec opt pathspec opt…”

Each pathspec is separated with space from the scanf option

For example

fyn = { foo: 3 } -> fy_node_scanf(fyn, “/foo d“, struct var) -> var = 3

The number of scanned arguments, or -1 on error.

Retrieve data via vscanf relative to document root
  • fyd (struct fy_document*) – The document
  • fmt (const char*) – The scanf based format string
  • ap (va_list) – The va_list containing the arguments

This method easily retrieves data using a familiar vscanf interface. The format string is a regular scanf format string with the following format.

“pathspec opt pathspec opt…”

Each pathspec is separated with space from the scanf option

For example

fyd = { foo: 3 } -> fy_document_scanf(fyd, “/foo d“, struct var) -> var = 3

The number of scanned arguments, or -1 on error.

Retrieve data via scanf relative to document root
  • fyd (struct fy_document*) – The document
  • fmt (const char*) – The scanf based format string
  • ellipsis (ellipsis) – The arguments

This method easily retrieves data using a familiar vscanf interface. The format string is a regular scanf format string with the following format.

“pathspec opt pathspec opt…”

Each pathspec is separated with space from the scanf option

For example

fyn = { foo: 3 } -> fy_node_scanf(fyd, “/foo d“, struct var) -> var = 3

The number of scanned arguments, or -1 on error.

Iterate over a document’s tag directives
  • fyd (struct fy_document*) – The document
  • prevp (void**) – The previous state of the iterator

This method iterates over all the documents tag directives. The start of the iteration is signalled by a NULL in *prevp.

The next tag directive token in the document or NULL at the end of them.

Retreive a document’s tag directive
  • fyd (struct fy_document*) – The document
  • handle (const char*) – The handle to look for

Retreives the matching tag directive token of the document matching the handle.

The tag directive token with the given handle or NULL if not found

Get a tag directive handle
  • fyt (struct fy_token*) – The tag directive token
  • lenp (size_t*) – Pointer to a variable that will hold the returned length

Retreives the tag directives token handle value. Only valid on tag directive tokens.

A pointer to the tag directive’s handle, while lenp will be assigned the length of said handle. A NULL will be returned in case of an error.

Get a tag directive prefix
  • fyt (struct fy_token*) – The tag directive token
  • lenp (size_t*) – Pointer to a variable that will hold the returned length

Retreives the tag directives token prefix value. Only valid on tag directive tokens.

A pointer to the tag directive’s prefix, while lenp will be assigned the length of said prefix. A NULL will be returned in case of an error.

Add a tag directive to a document
  • fyd (struct fy_document*) – The document
  • handle (const char*) – The handle of the tag directive
  • prefix (const char*) – The prefix of the tag directive

Add tag directive to the document.

0 on success, -1 on error

Remove a tag directive
  • fyd (struct fy_document*) – The document
  • handle (const char*) – The handle of the tag directive to remove.

Remove a tag directive from a document. Note that removal is prohibited if any node is still using this tag directive.

0 on success, -1 on error

Lookup an anchor
  • fyd (struct fy_document*) – The document
  • anchor (const char*) – The anchor to look for
  • len (size_t) – The length of the anchor (or -1 if ‘0’ terminated)

Lookup for an anchor having the name provided

The anchor if found, NULL otherwise

Lookup an anchor by token text
  • fyd (struct fy_document*) – The document
  • anchor (struct fy_token*) – The token contains the anchor text to look for

Lookup for an anchor having the name provided from the text of the token

The anchor if found, NULL otherwise

Lookup an anchor by node
  • fyd (struct fy_document*) – The document
  • fyn (struct fy_node*) – The node

Lookup for an anchor located in the given node

The anchor if found, NULL otherwise

Get the text of an anchor
  • fya (struct fy_anchor*) – The anchor
  • lenp (size_t*) – Pointer to a variable that will hold the returned length

This method will return a pointer to the text of an anchor along with the length of it. Note that this text is not NULL terminated.

A pointer to the text of the anchor, while lenp will be assigned the length of said anchor. A NULL will be returned in case of an error.

Get the node of an anchor
fya (struct fy_anchor*) – The anchor

This method returns the node associated with the anchor.

The node of the anchor, or NULL in case of an error.

Iterate over a document’s anchors
  • fyd (struct fy_document*) – The document
  • prevp (void**) – The previous state of the iterator

This method iterates over all the documents anchors. The start of the iteration is signalled by a NULL in *prevp.

The next anchor in the document or NULL at the end of them.

Place an anchor
  • fyd (struct fy_document*) – The document
  • fyn (struct fy_node*) – The node to set the anchor to
  • text (const char*) – Pointer to the anchor text
  • len (size_t) – Size of the anchor text, or (size_t)-1 for ‘0’ terminated.

Places an anchor to the node with the give text name.

Note that the data are not copied, merely a reference is taken, so it must be available while the node is in use.

Also not that this method is deprecated; use fy_node_set_anchor() instead.

0 on success, -1 on error.

Place an anchor to the node
  • fyn (struct fy_node*) – The node to set the anchor to
  • text (const char*) – Pointer to the anchor text
  • len (size_t) – Size of the anchor text, or (size_t)-1 for ‘0’ terminated.

Places an anchor to the node with the give text name.

Note that the data are not copied, merely a reference is taken, so it must be available while the node is in use.

This is similar to fy_document_set_anchor() with the document set to the document of the fyn node.

0 on success, -1 on error.

Place an anchor to the node copying the text
  • fyn (struct fy_node*) – The node to set the anchor to
  • text (const char*) – Pointer to the anchor text
  • len (size_t) – Size of the anchor text, or (size_t)-1 for ‘0’ terminated.

Places an anchor to the node with the give text name, which will be copied, so it’s safe to dispose the text after the call.

0 on success, -1 on error.

Place an anchor to the node using a vprintf interface.
  • fyn (struct fy_node*) – The node to set the anchor to
  • fmt (const char*) – Pointer to the anchor format string
  • ap (va_list) – The argument list.

Places an anchor to the node with the give text name as created via vprintf’ing the arguments.

0 on success, -1 on error.

Place an anchor to the node using a printf interface.
  • fyn (struct fy_node*) – The node to set the anchor to
  • fmt (const char*) – Pointer to the anchor format string
  • ellipsis (ellipsis) – The extra arguments.

Places an anchor to the node with the give text name as created via printf’ing the arguments.

0 on success, -1 on error.

Remove an anchor
fyn (struct fy_node*) – The node to remove anchors from

Remove an anchor for the given node (if it exists)

0 on success, -1 on error.

Get the anchor of a node
fyn (struct fy_node*) – The node

Retrieve the anchor of the given node (if it exists)

The anchor if there’s one at the node, or NULL otherwise

Get the nearest anchor of the node
fyn (struct fy_node*) – The node

Retrieve the anchor of the nearest parent of the given node or the given node if it has one.

The nearest anchor if there’s one, or NULL otherwise

Get the nearest node which is a child of the base
  • fyn_base (struct fy_node*) – The base node
  • fyn (struct fy_node*) – The node to start from

Retrieve the nearest node which is a child of fyn_base starting at fyn and working upwards.

The nearest child of the base if there’s one, or NULL otherwise

Create an alias node
  • fyd (struct fy_document*) – The document
  • alias (const char*) – The alias text
  • len (size_t) – The length of the alias (or -1 if ‘0’ terminated)

Create an alias on the given document

Note that the data are not copied, merely a reference is taken, so it must be available while the node is in use.

The created alias node, or NULL in case of an error

Create an alias node copying the data
  • fyd (struct fy_document*) – The document
  • alias (const char*) – The alias text
  • len (size_t) – The length of the alias (or -1 if ‘0’ terminated)

Create an alias on the given document

A copy of the data will be made, so it is safe to free the data after the call.

The created alias node, or NULL in case of an error

Get the meta pointer of a node
fyn (struct fy_node*) – The node to get meta data from

Return the meta pointer of a node.

The stored meta data pointer

Set the meta pointer of a node
  • fyn (struct fy_node*) – The node to set meta data
  • meta (void*) – The meta data pointer

Set the meta pointer of a node. If meta is NULL then clear the meta data.

0 on success, -1 on error

Clear the meta data of a node
fyn (struct fy_node*) – The node to clear meta data

Clears the meta data of a node.

Meta data clear method
  • fyn (struct fy_node*) – The node which the meta data is being cleared
  • meta (void*) – The meta data of the node assigned via fy_node_set_meta()
  • user (void*) – The user pointer of fy_document_register_meta()

This is the callback called when meta data are cleared.

Register a meta cleanup hook
  • fyd (struct fy_document*) – The document which the hook is registered to
  • clear_fn (fy_node_meta_clear_fn) – The clear hook method
  • user (void*) – Opaque user provided pointer to the clear method

Register a meta data cleanup hook, to be called when the node is freed via a final call to fy_node_free(). The hook is active for all nodes belonging to the document.

0 on success, -1 if another hook is already registered.

Unregister a meta cleanup hook
fyd (struct fy_document*) – The document to unregister it’s meta cleanup hook.

Unregister the currently active meta cleanup hook. The previous cleanup hook will be called for every node in the document.

Set a marker of a node
  • fyn (struct fy_node*) – The node
  • marker (unsigned int) – The marker to set

Sets the marker of the given node, while returning the previous state of the marker. Note that the markers use the same space as the node follow markers.

The previous value of the marker

Clear a marker of a node
  • fyn (struct fy_node*) – The node
  • marker (unsigned int) – The marker to clear

Clears the marker of the given node, while returning the previous state of the marker. Note that the markers use the same space as the node follow markers.

The previous value of the marker

Checks whether a marker is set
  • fyn (struct fy_node*) – The node
  • marker (unsigned int) – The marker index (must be less that FYNWF_MAX_USER_MARKER)

Check the state of the given marker.

The value of the marker (invalid markers return false)

Report about a node vprintf style
  • fyn (struct fy_node*) – The node
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a report about the given node via the specific error type, and using the reporting configuration of the node’s document.

Report about a node printf style
  • fyn (struct fy_node*) – The node
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments.

Output a report about the given node via the specific error type, and using the reporting configuration of the node’s document.

Report about a node vprintf style, overriding file, line and column info
  • fyn (struct fy_node*) – The node
  • type (enum fy_error_type) – The error type
  • file (const char*) – The file override
  • line (int) – The line override
  • column (int) – The column override
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a report about the given node via the specific error type, and using the reporting configuration of the node’s document. This method will use the overrides provided in order to massage the reporting information. If file is NULL, no file location will be reported. If either line or column is negative no location will be reported.

Report about a node printf style, overriding file, line and column info
  • fyn (struct fy_node*) – The node
  • type (enum fy_error_type) – The error type
  • file (const char*) – The file override
  • line (int) – The line override
  • column (int) – The column override
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments.

Output a report about the given node via the specific error type, and using the reporting configuration of the node’s document. This method will use the overrides provided in order to massage the reporting information. If file is NULL, no file location will be reported. If either line or column is negative no location will be reported.

Report about an event vprintf style
  • fyp (struct fy_parser*) – The parser of which the event was generated from
  • fye (struct fy_event*) – The event
  • fyep (enum fy_event_part) – The event part which the report is about
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a report about the given event via the specific error type, focusing at the given event part.

Report about an event printf style
  • fyp (struct fy_parser*) – The parser of which the event was generated from
  • fye (struct fy_event*) – The event
  • fyep (enum fy_event_part) – The event part which the report is about
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments.

Output a report about the given event via the specific error type, focusing at the given event part.

The diagnostics configuration

struct fy_diag_cfg {
    FILE *fp;
    fy_diag_output_fn output_fn;
    void *user;
    enum fy_error_type level;
    unsigned int module_mask;
    bool colorize : 1;
    bool show_source : 1;
    bool show_position : 1;
    bool show_type : 1;
    bool show_module : 1;
    int source_width;
    int position_width;
    int type_width;
    int module_width;
}

File descriptor of the error output
Callback to use when fp is NULL
User pointer to pass to the output_fn
The minimum debugging level
A bitmask of the enabled modules
true if output should be colorized using ANSI sequences
true if source location should be displayed
true if position should be displayed
true if the type should be displayed
true if the module should be displayed
Width of the source field
Width of the position field
Width of the type field
Width of the module field

This structure contains the configuration of the diagnostic object.

A collected diagnostic error

struct fy_diag_error {
    enum fy_error_type type;
    enum fy_error_module module;
    struct fy_token *fyt;
    const char *msg;
    const char *file;
    int line;
    int column;
}

Error type
The module
The token (may be NULL)
The message to be output alongside
The file which contained the input
The line at the error
The column at the error

This structure contains information about an error being collected by the diagnostic object.

Create a diagnostic object
cfg (const struct fy_diag_cfg*) – The configuration for the diagnostic object (NULL is default)

Creates a diagnostic object using the provided configuration.

A pointer to the diagnostic object or NULL in case of an error.

Destroy a diagnostic object
diag (struct fy_diag*) – The diagnostic object to destroy

Destroy a diagnostic object; note that the actual destruction only occurs when no more references to the object are present. However no output will be generated after this call.

Get a diagnostic object’s configuration
diag (struct fy_diag*) – The diagnostic object

Return the current configuration of a diagnostic object

A const pointer to the diagnostic object configuration, or NULL in case where diag is NULL

Set a diagnostic object’s configuration
  • diag (struct fy_diag*) – The diagnostic object
  • cfg (const struct fy_diag_cfg*) – The diagnostic configuration

Replace the current diagnostic configuration with the given configuration passed as an argument.

Set a diagnostic object’s debug error level
  • diag (struct fy_diag*) – The diagnostic object
  • level (enum fy_error_type) – The debugging level to set

Set a diagnostic object’s colorize option
  • diag (struct fy_diag*) – The diagnostic object
  • colorize (bool) – The colorize option

Increment that reference counter of a diagnostic object
diag (struct fy_diag*) – The diagnostic object to reference

Increment the reference.

Always returns the diag argument

Take away a ref from a diagnostic object
diag (struct fy_diag*) – The diagnostic object to unref

Take away a reference, if it gets to 0, the diagnostic object is freed.

Test whether an error level diagnostic has been produced
diag (struct fy_diag*) – The diagnostic object

Tests whether an error diagnostic has been produced.

true if an error has been produced, false otherwise

Sets the error produced state
  • diag (struct fy_diag*) – The diagnostic object
  • on_error (bool) – The set error state

Sets the error produced state

Reset the error flag of the diagnostic object
diag (struct fy_diag*) – The diagnostic object

Clears the error flag which was set by an output of an error level diagnostic

Collect errors instead of outputting
  • diag (struct fy_diag*) – The diagnostic object
  • collect_errors (bool) – The collect errors mode

Set the collect errors mode. When true instead of outputting to the diagnostic interface, errors are collected for later retrieval.

Get collect errors state
diag (struct fy_diag*) – The diagnostic object

Get the collect errors mode.

true collecting errors, false otherwise

Fill in the configuration structure with defaults
cfg (struct fy_diag_cfg*) – The diagnostic configuration structure

Fills the configuration structure with defaults. The default always associates the file descriptor to stderr.

Fill partial diagnostic config structure from parser config flags
  • cfg (struct fy_diag_cfg*) – The diagnostic configuration structure
  • pflags (enum fy_parse_cfg_flags) – The parser flags

Fills in part of the configuration structure using parser flags. Since the parser flags do not contain debugging flags anymore this method is deprecated.

vprintf raw interface to diagnostics
  • diag (struct fy_diag*) – The diagnostic object to use
  • fmt (const char*) – The vprintf format string
  • ap (va_list) – The arguments

Raw output to the diagnostic object using a standard vprintf interface. Note that this is the lowest level interface, and as such is not recommended for use, since no formatting or coloring will take place.

The number of characters output, or -1 in case of an error Note that 0 shall be returned if the diagnostic object has been destroyed but not yet freed.

printf raw interface to diagnostics
  • diag (struct fy_diag*) – The diagnostic object to use
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The arguments

Raw output to the diagnostic object using a standard printf interface. Note that this is the lowest level interface, and as such is not recommended for use, since no formatting or coloring will take place.

The number of characters output, or -1 in case of an error Note that 0 shall be returned if the diagnostic object has been destroyed but not yet freed.

The diagnostics context

struct fy_diag_ctx {
    enum fy_error_type level;
    enum fy_error_module module;
    const char *source_func;
    const char *source_file;
    int source_line;
    const char *file;
    int line;
    int column;
}

The level of the diagnostic
The module of the diagnostic
The source function
The source file
The source line
The file that caused the error
The line where the diagnostic occured
The column where the diagnostic occured

This structure contains the diagnostic context

context aware diagnostic output like vprintf
  • diag (struct fy_diag*) – The diagnostic object to use
  • fydc (const struct fy_diag_ctx*) – The diagnostic context
  • fmt (const char*) – The vprintf format string
  • ap (va_list) – The arguments

Context aware output to the diagnostic object using a standard vprintf interface.

The number of characters output, or -1 in case of an error Note that 0 shall be returned if the diagnostic object has been destroyed but not yet freed.

context aware diagnostic output like printf
  • diag (struct fy_diag*) – The diagnostic object to use
  • fydc (const struct fy_diag_ctx*) – The diagnostic context
  • fmt (const char*) – The vprintf format string
  • ellipsis (ellipsis) – variable arguments

Context aware output to the diagnostic object using a standard printf interface.

The number of characters output, or -1 in case of an error Note that 0 shall be returned if the diagnostic object has been destroyed but not yet freed.

Report about a token vprintf style using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fyt (struct fy_token*) – The token
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a report about the given token via the specific error type, and using the reporting configuration of the token’s document.

Report about a token printf style using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fye (struct fy_token*) – The token
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments.

Output a report about the given token via the specific error type, and using the reporting configuration of the token’s document.

Report about a token vprintf style, overriding file, line and column info using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fyt (struct fy_token*) – The token
  • type (enum fy_error_type) – The error type
  • file (const char*) – The file override
  • line (int) – The line override
  • column (int) – The column override
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a report about the given token via the specific error type, and using the reporting configuration of the token’s document. This method will use the overrides provided in order to massage the reporting information. If file is NULL, no file location will be reported. If either line or column is negative no location will be reported.

Report about a token printf style, overriding file, line and column info using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fyt (struct fy_token*) – The token
  • type (enum fy_error_type) – The error type
  • file (const char*) – The file override
  • line (int) – The line override
  • column (int) – The column override
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments.

Output a report about the given token via the specific error type, and using the reporting configuration of the token’s document. This method will use the overrides provided in order to massage the reporting information. If file is NULL, no file location will be reported. If either line or column is negative no location will be reported.

Report about a node vprintf style using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fyn (struct fy_node*) – The node
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a report about the given node via the specific error type, and using the reporting configuration of the node’s document.

Report about a node printf style using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fyn (struct fy_node*) – The node
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments.

Output a report about the given node via the specific error type, and using the reporting configuration of the node’s document.

Report about a node vprintf style, overriding file, line and column info using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fyn (struct fy_node*) – The node
  • type (enum fy_error_type) – The error type
  • file (const char*) – The file override
  • line (int) – The line override
  • column (int) – The column override
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a report about the given node via the specific error type, and using the reporting configuration of the node’s document. This method will use the overrides provided in order to massage the reporting information. If file is NULL, no file location will be reported. If either line or column is negative no location will be reported.

Report about a node printf style, overriding file, line and column info using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fyn (struct fy_node*) – The node
  • type (enum fy_error_type) – The error type
  • file (const char*) – The file override
  • line (int) – The line override
  • column (int) – The column override
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments.

Output a report about the given node via the specific error type, and using the reporting configuration of the node’s document. This method will use the overrides provided in order to massage the reporting information. If file is NULL, no file location will be reported. If either line or column is negative no location will be reported.

Report about an event vprintf style using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fye (struct fy_event*) – The event
  • fyep (enum fy_event_part) – The event part
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ap (va_list) – The argument list

Output a report about the given event part via the specific error type.

Report about a event printf style using the given diagnostic object
  • diag (struct fy_diag*) – The diag object
  • fye (struct fy_event*) – The event
  • fyep (enum fy_event_part) – The event part
  • type (enum fy_error_type) – The error type
  • fmt (const char*) – The printf format string
  • ellipsis (ellipsis) – The extra arguments.

Output a report about the given event part via the specific error type.

Iterate over the errors of a diagnostic object
  • diag (struct fy_diag*) – The diagnostic object
  • prevp (void**) – The previous result iterator

This method iterates over all the errors collected on the diagnostic object. The start of the iteration is signalled by a NULL in *prevp.

The next errors or NULL when there are not any more.

Create a parser checkpoint
fyp (struct fy_parser*) – The parser

Create a checkpoint of the parser’s current state. This allows you to save the parser state and potentially roll back to it later using fy_parser_rollback(). The checkpoint must be destroyed via fy_parser_checkpoint_destroy() when no longer needed.

A pointer to the checkpoint, or NULL in case of an error

Destroy a parser checkpoint
fypchk (struct fy_parser_checkpoint*) – The checkpoint to destroy

Destroy a checkpoint created earlier via fy_parser_checkpoint_create().

Roll back the parser to a checkpoint
  • fyp (struct fy_parser*) – The parser
  • fypc (struct fy_parser_checkpoint*) – The checkpoint to roll back to

Roll back the parser state to a previously created checkpoint. This allows you to revert the parser to an earlier state and re-parse from that point. The checkpoint remains valid after rollback and can be used again or destroyed via fy_parser_checkpoint_destroy().

0 on success, -1 on error

Token types

enum fy_token_type {
    FYTT_NONE,
    FYTT_STREAM_START,
    FYTT_STREAM_END,
    FYTT_VERSION_DIRECTIVE,
    FYTT_TAG_DIRECTIVE,
    FYTT_DOCUMENT_START,
    FYTT_DOCUMENT_END,
    FYTT_BLOCK_SEQUENCE_START,
    FYTT_BLOCK_MAPPING_START,
    FYTT_BLOCK_END,
    FYTT_FLOW_SEQUENCE_START,
    FYTT_FLOW_SEQUENCE_END,
    FYTT_FLOW_MAPPING_START,
    FYTT_FLOW_MAPPING_END,
    FYTT_BLOCK_ENTRY,
    FYTT_FLOW_ENTRY,
    FYTT_KEY,
    FYTT_VALUE,
    FYTT_ALIAS,
    FYTT_ANCHOR,
    FYTT_TAG,
    FYTT_SCALAR,
    FYTT_INPUT_MARKER,
    FYTT_PE_SLASH,
    FYTT_PE_ROOT,
    FYTT_PE_THIS,
    FYTT_PE_PARENT,
    FYTT_PE_MAP_KEY,
    FYTT_PE_SEQ_INDEX,
    FYTT_PE_SEQ_SLICE,
    FYTT_PE_SCALAR_FILTER,
    FYTT_PE_COLLECTION_FILTER,
    FYTT_PE_SEQ_FILTER,
    FYTT_PE_MAP_FILTER,
    FYTT_PE_UNIQUE_FILTER,
    FYTT_PE_EVERY_CHILD,
    FYTT_PE_EVERY_CHILD_R,
    FYTT_PE_ALIAS,
    FYTT_PE_SIBLING,
    FYTT_PE_COMMA,
    FYTT_PE_BARBAR,
    FYTT_PE_AMPAMP,
    FYTT_PE_LPAREN,
    FYTT_PE_RPAREN,
    FYTT_PE_EQEQ,
    FYTT_PE_NOTEQ,
    FYTT_PE_LT,
    FYTT_PE_GT,
    FYTT_PE_LTE,
    FYTT_PE_GTE,
    FYTT_SE_PLUS,
    FYTT_SE_MINUS,
    FYTT_SE_MULT,
    FYTT_SE_DIV,
    FYTT_PE_METHOD,
    FYTT_SE_METHOD,
    FYTT_PE_BANG,
    FYTT_PE_AT
};

No token
Stream start token
Stream end token
Version directive token
Tag directive token
Document start token
Document end token
Block sequence start token
Block mapping start token
Block end token
Flow sequence start token
Flow sequence end token
Flow mapping start token
Flow mapping end token
Block entry token
Flow entry token
Key token
Value token
Alias token
Anchor token
Tag token
Scalar token
Input marker token
Path expression slash token
Path expression root token
Path expression this token
Path expression parent token
Path expression map key token
Path expression sequence index token
Path expression sequence slice token
Path expression scalar filter token
Path expression collection filter token
Path expression sequence filter token
Path expression map filter token
Path expression unique filter token
Path expression every child token
Path expression every child recursive token
Path expression alias token
Path expression sibling token
Path expression comma token
Path expression || token
Path expression && token
Path expression ( token
Path expression ) token
Path expression == token
Path expression != token
Path expression < token
Path expression > token
Path expression <= token
Path expression >= token
Scalar expression + token
Scalar expression - token
Scalar expression * token
Scalar expression / token
Path expression method token
Scalar expression method token
Path expression ! token
Path expression @ token

Check token type validity
type (enum fy_token_type) – The token type

Check if argument token type is a valid one.

true if the token type is valid, false otherwise

Check if token type is valid for YAML
type (enum fy_token_type) – The token type

Check if argument token type is a valid YAML one.

true if the token type is a valid YAML one, false otherwise

Check if token type is valid for YAML content
type (enum fy_token_type) – The token type

Check if argument token type is a valid YAML content one.

true if the token type is a valid YAML content one, false otherwise

Check if token type is valid for a YPATH expression
type (enum fy_token_type) – The token type

Check if argument token type is a valid YPATH parse expression token

true if the token type is a valid YPATH one, false otherwise

Check if token type is valid for a YPATH scalar expression
type (enum fy_token_type) – The token type

Check if argument token type is a valid YPATH parse scalar expression token

true if the token type is a valid YPATH scalar one, false otherwise

Return the token’s type
fyt (struct fy_token*) – The token

Return the token’s type; if NULL then FYTT_NONE is returned

The token’s type; FYTT_NONE if not a valid token (or NULL)

Get token’s start marker
fyt (struct fy_token*) – The token to get its start marker

Return the token’s start marker if it exists. Note it is permissable for some token types to have no start marker because they are without content.

The token’s start marker, NULL if not available.

Get token’s end marker
fyt (struct fy_token*) – The token to get its end marker

Return the token’s end marker if it exists. Note it is permissable for some token types to have no end marker because they are without content.

The token’s end marker, NULL if not available.

Get token’s start marker (style)
fyt (struct fy_token*) – The token to get its style start marker

Return the token’s start marker if it exists, including the style indicators. Note it is permissable for some token types to have no start marker because they are without content.

The token’s style start marker, NULL if not available.

Get token’s end marker (style
fyt (struct fy_token*) – The token to get its style end marker

Return the token’s end marker if it exists, including the style indicators. Note it is permissable for some token types to have no end marker because they are without content.

The token’s style end marker, NULL if not available.

Low level access to the scanner
fyp (struct fy_parser*) – The parser to get the next token from.

Return the next scanner token. Note this is a very low level interface, intended for users that want/need to implement their own YAML parser. The returned token is expected to be disposed using fy_scan_token_free()

The next token, or NULL if no more tokens are available.

Free the token returned by fy_scan()
  • fyp (struct fy_parser*) – The parser of which the token was returned by fy_scan()
  • fyt (struct fy_token*) – The token to free

Free the token returned by fy_scan().

Get the prefix contained in the tag directive token as zero terminated string
fyt (struct fy_token*) – The tag directive token out of which the prefix pointer will be returned.

Retrieve the tag directive’s prefix contents as a zero terminated string. It is similar to fy_tag_directive_token_prefix(), with the difference that the returned string is zero terminated and memory may be allocated to hold it associated with the token.

A pointer to the zero terminated text representation of the prefix token. NULL in case of an error.

Get the handle contained in the tag directive token as zero terminated string
fyt (struct fy_token*) – The tag directive token out of which the handle pointer will be returned.

Retrieve the tag directive’s handle contents as a zero terminated string. It is similar to fy_tag_directive_token_handle(), with the difference that the returned string is zero terminated and memory may be allocated to hold it associated with the token.

A pointer to the zero terminated text representation of the handle token. NULL in case of an error.

Get the handle contained in the tag token
  • fyt (struct fy_token*) – The tag token out of which the handle pointer will be returned.
  • lenp (size_t*) – Pointer to a variable that will hold the returned length

Retrieve the tag handle contents. Will fail if token is not a tag token, or if a memory error happens.

A pointer to the text representation of the handle token, while lenp will be assigned the character length of said representation. NULL in case of an error.

Get the suffix contained in the tag token
  • fyt (struct fy_token*) – The tag token out of which the suffix pointer will be returned.
  • lenp (size_t*) – Pointer to a variable that will hold the returned length

Retrieve the tag suffix contents. Will fail if token is not a tag token, or if a memory error happens.

A pointer to the text representation of the suffix token, while lenp will be assigned the character length of said representation. NULL in case of an error.

Get the short tag of the tag token
  • fyt (struct fy_token*) – The tag token out of which the short pointer will be returned.
  • lenp (size_t*) – Pointer to a variable that will hold the returned length

Retrieve the short tag contents. The short tag is the same one that will need to be emitted. Will fail if token is not a tag token, or if a memory error happens.

A pointer to the text representation of the short tag, while lenp will be assigned the character length of said representation. NULL in case of an error.

Get the handle contained in the tag token as zero terminated string
fyt (struct fy_token*) – The tag token out of which the handle pointer will be returned.

Retrieve the tag handle contents as a zero terminated string. It is similar to fy_tag_token_handle(), with the difference that the returned string is zero terminated and memory may be allocated to hold it associated with the token.

A pointer to the zero terminated text representation of the handle token. NULL in case of an error.

Get the short tag of the tag token as zero terminated string.
fyt (struct fy_token*) – The tag token out of which the short pointer will be returned.

Retrieve the short tag contents. The short tag is the same one that will need to be emitted. Will fail if token is not a tag token, or if a memory error happens.

A pointer to the null terminated text representation of the short tag. NULL in case of an error.

Get the suffix contained in the tag token as zero terminated string
fyt (struct fy_token*) – The tag token out of which the suffix pointer will be returned.

Retrieve the tag suffix contents as a zero terminated string. It is similar to fy_tag_token_suffix(), with the difference that the returned string is zero terminated and memory may be allocated to hold it associated with the token.

A pointer to the zero terminated text representation of the suffix token. NULL in case of an error.

Return the version of a version directive token
fyt (struct fy_token*) – The version directive token

Retrieve the version stored in a version directive token.

A pointer to the version stored in the version directive token, or NULL in case of an error, or the token not being a version directive token.

Return the style of a scalar token
fyt (struct fy_token*) – The scalar token

Retrieve the style of a scalar token.

The scalar style of the token, or FYSS_ANY for an error

Get tag of a tag token
fyt (struct fy_token*) – The tag token

Retrieve the tag of a tag token.

A pointer to the tag or NULL in case of an error

Get tag of a tag directive token
fyt (struct fy_token*) – The tag directive token

Retrieve the tag of a tag directive token.

A pointer to the tag or NULL in case of an error

Return the main token of an event
fye (struct fy_event*) – The event to get its main token

Retrieve the main token (i.e. not the tag or the anchor) of an event. It may be NULL in case of an implicit event.

The main token if it exists, NULL otherwise or in case of an error

Return the anchor token of an event
fye (struct fy_event*) – The event to get its anchor token

Retrieve the anchor token if it exists. Only valid for mapping/sequence start and scalar events.

The anchor token if it exists, NULL otherwise or in case of an error

Return the tag token of an event
fye (struct fy_event*) – The event to get its tag token

Retrieve the tag token if it exists. Only valid for mapping/sequence start and scalar events.

The tag token if it exists, NULL otherwise or in case of an error

Get event’s start marker
fye (struct fy_event*) – The event to get its start marker

Return the event’s start marker if it exists. The start marker is the one of the event’s main token.

The event’s start marker, NULL if not available.

Get event’s end marker
fye (struct fy_event*) – The event to get its end marker

Return the event’s end marker if it exists. The end marker is the one of the event’s main token.

The event’s end marker, NULL if not available.

Get event’s start marker (style)
fye (struct fy_event*) – The event to get its style start marker

Return the event’s style start marker if it exists. The start marker is the one of the event’s main token, including the style marks. But if the event contains a tag then the start mark is the start of the tag token.

The event’s start marker, NULL if not available.

Get event’s end marker (style)
fye (struct fy_event*) – The event to get its end marker

Return the event’s style end marker if it exists. The end marker is the one of the event’s main token.

The event’s end marker, NULL if not available.

Get the node style of an event
fye (struct fy_event*) – The event to get it’s node style

Return the node style (FYNS_*) of an event. May return FYNS_ANY if the event is implicit. For collection start events the only possible values is FYNS_ANY, FYNS_FLOW, FYNS_BLOCK. A scalar event may return any.

The event’s end marker, NULL if not available.

Return the version of a document start event
fye (struct fy_event*) – The document start event

Retrieve the version stored in a document start event

A pointer to the version, or NULL in case of an error, or the event not being a document start event.

Return the version of a document state object
fyds (struct fy_document_state*) – The document state object

Retrieve the version stored in a document state object

A pointer to the version, or NULL in case of an error

Get document state’s start mark
fyds (struct fy_document_state*) – The document state object

Return the document state’s start mark (if it exists). Note that purely synthetic documents do not contain one

The document’s start marker, NULL if not available.

Get document state’s end mark
fyds (struct fy_document_state*) – The document state object

Return the document state’s end mark (if it exists). Note that purely synthetic documents do not contain one

The document’s end marker, NULL if not available.

Version explicit?
fyds (struct fy_document_state*) – The document state object

Find out if a document state object’s version was explicitly set in the document. Note that for synthetic documents this method returns false.

true if version was set explicitly, false otherwise

Tags explicit?
fyds (struct fy_document_state*) – The document state object

Find out if a document state object’s tags were explicitly set in the document. Note that for synthetic documents this method returns false.

true if document had tags set explicitly, false otherwise

Started implicitly?
fyds (struct fy_document_state*) – The document state object

Find out if a document state object’s document was started implicitly. Note that for synthetic documents this method returns false.

true if document was started implicitly, false otherwise

Started implicitly?
fyds (struct fy_document_state*) – The document state object

Find out if a document state object’s document was ended implicitly. Note that for synthetic documents this method returns false.

true if document was ended implicitly, false otherwise

Input was JSON?
fyds (struct fy_document_state*) – The document state object

Find out if a document state object’s document was created by a JSON input. Note that for synthetic documents this method returns false.

true if document was created in JSON mode, false otherwise

Iterate over the tag directives of a document state object
  • fyds (struct fy_document_state*) – The document state
  • prevp (void**) – The previous iterator

This method iterates over all the tag directives nodes in the document state object. The start of the iteration is signalled by a NULL in *prevp.

The next tag or NULL at the end of the iteration sequence.

Get all the tag directives in a malloc’ed array
fyds (struct fy_document_state*) – The document state

Return all the tag directives in a dynamically allocated area. Must be free()‘d when not in use.

An array of fy_tag pointer structures, terminated with a NULL pointer NULL on error

Test whether the given tag is a default one
  • fyds (struct fy_document_state*) – The document state
  • tag (const struct fy_tag*) – The tag to check

Test whether a tag is a default (i.e. impliciticly set)

true in case that the tag is a default one, false otherwise

Get the document state of a parser object
fyp (struct fy_parser*) – The parser

Retrieve the document state object of a parser. Note that this is only valid during parsing.

The active document state object of the parser, NULL otherwise

Get the document state of a document
fyd (struct fy_document*) – The document

Retrieve the document state object of a document.

The document state object of the document, NULL otherwise

Set the document state of a document
  • fyd (struct fy_document*) – The document
  • fyds (struct fy_document_state*) – The document state to use, or NULL for default

Set the document state of a document

0 if set operation was successful, -1 otherwise

Create an empty document using the event
  • fyp (struct fy_parser*) – The parser
  • fye (struct fy_event*) – The event

Create an empty document using the FYET_DOCUMENT_START event generated by the parser.

The created empty document, or NULL on error.

Update the document with the event
  • fyd (struct fy_document*) – The document
  • fyp (struct fy_parser*) – The parser
  • fye (struct fy_event*) – The event

Update the document using the FYET_DOCUMENT_END event generated by the parser.

0 on success, -1 on error

Create a node using the event
  • fyd (struct fy_document*) – The document
  • fyp (struct fy_parser*) – The parser
  • fye (struct fy_event*) – The event

Create a new node using the supplied event. Allowed events are FYET_SCALAR, FYET_ALIAS, FYET_MAPPING_START & FYET_SEQUENCE_START

The newly created node, or NULL on error

Update a node using the event
  • fyn (struct fy_node*) – The node
  • fyp (struct fy_parser*) – The parser
  • fye (struct fy_event*) – The event

Update information of node created using fy_node_create_from_event() Allowed events are FYET_MAPPING_END & FYET_SEQUENCE_END

0 on success, -1 on error

Create a new node pair and set it’s key
  • fyd (struct fy_document*) – The document
  • fyn_parent (struct fy_node*) – The mapping
  • fyn (struct fy_node*) – The node pair key

Create a new node pair using the supplied fyn_parent mapping and fyn node as a key. Note that the nodes _must_ have been created by fy_node_create_from_event and they are not interchangeable with other node pair methods.

The node pair will be added to the fyn_parent mapping with a subsequent call to fy_node_pair_update_with_value().

The newly created node pair, or NULL on error

Update a node pair with a value and add it to the parent mapping
  • fynp (struct fy_node_pair*) – The node pair
  • fyn (struct fy_node*) – The node pair value

Update the node pair with the given value and add it to the parent mapping. Note that the fyn node _must_ have been created by fy_node_create_from_event and the node pair created by fy_node_pair_create_with_key(). Do not intermix other node pair manipulation methods.

0 on success, -1 on error

Add an item node to a sequence node
  • fyn_parent (struct fy_node*) – The parent sequence node
  • fyn (struct fy_node*) – The node pair item

Add an item to the end of the sequence node fyn_parent. Note that the fyn_parent and fyn nodes _must_ have been created by fy_node_create_from_event. Do not intermix other sequence node manipulation methods.

0 on success, -1 on error

Get the document state of an emitter object
emit (struct fy_emitter*) – The emitter

Retrieve the document state object of an emitter. Note that this is only valid during emitting.

The active document state object of the emitter, NULL otherwise

Create an emit event.
  • emit (struct fy_emitter*) – The emitter
  • type (enum fy_event_type) – The event type to create
  • ellipsis (ellipsis) – The optional extra arguments

Create an emit event to pass to fy_emit_event() The extra arguments differ according to the event to be created

None

None

true if document start should be marked implicit false if document start should not be marked implicit
Pointer to version to use for the document, or NULL for default
Pointer to a NULL terminated array of tag pointers (like argv) NULL if no extra tags are to be used

true if document end should be marked implicit false if document end should not be marked implicit

Style of the mapping (one of FYNS_ANY, FYNS_BLOCK or FYNS_FLOW)
Anchor to place at the mapping, or NULL for none
Tag to place at the mapping, or NULL for none

None

Style of the sequence (one of FYNS_ANY, FYNS_BLOCK or FYNS_FLOW)
Anchor to place at the sequence, or NULL for none
Tag to place at the sequence, or NULL for none

None

Style of the scalar, any valid FYSS_* value Note that certain styles may not be used according to the contents of the data
Pointer to the scalar contents.
Length of the scalar contents, of FY_NT (-1) for strlen(value)
Anchor to place at the scalar, or NULL for none
Tag to place at the scalar, or NULL for none

Pointer to the alias.

The created event or NULL in case of an error

Create an emit event using varargs.
  • emit (struct fy_emitter*) – The emitter
  • type (enum fy_event_type) – The event type to create
  • ap (va_list) – The variable argument list pointer.

Create an emit event to pass to fy_emit_event() The varargs analogous to fy_emit_event_create().

The created event or NULL in case of an error

Free an event created via fy_emit_event_create()
  • emit (struct fy_emitter*) – The emitter
  • fye (struct fy_event*) – The event to free

Free an event previously created via fy_emit_event_create(). Note that usually you don’t have to call this method since if you pass the event to fy_emit_event() it shall be disposed properly. Only use is error recovery and cleanup.

Create an emit event.
  • fyp (struct fy_parser*) – The parser
  • type (enum fy_event_type) – The event type to create
  • ellipsis (ellipsis) – variable arguments

See fy_emit_event_create()

The created event or NULL in case of an error

Create an emit event using varargs.
  • fyp (struct fy_parser*) – The parser
  • type (enum fy_event_type) – The event type to create
  • ap (va_list) – The variable argument list pointer.

Create an emit event to pass to fy_emit_event() The varargs analogous to fy_parse_event_create().

The created event or NULL in case of an error

This header provides the ypath subsystem — a JSONPath / XPath-like query language for navigating YAML document trees.

A ypath expression such as /servers/0/host is first parsed into a compiled struct fy_path_expr and then executed against a starting node in any struct fy_document to produce a result set of matching nodes. Filter predicates and wildcards are also supported.

Typical workflow:

// 1. Create a path parser
struct fy_path_parser *fypp = fy_path_parser_create(NULL);
// 2. Compile an expression
struct fy_path_expr *expr =
    fy_path_parse_expr_from_string(fypp, "/servers/0/host", -1);
// 3. Create an executor and run the expression
struct fy_path_exec *fypx = fy_path_exec_create(NULL);
fy_path_exec_execute(fypx, expr, fy_document_root(fyd));
// 4. Iterate results
void *iter = NULL;
struct fy_node *fyn;
while ((fyn = fy_path_exec_results_iterate(fypx, &iter)) != NULL)
    process(fyn);
// 5. Cleanup
fy_path_exec_destroy(fypx);
fy_path_expr_free(expr);
fy_path_parser_destroy(fypp);

For one-shot use, fy_path_expr_build_from_string() wraps steps 1 and 2 into a single call.

The executor can be reset and re-used for multiple executions against the same or different documents. The compiled expression is independent of any document and may be executed repeatedly.

Path parse configuration flags

enum fy_path_parse_cfg_flags {
    FYPPCF_QUIET,
    FYPPCF_DISABLE_RECYCLING,
    FYPPCF_DISABLE_ACCELERATORS
};

Quiet, do not output any information messages
Disable recycling optimization
Disable use of access accelerators (saves memory)

These flags control the operation of the path parse

path parser configuration structure.

struct fy_path_parse_cfg {
    enum fy_path_parse_cfg_flags flags;
    void *userdata;
    struct fy_diag *diag;
}

Configuration flags
Opaque user data pointer
Optional diagnostic interface to use

Argument to the fy_path_parser_create() method which performs parsing of a ypath expression

Create a ypath parser.
cfg (const struct fy_path_parse_cfg*) – The configuration for the path parser

Creates a path parser with its configuration cfg The path parser may be destroyed by a corresponding call to fy_path_parser_destroy(). If cfg is NULL a default yaml parser is created.

A pointer to the path parser or NULL in case of an error.

Destroy the given path parser
fypp (struct fy_path_parser*) – The path parser to destroy

Destroy a path parser created earlier via fy_path_parser_create().

Reset a path parser completely
fypp (struct fy_path_parser*) – The path parser to reset

Completely reset a path parser, including after an error that caused a parser error to be emitted.

0 if the reset was successful, -1 otherwise

Parse an expression from a given string
  • fypp (struct fy_path_parser*) – The path parser to use
  • str (const char*) – The ypath source to use.
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)

Create a path expression from a string using the provided path parser.

The created path expression or NULL on error.

Parse an expression from a given string
  • pcfg (const struct fy_path_parse_cfg*) – The path parser configuration to use, or NULL for default
  • str (const char*) – The ypath source to use.
  • len (size_t) – The length of the string (or -1 if ‘0’ terminated)

Create a path expression from a string using the provided path parser configuration.

The created path expression or NULL on error.

Free a path expression
expr (struct fy_path_expr*) – The expression to free (may be NULL)

Free a previously returned expression from any of the path parser methods like fy_path_expr_build_from_string()

Dump the contents of a path expression to the diagnostic object
  • expr (struct fy_path_expr*) – The expression to dump
  • diag (struct fy_diag*) – The diagnostic object to use
  • errlevel (enum fy_error_type) – The error level which the diagnostic will use
  • level (int) – The nest level; should be set to 0
  • banner (const char*) – The banner to display on level 0

Dumps the expression using the provided error level.

Converts the path expression to a YAML document
expr (struct fy_path_expr*) – The expression to convert to a document

Converts the expression to a YAML document which is useful for understanding what the expression evaluates to.

The document of the expression or NULL on error.

Path executor configuration flags

enum fy_path_exec_cfg_flags {
    FYPXCF_QUIET,
    FYPXCF_DISABLE_RECYCLING,
    FYPXCF_DISABLE_ACCELERATORS
};

Quiet, do not output any information messages
Disable recycling optimization
Disable use of access accelerators (saves memory)

These flags control the operation of the path expression executor

path expression executor configuration structure.

struct fy_path_exec_cfg {
    enum fy_path_exec_cfg_flags flags;
    void *userdata;
    struct fy_diag *diag;
}

Configuration flags
Opaque user data pointer
Optional diagnostic interface to use

Argument to the fy_path_exec_create() method which performs execution of a ypath expression

Create a ypath expression executor.
xcfg (const struct fy_path_exec_cfg*) – The configuration for the executor

Creates a ypath expression parser with its configuration cfg The executor may be destroyed by a corresponding call to fy_path_exec_destroy().

A pointer to the executor or NULL in case of an error.

Destroy the given path expression executor
fypx (struct fy_path_exec*) – The path parser to destroy

Destroy ane executor created earlier via fy_path_exec_create().

Reset an executor
fypx (struct fy_path_exec*) – The executor to reset

Completely reset an executor without releasing it.

0 if the reset was successful, -1 otherwise

Execute a path expression starting at the given start node
  • fypx (struct fy_path_exec*) – The executor to use
  • expr (struct fy_path_expr*) – The expression to use
  • fyn_start (struct fy_node*) – The node on which the expression will begin.

Execute the expression starting at fyn_start. If execution is successful the results are available via fy_path_exec_results_iterate()

Note that it is illegal to modify the state of the document that the results reside between this call and the results collection.

0 if the execution was successful, -1 otherwise

Note that the execution may be successful but no results were produced, in which case the iterator will return NULL.

Iterate over the results of execution
  • fypx (struct fy_path_exec*) – The executor
  • prevp (void**) – The previous result iterator

This method iterates over all the results in the executor. The start of the iteration is signalled by a NULL in *prevp.

The next node in the result set or NULL at the end of the results.

This header provides struct fy_document_iterator, which traverses a document tree depth-first without using system stack recursion. Two usage modes are supported:

Node iteration — visit every node in a subtree in document order:

struct fy_document_iterator *fydi = fy_document_iterator_create();
fy_document_iterator_node_start(fydi, fy_document_root(fyd));
struct fy_node *fyn;
while ((fyn = fy_document_iterator_node_next(fydi)) != NULL)
    process(fyn);
fy_document_iterator_destroy(fydi);

Event replay — regenerate the YAML event stream that produced the document, suitable for feeding into a parser, emitter, or composer:

struct fy_document_iterator *fydi =
    fy_document_iterator_create_on_document(fyd);
struct fy_event *fye;
while ((fye = fy_document_iterator_generate_next(fydi)) != NULL) {
    process_event(fye);
    fy_document_iterator_event_free(fydi, fye);
}
fy_document_iterator_destroy(fydi);

The iterator can also be attached to a struct fy_parser via fy_parser_set_document_iterator(), making a parser transparently replay the events of an existing document rather than parsing fresh input.

Events emitted by the iterator are in the same order as those that originally created the document, so round-trip fidelity is preserved.

Document iterator configuration flags

enum fy_document_iterator_cfg_flags {
    FYDICF_WANT_BODY_EVENTS,
    FYDICF_WANT_DOCUMENT_BODY_EVENTS,
    FYDICF_WANT_STREAM_DOCUMENT_BODY_EVENTS
};

Generate body events
Generate document and body events
Generate stream, document and body events

These flags control the operation of the document iterator

document iterator configuration structure.

struct fy_document_iterator_cfg {
    enum fy_document_iterator_cfg_flags flags;
    struct fy_document *fyd;
    struct fy_node *iterate_root;
}

The document iterator flags
The document to iterate on (or NULL if iterate_root is set)
The root of iteration (NULL when fyd is not NULL)

Argument to the fy_document_iterator_create_cfg() method.

Create a document iterator
void – no arguments

Creates a document iterator, that can trawl through a document without using recursion.

The newly created document iterator or NULL on error

Create a document iterator using config
cfg (const struct fy_document_iterator_cfg*) – The document iterator to destroy

Creates a document iterator, that can trawl through a document without using recursion. The iterator will generate all the events that created the given document starting at iterator root.

The newly created document iterator or NULL on error

Create a document iterator on document
fyd (struct fy_document*) – The document to iterate on

Creates a document iterator, starting at the root of the given document.

The newly created document iterator or NULL on error

Create a document iterator on node
fyn (struct fy_node*) – The node to iterate on

Creates a document iterator, starting at the given node

The newly created document iterator or NULL on error

Destroy the given document iterator
fydi (struct fy_document_iterator*) – The document iterator to destroy

Destroy a document iterator created earlier via fy_document_iterator_create().

Free an event that was created by a document iterator
  • fydi (struct fy_document_iterator*) – The document iterator that created the event
  • fye (struct fy_event*) – The event

Free (possibly recycling) an event that was created by a document iterator.

Create a stream start event using the iterator
fydi (struct fy_document_iterator*) – The document iterator to create the event

Creates a stream start event on the document iterator and advances the internal state of it accordingly.

The newly created stream start event, or NULL on error.

Create a stream end event using the iterator
fydi (struct fy_document_iterator*) – The document iterator to create the event

Creates a stream end event on the document iterator and advances the internal state of it accordingly.

The newly created stream end event, or NULL on error.

Create a document start event using the iterator
  • fydi (struct fy_document_iterator*) – The document iterator to create the event
  • fyd (struct fy_document*) – The document containing the document state that is used in the event

Creates a document start event on the document iterator and advances the internal state of it accordingly. The document must not be released until an error, cleanup or a call to fy_document_iterator_document_end().

The newly created document start event, or NULL on error.

Create a document end event using the iterator
fydi (struct fy_document_iterator*) – The document iterator to create the event

Creates a document end event on the document iterator and advances the internal state of it accordingly. The document that was used earlier in the call of fy_document_iterator_document_start() can now be released.

The newly created document end event, or NULL on error.

Create document body events until the end
fydi (struct fy_document_iterator*) – The document iterator to create the event

Creates the next document body, depth first until the end of the document. The events are created depth first and are in same exact sequence that the original events that created the document.

That means that the finite event stream that generated the document is losslesly preserved in such a way that the document tree representation is functionally equivalent.

Repeated calls to this function will generate a stream of SCALAR, ALIAS, SEQUENCE START, SEQUENCE END, MAPPING START and MAPPING END events, returning NULL at the end of the body event stream.

The newly created document body event or NULL at an error, or an end of the event stream. Use fy_document_iterator_get_error() to check if an error occured.

Start a document node iteration run using a starting point
  • fydi (struct fy_document_iterator*) – The document iterator to run with
  • fyn (struct fy_node*) – The iterator root for the iteration

Starts an iteration run starting at the given node.

Return the next node in the iteration sequence
fydi (struct fy_document_iterator*) – The document iterator to use for the iteration

Returns a pointer to the next node iterating using as a start the node given at fy_document_iterator_node_start(). The first node returned will be that, followed by all the remaing nodes in the subtree.

The next node in the iteration sequence or NULL at the end, or if an error occured.

Create events from document iterator
fydi (struct fy_document_iterator*) – The document iterator to create the event

This is a method that will handle the complex state of generating stream, document and body events on the given iterator.

When generation is complete a NULL event will be generated.

The newly created event or NULL at an error, or an end of the event stream. Use fy_document_iterator_get_error() to check if an error occured.

Get the error state of the document iterator
fydi (struct fy_document_iterator*) – The document iterator to use for checking it’s error state.

Returns the error state of the iterator. If it’s in error state, return true and reset the iterator to the state just after creation.

true if it was in an error state, false otherwise.

The parser event generator flags

enum fy_parser_event_generator_flags {
    FYPEGF_GENERATE_DOCUMENT_EVENTS,
    FYPEGF_GENERATE_STREAM_EVENTS,
    FYPEGF_GENERATE_ALL_EVENTS
};

generate document events
generate stream events
generate all events

Associate a parser with a document iterator
  • fyp (struct fy_parser*) – The parser
  • flags (enum fy_parser_event_generator_flags) – The event generation flags
  • fydi (struct fy_document_iterator*) – The document iterator to associate

Associate a parser with a document iterator, that is instead of parsing the events will be generated by the document iterator.

0 on success, -1 on error

This header provides struct fy_document_builder, which accumulates YAML parser events and assembles them into a struct fy_document tree.

The builder supports two operating modes:

Pull mode — the builder drives a parser internally:

struct fy_document_builder *fydb =
    fy_document_builder_create_on_parser(fyp);
struct fy_document *fyd;
while ((fyd = fy_document_builder_load_document(fydb, fyp)) != NULL) {
    process(fyd);
    fy_document_destroy(fyd);
}
fy_document_builder_destroy(fydb);

Push mode — the caller feeds events one at a time and takes ownership when the document is complete:

fy_document_builder_set_in_stream(fydb);
struct fy_event *fye;
while ((fye = get_next_event()) != NULL) {
    fy_document_builder_process_event(fydb, fye);
    if (fy_document_builder_is_document_complete(fydb)) {
        struct fy_document *fyd =
            fy_document_builder_take_document(fydb);
        process(fyd);
        fy_document_destroy(fyd);
    }
}

Push mode is useful when events arrive asynchronously or from a source other than a libfyaml parser, such as a document iterator or a network stream.

fy_parse_load_document_with_builder() provides the simplest interface: a single call that returns the next complete document from a parser.

document builder configuration structure.

struct fy_document_builder_cfg {
    struct fy_parse_cfg parse_cfg;
    void *userdata;
    struct fy_diag *diag;
}

Parser configuration
Opaque user data pointer
Optional diagnostic interface to use

Argument to the fy_document_builder_create() method

Create a document builder
cfg (const struct fy_document_builder_cfg*) – The configuration for the document builder

Creates a document builder with its configuration cfg The document builder may be destroyed by a corresponding call to fy_document_builder_destroy().

A pointer to the document builder or NULL in case of an error.

Create a document builder pulling state from the parser
fyp (struct fy_parser*) – The parser to associate with

Creates a document builder pulling state from the given parser

A pointer to the document builder or NULL in case of an error.

Reset a document builder
fydb (struct fy_document_builder*) – The document builder

Resets a document builder without destroying it

Destroy a document builder
fydb (struct fy_document_builder*) – The document builder

Destroy a document builder

Get the document of a builder
fydb (struct fy_document_builder*) – The document builder

Retrieve the document of a document builder. This document may be incomplete. If you need to take ownership use fy_document_builder_take_document().

The document that the builder built, or NULL in case of an error

Test document builder in stream
fydb (struct fy_document_builder*) – The document builder

Find out if the document builder is in ‘stream’ state, i.e. after stream start but before stream end events are generated.

true if in stream, false otherwise

Test document builder in document
fydb (struct fy_document_builder*) – The document builder

Find out if the document builder is in ‘document’ state, i.e. after document start but before document end events are generated.

true if in document, false otherwise

Test document builder complete
fydb (struct fy_document_builder*) – The document builder

Find out if the document of the builder is complete. If it is complete then a call to fy_document_builder_take_document() will transfer ownership of the document to the caller.

true if document complete, false otherwise

Take ownership the document of a builder
fydb (struct fy_document_builder*) – The document builder

Take ownership of the document of a document builder. The document builder’s document must be complete.

The document that the builder built, or NULL in case of an error

Peek at the document of a builder
fydb (struct fy_document_builder*) – The document builder

Peek at the document of a document builder. Ownership still remains with the builder.

A peek to the document that the builder built, or NULL in case of an error

Set the builders state in ‘stream’
fydb (struct fy_document_builder*) – The document builder

Set the document builders state to in ‘stream’

Set the builders state in ‘document’
  • fydb (struct fy_document_builder*) – The document builder
  • fyds (struct fy_document_state*) – The document state
  • single (bool) – Single document mode

Set the document builders state to in ‘document’

0 on success, -1 on error

Create a document from parser events
  • fydb (struct fy_document_builder*) – The document builder
  • fyp (struct fy_parser*) – The parser

Load a document by pumping the parser for events and then processing them with the builder.

The document that results from the parser, or NULL in case of an error (or EOF)

Parse a document via built-in builder
fyp (struct fy_parser*) – The parser

Load a document by pumping the parser for events and then processing them with the in-parser builder.

The document that results from the parser, or NULL in case of an error (or EOF)

Process an event with a builder
  • fydb (struct fy_document_builder*) – The document builder
  • fye (struct fy_event*) – The event

Pump an event to a document builder for processing.

0 on success, -1 on error

This header provides two complementary interfaces for processing YAML event streams with awareness of the current position in the document hierarchy, without committing to building a full in-memory tree.

Simple callback interfacefy_parse_compose() calls a user function for each event, passing both the event and the current struct fy_path so the callback can make intelligent decisions without maintaining its own path stack:

enum fy_composer_return my_cb(struct fy_parser *fyp,
                              struct fy_event *fye,
                              struct fy_path *path,
                              void *userdata)
{
    if (fy_path_depth(path) > 3)
        return FYCR_OK_START_SKIP;
    process(fye);
    return FYCR_OK_CONTINUE;
}
fy_parse_compose(fyp, my_cb, ctx);

Object-based interfacestruct fy_composer wraps the same mechanism in a reusable object with ops callbacks, optional document builder integration, and helpers for navigating the path hierarchy.

Path inspection helpers — functions such as fy_path_in_mapping(), fy_path_depth(), fy_path_component_is_sequence(), and the user-data attach/retrieve pairs let callbacks annotate and query the live path stack without any external bookkeeping.

Callbacks control event processing by returning one of:

  • FYCR_OK_CONTINUE — consume the event and continue
  • FYCR_OK_STOP — consume the event and stop
  • FYCR_OK_START_SKIP — start skipping the current subtree
  • FYCR_OK_STOP_SKIP — stop an active skip and resume processing
  • FYCR_ERROR — abort with an error

The returns of the composer callback

enum fy_composer_return {
    FYCR_OK_CONTINUE,
    FYCR_OK_STOP,
    FYCR_OK_START_SKIP,
    FYCR_OK_STOP_SKIP,
    FYCR_ERROR
};

continue processing, event processed
stop processing, event processed
start skip object(s), event processed
stop skipping of objects, event processed
error, stop processing

Check if the return code is OK
ret (enum fy_composer_return) – the composer return to check

Convenience method for checking if it’s OK to continue

true if non error or skip condition

composer callback method
  • fyp (struct fy_parser*) – The parser
  • fye (struct fy_event*) – The event
  • path (struct fy_path*) – The path that the parser is processing
  • userdata (void*) – The user data of the fy_parse_compose() method

This method is called by the fy_parse_compose() method when an event must be processed.

fy_composer_return code telling the parser what to do

Parse using a compose callback
  • fyp (struct fy_parser*) – The parser
  • cb (fy_parse_composer_cb) – The callback that will be called
  • userdata (void*) – user pointer to pass to the callback

Alternative parsing method using a composer callback.

The parser will construct a path argument that is used by the callback to make intelligent decisions about creating a document and/or DOM.

0 if no error occured -1 on error

Check if the component is a mapping
fypc (struct fy_path_component*) – The path component to check

true if the path component is a mapping, false otherwise

Check if the component is a sequence
fypc (struct fy_path_component*) – The path component to check

true if the path component is a sequence, false otherwise

Get the index of sequence path component
fypc (struct fy_path_component*) – The sequence path component to return it’s index value

>= 0 the sequence index -1 if the component is either not in the proper mode, or not a sequence

Get the scalar key of a mapping
fypc (struct fy_path_component*) – The mapping path component to return it’s scalar key

a non NULL scalar or alias token if the mapping contains a scalar key NULL in case of an error, or if the component has a complex key

Get the scalar key’s tag of a mapping
fypc (struct fy_path_component*) – The mapping path component to return it’s scalar key’s tag

a non NULL tag token if the mapping contains a scalar key with a tag or NULL in case of an error, or if the component has a complex key

Get the complex key of a mapping
fypc (struct fy_path_component*) – The mapping path component to return it’s complex key

a non NULL document if the mapping contains a complex key NULL in case of an error, or if the component has a simple key

Get the textual representation of a path component
fypc (struct fy_path_component*) – The path component to get it’s textual representation

Given a path component, return a malloc’ed string which contains the textual representation of it.

Note that this method will only return fully completed components and not ones that are in the building process.

The textual representation of the path component, NULL on error, or if the component has not been completely built during the composition of a complex key. The string must be free’ed using free.

Get the depth of a path
fypp (struct fy_path*) – The path to query

The depth of the path, or -1 on error

Get the parent of a path
fypp (struct fy_path*) – The path to return it’s parent

Paths may contain parents when traversing complex keys. This method returns the immediate parent.

The path parent or NULL on error, if it doesn’t exist

Get the textual representation of a path
fypp (struct fy_path*) – The path to get it’s textual representation

Given a path, return a malloc’ed string which contains the textual representation of it.

Note that during processing, complex key paths are simply indicative and not to be used for addressing.

The textual representation of the path, NULL on error. The string must be free’ed using free.

Check if the path is in the root of the document
fypp (struct fy_path*) – The path

true if the path is located within the root of the document

Check if the path is in a mapping
fypp (struct fy_path*) – The path

true if the path is located within a mapping

Check if the path is in a sequence
fypp (struct fy_path*) – The path

true if the path is located within a sequence

Check if the path is in a mapping key state
fypp (struct fy_path*) – The path

true if the path is located within a mapping key state

Check if the path is in a mapping value state
fypp (struct fy_path*) – The path

true if the path is located within a mapping value state

Check if the path is in a collection root
fypp (struct fy_path*) – The path

A collection root state is when the path points to a sequence or mapping but the state does not allow setting keys, values or adding items.

This occurs on MAPPING/SEQUENCE START/END events.

true if the path is located within a collectin root state

Return the userdata associated with the path root
fypp (struct fy_path*) – The path

The user data associated with the root of the path, or NULL if no path

Set the user data associated with the root
  • fypp (struct fy_path*) – The path
  • data (void*) – The data to set as root data

Note, no error condition if not a path

Return the userdata associated with the mapping
fypc (struct fy_path_component*) – The path component

The user data associated with the mapping, or NULL if not a mapping or the user data are NULL

Return the userdata associated with the mapping key
fypc (struct fy_path_component*) – The path component

The user data associated with the mapping key, or NULL if not a mapping or the user data are NULL

Return the userdata associated with the sequence
fypc (struct fy_path_component*) – The path component

The user data associated with the sequence, or NULL if not a sequence or the user data are NULL

Set the user data associated with a mapping
  • fypc (struct fy_path_component*) – The path component
  • data (void*) – The data to set as mapping data

Note, no error condition if not a mapping

Set the user data associated with a mapping key
  • fypc (struct fy_path_component*) – The path component
  • data (void*) – The data to set as mapping key data

Note, no error condition if not in a mapping key state

Set the user data associated with a sequence
  • fypc (struct fy_path_component*) – The path component
  • data (void*) – The data to set as sequence data

Note, no error condition if not a sequence

Return the userdata of the parent collection
path (struct fy_path*) – The path

The user data associated with the parent collection of the path, or NULL if no path

Set the user data associated with the parent collection
  • path (struct fy_path*) – The path
  • data (void*) – The data to set as parent collection data

Note, no error condition if not a path

Return the userdata of the last collection
path (struct fy_path*) – The path

The user data associated with the last collection of the path, or NULL if no path

Set the user data associated with the last collection
  • path (struct fy_path*) – The path
  • data (void*) – The data to set as last collection data

Note, no error condition if not a path

Get the very last component of a path
fypp (struct fy_path*) – The path

Returns the last component of a path.

The last path component (which may be a collection root component), or NULL if it does not exist

Get the last non collection root component of a path
fypp (struct fy_path*) – The path

Returns the last non collection root component of a path. This may not be the last component that is returned by fy_path_last_component().

The difference is present on MAPPING/SEQUENCE START/END events where the last component is present but not usuable as a object parent.

The last non collection root component, or NULL if it does not exist

Composer operation callbacks

struct fy_composer_ops {
    enum fy_composer_return (*process_event)(struct fy_composer *fyc, struct fy_path *path, struct fy_event *fye);
    struct fy_document_builder *(*create_document_builder)(struct fy_composer *fyc);
}

Callback for processing a single YAML event with path context
Callback for creating a document builder instance

Callbacks used by the composer to process events and create document builders.

Composer configuration structure

struct fy_composer_cfg {
    const struct fy_composer_ops *ops;
    void *userdata;
    struct fy_diag *diag;
}

Pointer to composer operation callbacks
Opaque user data pointer passed to callbacks
Optional diagnostic interface to use, NULL for default

Configuration structure for creating a composer instance.

Create a composer
cfg (struct fy_composer_cfg*) – The configuration for the composer

Creates a composer with the given configuration. The composer processes YAML events using callback methods and maintains path information for intelligent document composition. The composer may be destroyed by a corresponding call to fy_composer_destroy().

A pointer to the composer or NULL in case of an error.

Destroy the given composer
fyc (struct fy_composer*) – The composer to destroy

Destroy a composer created earlier via fy_composer_create().

Process a YAML event through the composer
  • fyc (struct fy_composer*) – The composer
  • fye (struct fy_event*) – The event to process

Process a YAML event by calling the configured process_event callback with path context. The composer maintains the current path and provides it to the callback for intelligent processing decisions.

A fy_composer_return code indicating how to proceed (continue, stop, skip, or error)

Get the configuration of a composer
fyc (struct fy_composer*) – The composer

The configuration of the composer

Get the userdata from composer configuration
fyc (struct fy_composer*) – The composer

Retrieve the opaque userdata pointer from the composer’s configuration.

The userdata pointer from the configuration

Get the diagnostic object of a composer
fyc (struct fy_composer*) – The composer to get the diagnostic object

Return a pointer to the diagnostic object of a composer object. Note that the returned diag object has a reference taken so you should fy_diag_unref() it when you’re done with it.

A pointer to a ref’ed diagnostic object or NULL in case of an error.

Get the current path of the composer
fyc (struct fy_composer*) – The composer

Retrieve the current path being processed by the composer. The path represents the location in the YAML document structure where the composer is currently positioned.

The current path, or NULL if no path is active

Get the root path of the composer
fyc (struct fy_composer*) – The composer

Retrieve the root path of the composer’s path hierarchy.

The root path, or NULL if no root exists

Get the next path in the composer’s path list
  • fyc (struct fy_composer*) – The composer
  • fypp (struct fy_path*) – The previous path, or NULL to get the first path

Iterate through the composer’s path list. Pass NULL to get the first path, or pass the previous path to get the next one.

The next path in the list, or NULL if no more paths exist

2019-2026, Pantelis Antoniou

March 15, 2026