Public API

struct fy_version

struct fy_version

The YAML version

Definition

struct fy_version {
    int major;
    int minor;
}

Members

major
Major version number
minor
Major version number

Description

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

struct fy_tag

struct fy_tag

The YAML tag structure.

Definition

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

Members

handle
Handle of the tag (i.e. “!!” )
prefix
The prefix of the tag (i.e. “tag:yaml.org,2002:”

Description

The parser fills it according to the %TAG directives encountered during parsing.

struct fy_mark

struct fy_mark

marker holding information about a location in a struct fy_input

Definition

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

Members

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

enum fy_error_type

enum fy_error_type

The supported diagnostic/error types

Definition

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

Constants

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

enum fy_error_module

enum fy_error_module

Module which generated the diagnostic/error

Definition

enum fy_error_module {
    FYEM_UNKNOWN,
    FYEM_ATOM,
    FYEM_SCAN,
    FYEM_PARSE,
    FYEM_DOC,
    FYEM_BUILD,
    FYEM_INTERNAL,
    FYEM_SYSTEM,
    FYEM_MAX
};

Constants

FYEM_UNKNOWN
Unknown, default if not specific
FYEM_ATOM
Atom module, used by atom chunking
FYEM_SCAN
Scanner module
FYEM_PARSE
Parser module
FYEM_DOC
Document module
FYEM_BUILD
Build document module (after tree is constructed)
FYEM_INTERNAL
Internal error/diagnostic module
FYEM_SYSTEM
System error/diagnostic module
FYEM_MAX
Non inclusive maximum fy_error_module value

enum fy_parse_cfg_flags

enum fy_parse_cfg_flags

Parse configuration flags

Definition

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_JSON_AUTO,
    FYPCF_JSON_NONE,
    FYPCF_JSON_FORCE
};

Constants

FYPCF_QUIET
Quiet, do not output any information messages
FYPCF_COLLECT_DIAG
Collect diagnostic/error messages
FYPCF_RESOLVE_DOCUMENT
When producing documents, automatically resolve them
FYPCF_DISABLE_MMAP_OPT
Disable mmap optimization
FYPCF_DISABLE_RECYCLING
Disable recycling optimization
FYPCF_PARSE_COMMENTS
Enable parsing of comments (experimental)
FYPCF_DISABLE_DEPTH_LIMIT
Disable depth limit check, use with enlarged stack
FYPCF_DISABLE_ACCELERATORS
Disable use of access accelerators (saves memory)
FYPCF_DISABLE_BUFFERING
Disable use of buffering where possible
FYPCF_JSON_AUTO
Automatically enable JSON mode (when extension is .json)
FYPCF_JSON_NONE
Never enable JSON input mode
FYPCF_JSON_FORCE
Force JSON mode always

Description

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

struct fy_parse_cfg

struct fy_parse_cfg

parser configuration structure.

Definition

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

Members

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

Description

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

enum fy_event_type

enum fy_event_type

Event types

Definition

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
};

Constants

FYET_NONE
No event
FYET_STREAM_START
Stream start event
FYET_STREAM_END
Stream end event
FYET_DOCUMENT_START
Document start event
FYET_DOCUMENT_END
Document end event
FYET_MAPPING_START
YAML mapping start event
FYET_MAPPING_END
YAML mapping end event
FYET_SEQUENCE_START
YAML sequence start event
FYET_SEQUENCE_END
YAML sequence end event
FYET_SCALAR
YAML scalar event
FYET_ALIAS
YAML alias event

enum fy_scalar_style

enum fy_scalar_style

Scalar styles supported by the parser/emitter

Definition

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

Constants

FYSS_ANY
Any scalar style, not generated by the parser. Lets the emitter to choose
FYSS_PLAIN
Plain scalar style
FYSS_SINGLE_QUOTED
Single quoted style
FYSS_DOUBLE_QUOTED
Double quoted style
FYSS_LITERAL
YAML literal block style
FYSS_FOLDED
YAML folded block style
FYSS_MAX
marks end of scalar styles

struct fy_event

struct fy_event

Event generated by the parser

Definition

struct fy_event {
    enum fy_event_type type;
    union {
        struct {
            struct fy_token *stream_start;
        } stream_start;
        struct {
            struct fy_token *stream_end;
        } stream_end;
        struct {
            struct fy_token *document_start;
            struct fy_document_state *document_state;
            bool implicit;
        } document_start;
        struct {
            struct fy_token *document_end;
            bool implicit;
        } document_end;
        struct {
            struct fy_token *anchor;
        } alias;
        struct {
            struct fy_token *anchor;
            struct fy_token *tag;
            struct fy_token *value;
            bool tag_implicit;
        } scalar;
        struct {
            struct fy_token *anchor;
            struct fy_token *tag;
            struct fy_token *sequence_start;
        } sequence_start;
        struct {
            struct fy_token *sequence_end;
        } sequence_end;
        struct {
            struct fy_token *anchor;
            struct fy_token *tag;
            struct fy_token *mapping_start;
        } mapping_start;
        struct {
            struct fy_token *mapping_end;
        } mapping_end;
    } ;
}

Members

type
Type of the event, see enum fy_event_type
{unnamed_union}
anonymous
stream_start
Stream start information, it is valid when fy_event->type is enum FYET_STREAM_START
stream_start.stream_start
The token that started the stream
stream_end
Stream end information, it is valid when fy_event->type is enum FYET_STREAM_END
stream_end.stream_end
The token that ended the stream
document_start
Document start information, it is valid when fy_event->type is enum FYET_DOCUMENT_START
document_start.document_start
The token that started the document, or NULL if the document was implicitly started
document_start.document_state
The state of the document (i.e. information about the YAML version and configured tags)
document_start.implicit
True if the document started implicitly
document_end
Document end information, it is valid when fy_event->type is enum FYET_DOCUMENT_END
document_end.document_end
The token that ended the document, or NULL if the document was implicitly ended
document_end.implicit
True if the document ended implicitly
alias
Alias information, it is valid when fy_event->type is enum FYET_ALIAS
alias.anchor
The anchor token definining this alias.
scalar
Scalar information, it is valid when fy_event->type is enum FYET_SCALAR
scalar.anchor
anchor token or NULL
scalar.tag
tag token or NULL
scalar.value
scalar value token (cannot be NULL)
scalar.tag_implicit
true if the tag was implicit or explicit
sequence_start
Sequence start information, it is valid when fy_event->type is enum FYET_SEQUENCE_START
sequence_start.anchor
anchor token or NULL
sequence_start.tag
tag token or NULL
sequence_start.sequence_start
sequence start value token or NULL if the sequence was started implicitly
sequence_end
Sequence end information, it is valid when fy_event->type is enum FYET_SEQUENCE_END
sequence_end.sequence_end
The token that ended the sequence, or NULL if the sequence was implicitly ended
mapping_start
Mapping start information, it is valid when fy_event->type is enum FYET_MAPPING_START
mapping_start.anchor
anchor token or NULL
mapping_start.tag
tag token or NULL
mapping_start.mapping_start
mapping start value token or NULL if the mapping was started implicitly
mapping_end
Mapping end information, it is valid when fy_event->type is enum FYET_MAPPING_END
mapping_end.mapping_end
The token that ended the mapping, or NULL if the mapping was implicitly ended

Description

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

fy_library_version

const char *fy_library_version(void)

Return the library version string

Parameters:
  • void – no arguments

Return

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

fy_string_to_error_type

enum fy_error_type fy_string_to_error_type(const char *str)

Return the error type from a string

Parameters:
  • str (const char *) – The string to convert to an error type

Return

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

fy_error_type_to_string

const char *fy_error_type_to_string(enum fy_error_type type)

Convert an error type to string

Parameters:
  • type (enum fy_error_type) – The error type to convert

Return

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

fy_string_to_error_module

enum fy_error_module fy_string_to_error_module(const char *str)

Return the error module from a string

Parameters:
  • str (const char *) – The string to convert to an error module

Return

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

fy_error_module_to_string

const char *fy_error_module_to_string(enum fy_error_module module)

Convert an error module to string

Parameters:
  • module (enum fy_error_module) – The error module to convert

Return

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

fy_document_event_is_implicit

bool fy_document_event_is_implicit(const struct fy_event *fye)

Check whether the given document event is an implicit one

Parameters:
  • 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.

Return

true if the event is an implicit one.

fy_parser_create

struct fy_parser *fy_parser_create(const struct fy_parse_cfg *cfg)

Create a parser.

Parameters:
  • cfg (const struct fy_parse_cfg *) – The configuration for the parser

Description

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

Return

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

fy_parser_destroy

void fy_parser_destroy(struct fy_parser *fyp)

Destroy the given parser

Parameters:
  • fyp (struct fy_parser *) – The parser to destroy

Description

Destroy a parser created earlier via fy_parser_create().

fy_parser_get_cfg

const struct fy_parse_cfg *fy_parser_get_cfg(struct fy_parser *fyp)

Get the configuration of a parser

Parameters:
  • fyp (struct fy_parser *) – The parser

Return

The configuration of the parser

fy_parser_get_diag

struct fy_diag *fy_parser_get_diag(struct fy_parser *fyp)

Get the diagnostic object of a parser

Parameters:
  • fyp (struct fy_parser *) – The parser to get the diagnostic object

Description

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.

Return

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

fy_parser_set_diag

int fy_parser_set_diag(struct fy_parser *fyp, struct fy_diag *diag)

Set the diagnostic object of a parser

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

Description

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.

Return

0 if everything OK, -1 otherwise

fy_parser_reset

int fy_parser_reset(struct fy_parser *fyp)

Reset a parser completely

Parameters:
  • fyp (struct fy_parser *) – The parser to reset

Description

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

Return

0 if the reset was successful, -1 otherwise

fy_parser_set_input_file

int fy_parser_set_input_file(struct fy_parser *fyp, const char *file)

Set the parser to process the given file

Parameters:
  • fyp (struct fy_parser *) – The parser
  • file (const char *) – The file to parse.

Description

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.

Return

zero on success, -1 on error

fy_parser_set_string

int fy_parser_set_string(struct fy_parser *fyp, const char *str, size_t len)

Set the parser to process the given string.

Parameters:
  • 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)

Description

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

Return

zero on success, -1 on error

fy_parser_set_malloc_string

int fy_parser_set_malloc_string(struct fy_parser *fyp, char *str, size_t len)

Set the parser to process the given malloced string.

Parameters:
  • 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)

Description

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.

Return

zero on success, -1 on error

fy_parser_set_input_fp

int fy_parser_set_input_fp(struct fy_parser *fyp, const char *name, FILE *fp)

Set the parser to process the given file

Parameters:
  • 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.

Description

Point the parser to use fp for processing.

Return

zero on success, -1 on error

fy_parser_parse

struct fy_event *fy_parser_parse(struct fy_parser *fyp)

Parse and return the next event.

Parameters:
  • fyp (struct fy_parser *) – The parser

Description

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().

Return

The next event in the stream or NULL.

fy_parser_event_free

void fy_parser_event_free(struct fy_parser *fyp, struct fy_event *fye)

Free an event

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

Description

Free a previously returned event from fy_parser_parse().

fy_parser_get_stream_error

bool fy_parser_get_stream_error(struct fy_parser *fyp)

Check the parser for stream errors

Parameters:
  • fyp (struct fy_parser *) – The parser

Return

true in case of a stream error, false otherwise.

fy_token_scalar_style

enum fy_scalar_style fy_token_scalar_style(struct fy_token *fyt)

Get the style of a scalar token

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

Return

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

fy_token_get_text

const char *fy_token_get_text(struct fy_token *fyt, size_t *lenp)

Get text (and length of it) of a token

Parameters:
  • 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

Description

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.

Return

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.

fy_token_get_text0

const char *fy_token_get_text0(struct fy_token *fyt)

Get zero terminated text of a token

Parameters:
  • fyt (struct fy_token *) – The token out of which the text pointer will be returned.

Description

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.

Return

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

fy_token_get_text_length

size_t fy_token_get_text_length(struct fy_token *fyt)

Get length of the text of a token

Parameters:
  • fyt (struct fy_token *) – The token

Description

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

Return

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.

fy_token_get_utf8_length

size_t fy_token_get_utf8_length(struct fy_token *fyt)

Get length of the text of a token

Parameters:
  • fyt (struct fy_token *) – The token

Description

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

Return

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

struct fy_iter_chunk

struct fy_iter_chunk

An iteration chunk

Definition

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

Members

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

Description

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

fy_token_iter_create

struct fy_token_iter *fy_token_iter_create(struct fy_token *fyt)

Create a token iterator

Parameters:
  • fyt (struct fy_token *) – The token to iterate, or NULL.

Description

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().

Return

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

fy_token_iter_destroy

void fy_token_iter_destroy(struct fy_token_iter *iter)

Destroy the iterator

Parameters:
  • iter (struct fy_token_iter *) – The iterator to destroy.

Description

Destroy the iterator created by fy_token_iter_create().

fy_token_iter_start

void fy_token_iter_start(struct fy_token *fyt, struct fy_token_iter *iter)

Start iterating over the contents of a token

Parameters:
  • fyt (struct fy_token *) – The token to iterate over
  • iter (struct fy_token_iter *) – The iterator to prepare.

Description

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.

fy_token_iter_finish

void fy_token_iter_finish(struct fy_token_iter *iter)

Stop iterating over the contents of a token

Parameters:
  • iter (struct fy_token_iter *) – The iterator.

Description

Stop the iteration operation.

fy_token_iter_peek_chunk

const struct fy_iter_chunk *fy_token_iter_peek_chunk(struct fy_token_iter *iter)

Peek at the next iterator chunk

Parameters:
  • iter (struct fy_token_iter *) – The iterator.

Description

Peek at the next iterator chunk

Return

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

fy_token_iter_chunk_next

const struct fy_iter_chunk *fy_token_iter_chunk_next(struct fy_token_iter *iter, const struct fy_iter_chunk *curr, int *errp)

Get next iterator chunk

Parameters:
  • 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

Description

Get the next iterator chunk in sequence,

Return

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.

fy_token_iter_advance

void fy_token_iter_advance(struct fy_token_iter *iter, size_t len)

Advance the iterator position

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

Description

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.

fy_token_iter_read

ssize_t fy_token_iter_read(struct fy_token_iter *iter, void *buf, size_t count)

Read a block from an iterator

Parameters:
  • 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.

Description

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

Return

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

fy_token_iter_getc

int fy_token_iter_getc(struct fy_token_iter *iter)

Get a single character from an iterator

Parameters:
  • iter (struct fy_token_iter *) – The iterator.

Description

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.

Return

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

fy_token_iter_ungetc

int fy_token_iter_ungetc(struct fy_token_iter *iter, int c)

Ungets a single character from an iterator

Parameters:
  • iter (struct fy_token_iter *) – The iterator.
  • c (int) – The character to push back, or -1 to reset the pushback buffer.

Description

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.

Return

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.

fy_token_iter_peekc

int fy_token_iter_peekc(struct fy_token_iter *iter)

Peeks at single character from an iterator

Parameters:
  • iter (struct fy_token_iter *) – The iterator.

Description

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.

Return

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

fy_token_iter_utf8_get

int fy_token_iter_utf8_get(struct fy_token_iter *iter)

Get a single utf8 character from an iterator

Parameters:
  • iter (struct fy_token_iter *) – The iterator.

Description

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.

Return

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

fy_token_iter_utf8_unget

int fy_token_iter_utf8_unget(struct fy_token_iter *iter, int c)

Ungets a single utf8 character from an iterator

Parameters:
  • iter (struct fy_token_iter *) – The iterator.
  • c (int) – The character to push back, or -1 to reset the pushback buffer.

Description

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.

Return

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.

fy_token_iter_utf8_peek

int fy_token_iter_utf8_peek(struct fy_token_iter *iter)

Peeks at single utf8 character from an iterator

Parameters:
  • iter (struct fy_token_iter *) – The iterator.

Description

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.

Return

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

fy_parse_load_document

struct fy_document *fy_parse_load_document(struct fy_parser *fyp)

Parse the next document from the parser stream

Parameters:
  • fyp (struct fy_parser *) – The parser

Description

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.

Return

The next document from the parser stream.

fy_parse_document_destroy

void fy_parse_document_destroy(struct fy_parser *fyp, struct fy_document *fyd)

Destroy a document created by fy_parse_load_document()

Parameters:
  • fyp (struct fy_parser *) – The parser
  • fyd (struct fy_document *) – The document to destroy

fy_document_resolve

int fy_document_resolve(struct fy_document *fyd)

Resolve anchors and merge keys

Parameters:
  • fyd (struct fy_document *) – The document to resolve

Description

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

Return

zero on success, -1 on error

fy_document_has_directives

bool fy_document_has_directives(const struct fy_document *fyd)

Document directive check

Parameters:
  • fyd (const struct fy_document *) – The document to check for directives existence

Description

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

Return

true if directives exist, false if not

fy_document_has_explicit_document_start

bool fy_document_has_explicit_document_start(const struct fy_document *fyd)

Explicit document start check

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

Description

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

Return

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

fy_document_has_explicit_document_end

bool fy_document_has_explicit_document_end(const struct fy_document *fyd)

Explicit document end check

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

Description

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

Return

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

fy_node_document

struct fy_document *fy_node_document(struct fy_node *fyn)

Retreive the document the node belong to

Parameters:
  • fyn (struct fy_node *) – The node to retreive it’s document

Description

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.

Return

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

enum fy_emitter_cfg_flags

enum fy_emitter_cfg_flags

Emitter configuration flags

Definition

enum fy_emitter_cfg_flags {
    FYECF_SORT_KEYS,
    FYECF_OUTPUT_COMMENTS,
    FYECF_STRIP_LABELS,
    FYECF_STRIP_TAGS,
    FYECF_STRIP_DOC,
    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_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
};

Constants

FYECF_SORT_KEYS
Sort key when emitting
FYECF_OUTPUT_COMMENTS
Output comments (experimental)
FYECF_STRIP_LABELS
Strip labels when emitting
FYECF_STRIP_TAGS
Strip tags when emitting
FYECF_STRIP_DOC
Strip document tags and markers when emitting
FYECF_INDENT_DEFAULT
Default emit output indent
FYECF_INDENT_1
Output indent is 1
FYECF_INDENT_2
Output indent is 2
FYECF_INDENT_3
Output indent is 3
FYECF_INDENT_4
Output indent is 4
FYECF_INDENT_5
Output indent is 5
FYECF_INDENT_6
Output indent is 6
FYECF_INDENT_7
Output indent is 7
FYECF_INDENT_8
Output indent is 8
FYECF_INDENT_9
Output indent is 9
FYECF_WIDTH_DEFAULT
Default emit output width
FYECF_WIDTH_80
Output width is 80
FYECF_WIDTH_132
Output width is 132
FYECF_WIDTH_INF
Output width is infinite
FYECF_MODE_ORIGINAL
Emit using the same flow mode as the original
FYECF_MODE_BLOCK
Emit using only the block mode
FYECF_MODE_FLOW
Emit using only the flow mode
FYECF_MODE_FLOW_ONELINE
Emit using only the flow mode (in one line)
FYECF_MODE_JSON
Emit using JSON mode (non type preserving)
FYECF_MODE_JSON_TP
Emit using JSON mode (type preserving)
FYECF_MODE_JSON_ONELINE
Emit using JSON mode (non type preserving, one line)
FYECF_MODE_DEJSON
Emit YAML trying to pretify JSON
FYECF_DOC_START_MARK_AUTO
Automatically generate document start markers if required
FYECF_DOC_START_MARK_OFF
Do not generate document start markers
FYECF_DOC_START_MARK_ON
Always generate document start markers
FYECF_DOC_END_MARK_AUTO
Automatically generate document end markers if required
FYECF_DOC_END_MARK_OFF
Do not generate document end markers
FYECF_DOC_END_MARK_ON
Always generate document end markers
FYECF_VERSION_DIR_AUTO
Automatically generate version directive
FYECF_VERSION_DIR_OFF
Never generate version directive
FYECF_VERSION_DIR_ON
Always generate version directive
FYECF_TAG_DIR_AUTO
Automatically generate tag directives
FYECF_TAG_DIR_OFF
Never generate tag directives
FYECF_TAG_DIR_ON
Always generate tag directives
FYECF_DEFAULT
The default emitter configuration

Description

These flags control the operation of the emitter

struct fy_emitter_cfg

struct fy_emitter_cfg

emitter configuration structure.

Definition

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;
}

Members

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

Description

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

fy_emitter_create

struct fy_emitter *fy_emitter_create(const struct fy_emitter_cfg *cfg)

Create an emitter

Parameters:
  • cfg (const struct fy_emitter_cfg *) – The emitter configuration

Description

Creates an emitter using the supplied configuration

Return

The newly created emitter or NULL on error.

fy_emitter_destroy

void fy_emitter_destroy(struct fy_emitter *emit)

Destroy an emitter

Parameters:
  • emit (struct fy_emitter *) – The emitter to destroy

Description

Destroy an emitter previously created by fy_emitter_create()

fy_emitter_get_cfg

const struct fy_emitter_cfg *fy_emitter_get_cfg(struct fy_emitter *emit)

Get the configuration of an emitter

Parameters:
  • emit (struct fy_emitter *) – The emitter

Return

The configuration of the emitter

fy_emitter_get_diag

struct fy_diag *fy_emitter_get_diag(struct fy_emitter *emit)

Get the diagnostic object of an emitter

Parameters:
  • emit (struct fy_emitter *) – The emitter to get the diagnostic object

Description

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.

Return

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

fy_emitter_set_diag

int fy_emitter_set_diag(struct fy_emitter *emit, struct fy_diag *diag)

Set the diagnostic object of an emitter

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

Description

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.

Return

0 if everything OK, -1 otherwise

fy_emit_event

int fy_emit_event(struct fy_emitter *emit, struct fy_event *fye)

Queue (and possibly emit) an event

Parameters:
  • emit (struct fy_emitter *) – The emitter to use
  • fye (struct fy_event *) – The event to queue for emission

Description

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

Return

0 on success, -1 on error

fy_emit_document

int fy_emit_document(struct fy_emitter *emit, struct fy_document *fyd)

Emit the document using the emitter

Parameters:
  • emit (struct fy_emitter *) – The emitter
  • fyd (struct fy_document *) – The document to emit

Description

Emits a document in YAML format using the emitter.

Return

0 on success, -1 on error

fy_emit_document_start

int fy_emit_document_start(struct fy_emitter *emit, struct fy_document *fyd, struct fy_node *fyn)

Emit document start using the emitter

Parameters:
  • 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)

Description

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

Return

0 on success, -1 on error

fy_emit_document_end

int fy_emit_document_end(struct fy_emitter *emit)

Emit document end using the emitter

Parameters:
  • emit (struct fy_emitter *) – The emitter

Description

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

Return

0 on success, -1 on error

fy_emit_node

int fy_emit_node(struct fy_emitter *emit, struct fy_node *fyn)

Emit a single node using the emitter

Parameters:
  • emit (struct fy_emitter *) – The emitter
  • fyn (struct fy_node *) – The node to emit

Description

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

Return

0 on success, -1 on error

fy_emit_root_node

int fy_emit_root_node(struct fy_emitter *emit, struct fy_node *fyn)

Emit a single root node using the emitter

Parameters:
  • emit (struct fy_emitter *) – The emitter
  • fyn (struct fy_node *) – The root node to emit

Description

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

Return

0 on success, -1 on error

fy_emit_explicit_document_end

int fy_emit_explicit_document_end(struct fy_emitter *emit)

Emit an explicit document end

Parameters:
  • emit (struct fy_emitter *) – The emitter

Description

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

Return

0 on success, -1 on error

fy_emit_document_to_fp

int fy_emit_document_to_fp(struct fy_document *fyd, enum fy_emitter_cfg_flags flags, FILE *fp)

Emit a document to an file pointer

Parameters:
  • 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

Description

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

Return

0 on success, -1 on error

fy_emit_document_to_file

int fy_emit_document_to_file(struct fy_document *fyd, enum fy_emitter_cfg_flags flags, const char *filename)

Emit a document to file

Parameters:
  • 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

Description

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

Return

0 on success, -1 on error

fy_emit_document_to_buffer

int fy_emit_document_to_buffer(struct fy_document *fyd, enum fy_emitter_cfg_flags flags, char *buf, int size)

Emit a document to a buffer

Parameters:
  • 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 (int) – Size of the buffer

Description

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

Return

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

fy_emit_document_to_string

char *fy_emit_document_to_string(struct fy_document *fyd, enum fy_emitter_cfg_flags flags)

Emit a document to an allocated string

Parameters:
  • fyd (struct fy_document *) – The document to emit
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use

Description

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

Return

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

fy_emit_node_to_buffer

int fy_emit_node_to_buffer(struct fy_node *fyn, enum fy_emitter_cfg_flags flags, char *buf, int size)

Emit a node (recursively) to a buffer

Parameters:
  • 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 (int) – Size of the buffer

Description

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

Return

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

fy_emit_node_to_string

char *fy_emit_node_to_string(struct fy_node *fyn, enum fy_emitter_cfg_flags flags)

Emit a node to an allocated string

Parameters:
  • fyn (struct fy_node *) – The node to emit
  • flags (enum fy_emitter_cfg_flags) – The emitter flags to use

Description

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

Return

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

fy_node_copy

struct fy_node *fy_node_copy(struct fy_document *fyd, struct fy_node *fyn_from)

Copy a node, associating the new node with the given document

Parameters:
  • 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

Description

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.

Return

The copied node on success, NULL on error

fy_node_insert

int fy_node_insert(struct fy_node *fyn_to, struct fy_node *fyn_from)

Insert a node to the given node

Parameters:
  • fyn_to (struct fy_node *) – The target node
  • fyn_from (struct fy_node *) – The source node

Description

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

The operation varies according to the types of the arguments

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 }

The rules are

  • 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.

Return

0 on success, -1 on error

fy_document_insert_at

int fy_document_insert_at(struct fy_document *fyd, const char *path, size_t pathlen, struct fy_node *fyn)

Insert a node to the given path in the document

Parameters:
  • 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

Description

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.

Return

0 on success, -1 on error

enum fy_node_type

enum fy_node_type

Node type

Definition

enum fy_node_type {
    FYNT_SCALAR,
    FYNT_SEQUENCE,
    FYNT_MAPPING
};

Constants

FYNT_SCALAR
Node is a scalar
FYNT_SEQUENCE
Node is a sequence
FYNT_MAPPING
Node is a mapping

Description

Each node may be one of the following types

enum fy_node_style

enum fy_node_style

Node style

Definition

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

Constants

FYNS_ANY
No hint, let the emitter decide
FYNS_FLOW
Prefer flow style (for sequence/mappings)
FYNS_BLOCK
Prefer block style (for sequence/mappings)
FYNS_PLAIN
Plain style preferred
FYNS_SINGLE_QUOTED
Single quoted style preferred
FYNS_DOUBLE_QUOTED
Double quoted style preferred
FYNS_LITERAL
Literal style preferred (valid in block context)
FYNS_FOLDED
Folded style preferred (valid in block context)
FYNS_ALIAS
It’s an alias

Description

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

enum fy_node_walk_flags

enum fy_node_walk_flags

Node walk flags

Definition

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

Constants

FYNWF_DONT_FOLLOW
Don’t follow aliases during pathwalk
FYNWF_FOLLOW
Follow aliases during pathwalk
FYNWF_PTR_YAML
YAML pointer path walks
FYNWF_PTR_JSON
JSON pointer path walks
FYNWF_PTR_RELJSON
Relative JSON pointer path walks
FYNWF_URI_ENCODED
The path is URI encoded
FYNWF_MAXDEPTH_DEFAULT
Max follow depth is automatically determined
FYNWF_MARKER_DEFAULT
Default marker to use when scanning
FYNWF_PTR_DEFAULT
Default path type

fy_node_style_from_scalar_style

enum fy_node_style fy_node_style_from_scalar_style(enum fy_scalar_style sstyle)

Convert from scalar to node style

Parameters:
  • sstyle (enum fy_scalar_style) – The input scalar style

Description

Convert a scalar style to a node style.

Return

The matching node style

fy_node_mapping_sort_fn

int fy_node_mapping_sort_fn(const struct fy_node_pair *fynp_a, const struct fy_node_pair *fynp_b, void *arg)

Mapping sorting method function

Parameters:
  • 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

Return

<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

fy_node_scalar_compare_fn

int fy_node_scalar_compare_fn(struct fy_node *fyn_a, struct fy_node *fyn_b, void *arg)

Node compare method function for scalars

Parameters:
  • 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

Return

<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

fy_node_compare

bool fy_node_compare(struct fy_node *fyn1, struct fy_node *fyn2)

Compare two nodes for equality

Parameters:
  • fyn1 (struct fy_node *) – The first node to use in the comparison
  • fyn2 (struct fy_node *) – The second node to use in the comparison

Description

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.

Return

true if the nodes contain the same content, false otherwise

fy_node_compare_user

bool fy_node_compare_user(struct fy_node *fyn1, struct fy_node *fyn2, fy_node_mapping_sort_fn sort_fn, void *sort_fn_arg, fy_node_scalar_compare_fn cmp_fn, void *cmp_fn_arg)

Compare two nodes for equality using user supplied sort and scalar compare methods

Parameters:
  • 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

Description

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.

Return

true if the nodes contain the same content, false otherwise

fy_node_compare_string

bool fy_node_compare_string(struct fy_node *fyn, const char *str, size_t len)

Compare a node for equality with a YAML string

Parameters:
  • 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)

Description

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.

Return

true if the node and the string are equal.

fy_document_create

struct fy_document *fy_document_create(const struct fy_parse_cfg *cfg)

Create an empty document

Parameters:
  • cfg (const struct fy_parse_cfg *) – The parse configuration to use or NULL for the default.

Description

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

Return

The created empty document, or NULL on error.

fy_document_destroy

void fy_document_destroy(struct fy_document *fyd)

Destroy a document previously created via fy_document_create()

Parameters:
  • fyd (struct fy_document *) – The document to destroy

Description

Destroy a document (along with all children documents)

fy_document_get_cfg

const struct fy_parse_cfg *fy_document_get_cfg(struct fy_document *fyd)

Get the configuration of a document

Parameters:
  • fyd (struct fy_document *) – The document

Return

The configuration of the document

fy_document_get_diag

struct fy_diag *fy_document_get_diag(struct fy_document *fyd)

Get the diagnostic object of a document

Parameters:
  • fyd (struct fy_document *) – The document to get the diagnostic object

Description

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.

Return

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

fy_document_set_diag

int fy_document_set_diag(struct fy_document *fyd, struct fy_diag *diag)

Set the diagnostic object of a document

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

Description

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.

Return

0 if everything OK, -1 otherwise

fy_document_set_parent

int fy_document_set_parent(struct fy_document *fyd, struct fy_document *fyd_child)

Make a document a child of another

Parameters:
  • fyd (struct fy_document *) – The parent document
  • fyd_child (struct fy_document *) – The child document

Description

Set the parent of fyd_child document to be fyd

Return

0 if all OK, -1 on error.

fy_document_build_from_string

struct fy_document *fy_document_build_from_string(const struct fy_parse_cfg *cfg, const char *str, size_t len)

Create a document using the provided YAML source.

Parameters:
  • 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)

Description

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

Return

The created document, or NULL on error.

fy_document_build_from_malloc_string

struct fy_document *fy_document_build_from_malloc_string(const struct fy_parse_cfg *cfg, char *str, size_t len)

Create a document using the provided YAML source which was malloced.

Parameters:
  • 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)

Description

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.

Return

The created document, or NULL on error.

fy_document_build_from_file

struct fy_document *fy_document_build_from_file(const struct fy_parse_cfg *cfg, const char *file)

Create a document parsing the given file

Parameters:
  • 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

Description

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

Return

The created document, or NULL on error.

fy_document_build_from_fp

struct fy_document *fy_document_build_from_fp(const struct fy_parse_cfg *cfg, FILE *fp)

Create a document parsing the given file pointer

Parameters:
  • cfg (const struct fy_parse_cfg *) – The parse configuration to use or NULL for the default.
  • fp (FILE *) – The file pointer

Description

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

Return

The created document, or NULL on error.

fy_document_vbuildf

struct fy_document *fy_document_vbuildf(const struct fy_parse_cfg *cfg, const char *fmt, va_list ap)

Create a document using the provided YAML via vprintf formatting

Parameters:
  • 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

Description

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

Return

The created document, or NULL on error.

fy_document_buildf

struct fy_document *fy_document_buildf(const struct fy_parse_cfg *cfg, const char *fmt, ...)

Create a document using the provided YAML source via printf formatting

Parameters:
  • 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

Description

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

Return

The created document, or NULL on error.

fy_document_root

struct fy_node *fy_document_root(struct fy_document *fyd)

Return the root node of the document

Parameters:
  • fyd (struct fy_document *) – The document

Description

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

Return

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

fy_document_set_root

int fy_document_set_root(struct fy_document *fyd, struct fy_node *fyn)

Set the root of the document

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

Description

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.

Return

0 on success, -1 on error

fy_node_get_type

enum fy_node_type fy_node_get_type(struct fy_node *fyn)

Get the node type

Parameters:
  • fyn (struct fy_node *) – The node

Description

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

Return

The node type

fy_node_get_style

enum fy_node_style fy_node_get_style(struct fy_node *fyn)

Get the node style

Parameters:
  • fyn (struct fy_node *) – The node

Description

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

Return

The node style

fy_node_is_scalar

bool fy_node_is_scalar(struct fy_node *fyn)

Check whether the node is a scalar

Parameters:
  • fyn (struct fy_node *) – The node

Description

Convenience method for checking whether a node is a scalar.

Return

true if the node is a scalar, false otherwise

fy_node_is_sequence

bool fy_node_is_sequence(struct fy_node *fyn)

Check whether the node is a sequence

Parameters:
  • fyn (struct fy_node *) – The node

Description

Convenience method for checking whether a node is a sequence.

Return

true if the node is a sequence, false otherwise

fy_node_is_mapping

bool fy_node_is_mapping(struct fy_node *fyn)

Check whether the node is a mapping

Parameters:
  • fyn (struct fy_node *) – The node

Description

Convenience method for checking whether a node is a mapping.

Return

true if the node is a mapping, false otherwise

fy_node_is_alias

bool fy_node_is_alias(struct fy_node *fyn)

Check whether the node is an alias

Parameters:
  • fyn (struct fy_node *) – The node

Description

Convenience method for checking whether a node is an alias.

Return

true if the node is an alias, false otherwise

fy_node_is_attached

bool fy_node_is_attached(struct fy_node *fyn)

Check whether the node is attached

Parameters:
  • fyn (struct fy_node *) – The node

Description

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.

Return

true if the node is attached, false otherwise

fy_node_get_tag_token

struct fy_token *fy_node_get_tag_token(struct fy_node *fyn)

Gets the tag token of a node (if it exists)

Parameters:
  • fyn (struct fy_node *) – The node which has the tag token to be returned

Description

Gets the tag token of a node, if it exists

Return

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

fy_node_get_scalar_token

struct fy_token *fy_node_get_scalar_token(struct fy_node *fyn)

Gets the scalar token of a node (if it exists)

Parameters:
  • fyn (struct fy_node *) – The node which has the scalar token to be returned

Description

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.

Return

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

fy_node_resolve_alias

struct fy_node *fy_node_resolve_alias(struct fy_node *fyn)

Resolve an alias node

Parameters:
  • fyn (struct fy_node *) – The alias node to be resolved

Description

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.

Return

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

fy_node_dereference

struct fy_node *fy_node_dereference(struct fy_node *fyn)

Dereference a single alias node

Parameters:
  • fyn (struct fy_node *) – The alias node to be dereferenced

Description

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.

Return

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

fy_node_free

int fy_node_free(struct fy_node *fyn)

Free a node

Parameters:
  • fyn (struct fy_node *) – The node to free

Description

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.

Return

0 on success, -1 on error.

fy_node_build_from_string

struct fy_node *fy_node_build_from_string(struct fy_document *fyd, const char *str, size_t len)

Create a node using the provided YAML source.

Parameters:
  • 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)

Description

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

Return

The created node, or NULL on error.

fy_node_build_from_malloc_string

struct fy_node *fy_node_build_from_malloc_string(struct fy_document *fyd, char *str, size_t len)

Create a node using the provided YAML source which was malloced.

Parameters:
  • 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)

Description

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.

Return

The created node, or NULL on error.

fy_node_build_from_file

struct fy_node *fy_node_build_from_file(struct fy_document *fyd, const char *file)

Create a node using the provided YAML file.

Parameters:
  • fyd (struct fy_document *) – The document
  • file (const char *) – The name of the file to parse

Description

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

Return

The created node, or NULL on error.

fy_node_build_from_fp

struct fy_node *fy_node_build_from_fp(struct fy_document *fyd, FILE *fp)

Create a node using the provided file pointer.

Parameters:
  • fyd (struct fy_document *) – The document
  • fp (FILE *) – The file pointer

Description

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

Return

The created node, or NULL on error.

fy_node_vbuildf

struct fy_node *fy_node_vbuildf(struct fy_document *fyd, const char *fmt, va_list ap)

Create a node using the provided YAML source via vprintf formatting

Parameters:
  • 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

Description

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

Return

The created node, or NULL on error.

fy_node_buildf

struct fy_node *fy_node_buildf(struct fy_document *fyd, const char *fmt, ...)

Create a node using the provided YAML source via printf formatting

Parameters:
  • fyd (struct fy_document *) – The document
  • fmt (const char *) – The format string creating the YAML source to use.
  • ellipsis (ellipsis) – The printf arguments

Description

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

Return

The created node, or NULL on error.

fy_node_by_path

struct fy_node *fy_node_by_path(struct fy_node *fyn, const char *path, size_t len, enum fy_node_walk_flags flags)

Retrieve a node using the provided path spec.

Parameters:
  • 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

Description

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

Return

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

fy_node_get_path

char *fy_node_get_path(struct fy_node *fyn)

Get the path of this node

Parameters:
  • fyn (struct fy_node *) – The node

Description

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.

Return

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

fy_node_get_parent

struct fy_node *fy_node_get_parent(struct fy_node *fyn)

Get the parent node of a node

Parameters:
  • fyn (struct fy_node *) – The node

Description

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.

Return

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

fy_node_get_parent_address

char *fy_node_get_parent_address(struct fy_node *fyn)

Get the path address of this node’s parent

Parameters:
  • fyn (struct fy_node *) – The node

Description

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

Return

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

fy_node_get_path_relative_to

char *fy_node_get_path_relative_to(struct fy_node *fyn_parent, struct fy_node *fyn)

Get a path address of a node relative to one of it’s parents

Parameters:
  • fyn_parent (struct fy_node *) – The node parent/grandparent…
  • fyn (struct fy_node *) – The node

Description

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.

Return

The relative address from the parent to the node

fy_node_get_short_path

char *fy_node_get_short_path(struct fy_node *fyn)

Get a path address of a node in the shortest path possible

Parameters:
  • fyn (struct fy_node *) – The node

Description

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

struct foo foo: struct 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.

Return

The shortest path describing the node

fy_node_get_reference

char *fy_node_get_reference(struct fy_node *fyn)

Get a textual reference to a node

Parameters:
  • fyn (struct fy_node *) – The node

Description

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.

Return

The node’s text reference.

fy_node_create_reference

struct fy_node *fy_node_create_reference(struct fy_node *fyn)

Create an alias reference node

Parameters:
  • fyn (struct fy_node *) – The node

Description

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.

Return

An alias node referencing the argument node

fy_node_get_relative_reference

char *fy_node_get_relative_reference(struct fy_node *fyn_base, struct fy_node *fyn)

Get a textual reference to a node relative to a base node.

Parameters:
  • fyn_base (struct fy_node *) – The base node
  • fyn (struct fy_node *) – The node

Description

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.

Return

The node’s text reference.

fy_node_create_relative_reference

struct fy_node *fy_node_create_relative_reference(struct fy_node *fyn_base, struct fy_node *fyn)

Create an alias reference node

Parameters:
  • fyn_base (struct fy_node *) – The base node
  • fyn (struct fy_node *) – The node

Description

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.

Return

An alias node referencing the argument node relative to the base

fy_node_create_scalar

struct fy_node *fy_node_create_scalar(struct fy_document *fyd, const char *data, size_t size)

Create a scalar node.

Parameters:
  • 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.

Description

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.

Return

The created node, or NULL on error.

fy_node_create_scalar_copy

struct fy_node *fy_node_create_scalar_copy(struct fy_document *fyd, const char *data, size_t size)

Create a scalar node copying the data.

Parameters:
  • 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.

Description

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.

Return

The created node, or NULL on error.

fy_node_create_vscalarf

struct fy_node *fy_node_create_vscalarf(struct fy_document *fyd, const char *fmt, va_list ap)

vprintf interface for creating scalars

Parameters:
  • 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

Description

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.

Return

The created node, or NULL on error.

fy_node_create_scalarf

struct fy_node *fy_node_create_scalarf(struct fy_document *fyd, const char *fmt, ...)

printf interface for creating scalars

Parameters:
  • 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

Description

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.

Return

The created node, or NULL on error.

fy_node_create_sequence

struct fy_node *fy_node_create_sequence(struct fy_document *fyd)

Create an empty sequence node.

Parameters:
  • fyd (struct fy_document *) – The document which the resulting node will be associated with

Description

Create an empty sequence node associated with the given document.

Return

The created node, or NULL on error.

fy_node_create_mapping

struct fy_node *fy_node_create_mapping(struct fy_document *fyd)

Create an empty mapping node.

Parameters:
  • fyd (struct fy_document *) – The document which the resulting node will be associated with

Description

Create an empty mapping node associated with the given document.

Return

The created node, or NULL on error.

fy_node_set_tag

int fy_node_set_tag(struct fy_node *fyn, const char *data, size_t len)

Set the tag of node

Parameters:
  • 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.

Description

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.

Return

0 on success, -1 on error.

fy_node_get_tag

const char *fy_node_get_tag(struct fy_node *fyn, size_t *lenp)

Get the tag of the node

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

Description

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.

Return

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.

fy_node_get_scalar

const char *fy_node_get_scalar(struct fy_node *fyn, size_t *lenp)

Get the scalar content of the node

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

Description

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.

Return

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.

fy_node_get_scalar0

const char *fy_node_get_scalar0(struct fy_node *fyn)

Get the scalar content of the node

Parameters:
  • fyn (struct fy_node *) – The scalar node

Description

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()

Return

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

fy_node_get_scalar_length

size_t fy_node_get_scalar_length(struct fy_node *fyn)

Get the length of the scalar content

Parameters:
  • fyn (struct fy_node *) – The scalar node

Description

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

Return

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

fy_node_get_scalar_utf8_length

size_t fy_node_get_scalar_utf8_length(struct fy_node *fyn)

Get the length of the scalar content in utf8 characters

Parameters:
  • fyn (struct fy_node *) – The scalar node

Description

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.

Return

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

fy_node_sequence_iterate

struct fy_node *fy_node_sequence_iterate(struct fy_node *fyn, void **prevp)

Iterate over a sequence node

Parameters:
  • fyn (struct fy_node *) – The sequence node
  • prevp (void **) – The previous sequence iterator

Description

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

Return

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

fy_node_sequence_reverse_iterate

struct fy_node *fy_node_sequence_reverse_iterate(struct fy_node *fyn, void **prevp)

Iterate over a sequence node in reverse

Parameters:
  • fyn (struct fy_node *) – The sequence node
  • prevp (void **) – The previous sequence iterator

Description

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.

Return

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

fy_node_sequence_item_count

int fy_node_sequence_item_count(struct fy_node *fyn)

Return the item count of the sequence

Parameters:
  • fyn (struct fy_node *) – The sequence node

Description

Get the item count of the sequence.

Return

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

fy_node_sequence_is_empty

bool fy_node_sequence_is_empty(struct fy_node *fyn)

Check whether the sequence is empty

Parameters:
  • fyn (struct fy_node *) – The sequence node

Description

Check whether the sequence contains items.

Return

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

fy_node_sequence_get_by_index

struct fy_node *fy_node_sequence_get_by_index(struct fy_node *fyn, int index)

Return a sequence item by index

Parameters:
  • 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

Description

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.

Return

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

fy_node_sequence_append

int fy_node_sequence_append(struct fy_node *fyn_seq, struct fy_node *fyn)

Append a node item to a sequence

Parameters:
  • fyn_seq (struct fy_node *) – The sequence node
  • fyn (struct fy_node *) – The node item to append

Description

Append a node item to a sequence.

Return

0 on success, -1 on error

fy_node_sequence_prepend

int fy_node_sequence_prepend(struct fy_node *fyn_seq, struct fy_node *fyn)

Append a node item to a sequence

Parameters:
  • fyn_seq (struct fy_node *) – The sequence node
  • fyn (struct fy_node *) – The node item to prepend

Description

Prepend a node item to a sequence.

Return

0 on success, -1 on error

fy_node_sequence_insert_before

int fy_node_sequence_insert_before(struct fy_node *fyn_seq, struct fy_node *fyn_mark, struct fy_node *fyn)

Insert a node item before another

Parameters:
  • 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.

Description

Insert a node item before another in the sequence.

Return

0 on success, -1 on error

fy_node_sequence_insert_after

int fy_node_sequence_insert_after(struct fy_node *fyn_seq, struct fy_node *fyn_mark, struct fy_node *fyn)

Insert a node item after another

Parameters:
  • 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.

Description

Insert a node item after another in the sequence.

Return

0 on success, -1 on error

fy_node_sequence_remove

struct fy_node *fy_node_sequence_remove(struct fy_node *fyn_seq, struct fy_node *fyn)

Remove an item from a sequence

Parameters:
  • fyn_seq (struct fy_node *) – The sequence node
  • fyn (struct fy_node *) – The node item to remove from the sequence.

Description

Remove a node item from a sequence and return it.

Return

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

fy_node_mapping_iterate

struct fy_node_pair *fy_node_mapping_iterate(struct fy_node *fyn, void **prevp)

Iterate over a mapping node

Parameters:
  • fyn (struct fy_node *) – The mapping node
  • prevp (void **) – The previous sequence iterator

Description

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.

Return

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

fy_node_mapping_reverse_iterate

struct fy_node_pair *fy_node_mapping_reverse_iterate(struct fy_node *fyn, void **prevp)

Iterate over a mapping node in reverse

Parameters:
  • fyn (struct fy_node *) – The mapping node
  • prevp (void **) – The previous sequence iterator

Description

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.

Return

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

fy_node_mapping_item_count

int fy_node_mapping_item_count(struct fy_node *fyn)

Return the node pair count of the mapping

Parameters:
  • fyn (struct fy_node *) – The mapping node

Description

Get the count of the node pairs in the mapping.

Return

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

fy_node_mapping_is_empty

bool fy_node_mapping_is_empty(struct fy_node *fyn)

Check whether the mapping is empty

Parameters:
  • fyn (struct fy_node *) – The mapping node

Description

Check whether the mapping contains any node pairs.

Return

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

fy_node_mapping_get_by_index

struct fy_node_pair *fy_node_mapping_get_by_index(struct fy_node *fyn, int index)

Return a node pair by index

Parameters:
  • 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

Description

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.

Return

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

fy_node_mapping_lookup_by_string

struct fy_node *fy_node_mapping_lookup_by_string(struct fy_node *fyn, const char *key, size_t len)

Lookup a node value in mapping by string

Parameters:
  • 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)

Description

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()

Return

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

fy_node_mapping_lookup_pair_by_simple_key

struct fy_node_pair *fy_node_mapping_lookup_pair_by_simple_key(struct fy_node *fyn, const char *key, size_t len)

Lookup a node pair in mapping by simple string

Parameters:
  • 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)

Description

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.

Return

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

fy_node_mapping_lookup_value_by_simple_key

struct fy_node *fy_node_mapping_lookup_value_by_simple_key(struct fy_node *fyn, const char *key, size_t len)

Lookup a node value in mapping by simple string

Parameters:
  • 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)

Description

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.

Return

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

fy_node_mapping_lookup_scalar_by_simple_key

const char *fy_node_mapping_lookup_scalar_by_simple_key(struct fy_node *fyn, size_t *lenp, const char *key, size_t keylen)

Lookup a scalar in mapping by simple string

Parameters:
  • 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)

Description

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.

Return

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

fy_node_mapping_lookup_scalar0_by_simple_key

const char *fy_node_mapping_lookup_scalar0_by_simple_key(struct fy_node *fyn, const char *key, size_t keylen)

Lookup a scalar in mapping by simple string returning a ‘0’ terminated scalar

Parameters:
  • 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)

Description

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.

Return

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

fy_node_mapping_lookup_pair

struct fy_node_pair *fy_node_mapping_lookup_pair(struct fy_node *fyn, struct fy_node *fyn_key)

Lookup a node pair matching the provided key

Parameters:
  • fyn (struct fy_node *) – The mapping node
  • fyn_key (struct fy_node *) – The node to use as key

Description

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

Return

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

fy_node_mapping_lookup_value_by_key

struct fy_node *fy_node_mapping_lookup_value_by_key(struct fy_node *fyn, struct fy_node *fyn_key)

Lookup a node pair matching the provided key

Parameters:
  • fyn (struct fy_node *) – The mapping node
  • fyn_key (struct fy_node *) – The node to use as key

Description

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.

Return

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

fy_node_mapping_get_pair_index

int fy_node_mapping_get_pair_index(struct fy_node *fyn, const struct fy_node_pair *fynp)

Return the node pair index in the mapping

Parameters:
  • fyn (struct fy_node *) – The mapping node
  • fynp (const struct fy_node_pair *) – The node pair

Description

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

Return

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

fy_node_pair_key

struct fy_node *fy_node_pair_key(struct fy_node_pair *fynp)

Return the key of a node pair

Parameters:
  • fynp (struct fy_node_pair *) – The node pair

Description

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.

Return

The node pair key

fy_node_pair_value

struct fy_node *fy_node_pair_value(struct fy_node_pair *fynp)

Return the value of a node pair

Parameters:
  • fynp (struct fy_node_pair *) – The node pair

Description

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.

Return

The node pair value

fy_node_pair_set_key

int fy_node_pair_set_key(struct fy_node_pair *fynp, struct fy_node *fyn)

Sets the key of a node pair

Parameters:
  • fynp (struct fy_node_pair *) – The node pair
  • fyn (struct fy_node *) – The key node

Description

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.

Return

0 on success, -1 on error

fy_node_pair_set_value

int fy_node_pair_set_value(struct fy_node_pair *fynp, struct fy_node *fyn)

Sets the value of a node pair

Parameters:
  • fynp (struct fy_node_pair *) – The node pair
  • fyn (struct fy_node *) – The value node

Description

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

Return

0 on success, -1 on error

fy_node_mapping_append

int fy_node_mapping_append(struct fy_node *fyn_map, struct fy_node *fyn_key, struct fy_node *fyn_value)

Append a node item to a mapping

Parameters:
  • 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

Description

Append a node pair to a mapping.

Return

0 on success, -1 on error

fy_node_mapping_prepend

int fy_node_mapping_prepend(struct fy_node *fyn_map, struct fy_node *fyn_key, struct fy_node *fyn_value)

Prepend a node item to a mapping

Parameters:
  • 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

Description

Prepend a node pair to a mapping.

Return

0 on success, -1 on error

fy_node_mapping_remove

int fy_node_mapping_remove(struct fy_node *fyn_map, struct fy_node_pair *fynp)

Remove a node pair from a mapping

Parameters:
  • fyn_map (struct fy_node *) – The mapping node
  • fynp (struct fy_node_pair *) – The node pair to remove

Description

Remove node pair from a mapping.

Return

0 on success, -1 on failure.

fy_node_mapping_remove_by_key

struct fy_node *fy_node_mapping_remove_by_key(struct fy_node *fyn_map, struct fy_node *fyn_key)

Remove a node pair from a mapping returning the value

Parameters:
  • fyn_map (struct fy_node *) – The mapping node
  • fyn_key (struct fy_node *) – The node pair’s key

Description

Remove node pair from a mapping using the supplied key.

Return

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

fy_node_sort

int fy_node_sort(struct fy_node *fyn, fy_node_mapping_sort_fn key_cmp, void *arg)

Recursively sort node

Parameters:
  • 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

Description

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

Return

0 on success, -1 on error

fy_node_vscanf

int fy_node_vscanf(struct fy_node *fyn, const char *fmt, va_list ap)

Retrieve data via vscanf

Parameters:
  • 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

Description

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

Return

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

fy_node_scanf

int fy_node_scanf(struct fy_node *fyn, const char *fmt, ...)

Retrieve data via scanf

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

Description

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

Return

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

fy_document_vscanf

int fy_document_vscanf(struct fy_document *fyd, const char *fmt, va_list ap)

Retrieve data via vscanf relative to document root

Parameters:
  • fyd (struct fy_document *) – The document
  • fmt (const char *) – The scanf based format string
  • ap (va_list) – The va_list containing the arguments

Description

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

Return

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

fy_document_scanf

int fy_document_scanf(struct fy_document *fyd, const char *fmt, ...)

Retrieve data via scanf relative to document root

Parameters:
  • fyd (struct fy_document *) – The document
  • fmt (const char *) – The scanf based format string
  • ellipsis (ellipsis) – The arguments

Description

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

Return

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

fy_document_tag_directive_iterate

struct fy_token *fy_document_tag_directive_iterate(struct fy_document *fyd, void **prevp)

Iterate over a document’s tag directives

Parameters:
  • fyd (struct fy_document *) – The document
  • prevp (void **) – The previous state of the iterator

Description

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

Return

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

fy_document_tag_directive_lookup

struct fy_token *fy_document_tag_directive_lookup(struct fy_document *fyd, const char *handle)

Retreive a document’s tag directive

Parameters:
  • fyd (struct fy_document *) – The document
  • handle (const char *) – The handle to look for

Description

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

Return

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

fy_tag_directive_token_handle

const char *fy_tag_directive_token_handle(struct fy_token *fyt, size_t *lenp)

Get a tag directive handle

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

Description

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

Return

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.

fy_tag_directive_token_prefix

const char *fy_tag_directive_token_prefix(struct fy_token *fyt, size_t *lenp)

Get a tag directive prefix

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

Description

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

Return

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.

fy_document_tag_directive_add

int fy_document_tag_directive_add(struct fy_document *fyd, const char *handle, const char *prefix)

Add a tag directive to a document

Parameters:
  • fyd (struct fy_document *) – The document
  • handle (const char *) – The handle of the tag directive
  • prefix (const char *) – The prefix of the tag directive

Description

Add tag directive to the document.

Return

0 on success, -1 on error

fy_document_tag_directive_remove

int fy_document_tag_directive_remove(struct fy_document *fyd, const char *handle)

Remove a tag directive

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

Description

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

Return

0 on success, -1 on error

fy_document_lookup_anchor

struct fy_anchor *fy_document_lookup_anchor(struct fy_document *fyd, const char *anchor, size_t len)

Lookup an anchor

Parameters:
  • 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)

Description

Lookup for an anchor having the name provided

Return

The anchor if found, NULL otherwise

fy_document_lookup_anchor_by_token

struct fy_anchor *fy_document_lookup_anchor_by_token(struct fy_document *fyd, struct fy_token *anchor)

Lookup an anchor by token text

Parameters:
  • fyd (struct fy_document *) – The document
  • anchor (struct fy_token *) – The token contains the anchor text to look for

Description

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

Return

The anchor if found, NULL otherwise

fy_document_lookup_anchor_by_node

struct fy_anchor *fy_document_lookup_anchor_by_node(struct fy_document *fyd, struct fy_node *fyn)

Lookup an anchor by node

Parameters:
  • fyd (struct fy_document *) – The document
  • fyn (struct fy_node *) – The node

Description

Lookup for an anchor located in the given node

Return

The anchor if found, NULL otherwise

fy_anchor_get_text

const char *fy_anchor_get_text(struct fy_anchor *fya, size_t *lenp)

Get the text of an anchor

Parameters:
  • fya (struct fy_anchor *) – The anchor
  • lenp (size_t *) – Pointer to a variable that will hold the returned length

Description

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.

Return

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.

fy_anchor_node

struct fy_node *fy_anchor_node(struct fy_anchor *fya)

Get the node of an anchor

Parameters:
  • fya (struct fy_anchor *) – The anchor

Description

This method returns the node associated with the anchor.

Return

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

fy_document_anchor_iterate

struct fy_anchor *fy_document_anchor_iterate(struct fy_document *fyd, void **prevp)

Iterate over a document’s anchors

Parameters:
  • fyd (struct fy_document *) – The document
  • prevp (void **) – The previous state of the iterator

Description

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

Return

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

fy_document_set_anchor

int fy_document_set_anchor(struct fy_document *fyd, struct fy_node *fyn, const char *text, size_t len)

Place an anchor

Parameters:
  • 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.

Description

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.

Return

0 on success, -1 on error.

fy_node_set_anchor

int fy_node_set_anchor(struct fy_node *fyn, const char *text, size_t len)

Place an anchor to the node

Parameters:
  • 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.

Description

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.

Return

0 on success, -1 on error.

fy_node_set_anchor_copy

int fy_node_set_anchor_copy(struct fy_node *fyn, const char *text, size_t len)

Place an anchor to the node copying the text

Parameters:
  • 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.

Description

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.

Return

0 on success, -1 on error.

fy_node_set_vanchorf

int fy_node_set_vanchorf(struct fy_node *fyn, const char *fmt, va_list ap)

Place an anchor to the node using a vprintf interface.

Parameters:
  • 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.

Description

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

Return

0 on success, -1 on error.

fy_node_set_anchorf

int fy_node_set_anchorf(struct fy_node *fyn, const char *fmt, ...)

Place an anchor to the node using a printf interface.

Parameters:
  • 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.

Description

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

Return

0 on success, -1 on error.

fy_node_remove_anchor

int fy_node_remove_anchor(struct fy_node *fyn)

Remove an anchor

Parameters:
  • fyn (struct fy_node *) – The node to remove anchors from

Description

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

Return

0 on success, -1 on error.

fy_node_get_anchor

struct fy_anchor *fy_node_get_anchor(struct fy_node *fyn)

Get the anchor of a node

Parameters:
  • fyn (struct fy_node *) – The node

Description

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

Return

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

fy_node_get_nearest_anchor

struct fy_anchor *fy_node_get_nearest_anchor(struct fy_node *fyn)

Get the nearest anchor of the node

Parameters:
  • fyn (struct fy_node *) – The node

Description

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

Return

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

fy_node_get_nearest_child_of

struct fy_node *fy_node_get_nearest_child_of(struct fy_node *fyn_base, struct fy_node *fyn)

Get the nearest node which is a child of the base

Parameters:
  • fyn_base (struct fy_node *) – The base node
  • fyn (struct fy_node *) – The node to start from

Description

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

Return

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

fy_node_create_alias

struct fy_node *fy_node_create_alias(struct fy_document *fyd, const char *alias, size_t len)

Create an alias node

Parameters:
  • 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)

Description

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.

Return

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

fy_node_create_alias_copy

struct fy_node *fy_node_create_alias_copy(struct fy_document *fyd, const char *alias, size_t len)

Create an alias node copying the data

Parameters:
  • 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)

Description

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.

Return

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

fy_node_get_meta

void *fy_node_get_meta(struct fy_node *fyn)

Get the meta pointer of a node

Parameters:
  • fyn (struct fy_node *) – The node to get meta data from

Description

Return the meta pointer of a node.

Return

The stored meta data pointer

fy_node_set_meta

int fy_node_set_meta(struct fy_node *fyn, void *meta)

Set the meta pointer of a node

Parameters:
  • fyn (struct fy_node *) – The node to set meta data
  • meta (void *) – The meta data pointer

Description

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

Return

0 on success, -1 on error

fy_node_clear_meta

void fy_node_clear_meta(struct fy_node *fyn)

Clear the meta data of a node

Parameters:
  • fyn (struct fy_node *) – The node to clear meta data

Description

Clears the meta data of a node.

fy_node_meta_clear_fn

void fy_node_meta_clear_fn(struct fy_node *fyn, void *meta, void *user)

Meta data clear method

Parameters:

Description

This is the callback called when meta data are cleared.

fy_document_register_meta

int fy_document_register_meta(struct fy_document *fyd, fy_node_meta_clear_fn clear_fn, void *user)

Register a meta cleanup hook

Parameters:
  • 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

Description

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.

Return

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

fy_document_unregister_meta

void fy_document_unregister_meta(struct fy_document *fyd)

Unregister a meta cleanup hook

Parameters:
  • fyd (struct fy_document *) – The document to unregister it’s meta cleanup hook.

Description

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

fy_node_set_marker

bool fy_node_set_marker(struct fy_node *fyn, unsigned int marker)

Set a marker of a node

Parameters:
  • fyn (struct fy_node *) – The node
  • marker (unsigned int) – The marker to set

Description

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.

Return

The previous value of the marker

fy_node_clear_marker

bool fy_node_clear_marker(struct fy_node *fyn, unsigned int marker)

Clear a marker of a node

Parameters:
  • fyn (struct fy_node *) – The node
  • marker (unsigned int) – The marker to clear

Description

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.

Return

The previous value of the marker

fy_node_is_marker_set

bool fy_node_is_marker_set(struct fy_node *fyn, unsigned int marker)

Checks whether a marker is set

Parameters:
  • fyn (struct fy_node *) – The node
  • marker (unsigned int) – The marker index (must be less that FYNWF_MAX_USER_MARKER)

Description

Check the state of the given marker.

Return

The value of the marker (invalid markers return false)

fy_node_vreport

void fy_node_vreport(struct fy_node *fyn, enum fy_error_type type, const char *fmt, va_list ap)

Report about a node vprintf style

Parameters:
  • 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

Description

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

fy_node_report

void fy_node_report(struct fy_node *fyn, enum fy_error_type type, const char *fmt, ...)

Report about a node printf style

Parameters:
  • 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.

Description

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

fy_node_override_vreport

void fy_node_override_vreport(struct fy_node *fyn, enum fy_error_type type, const char *file, int line, int column, const char *fmt, va_list ap)

Report about a node vprintf style, overriding file, line and column info

Parameters:
  • 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

Description

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.

fy_node_override_report

void fy_node_override_report(struct fy_node *fyn, enum fy_error_type type, const char *file, int line, int column, const char *fmt, ...)

Report about a node printf style, overriding file, line and column info

Parameters:
  • 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.

Description

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.

struct fy_diag_cfg

struct fy_diag_cfg

The diagnostics configuration

Definition

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;
}

Members

fp
File descriptor of the error output
output_fn
Callback to use when fp is NULL
user
User pointer to pass to the output_fn
level
The minimum debugging level
module_mask
A bitmask of the enabled modules
colorize
true if output should be colorized using ANSI sequences
show_source
true if source location should be displayed
show_position
true if position should be displayed
show_type
true if the type should be displayed
show_module
true if the module should be displayed
source_width
Width of the source field
position_width
Width of the position field
type_width
Width of the type field
module_width
Width of the module field

Description

This structure contains the configuration of the diagnostic object.

fy_diag_create

struct fy_diag *fy_diag_create(const struct fy_diag_cfg *cfg)

Create a diagnostic object

Parameters:
  • cfg (const struct fy_diag_cfg *) – The configuration for the diagnostic object (NULL is default)

Description

Creates a diagnostic object using the provided configuration.

Return

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

fy_diag_destroy

void fy_diag_destroy(struct fy_diag *diag)

Destroy a diagnostic object

Parameters:
  • diag (struct fy_diag *) – The diagnostic object to destroy

Description

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.

fy_diag_get_cfg

const struct fy_diag_cfg *fy_diag_get_cfg(struct fy_diag *diag)

Get a diagnostic object’s configuration

Parameters:
  • diag (struct fy_diag *) – The diagnostic object

Description

Return the current configuration of a diagnostic object

Return

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

fy_diag_set_cfg

void fy_diag_set_cfg(struct fy_diag *diag, const struct fy_diag_cfg *cfg)

Set a diagnostic object’s configuration

Parameters:
  • diag (struct fy_diag *) – The diagnostic object
  • cfg (const struct fy_diag_cfg *) – The diagnostic configuration

Description

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

fy_diag_set_level

void fy_diag_set_level(struct fy_diag *diag, enum fy_error_type level)

Set a diagnostic object’s debug error level

Parameters:
  • diag (struct fy_diag *) – The diagnostic object
  • level (enum fy_error_type) – The debugging level to set

fy_diag_set_colorize

void fy_diag_set_colorize(struct fy_diag *diag, bool colorize)

Set a diagnostic object’s colorize option

Parameters:
  • diag (struct fy_diag *) – The diagnostic object
  • colorize (bool) – The colorize option

fy_diag_ref

struct fy_diag *fy_diag_ref(struct fy_diag *diag)

Increment that reference counter of a diagnostic object

Parameters:
  • diag (struct fy_diag *) – The diagnostic object to reference

Description

Increment the reference.

Return

Always returns the diag argument

fy_diag_unref

void fy_diag_unref(struct fy_diag *diag)

Take away a ref from a diagnostic object

Parameters:
  • diag (struct fy_diag *) – The diagnostic object to unref

Description

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

fy_diag_got_error

bool fy_diag_got_error(struct fy_diag *diag)

Test whether an error level diagnostic has been produced

Parameters:
  • diag (struct fy_diag *) – The diagnostic object

Description

Tests whether an error diagnostic has been produced.

Return

true if an error has been produced, false otherwise

fy_diag_reset_error

void fy_diag_reset_error(struct fy_diag *diag)

Reset the error flag of the diagnostic object

Parameters:
  • diag (struct fy_diag *) – The diagnostic object

Description

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

fy_diag_cfg_default

void fy_diag_cfg_default(struct fy_diag_cfg *cfg)

Fill in the configuration structure with defaults

Parameters:
  • cfg (struct fy_diag_cfg *) – The diagnostic configuration structure

Description

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

fy_diag_cfg_from_parser_flags

void fy_diag_cfg_from_parser_flags(struct fy_diag_cfg *cfg, enum fy_parse_cfg_flags pflags)

Fill partial diagnostic config structure from parser config flags

Parameters:
  • cfg (struct fy_diag_cfg *) – The diagnostic configuration structure
  • pflags (enum fy_parse_cfg_flags) – The parser flags

Description

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

fy_diag_vprintf

int fy_diag_vprintf(struct fy_diag *diag, const char *fmt, va_list ap)

vprintf raw interface to diagnostics

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

Description

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.

Return

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.

fy_diag_printf

int fy_diag_printf(struct fy_diag *diag, const char *fmt, ...)

printf raw interface to diagnostics

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

Description

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.

Return

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.

struct fy_diag_ctx

struct fy_diag_ctx

The diagnostics context

Definition

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;
}

Members

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

Description

This structure contains the diagnostic context

fy_vdiag

int fy_vdiag(struct fy_diag *diag, const struct fy_diag_ctx *fydc, const char *fmt, va_list ap)

context aware diagnostic output like vprintf

Parameters:
  • 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

Description

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

Return

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.

fy_diagf

int fy_diagf(struct fy_diag *diag, const struct fy_diag_ctx *fydc, const char *fmt, ...)

context aware diagnostic output like printf

Parameters:
  • 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

Description

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

Return

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.

fy_diag_node_vreport

void fy_diag_node_vreport(struct fy_diag *diag, struct fy_node *fyn, enum fy_error_type type, const char *fmt, va_list ap)

Report about a node vprintf style using the given diagnostic object

Parameters:
  • 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

Description

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

fy_diag_node_report

void fy_diag_node_report(struct fy_diag *diag, struct fy_node *fyn, enum fy_error_type type, const char *fmt, ...)

Report about a node printf style using the given diagnostic object

Parameters:
  • 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.

Description

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

fy_diag_node_override_vreport

void fy_diag_node_override_vreport(struct fy_diag *diag, struct fy_node *fyn, enum fy_error_type type, const char *file, int line, int column, const char *fmt, va_list ap)

Report about a node vprintf style, overriding file, line and column info using the given diagnostic object

Parameters:
  • 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

Description

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.

fy_diag_node_override_report

void fy_diag_node_override_report(struct fy_diag *diag, struct fy_node *fyn, enum fy_error_type type, const char *file, int line, int column, const char *fmt, ...)

Report about a node printf style, overriding file, line and column info using the given diagnostic object

Parameters:
  • 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.

Description

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.

enum fy_path_parse_cfg_flags

enum fy_path_parse_cfg_flags

Path parse configuration flags

Definition

enum fy_path_parse_cfg_flags {
    FYPPCF_QUIET,
    FYPPCF_DISABLE_RECYCLING,
    FYPPCF_DISABLE_ACCELERATORS
};

Constants

FYPPCF_QUIET
Quiet, do not output any information messages
FYPPCF_DISABLE_RECYCLING
Disable recycling optimization
FYPPCF_DISABLE_ACCELERATORS
Disable use of access accelerators (saves memory)

Description

These flags control the operation of the path parse

struct fy_path_parse_cfg

struct fy_path_parse_cfg

path parser configuration structure.

Definition

struct fy_path_parse_cfg {
    enum fy_path_parse_cfg_flags flags;
    void *userdata;
    struct fy_diag *diag;
}

Members

flags
Configuration flags
userdata
Opaque user data pointer
diag
Optional diagnostic interface to use

Description

Argument to the fy_path_parser_create() method which performs parsing of a ypath expression

fy_path_parser_create

struct fy_path_parser *fy_path_parser_create(const struct fy_path_parse_cfg *cfg)

Create a ypath parser.

Parameters:
  • cfg (const struct fy_path_parse_cfg *) – The configuration for the path parser

Description

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

Return

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

fy_path_parser_destroy

void fy_path_parser_destroy(struct fy_path_parser *fypp)

Destroy the given path parser

Parameters:
  • fypp (struct fy_path_parser *) – The path parser to destroy

Description

Destroy a path parser created earlier via fy_path_parser_create().

fy_path_parser_reset

int fy_path_parser_reset(struct fy_path_parser *fypp)

Reset a path parser completely

Parameters:
  • fypp (struct fy_path_parser *) – The path parser to reset

Description

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

Return

0 if the reset was successful, -1 otherwise

fy_path_parse_expr_from_string

struct fy_path_expr *fy_path_parse_expr_from_string(struct fy_path_parser *fypp, const char *str, size_t len)

Parse an expression from a given string

Parameters:
  • 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)

Description

Create a path expression from a string using the provided path parser.

Return

The created path expression or NULL on error.

fy_path_expr_build_from_string

struct fy_path_expr *fy_path_expr_build_from_string(const struct fy_path_parse_cfg *pcfg, const char *str, size_t len)

Parse an expression from a given string

Parameters:
  • 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)

Description

Create a path expression from a string using the provided path parser configuration.

Return

The created path expression or NULL on error.

fy_path_expr_free

void fy_path_expr_free(struct fy_path_expr *expr)

Free a path expression

Parameters:
  • expr (struct fy_path_expr *) – The expression to free (may be NULL)

Description

Free a previously returned expression from any of the path parser methods like fy_path_expr_build_from_string()

fy_path_expr_dump

void fy_path_expr_dump(struct fy_path_expr *expr, struct fy_diag *diag, enum fy_error_type errlevel, int level, const char *banner)

Dump the contents of a path expression to the diagnostic object

Parameters:
  • 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

Description

Dumps the expression using the provided error level.

enum fy_path_exec_cfg_flags

enum fy_path_exec_cfg_flags

Path executor configuration flags

Definition

enum fy_path_exec_cfg_flags {
    FYPXCF_QUIET,
    FYPXCF_DISABLE_RECYCLING,
    FYPXCF_DISABLE_ACCELERATORS
};

Constants

FYPXCF_QUIET
Quiet, do not output any information messages
FYPXCF_DISABLE_RECYCLING
Disable recycling optimization
FYPXCF_DISABLE_ACCELERATORS
Disable use of access accelerators (saves memory)

Description

These flags control the operation of the path expression executor

struct fy_path_exec_cfg

struct fy_path_exec_cfg

path expression executor configuration structure.

Definition

struct fy_path_exec_cfg {
    enum fy_path_exec_cfg_flags flags;
    void *userdata;
    struct fy_diag *diag;
}

Members

flags
Configuration flags
userdata
Opaque user data pointer
diag
Optional diagnostic interface to use

Description

Argument to the fy_path_exec_create() method which performs execution of a ypath expression

fy_path_exec_create

struct fy_path_exec *fy_path_exec_create(const struct fy_path_exec_cfg *xcfg)

Create a ypath expression executor.

Parameters:
  • xcfg (const struct fy_path_exec_cfg *) – The configuration for the executor

Description

Creates a ypath expression parser with its configuration cfg The executor may be destroyed by a corresponding call to fy_path_exec_destroy().

Return

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

fy_path_exec_destroy

void fy_path_exec_destroy(struct fy_path_exec *fypx)

Destroy the given path expression executor

Parameters:
  • fypx (struct fy_path_exec *) – The path parser to destroy

Description

Destroy ane executor created earlier via fy_path_exec_create().

fy_path_exec_reset

int fy_path_exec_reset(struct fy_path_exec *fypx)

Reset an executor

Parameters:
  • fypx (struct fy_path_exec *) – The executor to reset

Description

Completely reset an executor without releasing it.

Return

0 if the reset was successful, -1 otherwise

fy_path_exec_execute

int fy_path_exec_execute(struct fy_path_exec *fypx, struct fy_path_expr *expr, struct fy_node *fyn_start)

Execute a path expression starting at the given start node

Parameters:
  • 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.

Description

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.

Return

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.

fy_path_exec_results_iterate

struct fy_node *fy_path_exec_results_iterate(struct fy_path_exec *fypx, void **prevp)

Iterate over the results of execution

Parameters:
  • fypx (struct fy_path_exec *) – The executor
  • prevp (void **) – The previous result iterator

Description

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

Return

The next node in the result set or NULL at the end of the results.

enum fy_token_type

enum fy_token_type

Token types

Definition

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_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
};

Constants

FYTT_NONE
No token
FYTT_STREAM_START
Stream start
FYTT_STREAM_END
Stream end
FYTT_VERSION_DIRECTIVE
Version directive
FYTT_TAG_DIRECTIVE
Tag directive
FYTT_DOCUMENT_START
Document start
FYTT_DOCUMENT_END
Document end
FYTT_BLOCK_SEQUENCE_START
Start of a block sequence
FYTT_BLOCK_MAPPING_START
Start of a block mapping
FYTT_BLOCK_END
End of a block mapping or a sequence
FYTT_FLOW_SEQUENCE_START
Start of a flow sequence
FYTT_FLOW_SEQUENCE_END
End of a flow sequence
FYTT_FLOW_MAPPING_START
Start of a flow mapping
FYTT_FLOW_MAPPING_END
End of a flow mapping
FYTT_BLOCK_ENTRY
A block entry
FYTT_FLOW_ENTRY
A flow entry
FYTT_KEY
A key of a mapping
FYTT_VALUE
A value of a mapping
FYTT_ALIAS
An alias
FYTT_ANCHOR
An anchor
FYTT_TAG
A tag
FYTT_SCALAR
A scalar
FYTT_INPUT_MARKER
Internal input marker token
FYTT_PE_SLASH
A slash
FYTT_PE_ROOT
A root
FYTT_PE_THIS
A this
FYTT_PE_PARENT
A parent
FYTT_PE_MAP_KEY
A map key
FYTT_PE_SEQ_INDEX
A sequence index
FYTT_PE_SEQ_SLICE
A sequence slice
FYTT_PE_SCALAR_FILTER
A scalar filter
FYTT_PE_COLLECTION_FILTER
A collection filter
FYTT_PE_SEQ_FILTER
A sequence filter
FYTT_PE_MAP_FILTER
A mapping filter
FYTT_PE_EVERY_CHILD
Every child
FYTT_PE_EVERY_CHILD_R
Every child recursive
FYTT_PE_ALIAS
An alias
FYTT_PE_SIBLING
A sibling marker
FYTT_PE_COMMA
A comma
FYTT_PE_BARBAR
A ||
FYTT_PE_AMPAMP
A &&
FYTT_PE_LPAREN
A left parenthesis
FYTT_PE_RPAREN
A right parenthesis

Description

The available token types that the tokenizer produces.

fy_token_type_is_valid

bool fy_token_type_is_valid(enum fy_token_type type)

Check token type validity

Parameters:
  • type (enum fy_token_type) – The token type

Description

Check if argument token type is a valid one.

Return

true if the token type is valid, false otherwise

fy_token_type_is_yaml

bool fy_token_type_is_yaml(enum fy_token_type type)

Check if token type is valid for YAML

Parameters:
  • type (enum fy_token_type) – The token type

Description

Check if argument token type is a valid YAML one.

Return

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

fy_token_type_is_content

bool fy_token_type_is_content(enum fy_token_type type)

Check if token type is valid for YAML content

Parameters:
  • type (enum fy_token_type) – The token type

Description

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

Return

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

fy_token_type_is_path_expr

bool fy_token_type_is_path_expr(enum fy_token_type type)

Check if token type is valid for a YPATH expression

Parameters:
  • type (enum fy_token_type) – The token type

Description

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

Return

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

fy_token_get_type

enum fy_token_type fy_token_get_type(struct fy_token *fyt)

Return the token’s type

Parameters:
  • fyt (struct fy_token *) – The token

Description

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

Return

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

fy_token_start_mark

const struct fy_mark *fy_token_start_mark(struct fy_token *fyt)

Get token’s start marker

Parameters:
  • fyt (struct fy_token *) – The token to get its start marker

Description

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.

Return

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

fy_token_end_mark

const struct fy_mark *fy_token_end_mark(struct fy_token *fyt)

Get token’s end marker

Parameters:
  • fyt (struct fy_token *) – The token to get its end marker

Description

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.

Return

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

fy_scan

struct fy_token *fy_scan(struct fy_parser *fyp)

Low level access to the scanner

Parameters:
  • fyp (struct fy_parser *) – The parser to get the next token from.

Description

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()

Return

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

fy_scan_token_free

void fy_scan_token_free(struct fy_parser *fyp, struct fy_token *fyt)

Free the token returned by fy_scan()

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

Description

Free the token returned by fy_scan().

fy_tag_directive_token_prefix0

const char *fy_tag_directive_token_prefix0(struct fy_token *fyt)

Get the prefix contained in the tag directive token as zero terminated string

Parameters:
  • fyt (struct fy_token *) – The tag directive token out of which the prefix pointer will be returned.

Description

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.

Return

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

fy_tag_directive_token_handle0

const char *fy_tag_directive_token_handle0(struct fy_token *fyt)

Get the handle contained in the tag directive token as zero terminated string

Parameters:
  • fyt (struct fy_token *) – The tag directive token out of which the handle pointer will be returned.

Description

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.

Return

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

fy_tag_token_handle

const char *fy_tag_token_handle(struct fy_token *fyt, size_t *lenp)

Get the handle contained in the tag token

Parameters:
  • 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

Description

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

Return

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.

fy_tag_token_suffix

const char *fy_tag_token_suffix(struct fy_token *fyt, size_t *lenp)

Get the suffix contained in the tag token

Parameters:
  • 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

Description

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

Return

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.

fy_tag_token_handle0

const char *fy_tag_token_handle0(struct fy_token *fyt)

Get the handle contained in the tag token as zero terminated string

Parameters:
  • fyt (struct fy_token *) – The tag token out of which the handle pointer will be returned.

Description

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.

Return

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

fy_tag_token_suffix0

const char *fy_tag_token_suffix0(struct fy_token *fyt)

Get the suffix contained in the tag token as zero terminated string

Parameters:
  • fyt (struct fy_token *) – The tag token out of which the suffix pointer will be returned.

Description

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.

Return

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

fy_version_directive_token_version

const struct fy_version *fy_version_directive_token_version(struct fy_token *fyt)

Return the version of a version directive token

Parameters:
  • fyt (struct fy_token *) – The version directive token

Description

Retrieve the version stored in a version directive token.

Return

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.

fy_scalar_token_get_style

enum fy_scalar_style fy_scalar_token_get_style(struct fy_token *fyt)

Return the style of a scalar token

Parameters:
  • fyt (struct fy_token *) – The scalar token

Description

Retrieve the style of a scalar token.

Return

The scalar style of the token, or FYSS_ANY for an error

fy_tag_token_tag

const struct fy_tag *fy_tag_token_tag(struct fy_token *fyt)

Get tag of a tag token

Parameters:
  • fyt (struct fy_token *) – The tag token

Description

Retrieve the tag of a tag token.

Return

A pointer to the tag or NULL in case of an error

fy_tag_directive_token_tag

const struct fy_tag *fy_tag_directive_token_tag(struct fy_token *fyt)

Get tag of a tag directive token

Parameters:
  • fyt (struct fy_token *) – The tag directive token

Description

Retrieve the tag of a tag directive token.

Return

A pointer to the tag or NULL in case of an error

fy_event_get_token

struct fy_token *fy_event_get_token(struct fy_event *fye)

Return the main token of an event

Parameters:
  • fye (struct fy_event *) – The event to get its main token

Description

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.

Return

The main token if it exists, NULL otherwise or in case of an error

fy_event_get_anchor_token

struct fy_token *fy_event_get_anchor_token(struct fy_event *fye)

Return the anchor token of an event

Parameters:
  • fye (struct fy_event *) – The event to get its anchor token

Description

Retrieve the anchor token if it exists. Only valid for mapping/sequence start and scalar events.

Return

The anchor token if it exists, NULL otherwise or in case of an error

fy_event_get_tag_token

struct fy_token *fy_event_get_tag_token(struct fy_event *fye)

Return the tag token of an event

Parameters:
  • fye (struct fy_event *) – The event to get its tag token

Description

Retrieve the tag token if it exists. Only valid for mapping/sequence start and scalar events.

Return

The tag token if it exists, NULL otherwise or in case of an error

fy_event_start_mark

const struct fy_mark *fy_event_start_mark(struct fy_event *fye)

Get event’s start marker

Parameters:
  • fye (struct fy_event *) – The event to get its start marker

Description

Return the event’s start marker if it exists. The start marker is the one of the event’s main token.

Return

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

fy_event_end_mark

const struct fy_mark *fy_event_end_mark(struct fy_event *fye)

Get event’s end marker

Parameters:
  • fye (struct fy_event *) – The event to get its end marker

Description

Return the event’s end marker if it exists. The end marker is the one of the event’s main token.

Return

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

fy_event_get_node_style

enum fy_node_style fy_event_get_node_style(struct fy_event *fye)

Get the node style of an event

Parameters:
  • fye (struct fy_event *) – The event to get it’s node style

Description

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_BLOC. A scalar event may return any.

Return

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

fy_document_start_event_version

const struct fy_version *fy_document_start_event_version(struct fy_event *fye)

Return the version of a document start event

Parameters:
  • fye (struct fy_event *) – The document start event

Description

Retrieve the version stored in a document start event

Return

A pointer to the version, or NULL in case of an error, or the event not being a document start event.

fy_document_state_version

const struct fy_version *fy_document_state_version(struct fy_document_state *fyds)

Return the version of a document state object

Parameters:
  • fyds (struct fy_document_state *) – The document state object

Description

Retrieve the version stored in a document state object

Return

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

fy_document_state_start_mark

const struct fy_mark *fy_document_state_start_mark(struct fy_document_state *fyds)

Get document state’s start mark

Parameters:
  • fyds (struct fy_document_state *) – The document state object

Description

Return the document state’s start mark (if it exists). Note that purely synthetic documents do not contain one

Return

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

fy_document_state_end_mark

const struct fy_mark *fy_document_state_end_mark(struct fy_document_state *fyds)

Get document state’s end mark

Parameters:
  • fyds (struct fy_document_state *) – The document state object

Description

Return the document state’s end mark (if it exists). Note that purely synthetic documents do not contain one

Return

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

fy_document_state_version_explicit

bool fy_document_state_version_explicit(struct fy_document_state *fyds)

Version explicit?

Parameters:
  • fyds (struct fy_document_state *) – The document state object

Description

Find out if a document state object’s version was explicitly set in the document. Note that for synthetic documents this method returns false.

Return

true if version was set explicitly, false otherwise

fy_document_state_tags_explicit

bool fy_document_state_tags_explicit(struct fy_document_state *fyds)

Tags explicit?

Parameters:
  • fyds (struct fy_document_state *) – The document state object

Description

Find out if a document state object’s tags were explicitly set in the document. Note that for synthetic documents this method returns false.

Return

true if document had tags set explicitly, false otherwise

fy_document_state_start_implicit

bool fy_document_state_start_implicit(struct fy_document_state *fyds)

Started implicitly?

Parameters:
  • fyds (struct fy_document_state *) – The document state object

Description

Find out if a document state object’s document was started implicitly. Note that for synthetic documents this method returns false.

Return

true if document was started implicitly, false otherwise

fy_document_state_end_implicit

bool fy_document_state_end_implicit(struct fy_document_state *fyds)

Started implicitly?

Parameters:
  • fyds (struct fy_document_state *) – The document state object

Description

Find out if a document state object’s document was ended implicitly. Note that for synthetic documents this method returns false.

Return

true if document was ended implicitly, false otherwise

fy_document_state_tag_directive_iterate

const struct fy_tag *fy_document_state_tag_directive_iterate(struct fy_document_state *fyds, void **prevp)

Iterate over the tag directives of a document state object

Parameters:
  • fyds (struct fy_document_state *) – The document state
  • prevp (void **) – The previous iterator

Description

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.

Return

The next tag or NULL at the end of the iteration sequence.

fy_parser_get_document_state

struct fy_document_state *fy_parser_get_document_state(struct fy_parser *fyp)

Get the document state of a parser object

Parameters:
  • fyp (struct fy_parser *) – The parser

Description

Retrieve the document state object of a parser. Note that this is only valid during parsing.

Return

The active document state object of the parser, NULL otherwise

fy_document_get_document_state

struct fy_document_state *fy_document_get_document_state(struct fy_document *fyd)

Get the document state of a document

Parameters:
  • fyd (struct fy_document *) – The document

Description

Retrieve the document state object of a document.

Return

The document state object of the document, NULL otherwise

fy_emitter_get_document_state

struct fy_document_state *fy_emitter_get_document_state(struct fy_emitter *emit)

Get the document state of an emitter object

Parameters:
  • emit (struct fy_emitter *) – The emitter

Description

Retrieve the document state object of an emitter. Note that this is only valid during emitting.

Return

The active document state object of the emitter, NULL otherwise

fy_emit_event_create

struct fy_event *fy_emit_event_create(struct fy_emitter *emit, enum fy_event_type type, ...)

Create an emit event.

Parameters:
  • emit (struct fy_emitter *) – The emitter
  • type (enum fy_event_type) – The event type to create
  • ellipsis (ellipsis) – variable arguments

Description

Create an emit event to pass to fy_emit_event() The extra arguments differ according to the event to be created

FYET_STREAM_START

  • None

FYET_STREAM_END

  • None

FYET_DOCUMENT_START

  • int implicit
    true if document start should be marked implicit false if document start should not be marked implicit
  • const struct fy_version *vers
    Pointer to version to use for the document, or NULL for default
  • const struct fy_tag * const *tags
    Pointer to a NULL terminated array of tag pointers (like argv) NULL if no extra tags are to be used

FYET_DOCUMENT_END

  • int implicit
    true if document end should be marked implicit false if document end should not be marked implicit

FYET_MAPPING_START

  • enum fy_node_style style
    Style of the mapping (one of FYNS_ANY, FYNS_BLOCK or FYNS_FLOW)
  • const char *anchor
    Anchor to place at the mapping, or NULL for none
  • const char *tag
    Tag to place at the mapping, or NULL for none

FYET_MAPPING_END

  • None

FYET_SEQUENCE_START

  • enum fy_node_style style
    Style of the sequence (one of FYNS_ANY, FYNS_BLOCK or FYNS_FLOW)
  • const char *anchor
    Anchor to place at the sequence, or NULL for none
  • const char *tag
    Tag to place at the sequence, or NULL for none

FYET_SEQUENCE_END

  • None

FYET_SCALAR

  • enum fy_scalar_style style
    Style of the scalar, any valid FYSS_* value Note that certain styles may not be used according to the contents of the data
  • const char *value
    Pointer to the scalar contents.
  • size_t len
    Length of the scalar contents, of FY_NT (-1) for strlen(value)
  • const char *anchor
    Anchor to place at the scalar, or NULL for none
  • const char *tag
    Tag to place at the scalar, or NULL for none

FYET_ALIAS

  • const char *value
    Pointer to the alias.

Return

The created event or NULL in case of an error

fy_emit_event_vcreate

struct fy_event *fy_emit_event_vcreate(struct fy_emitter *emit, enum fy_event_type type, va_list ap)

Create an emit event using varargs.

Parameters:
  • emit (struct fy_emitter *) – The emitter
  • type (enum fy_event_type) – The event type to create
  • ap (va_list) – The variable argument list pointer.

Description

Create an emit event to pass to fy_emit_event() The varargs analogous to fy_emit_event_create().

Return

The created event or NULL in case of an error

fy_emit_event_free

void fy_emit_event_free(struct fy_emitter *emit, struct fy_event *fye)

Free an event created via fy_emit_event_create()

Parameters:
  • emit (struct fy_emitter *) – The emitter
  • fye (struct fy_event *) – The event to free

Description

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.

fy_parse_event_create

struct fy_event *fy_parse_event_create(struct fy_parser *fyp, enum fy_event_type type, ...)

Create an emit event.

Parameters:
  • fyp (struct fy_parser *) – The parser
  • type (enum fy_event_type) – The event type to create
  • ellipsis (ellipsis) – variable arguments

Description

See fy_emit_event_create()

Return

The created event or NULL in case of an error

fy_parse_event_vcreate

struct fy_event *fy_parse_event_vcreate(struct fy_parser *fyp, enum fy_event_type type, va_list ap)

Create an emit event using varargs.

Parameters:
  • fyp (struct fy_parser *) – The parser
  • type (enum fy_event_type) – The event type to create
  • ap (va_list) – The variable argument list pointer.

Description

Create an emit event to pass to fy_emit_event() The varargs analogous to fy_parse_event_create().

Return

The created event or NULL in case of an error