LIBFYAML-CORE(3)
๐ LIBFYAML-CORE(3) ๐
okay so this is the libfyaml core API page โ like, the main character of the whole manual set. grab a strawberry drink ๐ and let's get into it.
โจ NAME โจ
libfyaml-core โ the libfyaml core API. that's it, that's the name, she's simple and she knows it ๐
๐ CORE ๐
okay so bestie, listen: this is the single top-level include for the entire libfyaml public API. like, one include and you get everything. including it pulls in all the subsystem headers, no cap:
- Core YAML parser, document tree, emitter, and diagnostics (
libfyaml/libfyaml-core.h) - General-purpose utilities and portability macros (
libfyaml/libfyaml-util.h) - YAML path expression parser and executor (
libfyaml/libfyaml-path-exec.h) - Document builder: event-stream to tree conversion (
libfyaml/libfyaml-docbuild.h) - Document iterator: tree traversal and event replay (
libfyaml/libfyaml-dociter.h) - Composer: callback-driven, path-aware event processing (
libfyaml/libfyaml-composer.h) - Pluggable memory allocators (
libfyaml/libfyaml-allocator.h) - Thread pool for parallel work (
libfyaml/libfyaml-thread.h) - BLAKE3 cryptographic hashing (
libfyaml/libfyaml-blake3.h) - Alignment macros and helpers (
libfyaml/libfyaml-align.h) - Portable endian detection (
libfyaml/libfyaml-endian.h) - Portable atomic operations (
libfyaml/libfyaml-atomics.h) - Variable-length size encoding (
libfyaml/libfyaml-vlsize.h)
but lowkey, for faster compilation you're allowed to include only the subsystem headers you actually need. slay, minimalism ๐ง
and the naming tea โ: all public symbols are prefixed with fy_ (functions/types) or FY_ (macros and constants). iykyk.
๐ YAML PARSER, DOCUMENT AND EMITTER ๐
this header provides the complete YAML 1.2 / JSON parser, document tree, and emitter API โ literally the core of libfyaml. it's the biggest and most-used part of the public interface. main character energy fr fr ๐
three complementary APIs cover the full lifecycle of a YAML document:
Event-based parsing (fy_parser_*) โ a streaming interface, similar to libyaml's. the parser produces a sequence of typed events (stream-start, document-start, scalar, sequence-start, โฆ) without building an in-memory tree. ideal for large documents, filters, and transcoding pipelines. so efficient โจ
Document tree (fy_document_*, fy_node_*) โ builds a fully navigable in-memory tree from a YAML or JSON source. nodes can be queried, modified, merged, and serialised. path-expression helpers (fy_document_scanf(), fy_document_insert_at(), โฆ) give you XPath-like access into the tree ๐ฆ
Emitter (fy_emitter_*) โ serialises documents or raw event streams back to YAML or JSON with full control over formatting style, indentation, and quoting. supports streaming output to files, memory buffers, or user-supplied callbacks ๐ซถ
Diagnostics (fy_diag_*) โ a structured error-reporting subsystem that attributes messages to precise source locations and integrates with IDE/compiler toolchains via a standard file:line:col: level: text format ๐
all types are opaque pointers (struct fy_parser *, struct fy_document *, struct fy_node *, โฆ) so the ABI is stable across minor releases. iconic behaviour honestly ๐
๐ธ struct fy_version ๐ธ
struct fy_version
the YAML version โจ
Definition
struct fy_version {
int major;
int minor;
}
Members
majorโ Major version numberminorโ Major version number ๐ญ (yes bestie, that's what it says โ both of them say "Major". not me questioning the docs, periodt)
Description
the parser fills it according to the %YAML directive found in the document.
๐ fy_version_compare ๐
int fy_version_compare(const struct fy_version *va, const struct fy_version *vb)
compare two yaml versions ๐
Parameters
va(const struct fy_version*) โ The first version, ifNULLuse default versionvb(const struct fy_version*) โ The second version, ifNULLuse default version
Description
compare the versions. that's the whole bit.
Return
0 if versions are equal, > 0 if version va is higher than vb, < 0 if version va is lower than vb.
๐ fy_version_default ๐
const struct fy_version *fy_version_default(void)
get the default version of the library ๐ธ
Parameters
voidโ no arguments
Description
return the default version of the library, i.e. the highest stable version that is supported.
Return
the default YAML version of this library ๐ซถ
๐ฆ fy_version_is_supported ๐ฆ
bool fy_version_is_supported(const struct fy_version *vers)
check if supported version โญ
Parameters
vers(const struct fy_version*) โ The version to check,NULLmeans default version.
Description
check if the given YAML version is supported.
Return
true if version supported, false otherwise.
๐ฅ fy_version_supported_iterate ๐ฅ
const struct fy_version *fy_version_supported_iterate(void **prevp)
iterate over the supported YAML versions ๐
Parameters
prevp(void**) โ The previous version iterator
Description
this method iterates over the supported YAML versions of this ibrary (their typo, not mine, i'm obsessed ๐ญ). 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_shutdown ๐ง
void fy_shutdown(void)
final cleanup before exit ๐
Parameters
voidโ no arguments
Description
some libraries โ cough*libclang*cough โ need explicit cleanup calls at the end of program execution, even if you've never called any of their functions. yes, really. rude, but true ๐
this method will make sure it calls their cleanup functions so that no memory leaks are reported in valgrind etc. doing the emotional labour so you don't have to ๐
๐ 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:"). The parser fills it according to the%TAGdirectives 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 levelFYET_NOTICEโ Notice levelFYET_WARNINGโ Warning levelFYET_ERRORโ Error level - error reporting is using this levelFYET_MAXโ Non inclusive maximumfy_error_typevalue
๐ 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_EMIT,
FYEM_TYPESET,
FYEM_DECODE,
FYEM_ENCODE,
FYEM_REFLECTION,
FYEM_MAX
};
Constants
FYEM_UNKNOWNโ Unknown, default if not specificFYEM_ATOMโ Atom module, used by atom chunkingFYEM_SCANโ Scanner moduleFYEM_PARSEโ Parser moduleFYEM_DOCโ Document moduleFYEM_BUILDโ Build document module (after tree is constructed)FYEM_INTERNALโ Internal error/diagnostic moduleFYEM_SYSTEMโ System error/diagnostic moduleFYEM_EMITโ Emitter moduleFYEM_TYPESETโ Prepare types module (C reflection)FYEM_DECODEโ Decode, serialization -> internal form moduleFYEM_ENCODEโ Encode, internal form -> serialized form moduleFYEM_REFLECTIONโ Generic reflection module messagesFYEM_MAXโ Non inclusive maximumfy_error_modulevalue
โญ 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_DEFAULT_VERSION_AUTO,
FYPCF_DEFAULT_VERSION_1_1,
FYPCF_DEFAULT_VERSION_1_2,
FYPCF_DEFAULT_VERSION_1_3,
FYPCF_SLOPPY_FLOW_INDENTATION,
FYPCF_PREFER_RECURSIVE,
FYPCF_JSON_AUTO,
FYPCF_JSON_NONE,
FYPCF_JSON_FORCE,
FYPCF_YPATH_ALIASES,
FYPCF_ALLOW_DUPLICATE_KEYS
};
Constants
FYPCF_QUIETโ Quiet, do not output any information messagesFYPCF_COLLECT_DIAGโ Collect diagnostic/error messagesFYPCF_RESOLVE_DOCUMENTโ When producing documents, automatically resolve themFYPCF_DISABLE_MMAP_OPTโ Disable mmap optimizationFYPCF_DISABLE_RECYCLINGโ Disable recycling optimizationFYPCF_PARSE_COMMENTSโ Enable parsing of comments (experimental)FYPCF_DISABLE_DEPTH_LIMITโ Disable depth limit check, use with enlarged stackFYPCF_DISABLE_ACCELERATORSโ Disable use of access accelerators (saves memory)FYPCF_DISABLE_BUFFERINGโ Disable use of buffering where possibleFYPCF_DEFAULT_VERSION_AUTOโ Automatically use the most recent version the library supportsFYPCF_DEFAULT_VERSION_1_1โ Default version is YAML 1.1FYPCF_DEFAULT_VERSION_1_2โ Default version is YAML 1.2FYPCF_DEFAULT_VERSION_1_3โ Default version is YAML 1.3 (experimental)FYPCF_SLOPPY_FLOW_INDENTATIONโ Allow sloppy indentation in flow modeFYPCF_PREFER_RECURSIVEโ Prefer recursive algorighms instead of iterative whenever possible (again with the typo, i can't ๐ญ)FYPCF_JSON_AUTOโ Automatically enable JSON mode (when extension is.json)FYPCF_JSON_NONEโ Never enable JSON input modeFYPCF_JSON_FORCEโ Force JSON mode alwaysFYPCF_YPATH_ALIASESโ Enable YPATH aliases modeFYPCF_ALLOW_DUPLICATE_KEYSโ Allow duplicate keys on mappings
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. (and we're stopping right here because the page cuts off โ more coming bestie, don't go anywhere ๐ซถ)
Definition
struct fy_parse_cfg {
const char *search_path;
enum fy_parse_cfg_flags flags;
void *userdata;
struct fy_diag *diag;
}
Members ๐
search_pathโ the search path to use when you're opening files, separated by':'(yes, like$PATH, bestie, same energy)flagsโ the configuration flags, your whole vibe-setting situationuserdataโ an opaque user data pointer, literally does not care what you put in therediagโ optional diagnostic interface to use, if you're feeling observant ๐ฉบ
Description
This is the argument you hand over to the fy_parser_create() method, which is the thing that actually does the parsing of YAML files. So like, this struct is the lil' permission slip your parser gets before it goes off and parses. ๐
๐ enum fy_event_type
enum fy_event_type
Event types, aka the whole cast of characters that can show up while you're parsing.
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, the void, the nothing, the "leave me alone" stateFYET_STREAM_STARTโ stream start event, the opening credits ๐ฌFYET_STREAM_ENDโ stream end event, roll creditsFYET_DOCUMENT_STARTโ document start eventFYET_DOCUMENT_ENDโ document end eventFYET_MAPPING_STARTโ YAML mapping start eventFYET_MAPPING_ENDโ YAML mapping end eventFYET_SEQUENCE_STARTโ YAML sequence start eventFYET_SEQUENCE_ENDโ YAML sequence end eventFYET_SCALARโ YAML scalar eventFYET_ALIASโ YAML alias event
๐ฆ fy_event_type_get_text
const char *fy_event_type_get_text(enum fy_event_type type)
Returns the text of an event type. Give it a type, get a string back, iconic trade.
Parameters
- type (
enum fy_event_type) โ the event type you want the text from
Return
A pointer to a text โ like, for FYET_SCALAR you get "=VAL". Slay. ๐
๐ง enum fy_collection_style
enum fy_collection_style
The collection styles that the parser/emitter supports, i.e. the two aesthetics a collection can serve.
Definition
enum fy_collection_style {
FYCS_ANY,
FYCS_BLOCK,
FYCS_FLOW,
FYCS_MAX
};
Constants
FYCS_ANYโ any collection style. Note: the parser never generates this one โ it just lets the emitter choose ๐FYCS_BLOCKโ block style (not{}[])FYCS_FLOWโ flow style{}[]FYCS_MAXโ marks end of scalar styles
๐ enum fy_scalar_style
enum fy_scalar_style
The scalar styles supported by the parser/emitter โ every way a scalar can dress itself.
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 โ it lets the emitter choose ๐FYSS_PLAINโ plain scalar styleFYSS_SINGLE_QUOTEDโ single quoted styleFYSS_DOUBLE_QUOTEDโ double quoted styleFYSS_LITERALโ YAML literal block styleFYSS_FOLDEDโ YAML folded block styleFYSS_MAXโ marks end of scalar styles
๐ struct fy_event_stream_start_data
struct fy_event_stream_start_data
Stream start event data, the little payload that rides along with a stream start.
Definition
struct fy_event_stream_start_data {
struct fy_token *stream_start;
}
Members
stream_startโ the token that started the stream ๐ซถ
๐ struct fy_event_stream_end_data
struct fy_event_stream_end_data
Stream end event data.
Definition
struct fy_event_stream_end_data {
struct fy_token *stream_end;
}
Members
stream_endโ the token that ended the stream
๐ struct fy_event_document_start_data
struct fy_event_document_start_data
Document start event data (the manpage says "doument", we love a typo queen ๐ญ).
Definition
struct fy_event_document_start_data {
struct fy_token *document_start;
struct fy_document_state *document_state;
bool implicit;
}
Members
document_startโ the token that started the document, orNULLif the document was implicitly starteddocument_stateโ the state of the document (i.e. info about the YAML version and the configured tags)implicitโtrueif the document started implicitly
๐ struct fy_event_document_end_data
struct fy_event_document_end_data
Document end event data (again with the "doument", we stan consistency ๐).
Definition
struct fy_event_document_end_data {
struct fy_token *document_end;
bool implicit;
}
Members
document_endโ the token that ended the document, orNULLif the document was implicitly endedimplicitโtrueif the document ended implicitly
๐ struct fy_event_alias_data
struct fy_event_alias_data
Alias event data.
Definition
struct fy_event_alias_data {
struct fy_token *anchor;
}
Members
anchorโ the anchor token defining this alias. It's giving "I know a guy" energy.
๐ struct fy_event_scalar_data
struct fy_event_scalar_data
Scalar event data.
Definition
struct fy_event_scalar_data {
struct fy_token *anchor;
struct fy_token *tag;
struct fy_token *value;
bool tag_implicit;
}
Members
anchorโ anchor token, orNULLtagโ tag token, orNULLvalueโ scalar value token (this one cannot beNULL, no cap)tag_implicitโtrueif the tag was implicit or explicit
๐ struct fy_event_sequence_start_data
struct fy_event_sequence_start_data
Sequence start event data.
Definition
struct fy_event_sequence_start_data {
struct fy_token *anchor;
struct fy_token *tag;
struct fy_token *sequence_start;
}
Members
anchorโ anchor token, orNULLtagโ tag token, orNULLsequence_startโ sequence start value token, orNULLif the sequence was started implicitly
๐ struct fy_event_sequence_end_data
struct fy_event_sequence_end_data
Sequence end event data.
Definition
struct fy_event_sequence_end_data {
struct fy_token *sequence_end;
}
Members
sequence_endโ the token that ended the sequence, orNULLif the sequence was implicitly ended
๐ struct fy_event_mapping_start_data
struct fy_event_mapping_start_data
Mapping start event data.
Definition
struct fy_event_mapping_start_data {
struct fy_token *anchor;
struct fy_token *tag;
struct fy_token *mapping_start;
}
Members
anchorโ anchor token, orNULLtagโ tag token, orNULLmapping_startโ mapping start value token, orNULLif the mapping was started implicitly
๐ struct fy_event_mapping_end_data
struct fy_event_mapping_end_data
Mapping end event data.
Definition
struct fy_event_mapping_end_data {
struct fy_token *mapping_end;
}
Members
mapping_endโ the token that ended the mapping, orNULLif the mapping was implicitly ended
๐ struct fy_event
struct fy_event
The event generated by the parser โ the main character of this whole section, honestly.
Definition
struct fy_event {
enum fy_event_type type;
union {
struct fy_event_stream_start_data stream_start;
struct fy_event_stream_end_data stream_end;
struct fy_event_document_start_data document_start;
struct fy_event_document_end_data document_end;
struct fy_event_alias_data alias;
struct fy_event_scalar_data scalar;
struct fy_event_sequence_start_data sequence_start;
struct fy_event_sequence_end_data sequence_end;
struct fy_event_mapping_start_data mapping_start;
struct fy_event_mapping_end_data mapping_end;
} ;
}
Members
typeโ type of the event, seeenum fy_event_type{unnamed_union}โ anonymous ๐ปstream_startโ stream start information, valid whenfy_event->typeisenum FYET_STREAM_STARTstream_endโ stream end information, valid whenfy_event->typeisenum FYET_STREAM_ENDdocument_startโ document start information, valid whenfy_event->typeisenum FYET_DOCUMENT_STARTdocument_endโ document end information, valid whenfy_event->typeisenum FYET_DOCUMENT_ENDaliasโ alias information, valid whenfy_event->typeisenum FYET_ALIASscalarโ scalar information, valid whenfy_event->typeisenum FYET_SCALARsequence_startโ sequence start information, valid whenfy_event->typeisenum FYET_SEQUENCE_STARTsequence_endโ sequence end information, valid whenfy_event->typeisenum FYET_SEQUENCE_ENDmapping_startโ mapping start information, valid whenfy_event->typeisenum FYET_MAPPING_STARTmapping_endโ mapping end information, valid whenfy_event->typeisenum FYET_MAPPING_END
Description
The parser generates one of these bad boys on every single call to fy_parser_parse(), and you release it with fy_parser_event_free(). Yes bestie, every call โ that's the whole cycle, don't forget the free or it's a leak situation ๐
โญ enum fy_event_part
enum fy_event_part
Lets you select a specific part of the event, like picking a track off an album.
Definition
enum fy_event_part {
FYEP_VALUE,
FYEP_TAG,
FYEP_ANCHOR
};
Constants
FYEP_VALUEโ the value of the event (the main token) ๐FYEP_TAGโ the tag of the eventFYEP_ANCHORโ the anchor of the event
๐ fy_event_get_type
enum fy_event_type fy_event_get_type(const struct fy_event *fye)
Gets the event's type. Detective behaviour, love that.
Parameters
- fye (
const struct fy_event*) โ the event
Description
Returns the type of the event.
Return
The event type, or FYET_NONE when the event is invalid.
๐ fy_event_data
void *fy_event_data(struct fy_event *fye)
Gets a pointer to the event data.
Parameters
- fye (
struct fy_event*) โ the event
Description
So here's the tea: some languages (cough*golang*cough) really don't like unions, and anonymous unions in particular. Like, they'll literally refuse.
You should not have to use this in other language bindings. It's a workaround, not a lifestyle.
Return
A pointer to the event data structure, or NULL if the event is invalid.
๐ธ fy_library_version
const char *fy_library_version(void)
Returns the library version string. Vibe check on the library itself.
Parameters
voidโ no arguments, she takes nothing ๐
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)
Returns the error type from a string โ hand it a string, get the matching error type back.
Parameters
โฆokay the parameter list is literally where this part of the page cuts off, hold on, next bit picks it right back up ๐ซถ
- str (
const char*) โ the string you want turned into an error type, bestie
Return
The error type if it's greater than or equal to zero, otherwise FYET_MAX (that's the "nope, didn't work" value, no cap) ๐
fy_error_type_to_string
const char *fy_error_type_to_string(enum fy_error_type type)
Turn an error type into a string. Like, giving the enum a little name tag โจ
Parameters
- type (
enum fy_error_type) โ the error type you want converted
Return
The string value of the error type, or the empty string "" on error (yes, literally just an empty string, that's the whole mood) ๐ญ
fy_string_to_error_module
enum fy_error_module fy_string_to_error_module(const char *str)
Give it a string, get back the error module. Reverse uno card ๐
Parameters
- str (
const char*) โ the string to convert to an error module
Return
The error type if it's greater than 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 a 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_event_is_implicit
bool fy_event_is_implicit(struct fy_event *fye)
Vibe check on an event: is it an implicit one or not? ๐
Parameters
- fye (
struct fy_event*) โ a pointer to astruct fy_eventto check
Return
true if the event is an implicit one ๐
fy_document_event_is_implicit
bool fy_document_event_is_implicit(const struct fy_event *fye)
Same vibe check but specifically for a document event ๐ฆ
Parameters
- fye (
const struct fy_event*) โ a pointer to astruct fy_eventto check. It must be either a document start or document end event. Like, that's the assignment, there's no negotiation here ๐ฅ
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. Main character energy, honestly ๐
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(). Slay, and also clean up after yourself ๐
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. It's not toxic, it's just over โจ
Parameters
- fyp (
struct fy_parser*) โ the parser to destroy
Description
Destroy a parser you created earlier via fy_parser_create(). Closure, but make it C ๐ซถ
fy_parser_get_cfg
const struct fy_parse_cfg *fy_parser_get_cfg(struct fy_parser *fyp)
Get the configuration of a parser. Receipts ๐
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 from
Description
Returns 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. Like, you can't just keep holding it forever, that's rude ๐ธ
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. Swapping out the whole personality fr fr ๐
Parameters
- fyp (
struct fy_parser*) โ the parser to replace the diagnostic object of - diag (
struct fy_diag*) โ the parser's new diagnostic object,NULLfor 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. Keep track of your refcounts bestie, that's the whole gig ๐
Return
0 if everything OK, -1 otherwise
fy_parser_reset
int fy_parser_reset(struct fy_parser *fyp)
Reset a parser completely. Fresh start, healed era ๐
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. So even your messiest era is recoverable, iconic honestly.
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 at 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 must be available โ like, don't go moving it mid-parse, that's chaos ๐ญ (the original literally says "the file will must be available", and honestly? same energy)
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-1if0terminated)
Description
Point the parser at the given (NULL terminated) string. Note that while the parser is active the string must not go out of scope. Do not let it wander off, bestie, that's undefined-behaviour territory ๐
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. Handing over the keys ๐๏ธ
Parameters
- fyp (
struct fy_parser*) โ the parser - str (
char*) โ the YAML string to parse (allocated) - len (
size_t) โ the length of the string (or-1if0terminated)
Description
Point the parser at 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 โ cute little memory-management situationship ๐
In case of an error the string is not freed. So if it errors, that malloc is still yours to deal with, no take-backs ๐ซ
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*) โ theFILEpointer, it must be open in read mode
Description
Point the parser to use fp for processing. Read mode only, we're not out here writing files by accident ๐
Return
Zero on success, -1 on error
fy_parser_set_input_callback
int fy_parser_set_input_callback(struct fy_parser *fyp, void *user, ssize_t (*callback)(void *user, void *buf, size_t count))
Set the parser to process via a callback. Very "you call me, I call you" of it ๐
Parameters
- fyp (
struct fy_parser*) โ the parser - user (
void*) โ the user data pointer - callback (
ssize_t (*)(void *user, void *buf, size_t count)) โ the callback method to request data with
Description
Point the parser to use a callback for input.
Return
Zero on success, -1 on error
fy_parser_set_input_fd
int fy_parser_set_input_fd(struct fy_parser *fyp, int fd)
Set the parser to process the given file descriptor ๐ข
Parameters
- fyp (
struct fy_parser*) โ the parser - fd (
int) โ the file descriptor to use
Description
Point the parser to use fd 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. The moment we've all been waiting for โญ
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(). Like, every event you take, you give back, that's the rule ๐ค
Return
The next event in the stream, or NULL
fy_parser_parse_peek
const struct fy_event *fy_parser_parse_peek(struct fy_parser *fyp)
Parse and peek at the next event. Looking respectfully ๐
Parameters
- fyp (
struct fy_parser*) โ the parser
Description
It will return the next event that a call to fy_parser_parse would generate, but as read-only.
You must not free this event. Look, don't touch, don't free ๐ โโ๏ธ
Return
A peek at the next event in the stream, or NULL
fy_parser_skip
int fy_parser_skip(struct fy_parser *fyp)
Skip the current scalar/collection. Leaving it on read, moving on ๐จ
Parameters
- fyp (
struct fy_parser*) โ the parser
Description
Skips the current scalar or collection.
Return
0 on success, -1 on error
fy_parser_count_sequence_items
int fy_parser_count_sequence_items(struct fy_parser *fyp)
Count the sequence items ๐ขโจ
Parameters
- fyp (
struct fy_parser*) โ the parser
Description
Counts the number of sequence items. The parser must already be in a sequence state. Note that this uses backtracking so it might not be very efficient โ it's giving "doing the most", honestly ๐ซ
Return
The number of sequence items on success, -1 on error. Note: if the number of items exceeds INT_MAX, INT_MAX will be returned. (Yes, it just caps out and doesn't tell you, iykyk ๐)
fy_parser_count_mapping_items
int fy_parser_count_mapping_items(struct fy_parser *fyp)
Count the mapping items ๐บ๏ธ
Parameters
- fyp (
struct fy_parser*) โ the parser
Description
Counts the number of mapping items. The parser must already be in a mapping state. Note that this uses backtracking so it might not be very efficient โ same energy as the sequence one, it's out here re-walking everything ๐ฎโ๐จ
Return
The number of mapping items on success, -1 on error. Note: if the number of items exceeds INT_MAX, INT_MAX will be returned.
fy_parser_event_free
void fy_parser_event_free(struct fy_parser *fyp, struct fy_event *fye)
Free an event. The little cleanup ritual ๐งน
Parameters
- fyp (
struct fy_parser*) โ the parser - fye (
struct fy_event*) โ the event to free (may beNULL)
Description
Free a previously returned event from fy_parser_parse(). Give it back to the universe ๐ซ
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_parser_get_mode
enum fy_parser_mode fy_parser_get_mode(struct fy_parser *fyp)
Get the parser mode ๐๏ธ
So like, real quick before we keep going โ this stretch is all about the parser's little diary entries (logs and reports) plus the token besties that hold all the text, styles, and comments. Buckle up, we're going in. ๐
the parser mode getter (yes, this one) โจ
Parameters
fyp(struct fy_parser *) โ the parser, obviously.
Description
Grab the parser's current mode, i.e. which YAML version / format it's chewing through rn โ YAML 1.1, 1.2, 1.3, or JSON. Iconic little identity check, no cap.
Return
The parser mode. Periodt.
fy_parser_vlog ๐ซถ
void fy_parser_vlog(struct fy_parser *fyp, enum fy_error_type type,
const char *fmt, va_list ap)
Log using the parser's diagnostics, printf style, but with the va_arg flavour.
Parameters
fyp(struct fy_parser *) โ the parser.type(enum fy_error_type) โ the error type.fmt(const char *) โ the printf format string.ap(va_list) โ the argument list.
Description
Drops a log entry onto the parser's diagnostic output. Lowkey the va_list sibling of fy_parser_log, iykyk.
fy_parser_log ๐ธ
void fy_parser_log(struct fy_parser *fyp, enum fy_error_type type,
const char *fmt, ...)
Log using the parser's diagnostics, printf style.
Parameters
fyp(struct fy_parser *) โ the parser.type(enum fy_error_type) โ the error type.fmt(const char *) โ the printf format string.ellipsis(ellipsis) โ the extra arguments.
Description
Outputs a report on the parser's diagnostics. Same vibe as fy_parser_vlog, just the variadic main-character version ๐
fy_parser_vreport ๐ฅ
void fy_parser_vreport(struct fy_parser *fyp, enum fy_error_type type,
struct fy_token *fyt, const char *fmt, va_list ap)
Report using the parser's diagnostics, printf style, and mark the token โ va_arg edition.
Parameters
fyp(struct fy_parser *) โ the parser.type(enum fy_error_type) โ the error type.fyt(struct fy_token *) โ the token.fmt(const char *) โ the printf format string.ap(va_list) โ the argument list.
Description
Outputs a report on the parser and points at the token's position while doing it. It's giving "here's the problem, and here's exactly where ๐".
fy_parser_report โญ
void fy_parser_report(struct fy_parser *fyp, enum fy_error_type type,
struct fy_token *fyt, const char *fmt, ...)
Report using the parser's diagnostics, printf style, and mark the token.
Parameters
fyp(struct fy_parser *) โ the parser.type(enum fy_error_type) โ the error type.fyt(struct fy_token *) โ the token.fmt(const char *) โ the printf format string.ellipsis(ellipsis) โ the extra arguments.
Description
Outputs a report on the parser and indicates the token's position. Fr the variadic twin of fy_parser_vreport ๐
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 whose style we're getting. Note: aNULLtoken counts asenum FYSS_PLAIN.
Return
The scalar style of the token, or FYSS_PLAIN in every other case. Soft launch, no drama ๐
fy_token_collection_style ๐
enum fy_collection_style fy_token_collection_style(struct fy_token *fyt)
Get the style of a collection token.
Parameters
fyt(struct fy_token *) โ the collection token whose style we're getting. Note: aNULLtoken counts asenum FYCS_ANY.
Return
The collection style of the token, or FYCS_ANY.
fy_token_scalar_is_null ๐
bool fy_token_scalar_is_null(struct fy_token *fyt)
Test whether the scalar is null (as in, its content).
Parameters
fyt(struct fy_token *) โ the scalar token to check for NULLity.
Description
Okay important distinction, bestie โ this is not the same as null in the YAML type system. It's null as in null content. It's also different from an empty scalar. Three different things, three different vibes. Don't mix them up ๐ญ
Return
true if it's a null scalar, false otherwise.
fy_token_get_text ๐
const char *fy_token_get_text(struct fy_token *fyt, size_t *lenp)
Get the text (and its length) of a token.
Parameters
fyt(struct fy_token *) โ the token whose text pointer you want back.lenp(size_t *) โ pointer to a variable that will hold the returned length.
Description
Returns a pointer to the token's text along with its length. Heads up: this text is not NULL terminated โ if you need a NULL terminated pointer, use fy_token_get_text0() instead.
If the token is "simple" enough (like a plain scalar) or something similar, the returned pointer is a direct pointer into the input space that holds the token. Which means the pointer is not guaranteed to be valid after the parser is destroyed ๐
If the token is "complex" enough, then space gets allocated, filled, and returned.
And yeah, the concept of "simple" vs "complex" is vague โ that's on purpose. We said what we said ๐ซถ
Return
A pointer to the text representation of the token, while lenp gets 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 whose text pointer you want back.
Description
Returns a pointer to the token's text, and this time it is zero terminated. It allocates memory to hold it inside the token structure โ so try to use fy_token_get_text() instead if you can, bestie. Your allocator will thank you ๐
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 the length of the text of a token.
Parameters
fyt(struct fy_token *) โ the token.
Description
Returns the length of the token's text representation. That's it, that's the whole job โจ
Return
The size of the text representation of a token, -1 in case of an error. Note that a NULL token returns a length of zero.
enum fy_comment_placement ๐ฌ
Comment placement relative to the token.
Definition
enum fy_comment_placement {
fycp_top,
fycp_right,
fycp_bottom
};
Constants
fycp_topโ comment on top of the token.fycp_rightโ comment to the right of the token.fycp_bottomโ comment to the bottom of the token.
Three directions, three moods, all valid ๐ธ
fy_token_get_comment ๐ผ
const char *fy_token_get_comment(struct fy_token *fyt,
enum fy_comment_placement which)
Get the zero-terminated comment of a token.
Parameters
fyt(struct fy_token *) โ the token whose comment text you want back.which(enum fy_comment_placement) โ the comment placement.
Description
Grabs the comment attached to a token at the given placement. Very "which one, bestie, top, right, or bottom?" energy.
Return
A pointer to a zero-terminated text representation of the token comment. NULL in case of an error or if the token has no comment.
fy_token_get_comments ๐ง
const char *fy_token_get_comments(struct fy_token *fyt)
Get all the comments of a token.
Parameters
fyt(struct fy_token *) โ the token.
Description
Gets every comment attached to a token. All of them. The whole collection โจ
Return
A pointer to a zero-terminated text representation of all the comments โ the comments from all the placements get concatenated and returned as one. NULL in case of an error or if the event has no comments.
fy_token_set_comment ๐
int fy_token_set_comment(struct fy_token *fyt, enum fy_comment_placement which,
const char *text, size_t len)
Attach a comment to a token.
Parameters
fyt(struct fy_token *) โ the token the comment text gets attached to.which(enum fy_comment_placement) โ the placement.text(const char *) โ the text of the comment.len(size_t) โ the length of the comment (FY_NTmeans the length oftext).
Description
Attaches the given comment onto the token at the specified placement. If another comment is already sitting there, it gets overridden โ no warning, no sorry, just replaced. And if text is NULL, the comment is removed entirely ๐ซง
Return
0 on success, -1 on failure.
fy_event_get_comments ๐
const char *fy_event_get_comments(struct fy_event *fye)
Get all the comments of an event.
Parameters
fye(struct fy_event *) โ the event.
Return
A pointer to a zero-terminated text representation of all the comments โ all placements concatenated into one. NULL in case of an error or if the event has no comments.
Careful, bestie: the pointer must be freed if it's notNULL, via a call tofree(). Don't leave it hanging ๐ญ
fy_node_get_comment ๐ท
const char *fy_node_get_comment(struct fy_node *fyn,
enum fy_comment_placement which)
Get a comment of a node.
Parameters
fyn(struct fy_node *) โ the node.which(enum fy_comment_placement) โ the placement of the comment.
Return
A pointer to a zero-terminated text representation of the comment. NULL in case of an error or if the event has no such comments.
fy_node_get_comments ๐ป
const char *fy_node_get_comments(struct fy_node *fyn)
Get all the comments of a node.
Parameters
fyn(struct fy_node *) โ the node.
Return
A pointer to a zero-terminated text representation of all the comments โ every placement concatenated and returned as one. NULL in case of an error or if the event has no comments.
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. Like little bite-sized pieces of the thing you're walking through ๐ฐ
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, orNULL.
Description
Creates an iterator for operating on the given token โ or, if you hand it NULL, a generic iterator for use with fy_token_iter_start(). The iterator must be destroyed with a matching call to fy_token_iter_destroy(). No ghost iterators, bestie ๐ป
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
Destroys the iterator created by fy_token_iter_create(). Clean up after yourself, it's the least you can do ๐
fy_token_iter_start
void fy_token_iter_start(struct fy_token *fyt, struct fy_token_iter *iter)
Ok so bestie, this one starts the whole iteration vibe over the contents of a token. ๐
Parameters
fyt(*struct fy_token**) โ the token you're gonna iterate over, the main character of this operationiter(*struct fy_token_iter**) โ the iterator you're prepping for the journey
Description
It sets up an iterator so it's ready to operate on the given token. Important little detail: the iterator has to have been created by a previous call to fy_token_iter_create() if you want user level API access. No shortcutting that, iykyk. โจ
fy_token_iter_finish
void fy_token_iter_finish(struct fy_token_iter *iter)
The graceful exit. Stops iterating over the contents of a token โ closing time, lights off. ๐
Parameters
iter(*struct fy_token_iter**) โ the iterator in question
Description
Stops the iteration operation. That's it, that's the whole thing. Periodt.
fy_token_iter_peek_chunk
const struct fy_iter_chunk *fy_token_iter_peek_chunk(struct fy_token_iter *iter)
A little looky-loo ๐ at the next iterator chunk โ no commitment, just peeking.
Parameters
iter(*struct fy_token_iter**) โ the iterator
Description
Peeks at the next iterator chunk. That's the assignment, and it ate.
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)
Gets the next chunk in the sequence โ like scrolling to the next slide in the deck. ๐ฆ
Parameters
iter(*struct fy_token_iter**) โ the iteratorcurr(*const struct fy_iter_chunk**) โ the current chunk, orNULLfor the first oneerrp(*int**) โ pointer to an error return value, orNULL
Description
Gets the next iterator chunk in sequence. Lowkey straightforward, highkey essential.
Return
A pointer to the next iterator chunk, or NULL in case there's no other. And heads up: when the return value is NULL, the errp variable gets filled with 0 for a normal end, or -1 in case of an error. Big distinction, don't sleep on it. ๐
fy_token_iter_advance
void fy_token_iter_advance(struct fy_token_iter *iter, size_t len)
Moves the iterator position forward like you're skipping ahead in a group chat. โญ
Parameters
iter(*struct fy_token_iter**) โ the iteratorlen(size_t*) โ the number of bytes to advance the iterator position
Description
It advances the read pointer of the iterator. But listen: 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. Not a cute look, don't do it. ๐ญ
fy_token_iter_read
ssize_t fy_token_iter_read(struct fy_token_iter *iter, void *buf, size_t count)
Reads a whole block from an iterator โ the "give me a handful" option. ๐
Parameters
iter(*struct fy_token_iter**) โ the iteratorbuf(*void**) โ pointer to a block of memory to receive the data; it must be at leastcountbytes longcount(size_t*) โ the amount of bytes to read
Description
Reads a block from an iterator. And same warning as before: mixing calls of this with any of the ungetc methods leads to undefined behavior. Fr fr, keep them separate.
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)
One singular character, please and thank you. ๐
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. And if any calls to ungetc have pushed a character into the iterator, it shall return that one instead.
Return
The next character in the iterator, or -1 in case of an error, or end of stream. Very demure, very mindful.
fy_token_iter_ungetc
int fy_token_iter_ungetc(struct fy_token_iter *iter, int c)
The pushback move โ putting a character back like you never took it. ๐
Parameters
iter(*struct fy_token_iter**) โ the iteratorc(int*) โ the character to push back, or-1to reset the pushback buffer
Description
Pushes back a single character to an iterator stream, and 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. One at a time, bestie, we're not made of buffer space. ๐
Return
The pushed back character given as argument, or -1 in case of an error. And a lil plot twist: 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 a single character like checking who's typing before you reply. ๐
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 into the iterator, it shall return that. Key detail: the character is not removed from the iterator stream. It stays. Iconic behavior, honestly.
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)
Same energy as getc but โจmultibyteโจ โ getting a single utf8 character. ๐
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 into 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)
The utf8 pushback โ putting a whole character back into the stream. ๐ง
Parameters
iter(*struct fy_token_iter**) โ the iteratorc(int*) โ the character to push back, or-1to 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. Same rule as the byte version, no cap.
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)
Peeking, but make it utf8. ๐
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 into the iterator, it shall return that. And again โ 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)
Parses the next document off the parser stream โ the actual main event. ๐ฅ
Parameters
fyp(*struct fy_parser**) โ the parser
Description
This method performs parsing on a parser stream and returns the next document. Which means for a compound document with multiple documents, each call will return the next one. Like flipping to the next page, one at a time. ๐
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)
Cleans up a document that came from fy_parse_load_document(). Closure, babes. ๐
Parameters
fyp(*struct fy_parser**) โ the parserfyd(*struct fy_document**) โ the document to destroy
fy_document_resolve
int fy_document_resolve(struct fy_document *fyd)
Resolves anchors and merge keys โ tying up all the loose ends. โจ
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 (<<). Very "make it make sense" of it.
Return
zero on success, -1 on error.
fy_document_has_directives
bool fy_document_has_directives(const struct fy_document *fyd)
A lil vibe check for directives. ๐
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)
Checking if the document rolled up with an explicit start marker. ๐
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 the 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)
And now the end-marker equivalent โ the "that's a wrap" 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 the document has an explicit document end marker, false if not.
fy_node_document
struct fy_document *fy_node_document(struct fy_node *fyn)
Retrieves the document that the node belongs to โ finding the node's home base. ๐
Parameters
fyn(*struct fy_node**) โ the node to retrieve its 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 a member of a document. So don't count it out just because you can't path your way there. ๐ซ
Return
The document of the node, or NULL in case of an error, or when the node has no document attached.
enum fy_emitter_write_type
enum fy_emitter_write_type
Type of the emitted output โ and yes, this is exactly where things keep going, don't go anywhere. ๐
Definition
okay so this is the enum that tags every little chunk the emitter spits out โ like each fragment gets a name badge so you know exactly what it is โจ
enum fy_emitter_write_type {
fyewt_document_indicator,
fyewt_tag_directive,
fyewt_version_directive,
fyewt_indent,
fyewt_indicator,
fyewt_whitespace,
fyewt_plain_scalar,
fyewt_single_quoted_scalar,
fyewt_double_quoted_scalar,
fyewt_literal_scalar,
fyewt_folded_scalar,
fyewt_anchor,
fyewt_tag,
fyewt_linebreak,
fyewt_alias,
fyewt_terminating_zero,
fyewt_plain_scalar_key,
fyewt_single_quoted_scalar_key,
fyewt_double_quoted_scalar_key,
fyewt_comment,
fyewt_indicator_question_mark,
fyewt_indicator_colon,
fyewt_indicator_dash,
fyewt_indicator_left_bracket,
fyewt_indicator_right_bracket,
fyewt_indicator_left_brace,
fyewt_indicator_right_brace,
fyewt_indicator_comma,
fyewt_indicator_bar,
fyewt_indicator_greater,
fyewt_indicator_single_quote_start,
fyewt_indicator_single_quote_end,
fyewt_indicator_double_quote_start,
fyewt_indicator_double_quote_end,
fyewt_indicator_ambersand,
fyewt_indicator_star,
fyewt_indicator_chomp,
fyewt_indicator_explicit_indent
};
๐ง Constants
so here's the whole cast, one by one ๐
fyewt_document_indicatorโ this chunk is a document indicator.fyewt_tag_directiveโ this chunk is a tag directive.fyewt_version_directiveโ this chunk is a version directive.fyewt_indentโ the manpage literally says "Output chunk is a document indicator" here too ๐ญ yes bestie, same sentence as above, I'm not making the rules, I'm just telling you what it says.fyewt_indicatorโ this chunk is an indicator.fyewt_whitespaceโ this chunk is white space.fyewt_plain_scalarโ this chunk is a plain scalar.fyewt_single_quoted_scalarโ this chunk is a single quoted scalar.fyewt_double_quoted_scalarโ this chunk is a double quoted scalar.fyewt_literal_scalarโ this chunk is a literal block scalar.fyewt_folded_scalarโ this chunk is a folded block scalar.fyewt_anchorโ this chunk is an anchor.fyewt_tagโ this chunk is a tag.fyewt_linebreakโ this chunk is a linebreak.fyewt_aliasโ this chunk is an alias.fyewt_terminating_zeroโ this chunk is a terminating zero.fyewt_plain_scalar_keyโ this chunk is a plain scalar key.fyewt_single_quoted_scalar_keyโ this chunk is a single quoted scalar key.fyewt_double_quoted_scalar_keyโ this chunk is a double quoted scalar key.fyewt_commentโ this chunk is a comment.fyewt_indicator_question_markโ the?indicator.fyewt_indicator_colonโ the:indicator.fyewt_indicator_dashโ the-indicator.fyewt_indicator_left_bracketโ the[indicator.fyewt_indicator_right_bracketโ the]indicator.fyewt_indicator_left_braceโ the{indicator.fyewt_indicator_right_braceโ the}indicator.fyewt_indicator_commaโ the,indicator.fyewt_indicator_barโ the|indicator.fyewt_indicator_greaterโ the>indicator.fyewt_indicator_single_quote_startโ theโindicator.fyewt_indicator_single_quote_endโ theโindicator.fyewt_indicator_double_quote_startโ theโindicator.fyewt_indicator_double_quote_endโ theโindicator.fyewt_indicator_ambersandโ the&indicator. (yes, "ambersand", that's how it's spelled here, love that for us ๐)fyewt_indicator_starโ the*indicator.fyewt_indicator_chompโ the chomp indicator (-or+).fyewt_indicator_explicit_indentโ the explicit indent indicator (0-9).
Description
it tells you the kind of emitted output, which means you can colorize the output, or do some other content related filtering. so cute, so useful, no cap ๐
๐ฆ enum fy_emitter_cfg_flags
enum fy_emitter_cfg_flags โ the emitter configuration flags, aka the big pile of switches that decides how your YAML comes out the other side.
Definition
enum fy_emitter_cfg_flags {
FYECF_SORT_KEYS,
FYECF_OUTPUT_COMMENTS,
FYECF_STRIP_LABELS,
FYECF_STRIP_TAGS,
FYECF_STRIP_DOC,
FYECF_NO_ENDING_NEWLINE,
FYECF_STRIP_EMPTY_KV,
FYECF_EXTENDED_CFG,
FYECF_INDENT_DEFAULT,
FYECF_INDENT_1,
FYECF_INDENT_2,
FYECF_INDENT_3,
FYECF_INDENT_4,
FYECF_INDENT_5,
FYECF_INDENT_6,
FYECF_INDENT_7,
FYECF_INDENT_8,
FYECF_INDENT_9,
FYECF_WIDTH_DEFAULT,
FYECF_WIDTH_80,
FYECF_WIDTH_132,
FYECF_WIDTH_INF,
FYECF_MODE_ORIGINAL,
FYECF_MODE_BLOCK,
FYECF_MODE_FLOW,
FYECF_MODE_FLOW_ONELINE,
FYECF_MODE_JSON,
FYECF_MODE_JSON_TP,
FYECF_MODE_JSON_ONELINE,
FYECF_MODE_DEJSON,
FYECF_MODE_PRETTY,
FYECF_MODE_MANUAL,
FYECF_MODE_FLOW_COMPACT,
FYECF_MODE_JSON_COMPACT,
FYECF_DOC_START_MARK_AUTO,
FYECF_DOC_START_MARK_OFF,
FYECF_DOC_START_MARK_ON,
FYECF_DOC_END_MARK_AUTO,
FYECF_DOC_END_MARK_OFF,
FYECF_DOC_END_MARK_ON,
FYECF_VERSION_DIR_AUTO,
FYECF_VERSION_DIR_OFF,
FYECF_VERSION_DIR_ON,
FYECF_TAG_DIR_AUTO,
FYECF_TAG_DIR_OFF,
FYECF_TAG_DIR_ON,
FYECF_DEFAULT
};
โจ Constants
FYECF_SORT_KEYSโ sort keys when emitting.FYECF_OUTPUT_COMMENTSโ output comments (experimental, bestie, so don't come for me if it's quirky ๐).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_NO_ENDING_NEWLINEโ don't output the ending new line (super handy for single line mode).FYECF_STRIP_EMPTY_KVโ remove all keys with empty values from the output. heads up: not available in streaming mode ๐ซถFYECF_EXTENDED_CFGโ extend the configuration; this config structure gets embedded in afy_emitter_xcfg.FYECF_INDENT_DEFAULTโ default emit output indent.FYECF_INDENT_1โ output indent is1.FYECF_INDENT_2โ output indent is2.FYECF_INDENT_3โ output indent is3.FYECF_INDENT_4โ output indent is4.FYECF_INDENT_5โ output indent is5.FYECF_INDENT_6โ output indent is6.FYECF_INDENT_7โ output indent is7.FYECF_INDENT_8โ output indent is8.FYECF_INDENT_9โ output indent is9.FYECF_WIDTH_DEFAULTโ default emit output width.FYECF_WIDTH_80โ output width is80.FYECF_WIDTH_132โ output width is132.FYECF_WIDTH_INFโ output width is infinite (no wrapping, live ur truth ๐).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, all 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_MODE_PRETTYโ emit YAML that tries to look good ๐ .FYECF_MODE_MANUALโ emit YAML respecting all manual style hints (reformats if needed).FYECF_MODE_FLOW_COMPACTโ emit using only the flow mode, in as much as possible compact form.FYECF_MODE_JSON_COMPACTโ emit using JSON compact form.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. that's the whole vibe, they're the knobs, you turn them, things change ๐๏ธ
๐ซถ 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
this is the argument to the fy_emitter_create() method, which is literally the way to convert a runtime document structure back to YAML. icon behavior only ๐โจ
๐ธ enum fy_emitter_xcfg_flags
enum fy_emitter_xcfg_flags โ emitter extended configuration flags. yes there's a whole extra layer, she's extra like that ๐
Definition
enum fy_emitter_xcfg_flags {
FYEXCF_COLOR_AUTO,
FYEXCF_COLOR_NONE,
FYEXCF_COLOR_FORCE,
FYEXCF_OUTPUT_STDOUT,
FYEXCF_OUTPUT_STDERR,
FYEXCF_OUTPUT_FILE,
FYEXCF_OUTPUT_FD,
FYEXCF_NULL_OUTPUT,
FYEXCF_OUTPUT_FILENAME,
FYEXCF_VISIBLE_WS,
FYEXCF_EXTENDED_INDICATORS,
FYEXCF_INDENTED_SEQ_IN_MAP,
FYEXCF_PRESERVE_FLOW_LAYOUT
};
๐ Constants
FYEXCF_COLOR_AUTOโ automatically colorize if on a terminal.FYEXCF_COLOR_NONEโ do not colorize output.FYEXCF_COLOR_FORCEโ force color generation (yes even when you're piping it, she said what she said ๐ฅ).FYEXCF_OUTPUT_STDOUTโ output tostdout(this is the default).FYEXCF_OUTPUT_STDERRโ output tostderr, instead ofstdout.FYEXCF_OUTPUT_FILEโ output to thefpFILEpointer.FYEXCF_OUTPUT_FDโ output to thefdfile descriptor.FYEXCF_NULL_OUTPUTโ no output.FYEXCF_OUTPUT_FILENAMEโ output to the given filename.FYEXCF_VISIBLE_WSโ make white space visible ๐ (yes, the invisible becomes visible, spooky season)FYEXCF_EXTENDED_INDICATORSโ extends the indicators that get generated ๐ซFYEXCF_INDENTED_SEQ_IN_MAPโ indents block sequences that are mapping values (yes bestie, the pretty version) ๐FYEXCF_PRESERVE_FLOW_LAYOUTโ preserves oneline flow collections when you're in streaming mode ๐
Description
These flags are literally the remote control for how the emitter behaves. If no extended configuration mode is enabled, all the flags are assumed 0. No mode, no flags, no drama. ๐
struct fy_emitter_xcfg
struct fy_emitter_xcfg โ the emitter's extended configuration structure. It's giving "main character struct" energy fr fr ๐
Definition
struct fy_emitter_xcfg {
struct fy_emitter_cfg cfg;
enum fy_emitter_xcfg_flags xflags;
const char *colors[FYEWT_COUNT];
union {
FILE *output_fp;
int output_fd;
const char *output_filename;
} ;
}
Members
cfgโ the standard emitter configuration, the og setup ๐ซถxflagsโ the extra configuration flags, aka the spicy add-ons ๐ถ๏ธcolorsโ ANSI color overrides for the default output method ๐{unnamed_union}โ anonymous (she has no name, mysterious icon behavior ๐)output_fpโ the outputFILE *;FYEXCF_FILE_OUTPUTmust be set or it's not happeningoutput_fdโ the output file descriptor;FYEXCF_FD_OUTPUTmust be setoutput_filenameโ the output filename;FYEXCF_FILENAME_OUTPUTmust be set
Description
This is what you pass as the argument to the emitter create when the FYECF_EXTENDED_CFG bit is set. That's the whole vibe. โจ
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 config you handed it. Like, it makes the emitter. That's the tweet. ๐ฆ
Return
The newly created emitter, or NULL on error. If you get NULL, something went wrong, no cap ๐ญ
fy_emitter_destroy
void fy_emitter_destroy(struct fy_emitter *emit)
Destroy an emitter ๐
Parameters
emit(*struct fy_emitter**) โ the emitter to destroy
Description
Destroys an emitter that was previously created by fy_emitter_create(). Cleanup era, we love to see it ๐งน
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. That's it, that's the whole function ๐ซถ
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 from
Description
Returns 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. Like please don't just ghost it, that's a leak bestie ๐ญ
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 ondiag(*struct fy_diag**) โ the emitter's new diagnostic object;NULLfor default
Description
Swaps out the emitter's current diagnostic object for the one you pass in. 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 โ everybody's holding refs, it's a whole group chat ๐
Return
0 if everything's OK, -1 otherwise.
fy_emitter_set_finalizer
void fy_emitter_set_finalizer(struct fy_emitter *emit, void (*finalizer)(struct fy_emitter *emit))
Set emitter finalizer ๐ฌ
Parameters
emit(*struct fy_emitter**) โ the emitter to replace the diagnostic object onfinalizer(void (*)(struct fy_emitter *emit)) โ the finalizer callback
Description
Sets a method callback that gets called when the emitter is disposed of. If finalizer is NULL, then the method is removed. Ghosted, gone, no more callback ๐ซฅ
struct fy_emitter_default_output_data
struct fy_emitter_default_output_data โ the emitter's default output configuration, the starter pack of output settings ๐
Definition
struct fy_emitter_default_output_data {
FILE *fp;
bool colorize;
bool visible;
}
Members
fpโ the file where the output is directed to ๐colorizeโ use ANSI color sequences to colorize the output ๐visibleโ make whitespace visible (requires a UTF8 capable terminal, so check before you commit bestie) ๐
Description
This is the argument to the default output method of the emitter. That's its whole job ๐ซก
fy_emitter_default_output
int fy_emitter_default_output(struct fy_emitter *fye, enum fy_emitter_write_type type, const char *str, int len, void *userdata)
The default colorizing output method ๐๐
Parameters
fye(*struct fy_emitter**) โ the emittertype(enum fy_emitter_write_type) โ the type of the emitted outputstr(*const char**) โ pointer to the string to outputlen(int) โ length of the stringuserdata(*void**) โ must point to afy_emitter_default_output_datastructure
Description
This is the default colorizing output method. It will be used when the output field of the emitter configuration is NULL. Default behavior, but make it fashion โจ
Return
0 on success, -1 on error.
fy_document_default_emit_to_fp
int fy_document_default_emit_to_fp(struct fy_document *fyd, FILE *fp)
Emit a document to a file, using defaults ๐โก๏ธ๐
Parameters
fyd(*struct fy_document**) โ the document to emitfp(*FILE**) โ the file where the output is sent
Description
Simple one-shot emitter to a file, using the default emitter output. The output will be colorized if the file points to a tty. Cute AND functional ๐
Return
0 on success, -1 on error.
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 usefye(*struct fy_event**) โ the event to queue for emission
Description
Queues and outputs using the emitter. This is the streaming output method, which does not require creating a document. No document, no problem ๐
Return
0 on success, -1 on error.
fy_emit_vevent
int fy_emit_vevent(struct fy_emitter *emit, enum fy_event_type type, va_list ap)
Queue (and possibly emit) an event using varargs ๐
Parameters
emit(*struct fy_emitter**) โ the emitter to usetype(enum fy_event_type) โ the event type to createap(va_list) โ the variable argument list pointer
Description
Queues and outputs using the emitter. The format is identical to the one used in fy_emit_event_vcreate(). Same format, different entry point, iykyk ๐ซถ
Return
0 on success, -1 on error.
fy_emit_eventf
int fy_emit_eventf(struct fy_emitter *emit, enum fy_event_type type, ...)
Queue (and possibly emit) an event using variable args โจ
Parameters
emit(*struct fy_emitter**) โ the emitter to usetype(enum fy_event_type) โ the event type to createellipsis(ellipsis) โ the optional extra arguments
Description
Queues and outputs using the emitter. The format is identical to the one used in fy_emit_event_create(). Yes it's basically the same description, they're siblings, let them live ๐
Return
0 on success, -1 on error.
fy_emit_scalar_write
int fy_emit_scalar_write(struct fy_emitter *fye, enum fy_scalar_style style, const char *anchor, const char *tag, const char *buf, size_t count)
Emit a scalar with write semantics โ๏ธ
Parameters
fye(*struct fy_emitter**) โ the emitter to usestyle(enum fy_scalar_style) โ the scalar style to useanchor(*const char**) โ the anchor, orNULLtag(*const char**) โ the tag, orNULLbuf(*const char**) โ pointer to the buffercount(size_t) โ the number of bytes to write
Description
Queues and outputs a scalar using the emitter, via a standard write interface. Bytes go in, YAML comes out ๐ธ
Return
0 on success, -1 on error.
fy_emit_scalar_vprintf
int fy_emit_scalar_vprintf(struct fy_emitter *fye, enum fy_scalar_style style, const char *anchor, const char *tag, const char *fmt, va_list ap)
Emit a scalar with vprintf semantics ๐จ๏ธ
Parameters
fye(*struct fy_emitter**) โ the emitter to usestyle(enum fy_scalar_style) โ the scalar style to useanchor(*const char**) โ the anchor, orNULLtag(*const char**) โ the tag, orNULLfmt(*const char**) โ the printf-like format stringap(va_list) โ the argument list
Description
Queues and outputs a scalar using the emitter, via a standard vprintf interface. Format strings but make it YAML ๐
Return
0 on success, -1 on error.
fy_emit_scalar_printf
int fy_emit_scalar_printf(struct fy_emitter *fye, enum fy_scalar_style style, const char *anchor, const char *tag, const char *fmt, ...)
Emit a scalar with printf semantics ๐ฅ
Parameters
fye(*struct fy_emitter**) โ the emitter to usestyle(enum fy_scalar_style) โ the scalar style to useanchor(*const char**) โ the anchor, orNULLtag(*const char**) โ the tag, orNULLfmt(*const char**) โ the printf-like format stringellipsis(ellipsis) โ the extra arguments
Description
Queues and outputs a scalar using the emitter, via a standard printf interface. The people's champion of scalar emission ๐
Return
0 on success, -1 on error.
fy_emit_event_from_parser
int fy_emit_event_from_parser(struct fy_emitter *emit, struct fy_parser *fyp, struct fy_event *fye)
Queue (and possibly emit) an event generated by the parser ๐
Parameters
emit(*struct fy_emitter**) โ the emitter to usefyp(*struct fy_parser**) โ the parser that generated the eventfye(*struct fy_event**) โ the event to queue for emission
Description
Queues and outputs using the emitter. This is the streaming output method, which does not require creating a document. Similar to fy_emit_event() but it is more efficient. Same energy, better performance, we stan ๐
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 emitterfyd(*struct fy_document**) โ the document to emit
Description
Emits a document in YAML format using the emitter. Whole document, one call, slay ๐
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 a document start using the emitter โจ
Parameters
emit(struct fy_emitter*) โ the emitterfyd(struct fy_document*) โ the document to pull its start from for emittingfyn(struct fy_node*) โ the root, orNULLif you want to just use the document's root
Description
Drops a document start through the emitter. Bestie, this is the one you reach for when you need finer control over the emitting output โ like, when you're hand-driving the whole thing instead of letting the library do it. ๐
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
Drops a document end through the emitter. Same deal as above: this exists so you get 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 emitterfyn(struct fy_node*) โ the node to emit
Description
Emits one single node through the emitter. Again โ finer control over the emitting output is the entire point, iykyk. โจ
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 emitterfyn(struct fy_node*) โ the root node to emit
Description
Emits a single root node through the emitter. Main character energy only โ and yes, it's for when you need finer control over the emitting output. ๐
Return
0 on success, -1 on error
fy_emit_body_node
int fy_emit_body_node(struct fy_emitter *emit, struct fy_node *fyn)
Emit a single body node using the emitter ๐ซถ
Parameters
emit(struct fy_emitter*) โ the emitterfyn(struct fy_node*) โ the body node to emit
Description
Emits a single body node through the emitter, for finer control over the emitting output. Important vibe check though: no stream and document events will be generated at all. Like, none. Zero. Not a single one. ๐ญ
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. ... โ yes, literally the three dots, that's the whole flex. Use this if you need finer control over the emitting output. (Also, tiny thing, the original docs say "if you you need" and I'm choosing to believe that was a stylistic choice. Anyway. ๐
)
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 a file pointer ๐
Parameters
fyd(struct fy_document*) โ the document to emitflags(enum fy_emitter_cfg_flags) โ the emitter flags to usefp(FILE*) โ the file pointer to output to
Description
Emits a document, starting from the root, straight out to the file pointer you handed it. ๐ค
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 a file ๐
Parameters
fyd(struct fy_document*) โ the document to emitflags(enum fy_emitter_cfg_flags) โ the emitter flags to usefilename(const char*) โ the filename to output to, orNULLfor stdout
Description
Emits a document, from the root, to the file you named. Heads up: the file gets fopen'ed using a "wa" mode. ๐๏ธ
Return
0 on success, -1 on error
fy_emit_document_to_fd
int fy_emit_document_to_fd(struct fy_document *fyd, enum fy_emitter_cfg_flags flags, int fd)
Emit a document to a file descriptor ๐
Parameters
fyd(struct fy_document*) โ the document to emitflags(enum fy_emitter_cfg_flags) โ the emitter flags to usefd(int) โ the file descriptor to output to
Description
Emits a document, from the root, to the file descriptor you gave it. ๐ง
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, size_t size)
Emit a document to a buffer ๐
Parameters
fyd(struct fy_document*) โ the document to emitflags(enum fy_emitter_cfg_flags) โ the emitter flags to usebuf(char*) โ pointer to the buffer area to fillsize(size_t) โ size of the buffer
Description
Emits a document, from the root, into the buffer you provided. And ngl, if the document doesn't fit? an error will be returned. So size it right, bestie. ๐ญ
Return
A positive number โ the size of the emitted document sitting in 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 emitflags(enum fy_emitter_cfg_flags) โ the emitter flags to use
Description
Emits a document, from the root, into a string which gets dynamically allocated for you. ๐ฆ
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, size_t size)
Emit a node (recursively) to a buffer ๐
Parameters
fyn(struct fy_node*) โ the node to emitflags(enum fy_emitter_cfg_flags) โ the emitter flags to usebuf(char*) โ pointer to the buffer area to fillsize(size_t) โ size of the buffer
Description
Emits a node recursively into the buffer you gave it. And again, if it doesn't fit, an error will be returned โ no silent truncation, no drama, just an error. ๐
Return
A positive number โ the size of the emitted node in 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 emitflags(enum fy_emitter_cfg_flags) โ the emitter flags to use
Description
Emits a node recursively into a string which will be dynamically allocated. Obsessed, honestly. ๐
Return
A pointer to the allocated string, or NULL in case of an error
fy_emit_to_buffer
struct fy_emitter *fy_emit_to_buffer(enum fy_emitter_cfg_flags flags, char *buf, size_t size)
Create an emitter for buffer output ๐ฅ
Parameters
flags(enum fy_emitter_cfg_flags) โ the emitter flags to usebuf(char*) โ pointer to the buffer area to fillsize(size_t) โ size of the buffer
Description
Creates a special purpose emitter that outputs into a buffer. Your fy_emit_event() calls populate that buffer, and then you go grab the contents with a call to fy_emit_to_buffer_collect(). ๐ซถ
Return
The newly created emitter, or NULL on error
fy_emit_to_buffer_collect
char *fy_emit_to_buffer_collect(struct fy_emitter *emit, size_t *sizep)
Collect the buffer emitter output ๐งบ
Parameters
emit(struct fy_emitter*) โ the emittersizep(size_t*) โ pointer to the size to be filled
Description
Collects the output of an emitter that was created by fy_emit_to_buffer() and then populated via fy_emit_event() calls. The returned buffer is NULL terminated, and it's the same one you passed into fy_emit_to_buffer() โ no surprise copy, no plot twist. The sizep argument gets filled with the size of the buffer. โจ
Return
The buffer, or NULL in case of an error
fy_emit_to_string
struct fy_emitter *fy_emit_to_string(enum fy_emitter_cfg_flags flags)
Create an emitter to create a dynamically allocated string ๐ซ
Parameters
flags(enum fy_emitter_cfg_flags) โ the emitter flags to use
Description
Creates a special purpose emitter that outputs into a dynamically allocated string. Your fy_emit_event() calls populate the buffer, and you retrieve the contents with a call to fy_emit_to_string_collect(). ๐
Return
The newly created emitter, or NULL on error
fy_emit_to_string_collect
char *fy_emit_to_string_collect(struct fy_emitter *emit, size_t *sizep)
Collect the string emitter output ๐
Parameters
emit(struct fy_emitter*) โ the emittersizep(size_t*) โ pointer to the size to be filled
Description
Collects the output of an emitter created by fy_emit_to_string() and populated using fy_emit_event() calls. The NULL terminated returned buffer is dynamically allocated and must be freed via a call to free(). Ma'am, free your memory. The sizep argument gets filled with the size of the buffer. ๐
Return
The dynamically 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 withfyn_from(struct fy_node*) โ the source node to recursively copy
Description
Makes a deep copy of a node and associates that copy with the document you passed in. And here's the slay part: no content copying takes place because the contents of the nodes are reference counted โ so this operation is relatively inexpensive. Literally so cheap. ๐ธ
Also worth flagging: the copy includes all anchors contained in the subtree of the source, so this call will register them with the document. Don't say I didn't warn you. ๐ธ
Return
The copied node on success, NULL on error
fy_document_clone
struct fy_document *fy_document_clone(struct fy_document *fydsrc)
Clones a document ๐
Parameters
fydsrc(struct fy_document*) โ the source document to clone
Description
okay so cloning a document is giving deep copy of the source, bestie. ๐ซถ And the cute part? No content copying takes place, because the contents of the nodes are reference counted. That means the operation is relatively inexpensive. Slay. ๐
Return
The newly created clone document, or NULL in case of an 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_node_delete
int fy_node_delete(struct fy_node *fyn)
Delete a node from a document.
Parameters
fyn(struct fy_node*) โ the node to delete.
Description
Delete the given node. If itโs part of a sequence, it will be removed from it. If itโs the value of a node key value pair, it will be removed from the mapping.
This is literally an alias for fy_document_insert_at(fyn, NULL). ๐
Note that it is expected this node is attached to a document. Do not call this to free a node, because if itโs part of a collection it will not be properly removed. Thatโs a no-no, bestie. ๐ซ
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-1if โ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. fr fr.
Return
0 on success, -1 on error.
๐ข 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. No cap. โจ
๐จ 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. Obsessed with the aesthetic control here. ๐
๐ถ 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_PTR_YPATH,
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_PTR_YPATHโ YPATH 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.
๐งฎ typedef 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.
๐ typedef 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. periodt. ๐
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, orNULLfor the default.sort_fn_arg(void*) โ the extra user supplied argument to thesort_fn.cmp_fn(fy_node_scalar_compare_fn) โ the method to use for comparing scalars, orNULLfor the default.cmp_fn_arg(void*) โ the extra user supplied argument to thecmp_fn.
Description
Compare two nodes for equality using user supplied sot and scalar compare methods. Yes, thatโs literally sot, bestie โ not me, the page said it. ๐ 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-1if โ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_node_compare_token
bool fy_node_compare_token(struct fy_node *fyn, struct fy_token *fyt)
Compare a node for equality against a token.
Parameters
fyn(struct fy_node*) โ the node to use in the comparison.fyt(struct fy_token*) โ the scalar token.
So basically this one does an equality check between a node and a token โ and listen, both of them have to be scalars, no exceptions, no vibes-based exceptions ๐
Return โ true if the node and the token are equal. That's it, that's the whole reward.
fy_node_compare_text
bool fy_node_compare_text(struct fy_node *fyn, const char *text, size_t len)
Compare a node for equality with a raw C text โจ
Parameters
fyn(struct fy_node *) โ the node you're putting in the comparisontext(const char *) โ the raw C text you're comparing againstlen(size_t) โ how long that text is (or-1if it's0terminated)
Description
Compares a node for equality with a raw C string. Soft requirement, hard requirement: the node must be a scalar. That's non-negotiable bestie ๐
Return
true if the node and the text are equal. Iconic behaviour, no notes.
fy_document_create
struct fy_document *fy_document_create(const struct fy_parse_cfg *cfg)
Create an empty document ๐ซถ a blank canvas, a fresh start, main character energy
Parameters
cfg(const struct fy_parse_cfg *) โ the parse configuration to use, orNULLfor the default
Description
Makes you an empty document using whatever parser configuration you handed over. If it's NULL, it just uses the default parse configuration. Lowkey the easiest call in the whole library.
Return
The freshly 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
Destroys a document โ and yes, along with all children documents. It's giving "take the whole friend group with you." Handle with care, bestie.
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. Slay, now you know what rules it's playing by.
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 from
Description
Returns a pointer to the diagnostic object of a document object. Important, don't skip this: the returned diag object has a reference taken, so you should fy_diag_unref() it when you're done with it. Not me reminding you to clean up โ okay yes, it's literally me reminding you ๐
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 whose diagnostic object gets replaceddiag(struct fy_diag *) โ the document's new diagnostic object,NULLfor default
Description
Swaps the document's current diagnostic object out for the one you passed in. The previous diagnostic object gets unref'ed (and freed if its reference count hits 0). Also note that the diag argument shall take a reference too โ yes, it's a whole two-way reference situation, keep up ๐ซถ
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 ๐ found family arc
Parameters
fyd(struct fy_document *) โ the parent documentfyd_child(struct fy_document *) โ the child document
Description
Sets the parent of the fyd_child document to be fyd. Simple as that.
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, orNULLfor the defaultstr(const char *) โ the YAML source to uselen(size_t) โ the length of the string (or-1if0terminated)
Description
Creates a document by parsing the string you gave it as a YAML source. Feed it text, get a document. Iconic.
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, orNULLfor the defaultstr(char *) โ the YAML source to uselen(size_t) โ the length of the string (or-1if0terminated)
Description
Creates a document by parsing the provided string as a YAML source. The twist: the string is expected to have been allocated by malloc(3), and when the document is destroyed it will be automatically freed. So like, don't go freeing it yourself afterward, that's not the vibe ๐ซถ
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, orNULLfor the defaultfile(const char *) โ the name of the file to parse
Description
Creates a document by parsing the provided file as a YAML source. File girlies, this one's for you.
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, orNULLfor the defaultfp(FILE *) โ the file pointer
Description
Creates a document by parsing the provided file pointer as a YAML source. Same energy as the file one, except you're already holding the FILE *.
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, orNULLfor the defaultfmt(const char *) โ the format string creating the YAML source to useap(va_list) โ theva_listargument pointer
Description
Creates a document by parsing the provided string as a YAML source โ except the string is created by applying vprintf formatting. Format string in, YAML document out, no cap.
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, orNULLfor the defaultfmt(const char *) โ the format string creating the YAML source to useellipsis(ellipsis) โ the printf arguments
Description
Creates a document by parsing the provided string as a YAML source, where the string is created by applying printf formatting. Yes it's the va_list one's louder sibling.
Return
The created document, or NULL on error.
fy_flow_document_build_from_string
struct fy_document *fy_flow_document_build_from_string(const struct fy_parse_cfg *cfg, const char *str, size_t len, size_t *consumed)
Create a document using the provided YAML source ๐ธ
Parameters
cfg(const struct fy_parse_cfg *) โ the parse configuration to use, orNULLfor the defaultstr(const char *) โ the YAML source to uselen(size_t) โ the length of the string (or-1if0terminated)consumed(size_t *) โ a pointer to the consumed amount
Description
Creates a document by parsing the provided string as a YAML source.
The document is a flow document, i.e. it does not contain any block content and is usually laid out in a single line.
Example of flow documents
plain-scalar โdouble-quoted-scalarโ โsingle-quoted-scalarโ { foo: bar } [ 0, 1, 2 ]
A flow document matters because parsing stops at the end of it, which means you can drop one inside other non-yaml content. That's the whole point, iykyk ๐ซถ
Return
The created document, or NULL on error.
fy_block_document_build_from_string
struct fy_document *fy_block_document_build_from_string(const struct fy_parse_cfg *cfg, const char *str, size_t len, size_t *consumed)
Create a document using the provided YAML source ๐ฆ
Parameters
cfg(const struct fy_parse_cfg *) โ the parse configuration to use, orNULLfor the defaultstr(const char *) โ the YAML source to uselen(size_t) โ the length of the string (or-1if0terminated)consumed(size_t *) โ a pointer to the consumed amount
Description
Creates a document by parsing the provided string as a YAML source.
The document is a block document, and it terminates when indentation appears to do so. Indentation is basically the vibe check here ๐
Example of block documents:
this-is-yaml
foo: bar <- starts here
baz: [1, 2]
this-is-yaml-no-more
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. Empty document, no root, no main character โ tragic but correct.
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 documentfyn(struct fy_node *) โ the new root of the document
Description
Sets the root of a document. If the document wasn't empty, the old root will be freed โ so don't come crying to me holding a stale pointer, bestie ๐ญ 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
Retrieves the node type. It is one of FYNT_SCALAR, FYNT_SEQUENCE or FYNT_MAPPING. And a fun little detail: a NULL node argument is a FYNT_SCALAR. Yes really, NULL counts as a scalar. That's the rule ๐
Return
The node type.
๐
fy_node_get_style
enum fy_node_style fy_node_get_style(struct fy_node *fyn);
Bestie, this one just tells you how a node likes to be rendered โจ โ like, what's its whole aesthetic.
Parameters
fyn(struct fy_node *) โ the node in question ๐
Description
Gets the node rendering style. And okay, plot twist: if the node is NULL then the style comes back as FYNS_PLAIN. So even a nothing node has a vibe, iconic.
Return
The node style ๐
๐ฆ fy_node_set_style
enum fy_node_style fy_node_set_style(struct fy_node *fyn, enum fy_node_style style);
Makeover time โ you're requesting a new look for a node ๐ .
Parameters
fyn(struct fy_node *) โ the nodestyle(enum fy_node_style) โ the requested node rendering style
Description
Tries to set the node rendering style. Notice the "tries" โ because if the style is illegal for that node (classic example: you literally can't set an arbitrary scalar that contains zeroes to plain), then whatever style actually got set is what comes back at you. No cap, the function tells you the truth ๐.
Return
The final node style โ as in, the one that actually stuck ๐ฅ
๐ง fy_node_get_start_token
struct fy_token *fy_node_get_start_token(struct fy_node *fyn);
Grabs the node's start token, like the opening credits of the node's whole era โญ.
Parameters
fyn(struct fy_node *) โ the node
Description
Retrieves the node start token. And for scalars? This is the exact same thing as the end token. Same token, different nickname, iykyk.
Return
The node start token ๐
๐ fy_node_get_end_token
struct fy_token *fy_node_get_end_token(struct fy_node *fyn);
The mirror image bestie โ the end token ๐ธ.
Parameters
fyn(struct fy_node *) โ the node
Description
Retrieves the node end token. For scalars, this is the same as the start token. (Yeah, we just said that, it's a vibe both ways.)
Return
The node end token ๐
โจ fy_node_is_scalar
bool fy_node_is_scalar(struct fy_node *fyn);
Parameters
fyn(struct fy_node *) โ the node
Description
A little convenience method that checks whether a node is a scalar. That's it, that's the whole thing ๐ซถ.
Return
true if the node is a scalar, false otherwise
๐ fy_node_is_sequence
bool fy_node_is_sequence(struct fy_node *fyn);
Parameters
fyn(struct fy_node *) โ the node
Description
Convenience method for checking whether a node is a sequence. Short, sweet, slays.
Return
true if the node is a sequence, false otherwise
๐ซ fy_node_is_mapping
bool fy_node_is_mapping(struct fy_node *fyn);
Parameters
fyn(struct fy_node *) โ the node
Description
Convenience method for checking whether a node is a mapping. Okay so it's giving "one job, does it well" ๐ .
Return
true if the node is a mapping, false otherwise
๐ fy_node_is_alias
bool fy_node_is_alias(struct fy_node *fyn);
Parameters
fyn(struct fy_node *) โ the node
Description
Convenience method for checking whether a node is an alias. (Aliases are lowkey the main characters of YAML, ngl.)
Return
true if the node is an alias, false otherwise
๐ซง fy_node_is_null
bool fy_node_is_null(struct fy_node *fyn);
Parameters
fyn(struct fy_node *) โ the node
Description
Convenience method for checking whether a node is a NULL scalar. And here's the cute little gotcha: a NULL node argument returns trueโฆ yes, really ๐.
Return
true if the node is a NULL scalar, false otherwise
๐งท fy_node_is_attached
bool fy_node_is_attached(struct fy_node *fyn);
Parameters
fyn(struct fy_node *) โ the node
Description
Checks whether a node is attached in a document structure. Real talk: an attached node may not be freed before being detached, so don't even try it ๐. And yes, there is no method that explicitly detaches a node โ that's handled internally by the sequence and mapping removal methods, so it's giving "the library handles it, stay out of it" energy.
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);
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. If it doesn't exist, no drama, you get nothing back.
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);
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. And heads up bestie: aliases are scalars, so if you call this on an alias node, what you get back shall be an alias token ๐. Plot twist handled.
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);
Parameters
fyn(struct fy_node *) โ the alias node to be resolved
Description
Resolves an alias node, following any subsequent aliases until a non-alias node has been found. Basically chasing the chain until someone's actually real ๐ฆ. This call performs cycle detection and excessive redirections checks, so it's totally safe to call in any context. No infinite loop jump scare, we promise.
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);
Parameters
fyn(struct fy_node *) โ the alias node to be dereferenced
Description
Dereferences an alias node. And this is different from resolution, bestie โ this one only performs a single alias follow call, and it will fail if the input is not an alias. One hop only, no chain-chasing ๐. It also 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);
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. Full cleanup, no crumbs ๐ .
But โ this method will return an error if the node is attached, or if it's not NULL and it isn't a member of a document. So, like, don't free attached nodes, we literally warned you ๐.
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 documentstr(const char *) โ the YAML source to uselen(size_t) โ the length of the string (or-1if'0'terminated)
Description
Creates a node by 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);
Same energy as above, except the string came from malloc and the library takes ownership of it ๐
.
Parameters
fyd(struct fy_document *) โ the documentstr(char *) โ the YAML source to uselen(size_t) โ the length of the string (or-1if'0'terminated)
Description
Creates a node by parsing the provided string as a YAML source, and the node created will be associated with the provided document. Key detail: the string is expected to have been allocated by malloc(3), and when the document is destroyed it will be automatically freed ๐ซถ. So don't go freeing it yourself afterward, that's double-free territory, bestie.
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);
Parameters
fyd(struct fy_document *) โ the documentfile(const char *) โ the name of the file to parse
Description
Creates a node by 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);
Parameters
fyd(struct fy_document *) โ the documentfp(FILE *) โ the file pointer
Description
Creates a node by 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 documentfmt(const char *) โ the format string creating the YAML source to useap(va_list) โ theva_listargument pointer
Description
Creates a node by parsing the resulting string as a YAML source. The string is created by applying vprintf formatting. Format-string girlies, this one's for you ๐.
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 documentfmt(const char *) โ the format string creating the YAML source to useellipsis(ellipsis) โ theprintfarguments
Description
Creates a node by parsing the resulting string as a YAML source. The string is created by applying printf formatting โ the comfy varargs version, no va_list required ๐ซถ.
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 operationpath(const char *) โ the path spec to use in the traversal operationlen(size_t) โ the length of the path (or-1if'0'terminated)flags(enum fy_node_walk_flags) โ the extra path walk flags
No return value documented in this part โ the page continues from here, so stay tuned bestie ๐
Okay so this method pulls up a node relative to the one you hand it, using the path spec you give it. ๐
Path specs are just keys stitched together with slashes /. Keys are either regular YAML expressions in flow format (for walking mappings) or indexes in brackets (for walking sequences). A path spec can start with /, and that leading slash is silently ignored. โจ
A few examples make it click:
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
Heads up: 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 itโs 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: Grab the given nodeโs path address relative to the document root, bestie. This address is dynamically allocated, so free it 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 in 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_document_parent โจ
struct fy_node *fy_node_get_document_parent(struct fy_node *fyn)
Get the document parent node of a node
Parameters:
fyn(*struct fy_node**) โ The node
Description: Get the document parent node of a node. The document parent differs from the regular parent in that a keyโs root node of a mapping is not NULL; instead it points to the actual node parent. ๐
Return: The nodeโs document parent, or NULL if fyn is the root.
โจ 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, so free it 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 its 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, so free it 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 its parent. If no such parent is found, it returns the absolute path from the start of the document. ๐ฆ
Example:
--- &foo
foo: &bar
bar
baz
- The short path of
/foois\*foo - The short path of
/foo/baris\*bar - The short path of
/bazis\*foo/baz
The address is dynamically allocated, so free it 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, so free it 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 nodefyn(*struct fy_node**) โ The node
Description: Retrieve the given nodeโs textual reference as generated using another parent (or grandparent) 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, so free it 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 nodefyn(*struct fy_node**) โ The node
Description: Create a relative alias node reference using another parent (or grandparent) 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 withdata(*const char**) โ Pointer to the data areasize(*size_t**) โ Size of the data area, or(size_t)-1for'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 withdata(*const char**) โ Pointer to the data areasize(*size_t**) โ Size of the data area, or(size_t)-1for'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 withfmt(*const char**) โ The printf based format stringap(*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 withfmt(*const char**) โ The printf based format stringellipsis(*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. That's the vibe check for the previous function โ success hands you a node, failure hands you NULL, periodt.
๐ fy_node_set_tag ๐
int fy_node_set_tag(struct fy_node *fyn, const char *data, size_t len)
Okay so bestie, this one manually sets the tag of a node.
Parameters
fyn(struct fy_node*) โ the node to set itโs tag. Yes, that apostrophe is in the original, weโre keeping the energy.data(const char*) โ pointer to the tag data.len(size_t) โ size of the tag data, or(size_t)-1for'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. No cap, that buffer has to stay alive as long as the node does.
If the node already contains a tag it will be overwriten.
Return
0 on success, -1 on error.
๐ fy_node_remove_tag ๐
int fy_node_remove_tag(struct fy_node *fyn)
Removes the tag from a node. Poof, gone, no tag era.
Parameters
fyn(struct fy_node*) โ the node to remove itโs tag.
Description
Remove the tag of a node.
Return
0 on success, -1 on error.
๐ฆ fy_node_get_tag ๐ฆ
const char *fy_node_get_tag(struct fy_node *fyn, size_t *lenp)
Gets you a pointer to the tag text, plus the length. Lowkey important: this text is not NULL terminated.
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_tag0 ๐ธ
const char *fy_node_get_tag0(struct fy_node *fyn)
Same tag-getting mission, but this one is NULL terminated. Very demure, very convenient.
Parameters
fyn(struct fy_node*) โ the node.
Description
This method will return a pointer to the text of a tag, which will be NULL terminated.
Return
A pointer to the null terminated tag of the node. A NULL will be returned in case of an error.
โจ fy_node_get_tag_length โจ
size_t fy_node_get_tag_length(struct fy_node *fyn)
Just the length of the nodeโs tag. If thereโs no tag, itโs giving 0.
Parameters
fyn(struct fy_node*) โ the tagged node.
Description
This method will return the size of the tag of the node. If the node is not tagged it will return 0.
Return
The size of the tag, or 0 if node is not tagged.
๐ fy_node_get_scalar ๐
const char *fy_node_get_scalar(struct fy_node *fyn, size_t *lenp)
Gets the scalar content of a node, with length. Heads up bestie: this pointer is not NULL terminated.
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)
Same scalar energy, but returns a NULL terminated string. Plot twist: it allocates memory to make that happen.
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 is returned in case of an error.
๐ง fy_node_get_scalar_length ๐ง
size_t fy_node_get_scalar_length(struct fy_node *fyn)
The size of the scalar content. Not a scalar? Then itโs 0, no drama.
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)
Same size check, but counted in utf8 characters. If itโs not a scalar, you get 0.
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)
Iterates over all the item nodes in a sequence node. Start of the iteration is signalled by a NULL in *prevp.
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)
Same as above but backwards. Main character energy: entering the sequence from the end.
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)
Gets the item count of the sequence. If somethingโs wrong, you get -1.
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)
Checks whether the sequence contains items. Thatโs what the description says, bestie.
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)
Grabs a sequence item by index. Positive or zero counts from the start, negative counts from the end โ so -1 is literally the last item.
Parameters
fyn(struct fy_node*) โ the sequence node.index(int) โ the index of the node to retrieve.>= 0counting from the start< 0counting 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)
Appends a node item to a sequence. Adding to the end, very last-slot-of-the-group-chat energy.
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)
The original one-liner says โAppend a node item to a sequenceโ โ yes, really โ but the description is prepend. Weโre keeping both because fidelity is the moment.
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)
Inserts a node item before another one in the sequence. Itโs giving โexcuse me, Iโm cutting the line.โ
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)
Same insert situation, but after the mark instead of before.
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)
Removes an item from a sequence and returns it. You get the node back โ take it, itโs yours.
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.
๐ typedef fy_node_sequence_sort_fn ๐
int fy_node_sequence_sort_fn(struct fy_node *fyn_a, struct fy_node *fyn_b, void *arg)
The comparison method used when sorting a sequence. It returns less-than/equal/greater-than vibes.
Parameters
fyn_a(struct fy_node*) โ the first node used in the comparison.fyn_b(struct fy_node*) โ the second node used in the comparison.arg(void*) โ the opaque user provided pointer to the sort operation.
Return
< 0iffyn_ais less thanfyn_b0iffyn_ais equal tofyn_b> 0iffyn_ais greater thanfyn_b
โจ fy_node_sequence_sort โจ
int fy_node_sequence_sort(struct fy_node *fyn_seq, fy_node_sequence_sort_fn cmp, void *arg)
Sorts a sequenceโs items using your comparison method. Put it in order, bestie.
Parameters
fyn_seq(struct fy_node*) โ the sequence node to sort.cmp(fy_node_sequence_sort_fn) โ the comparison method.arg(void*) โ an opaque user pointer for the comparison method.
Description
Sort the items of a sequence node using the given comparison method.
Return
0 on success, -1 on error.
๐ง fy_node_mapping_iterate ๐ง
struct fy_node_pair *fy_node_mapping_iterate(struct fy_node *fyn, void **prevp)
Iterate over a mapping node. Thatโs the brief โ this part of the page stops right here, so no params are listed yet.
fyn(struct fy_node*) โ the mapping node ๐prevp(void**) โ the previous sequence iterator (yeah, it literally says sequence on a mapping function โ not me, that's the source ๐ญ)
Description
okay so this one iterates over, like, all the node pairs in the mapping node. The start of the iteration is signalled by a NULL in *prevp โ that's your little green flag to begin โจ
note that while a mapping is an unordered collection of key/values, the order of which they are created is important for presentation purposes. periodt.
Return
The next node pair in the mapping, or NULL at the end of the mapping. iykyk ๐
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 โ walking backwards like it's a comeback era ๐
Parameters
fyn(struct fy_node*) โ the mapping nodeprevp(void**) โ the previous sequence iterator (again with the "sequence", we stay unbothered ๐ซถ)
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.
same energy as before: while a mapping is an unordered collection of key/values, the order of which they are created is important for presentation purposes. no cap.
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 โ literally just counting, bestie ๐ข
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. (yes, -1 is the "something went wrong" vibe check ๐ฉ)
fy_node_mapping_is_empty
bool fy_node_mapping_is_empty(struct fy_node *fyn)
Check whether the mapping is empty โ the "is this group chat dead" check ๐
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 โ pick your fave by number ๐ฏ
Parameters
fyn(struct fy_node*) โ the mapping nodeindex(int) โ the index of the node pair to retrieve>= 0counting from the start< 0counting 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. main character behaviour, honestly ๐
Return
The node pair at the specified index, or NULL if no such item exist.
fy_node_mapping_lookup_pair_by_string
struct fy_node_pair *fy_node_mapping_lookup_pair_by_string(struct fy_node *fyn, const char *key, size_t len)
Lookup a node pair in mapping by string ๐
Parameters
fyn(struct fy_node*) โ the mapping nodekey(const char*) โ the YAML source to use as keylen(size_t) โ the length of the key (or-1if'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 fy_node_compare().
Return
The value matching the given key, or NULL if not found. ๐
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 โ yes, the name says "lookup" and the summary says "value", we're just built different ๐ฆ
Parameters
fyn(struct fy_node*) โ the mapping nodekey(const char*) โ the YAML source to use as keylen(size_t) โ the length of the key (or-1if'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_value_by_string
struct fy_node *fy_node_mapping_lookup_value_by_string(struct fy_node *fyn, const char *key, size_t len)
Lookup a node value in mapping by string โ the explicit version, for the girlies who like to be very clear about their intentions ๐
Parameters
fyn(struct fy_node*) โ the mapping nodekey(const char*) โ the YAML source to use as keylen(size_t) โ the length of the key (or-1if'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().
It is synonymous with fy_node_mapping_lookup_by_string(). literally the same girl, different name โจ
Return
The value matching the given key, or NULL if not found.
fy_node_mapping_lookup_key_by_string
struct fy_node *fy_node_mapping_lookup_key_by_string(struct fy_node *fyn, const char *key, size_t len)
Lookup a node key in mapping by string โ the flip side, we want the key itself this time ๐
Parameters
fyn(struct fy_node*) โ the mapping nodekey(const char*) โ the YAML source to use as keylen(size_t) โ the length of the key (or-1if'0'terminated)
Description
This method will return the key of node pair that contains the same key from the YAML node created from the key argument. The comparison of the node is using fy_node_compare().
Return
The key 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 โ no YAML parsing arc, we're keeping it simple ๐ง
Parameters
fyn(struct fy_node*) โ the mapping nodekey(const char*) โ the string to use as keylen(size_t) โ the length of the key (or-1if'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 โ same simplicity, but gimme the value ๐
Parameters
fyn(struct fy_node*) โ the mapping nodekey(const char*) โ the string to use as keylen(size_t) โ the length of the key (or-1if'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_pair_by_null_key
struct fy_node_pair *fy_node_mapping_lookup_pair_by_null_key(struct fy_node *fyn)
Lookup a node pair in mapping that has a NULL key โ the chaotic one ๐ซ
Parameters
fyn(struct fy_node*) โ the mapping node
Description
This method will return the node pair that has a NULL key. Note this method is not using the mapping accelerator and arguably NULL keys should not exist. Alasโฆ
"Alasโฆ" is doing so much emotional labour in that sentence and honestly? felt ๐ญ
Return
The node pair with a NULL key, NULL otherwise.
fy_node_mapping_lookup_value_by_null_key
struct fy_node *fy_node_mapping_lookup_value_by_null_key(struct fy_node *fyn)
Lookup a node value with a NULL key. bestie we're in the void now ๐
Parameters
fyn(struct fy_node*) โ the mapping node
Description
Return the value of a node pair that has a NULL key.
Return
The value matching the null key, NULL otherwise. Note that the value may be NULL too, but for that pathological case use the node pair method instead. ๐
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 โ we're going straight for the raw scalar contents now โจ
Parameters
fyn(struct fy_node*) โ the mapping nodelenp(size_t*) โ pointer to a variable that will hold the returned lengthkey(const char*) โ the string to use as keykeylen(size_t) โ the length of the key (or-1if'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 โ the one with the NUL happily attached ๐
Parameters
fyn(struct fy_node*) โ the mapping nodekey(const char*) โ the string to use as keykeylen(size_t) โ the length of the key (or-1if'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 โ you bring your own node as the key, we love a self-sufficient queen ๐
Parameters
fyn(struct fy_node*) โ the mapping nodefyn_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's value matching the provided key โ node-in, value-out, the classic trade ๐ฅ
Parameters
fyn(struct fy_node*) โ the mapping nodefyn_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. so it goes deep, recursively, until it finds its match โ obsessed ๐
Return: The node value matching the given key, or NULL if not found. ๐ซถ
๐ธ fy_node_mapping_lookup_key_by_key ๐ธ
struct fy_node *fy_node_mapping_lookup_key_by_key(struct fy_node *fyn, struct fy_node *fyn_key)
Parameters
fyn(struct fy_node*) โ The mapping nodefyn_key(struct fy_node*) โ The node to use as key
Description Okay so this one hunts down the node pair that matches the fyn_key you hand it. The key can be a collection, and a content-match check gets performed recursively to find the right key. Recursive key matching is giving main character energy fr.
Return The node key 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)
Parameters
fyn(struct fy_node*) โ The mapping nodefynp(const struct fy_node_pair*) โ The node pair
Description Returns the node pair index in the mapping for the node pair you passed in. If it canโt find it, you get -1, no cap. ๐
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)
Parameters
fynp(struct fy_node_pair*) โ The node pair
Description Grabs the node pairโs key. Heads up bestie: this can be NULL, and it also returns NULL when the node pair argument itself is NULL, so protect against that case. ๐ซถ
Return The node pair key
๐ฆ fy_node_pair_value ๐ฆ
struct fy_node *fy_node_pair_value(struct fy_node_pair *fynp)
Parameters
fynp(struct fy_node_pair*) โ The node pair
Description Grabs the node pairโs value. Same warning as its key twin: this may be NULL, and itโs also returned when the node pair argument is NULL, so please protect against that 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)
Parameters
fynp(struct fy_node_pair*) โ The node pairfyn(struct fy_node*) โ The key node
Description Sets the key part of the node pair. It overwrites any previous key. Note that no checks for duplicate keys are going to be performed โ so if youโre out here making dupes, thatโs on you. ๐
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)
Parameters
fynp(struct fy_node_pair*) โ The node pairfyn(struct fy_node*) โ The value node
Description Sets the value part of the node pair. It overwrites any previous value. Simple, clean, iconic.
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)
Parameters
fyn_map(struct fy_node*) โ The mapping nodefyn_key(struct fy_node*) โ The node pairโs keyfyn_value(struct fy_node*) โ The node pairโs value
Description Appends a node pair to a mapping. Adding to the end of the mapping lineup, periodt.
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)
Parameters
fyn_map(struct fy_node*) โ The mapping nodefyn_key(struct fy_node*) โ The node pairโs keyfyn_value(struct fy_node*) โ The node pairโs value
Description Prepends a node pair to a mapping. Itโs giving โfront of the lineโ behavior. ๐
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)
Parameters
fyn_map(struct fy_node*) โ The mapping nodefynp(struct fy_node_pair*) โ The node pair to remove
Description Removes the node pair from a mapping. Bye bestie ๐
Return 0 on success, -1 on failure.
๐ธ fy_node_mapping_sort ๐ธ
int fy_node_mapping_sort(struct fy_node *fyn_map, fy_node_mapping_sort_fn key_cmp, void *arg)
Parameters
fyn_map(struct fy_node*) โ The mapping node to sortkey_cmp(fy_node_mapping_sort_fn) โ The comparison methodarg(void*) โ An opaque user pointer for the comparison method
Description Sorts the keys of a single mapping node using the comparison method you pass. If key_cmp is NULL, it uses the default one. Unlike fy_node_sort(), this does not recurse into child nodes โ it stays in its lane. ๐
Return 0 on success, -1 on error
๐ 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)
Parameters
fyn_map(struct fy_node*) โ The mapping nodefyn_key(struct fy_node*) โ The node pairโs key
Description Removes the node pair from the mapping using the supplied key. Itโs a remove-and-return-the-value situation.
Return The value part of the 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)
Parameters
fyn(struct fy_node*) โ The node to sortkey_cmp(fy_node_mapping_sort_fn) โ The comparison methodarg(void*) โ An opaque user pointer for the comparison method
Description Recursively sorts all mappings of the given node, using the comparison method you pass โ and if thatโs NULL, the default one. This one does go down into the child nodes, bestie. Recursive sorting ate. ๐ฅ
Return 0 on success, -1 on error
๐ fy_node_vscanf ๐
int fy_node_vscanf(struct fy_node *fyn, const char *fmt, va_list ap)
Parameters
fyn(struct fy_node*) โ The node to use as a pathspec rootfmt(const char*) โ The scanf based format stringap(va_list) โ Theva_listcontaining the arguments
Description This method easily retrieves data using a familiar vscanf interface. The format string is a regular scanf format string with this 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, ...)
Parameters
fyn(struct fy_node*) โ The node to use as a pathspec rootfmt(const char*) โ The scanf based format stringellipsis(ellipsis) โ The arguments
Description This method easily retrieves data using a familiar vscanf interface. The format string is a regular scanf format string with this 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)
Parameters
fyd(struct fy_document*) โ The documentfmt(const char*) โ The scanf based format stringap(va_list) โ Theva_listcontaining the arguments
Description This method easily retrieves data using a familiar vscanf interface. The format string is a regular scanf format string with this 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, ...)
Parameters
fyd(struct fy_document*) โ The documentfmt(const char*) โ The scanf based format stringellipsis(ellipsis) โ The arguments
Description This method easily retrieves data using a familiar vscanf interface. The format string is a regular scanf format string with this 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)
Parameters
fyd(struct fy_document*) โ The documentprevp(void**) โ The previous state of the iterator
Description This method iterates over all the documentโs tag directives. The start of the iteration is signalled by a NULL in *prevp. Itโs a little iterator situation, very demure.
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)
Parameters
fyd(struct fy_document*) โ The documenthandle(const char*) โ The handle to look for
Description Retrieves the matching tag directive token of the document that matches 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)
Parameters
fyt(struct fy_token*) โ The tag directive tokenlenp(size_t*) โ Pointer to a variable that will hold the returned length
Description
Bestie, this one retrieves the tag directive token's handle value. It's only valid on tag directive tokens, okay? Don't try it on anything else. ๐
Return
You get a pointer to the tag directive's handle, and lenp gets assigned the length of that handle. If something goes wrong, you get a NULL back. ๐ญ
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
This one retrieves the tag directive token's prefix value. Again, only valid on tag directive tokens! ๐
Return
You get a pointer to the tag directive's prefix, and lenp gets assigned the length of that prefix. A NULL comes back if there's 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
Adds a tag directive to the document. Slay. โจ
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
Removes a tag directive from a document. But bestie, removal is prohibited if any node is still using this tag directive. Don't even try it. ๐ซ
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-1if '0' terminated).
Description
Looks for an anchor having the name you provided. It's giving detective energy. ๐ต๏ธโโ๏ธ
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
Looks for an anchor having the name provided from the text of the token. Token vibes. ๐๏ธ
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
Looks for an anchor located in the given node. Node-based search, iykyk. ๐ณ
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 returns a pointer to the text of an anchor along with the length of it. Note: this text is not NULL terminated. So don't treat it like a C string, bestie. ๐ โโ๏ธ
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. Simple. โจ
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 document's anchors. The start of the iteration is signalled by a NULL in *prevp. So set *prevp to NULL to begin. ๐ฆ
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)-1for '0' terminated.
Description
Places an anchor to the node with the given text name.
Note: the data are not copied, merely a reference is taken, so it must be available while the node is in use. Don't let it go out of scope! ๐ฌ
Also note that this method is deprecated; use fy_node_set_anchor() instead. Periodt. ๐
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)-1for '0' terminated.
Description
Places an anchor to the node with the given text name.
Note: the data are not copied, merely a reference is taken, so it must be available while the node is in use. Same warning as before. โ ๏ธ
This is similar to fy_document_set_anchor() with the document set to the document of the fyn node. So it's the glow-up version. โจ
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)-1for '0' terminated.
Description
Places an anchor to the node with the given text name, which will be copied, so it's safe to dispose the text after the call. No take-backs, it's yours now. ๐ซถ
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 given text name as created via vprintf'ing the arguments. So you can format it all fancy. ๐
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 given text name as created via printf'ing the arguments. Variadic vibes. โจ
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
Removes an anchor for the given node (if it exists). If it doesn't exist, no biggie. ๐คทโโ๏ธ
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
Retrieves the anchor of the given node (if it exists). It's giving "do you have a moment to talk about our lord and savior, the anchor?" ๐
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
Retrieves the anchor of the nearest parent of the given node or the given node if it has one. So it climbs up the tree until it finds an anchor. ๐ณโฌ๏ธ
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
Retrieves the nearest node which is a child of fyn_base starting at fyn and working upwards. So you're climbing the tree from fyn up until you find a node that is a child of fyn_base. Family reunion vibes. ๐จโ๐ฉโ๐งโ๐ฆ
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-1if '0' terminated).
Description
Creates an alias on the given document.
Note: the data are not copied, merely a reference is taken, so it must be available while the node is in use. Same warning again, bestie. ๐ซ
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-1if '0' terminated).
Description
Creates an alias on the given document. (This one copies the data, so you don't have to worry about lifetime.) ๐ซถ
Okay okay, picking up mid-thought because we love a seamless transition: a copy of the data will be made, so it is safe to free the data after the call. The return value? The created alias node, or NULL in case of an error. No cap. ๐
fy_node_get_meta
void *fy_node_get_meta(struct fy_node *fyn)
Get the meta pointer of a node. Bestie, it literally does what it says on the tin. ๐
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. Slay.
fy_node_set_meta
int fy_node_set_meta(struct fy_node *fyn, void *meta)
Set the meta pointer of a node. Very demure, very mindful pointer assignment. โจ
Parameters:
fyn(struct fy_node*) โ The node to set meta datameta(void*) โ The meta data pointer
Description:
Set the meta pointer of a node. If meta is NULL then clear the meta data. Thatโs the vibe check: NULL means wipe it. ๐ซถ
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. Poof, gone, iconic. ๐จ
Parameters:
fyn(struct fy_node*) โ The node to clear meta data
Description:
Clears the meta data of a node.
typedef fy_node_meta_clear_fn
void fy_node_meta_clear_fn(struct fy_node *fyn, void *meta, void *user)
Meta data clear method. This is the callback energy we need. ๐ธ
Parameters:
fyn(struct fy_node*) โ The node which the meta data is being clearedmeta(void*) โ The meta data of the node assigned viafy_node_set_meta()user(void*) โ The user pointer offy_document_register_meta()
Description:
This is the callback called when meta data are cleared. Yep, itโs giving cleanup crew. ๐งน
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. Very official. Very โIโve got your back when the node gets freed.โ ๐
Parameters:
fyd(struct fy_document*) โ The document which the hook is registered toclear_fn(fy_node_meta_clear_fn) โ The clear hook methoduser(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. So like, every node in the doc gets the same energy. ๐
Return:
0 on success, -1 if another hook is already registered. One hook at a time, bestie โ weโre not running a circus. ๐ช
fy_document_unregister_meta
void fy_document_unregister_meta(struct fy_document *fyd)
Unregister a meta cleanup hook. Bye-bye, 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. That part matters โ the old hook still gets its moment. ๐ฌ
fy_node_set_marker
bool fy_node_set_marker(struct fy_node *fyn, unsigned int marker)
Set a marker of a node. Marking your territory, but make it YAML. ๐๏ธ
Parameters:
fyn(struct fy_node*) โ The nodemarker(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. Important detail, donโt forget it. โญ
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. Un-marking, but still returning the old state because weโre thorough. ๐ฆ
Parameters:
fyn(struct fy_node*) โ The nodemarker(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. Same rule, same space. ๐ซถ
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. The vibe check for markers. ๐
Parameters:
fyn(struct fy_node*) โ The nodemarker(unsigned int) โ The marker index (must be less thatFYNWF_MAX_USER_MARKER)
Description:
Check the state of the given marker.
Return:
The value of the marker (invalid markers return false). So if you pass nonsense, itโs a no from the marker. ๐
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. Diagnostic drama, but make it formatted. ๐ญ
Parameters:
fyn(struct fy_node*) โ The nodetype(enum fy_error_type) โ The error typefmt(const char*) โ The printf format stringap(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. Itโs giving structured complaints. ๐ข
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. Same energy, but with the ... varargs flex. โจ
Parameters:
fyn(struct fy_node*) โ The nodetype(enum fy_error_type) โ The error typefmt(const char*) โ The printf format stringellipsis(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. Custom location, custom chaos. ๐บ๏ธ
Parameters:
fyn(struct fy_node*) โ The nodetype(enum fy_error_type) โ The error typefile(const char*) โ The file overrideline(int) โ The line overridecolumn(int) โ The column overridefmt(const char*) โ The printf format stringap(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. So negative numbers mean โlocation? never heard of her.โ ๐
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. The varargs version of โmake the location say what I want.โ ๐
Parameters:
fyn(struct fy_node*) โ The nodetype(enum fy_error_type) โ The error typefile(const char*) โ The file overrideline(int) โ The line overridecolumn(int) โ The column overridefmt(const char*) โ The printf format stringellipsis(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. Same rules, same dramatic reporting energy. ๐ฅ
fy_event_vreport
void fy_event_vreport(struct fy_parser *fyp, struct fy_event *fye,
enum fy_event_part fyep, enum fy_error_type type,
const char *fmt, va_list ap)
Report about an event vprintf style. Event gossip, but official. ๐
Parameters:
fyp(struct fy_parser*) โ The parser of which the event was generated fromfye(struct fy_event*) โ The eventfyep(enum fy_event_part) โ The event part which the report is abouttype(enum fy_error_type) โ The error typefmt(const char*) โ The printf format stringap(va_list) โ The argument list
Description:
Output a report about the given event via the specific error type, focusing at the given event part. Focused. Intentional. Iconic. ๐ฏ
fy_event_report
void fy_event_report(struct fy_parser *fyp, struct fy_event *fye,
enum fy_event_part fyep, enum fy_error_type type,
const char *fmt, ...)
Report about an event printf style. Now with extra arguments and main character energy. ๐
Parameters:
fyp(struct fy_parser*) โ The parser of which the event was generated fromfye(struct fy_event*) โ The eventfyep(enum fy_event_part) โ The event part which the report is abouttype(enum fy_error_type) โ The error typefmt(const char*) โ The printf format stringellipsis(ellipsis) โ The extra arguments.
Description:
Output a report about the given event via the specific error type, focusing at the given event part. Same focus, same event, just printf style. ๐
struct fy_diag_cfg
struct fy_diag_cfg
The diagnostics configuration. This is the control room for how diagnostics look and behave. ๐๏ธ
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 outputoutput_fnโ Callback to use whenfpisNULLuserโ User pointer to pass to theoutput_fnlevelโ The minimum debugging levelmodule_maskโ A bitmask of the enabled modulescolorizeโtrueif output should be colorized using ANSI sequencesshow_sourceโtrueif source location should be displayedshow_positionโtrueif position should be displayedshow_typeโtrueif the type should be displayedshow_moduleโtrueif the module should be displayedsource_widthโ Width of the source fieldposition_widthโ Width of the position fieldtype_widthโ Width of the type fieldmodule_widthโ Width of the module field
Description:
This structure contains the configuration of the diagnostic object. Basically the settings screen for your diagnostics. ๐
struct fy_diag_error
struct fy_diag_error
A collected diagnostic error. Yes, an error that got collected. We love a documented problem. ๐
Definition
struct fy_diag_error {
enum fy_error_type type;
enum fy_error_module module;
struct fy_token *fyt;
const char *msg;
const char *file;
int line;
int column;
}
Members
typeโ the error type, bestie โจmoduleโ which module it came fromfytโ the token, and yes it might beNULLso pls check ๐ซถmsgโ the message that gets output right alongside itfileโ the file that held the inputlineโ the line where the error is sittingcolumnโ the column where the error is sitting
Description
Okay so this struct is literally just a little info packet about an error that the diagnostic object is collecting. That's it, that's the vibe ๐
fy_diag_create
struct fy_diag *fy_diag_create(const struct fy_diag_cfg *cfg)
Create a diagnostic object, iconic behaviour honestly ๐
Parameters
cfg(const struct fy_diag_cfg*) โ the configuration for the diagnostic object (NULLis default)
Description
Makes you a diagnostic object using the config you handed over.
Return
A pointer to the diagnostic object, or NULL if something went wrong ๐ญ
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
Destroys a diagnostic object โ but heads up, the actual destruction only happens once there are no more references left to it. However, no output will be generated after this call. So it's giving "I'm leaving the group chat but I'm still lurking" ๐
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
Returns the current configuration of a diagnostic object.
Return
A const pointer to the diagnostic object configuration, or NULL in the 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 objectcfg(const struct fy_diag_cfg*) โ the diagnostic configuration
Description
Swaps out the current diagnostic config for the one you passed in. Out with the old, in with the new ๐ฆ
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 objectlevel(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 objectcolorize(bool) โ the colorize option
fy_diag_ref
struct fy_diag *fy_diag_ref(struct fy_diag *diag)
Increment the reference counter of a diagnostic object.
Parameters
diag(struct fy_diag*) โ the diagnostic object to reference
Description
Increments the reference. Keeping it alive, holding space for it ๐ซถ
Return
Always returns the diag argument โ it literally hands it right back to you.
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
Takes away a reference, and if it hits 0, the diagnostic object gets freed. Last one out, turn off the lights ๐
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. Like a vibe check but for errors.
Return
true if an error has been produced, false otherwise.
fy_diag_set_error
void fy_diag_set_error(struct fy_diag *diag, bool on_error)
Sets the error produced state.
Parameters
diag(struct fy_diag*) โ the diagnostic objecton_error(bool) โ the set error state
Description
Sets the error produced state. Yeah, it says it twice, I'm just relaying the message fr fr.
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 that got set by an output of an error level diagnostic. Fresh start energy ๐ธ
fy_diag_set_collect_errors
void fy_diag_set_collect_errors(struct fy_diag *diag, bool collect_errors)
Collect errors instead of outputting.
Parameters
diag(struct fy_diag*) โ the diagnostic objectcollect_errors(bool) โ the collect errors mode
Description
Sets the collect errors mode. When it's true, instead of outputting to the diagnostic interface, the errors get collected so you can come back for them later. Little error scrapbook, iykyk ๐
fy_diag_get_collect_errors
bool fy_diag_get_collect_errors(struct fy_diag *diag)
Get collect errors state.
Parameters
diag(struct fy_diag*) โ the diagnostic object
Description
Gets the collect errors mode.
Return
true if it's collecting errors, false otherwise.
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 โ that's just how it is, no notes.
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 structurepflags(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 โ it's giving legacy era, don't @ me ๐
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 usefmt(const char*) โ the vprintf format stringap(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. You're rawdogging the output, essentially ๐
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 usefmt(const char*) โ the printf format stringellipsis(ellipsis) โ the arguments
Description
Raw output to the diagnostic object using a standard printf interface. Same warning as its vprintf sibling: this is the lowest level interface, so it's not recommended, 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. It's giving main character context packet ๐
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 diagnosticmoduleโ the module of the diagnosticsource_funcโ the source functionsource_fileโ the source filesource_lineโ the source linefileโ the file that caused the errorlineโ the line where the diagnostic occuredcolumnโ the column where the diagnostic occured
Description
This structure contains the diagnostic context. That's the whole lore ๐ธ
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 usefydc(const struct fy_diag_ctx*) โ the diagnostic contextfmt(const char*) โ the vprintf format stringap(va_list) โ the arguments
Description
Context aware output to the diagnostic object using a standard vprintf interface. Now with โจcontextโจ.
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 usefydc(const struct fy_diag_ctx*) โ the diagnostic contextfmt(const char*) โ the vprintf format stringellipsis(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_token_vreport
void fy_diag_token_vreport(struct fy_diag *diag, struct fy_token *fyt, enum fy_error_type type, const char *fmt, va_list ap)
Report about a token, vprintf style, using the given diagnostic object ๐ฅ
Parameters
diag(struct fy_diag*) โ the diag objectfyt(struct fy_token*) โ the tokentype(enum fy_error_type) โ the error typefmt(const char*) โ the printf format stringap(va_list) โ the argument list
Description
Outputs a report about the given token via the specific error type, and using the reporting configuration of the token's document. It's a whole relay situation โ the token's document calls the shots ๐
fy_diag_token_report
void fy_diag_token_report(struct fy_diag *diag, struct fy_token *fye,
enum fy_error_type type, const char *fmt, ...)
okay so this one is literally just "tell me about this token, printf style" ๐ it reports about a token using the diag object you hand it.
Parameters
diag(struct fy_diag *) โ the diag object, your reporter bestiefye(struct fy_token *) โ the token in questiontype(enum fy_error_type) โ the error typefmt(const char *) โ the printf format stringellipsis(ellipsis) โ the extra arguments
Description
Outputs a report about the given token via the specific error type, and uses the reporting configuration of the token's document ๐ so the token's doc decides how it gets dressed up.
fy_diag_token_override_vreport
void fy_diag_token_override_vreport(struct fy_diag *diag, struct
fy_token *fyt, enum fy_error_type type, const char *file, int line, int
column, const char *fmt, va_list ap)
the va_list twin of the override-y token reporter โจ vprintf style, and it lets you override the file, line and column info.
Parameters
diag(struct fy_diag *) โ the diag objectfyt(struct fy_token *) โ the tokentype(enum fy_error_type) โ the error typefile(const char *) โ the file overrideline(int) โ the line overridecolumn(int) โ the column overridefmt(const char *) โ the printf format stringap(va_list) โ the argument list
Description
Outputs a report about the given token via the specific error type, using the reporting configuration of the token's document. This method uses the overrides you provide in order to massage the reporting information ๐ซถ
fr fr: iffileisNULL, no file location will be reported. And if eitherlineorcolumnis negative, no location will be reported either. no cap.
fy_diag_token_override_report
void fy_diag_token_override_report(struct fy_diag *diag, struct fy_token
*fyt, enum fy_error_type type, const char *file, int line, int column,
const char *fmt, ...)
same energy as the last one but printf style with an ellipsis instead of a va_list ๐
Parameters
diag(struct fy_diag *) โ the diag objectfyt(struct fy_token *) โ the tokentype(enum fy_error_type) โ the error typefile(const char *) โ the file overrideline(int) โ the line overridecolumn(int) โ the column overridefmt(const char *) โ the printf format stringellipsis(ellipsis) โ the extra arguments
Description
Outputs a report about the given token via the specific error type, and uses the reporting configuration of the token's document. This method will use the overrides provided in order to massage the reporting information.
again, because it matters:filebeingNULLmeans no file location gets reported, and a negativelineorcolumnmeans no location gets reported. iconic consistency ๐ธ
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)
token who? we're on nodes now ๐ฆ report about a node, vprintf style.
Parameters
diag(struct fy_diag *) โ the diag objectfyn(struct fy_node *) โ the nodetype(enum fy_error_type) โ the error typefmt(const char *) โ the printf format stringap(va_list) โ the argument list
Description
Outputs a report about the given node via the specific error type, and uses 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, ...)
the printf version for nodes, and yes she ate ๐
Parameters
diag(struct fy_diag *) โ the diag objectfyn(struct fy_node *) โ the nodetype(enum fy_error_type) โ the error typefmt(const char *) โ the printf format stringellipsis(ellipsis) โ the extra arguments
Description
Outputs a report about the given node via the specific error type, and uses 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)
node report, vprintf style, but with the file/line/column glow-up overrides ๐
Parameters
diag(struct fy_diag *) โ the diag objectfyn(struct fy_node *) โ the nodetype(enum fy_error_type) โ the error typefile(const char *) โ the file overrideline(int) โ the line overridecolumn(int) โ the column overridefmt(const char *) โ the printf format stringap(va_list) โ the argument list
Description
Outputs a report about the given node via the specific error type, and uses the reporting configuration of the node's document. This method will use the overrides provided in order to massage the reporting information.
bestie, remember the rule:fileNULLโ no file location reported.lineorcolumnnegative โ no location reported. periodt ๐
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, ...)
and the printf-style version of the node override reporter, completing the set ๐ฅ
Parameters
diag(struct fy_diag *) โ the diag objectfyn(struct fy_node *) โ the nodetype(enum fy_error_type) โ the error typefile(const char *) โ the file overrideline(int) โ the line overridecolumn(int) โ the column overridefmt(const char *) โ the printf format stringellipsis(ellipsis) โ the extra arguments
Description
Outputs a report about the given node via the specific error type, and uses the reporting configuration of the node's document. This method will use the overrides provided in order to massage the reporting information.
fileisNULLโ no file location reported. Negativelineorcolumnโ no location reported. same as her sisters ๐ซถ
fy_diag_event_vreport
void fy_diag_event_vreport(struct fy_diag *diag, struct fy_event *fye,
enum fy_event_part fyep, enum fy_error_type type, const char *fmt,
va_list ap)
events have entered the chat ๐ญ vprintf style, and note the extra fyep โ you're reporting about a specific event part not the whole event.
Parameters
diag(struct fy_diag *) โ the diag objectfye(struct fy_event *) โ the eventfyep(enum fy_event_part) โ the event parttype(enum fy_error_type) โ the error typefmt(const char *) โ the printf format stringap(va_list) โ the argument list
Description
Outputs a report about the given event part via the specific error type โญ
fy_diag_event_report
void fy_diag_event_report(struct fy_diag *diag, struct fy_event *fye,
enum fy_event_part fyep, enum fy_error_type type, const char *fmt, ...)
the printf-style event-part reporter, same trio of vibes, different signature ๐
Parameters
diag(struct fy_diag *) โ the diag objectfye(struct fy_event *) โ the eventfyep(enum fy_event_part) โ the event parttype(enum fy_error_type) โ the error typefmt(const char *) โ the printf format stringellipsis(ellipsis) โ the extra arguments
Description
Outputs a report about the given event part via the specific error type ๐
fy_diag_errors_iterate
struct fy_diag_error *fy_diag_errors_iterate(struct fy_diag *diag, void
**prevp)
okay this one's a little iterator icon ๐ it walks over the errors of a diagnostic object.
Parameters
diag(struct fy_diag *) โ the diagnostic objectprevp(void **) โ the previous result iterator
Description
This method iterates over all the errors collected on the diagnostic object. The start of the iteration is signalled by a NULL in *prevp โ that's your "go" signal, no cap ๐
Return
The next errors, or NULL when there are not any more ๐
fy_parser_checkpoint_create
struct fy_parser_checkpoint *fy_parser_checkpoint_create(struct
fy_parser *fyp)
save point!! ๐ฎ this creates a checkpoint of the parser's current state, so you can stash where you're at and potentially roll back to it later using fy_parser_rollback(). it's giving "quicksave before the boss fight" energy fr fr.
important: the checkpoint must be destroyed via fy_parser_checkpoint_destroy() when it's no longer needed. don't just leave it lying around ๐
Parameters
fyp(struct fy_parser *) โ the parser
Return
A pointer to the checkpoint, or NULL in case of an error ๐ญ
fy_parser_checkpoint_destroy
void fy_parser_checkpoint_destroy(struct fy_parser_checkpoint *fypchk)
the cleanup crew ๐งน destroys a checkpoint you created earlier via fy_parser_checkpoint_create().
Parameters
fypchk(struct fy_parser_checkpoint *) โ the checkpoint to destroy
Description
Destroys a checkpoint created earlier via fy_parser_checkpoint_create() โจ
fy_parser_rollback
int fy_parser_rollback(struct fy_parser *fyp, struct
fy_parser_checkpoint *fypc)
the actual rewind button โช rolls the parser state back to a previously created checkpoint, so you can revert to an earlier state and re-parse from that point.
the checkpoint remains valid after rollback ๐ซถ so you can use it again, or destroy it via fy_parser_checkpoint_destroy(). reusable, we love to see it.
Parameters
fyp(struct fy_parser *) โ the parserfypc(struct fy_parser_checkpoint *) โ the checkpoint to roll back to
Return
0 on success, -1 on error ๐
enum fy_token_type
enum fy_token_type
Token types ๐ โ the roster of what a token can be.
Definition
okay bestie, this is the big enum that holds every token type fyaml knows about โ YAML tokens, path-expression (YPATH) tokens, scalar-expression tokens, all of it. yes, it's long. no, we're not skipping any. every single one gets its moment ๐
enum fy_token_type {
FYTT_NONE,
FYTT_STREAM_START,
FYTT_STREAM_END,
FYTT_VERSION_DIRECTIVE,
FYTT_TAG_DIRECTIVE,
FYTT_DOCUMENT_START,
FYTT_DOCUMENT_END,
FYTT_BLOCK_SEQUENCE_START,
FYTT_BLOCK_MAPPING_START,
FYTT_BLOCK_END,
FYTT_FLOW_SEQUENCE_START,
FYTT_FLOW_SEQUENCE_END,
FYTT_FLOW_MAPPING_START,
FYTT_FLOW_MAPPING_END,
FYTT_BLOCK_ENTRY,
FYTT_FLOW_ENTRY,
FYTT_KEY,
FYTT_VALUE,
FYTT_ALIAS,
FYTT_ANCHOR,
FYTT_TAG,
FYTT_SCALAR,
FYTT_INPUT_MARKER,
FYTT_PE_SLASH,
FYTT_PE_ROOT,
FYTT_PE_THIS,
FYTT_PE_PARENT,
FYTT_PE_MAP_KEY,
FYTT_PE_SEQ_INDEX,
FYTT_PE_SEQ_SLICE,
FYTT_PE_SCALAR_FILTER,
FYTT_PE_COLLECTION_FILTER,
FYTT_PE_SEQ_FILTER,
FYTT_PE_MAP_FILTER,
FYTT_PE_UNIQUE_FILTER,
FYTT_PE_EVERY_CHILD,
FYTT_PE_EVERY_CHILD_R,
FYTT_PE_ALIAS,
FYTT_PE_SIBLING,
FYTT_PE_COMMA,
FYTT_PE_BARBAR,
FYTT_PE_AMPAMP,
FYTT_PE_LPAREN,
FYTT_PE_RPAREN,
FYTT_PE_EQEQ,
FYTT_PE_NOTEQ,
FYTT_PE_LT,
FYTT_PE_GT,
FYTT_PE_LTE,
FYTT_PE_GTE,
FYTT_SE_PLUS,
FYTT_SE_MINUS,
FYTT_SE_MULT,
FYTT_SE_DIV,
FYTT_PE_METHOD,
FYTT_SE_METHOD,
FYTT_PE_BANG,
FYTT_PE_AT
};
Constants
welcome to the token zoo ๐ฆ โ every resident gets a lil intro, no cap:
FYTT_NONEโ no token. the void. the "there is literally nothing here" token ๐FYTT_STREAM_STARTโ stream start token โจFYTT_STREAM_ENDโ stream end token, the wrap-up ๐FYTT_VERSION_DIRECTIVEโ version directive tokenFYTT_TAG_DIRECTIVEโ tag directive tokenFYTT_DOCUMENT_STARTโ document start token, main character energy ๐FYTT_DOCUMENT_ENDโ document end tokenFYTT_BLOCK_SEQUENCE_STARTโ block sequence start tokenFYTT_BLOCK_MAPPING_STARTโ block mapping start tokenFYTT_BLOCK_ENDโ block end tokenFYTT_FLOW_SEQUENCE_STARTโ flow sequence start tokenFYTT_FLOW_SEQUENCE_ENDโ flow sequence end tokenFYTT_FLOW_MAPPING_STARTโ flow mapping start tokenFYTT_FLOW_MAPPING_ENDโ flow mapping end tokenFYTT_BLOCK_ENTRYโ block entry tokenFYTT_FLOW_ENTRYโ flow entry tokenFYTT_KEYโ key token ๐FYTT_VALUEโ value tokenFYTT_ALIASโ alias tokenFYTT_ANCHORโ anchor token โFYTT_TAGโ tag tokenFYTT_SCALARโ scalar tokenFYTT_INPUT_MARKERโ input marker tokenFYTT_PE_SLASHโ path expression slash tokenFYTT_PE_ROOTโ path expression root tokenFYTT_PE_THISโ path expression this tokenFYTT_PE_PARENTโ path expression parent tokenFYTT_PE_MAP_KEYโ path expression map key tokenFYTT_PE_SEQ_INDEXโ path expression sequence index tokenFYTT_PE_SEQ_SLICEโ path expression sequence slice tokenFYTT_PE_SCALAR_FILTERโ path expression scalar filter tokenFYTT_PE_COLLECTION_FILTERโ path expression collection filter tokenFYTT_PE_SEQ_FILTERโ path expression sequence filter tokenFYTT_PE_MAP_FILTERโ path expression map filter tokenFYTT_PE_UNIQUE_FILTERโ path expression unique filter tokenFYTT_PE_EVERY_CHILDโ path expression every child tokenFYTT_PE_EVERY_CHILD_Rโ path expression every child recursive tokenFYTT_PE_ALIASโ path expression alias tokenFYTT_PE_SIBLINGโ path expression sibling tokenFYTT_PE_COMMAโ path expression,tokenFYTT_PE_BARBARโ path expression||tokenFYTT_PE_AMPAMPโ path expression&&tokenFYTT_PE_LPARENโ path expression(tokenFYTT_PE_RPARENโ path expression)tokenFYTT_PE_EQEQโ path expression==tokenFYTT_PE_NOTEQโ path expression!=tokenFYTT_PE_LTโ path expression<tokenFYTT_PE_GTโ path expression>tokenFYTT_PE_LTEโ path expression<=tokenFYTT_PE_GTEโ path expression>=tokenFYTT_SE_PLUSโ scalar expression+tokenFYTT_SE_MINUSโ scalar expression-tokenFYTT_SE_MULTโ scalar expression*tokenFYTT_SE_DIVโ scalar expression/tokenFYTT_PE_METHODโ path expression method tokenFYTT_SE_METHODโ scalar expression method tokenFYTT_PE_BANGโ path expression!tokenFYTT_PE_ATโ path expression@token
fy_token_type_is_valid
bool fy_token_type_is_valid(enum fy_token_type type)
so this one does a vibe check on a token type โ is it even valid, yes or no? ๐ซถ
Parameters
- type (
enum fy_token_type) โ the token type in question
Description
literally just checks whether the token type you handed it 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)
same energy, but the question is "is this a YAML token type?" ๐ธ
Parameters
- type (
enum fy_token_type) โ the token type
Description
checks if the thing you passed in is a valid YAML token type.
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)
and now: is it a content token type? iykyk โจ
Parameters
- type (
enum fy_token_type) โ the token type
Description
checks if the 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)
YPATH check incoming ๐ฆ
Parameters
- type (
enum fy_token_type) โ the token type
Description
checks if the token type is a valid YPATH parse expression token.
Return
true if the token type is a valid YPATH one, false otherwise.
fy_token_type_is_scalar_expr
bool fy_token_type_is_scalar_expr(enum fy_token_type type)
same but for the scalar-expression side of YPATH ๐
Parameters
- type (
enum fy_token_type) โ the token type
Description
checks if the token type is a valid YPATH parse scalar expression token.
Return
true if the token type is a valid YPATH scalar one, false otherwise.
fy_token_get_type
enum fy_token_type fy_token_get_type(struct fy_token *fyt)
gimme the type, bestie ๐
Parameters
- fyt (
struct fy_token *) โ the token
Description
returns the token's type โ and if it's NULL, you get FYTT_NONE back. no crash, no drama, just the void token ๐
Return
the token's type; FYTT_NONE if it's not a valid token (or it's NULL).
fy_token_start_mark
const struct fy_mark *fy_token_start_mark(struct fy_token *fyt)
where does this token start? ๐
Parameters
- fyt (
struct fy_token *) โ the token to get its start marker
Description
returns the token's start marker if it exists. and ngl, it is permissible for some token types to have no start marker, because they're without content. so don't come for it if you get NULL ๐
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)
and where does it end? ๐
Parameters
- fyt (
struct fy_token *) โ the token to get its end marker
Description
returns the token's end marker if it exists. same deal as before: it is permissible for some token types to have no end marker because they're without content.
Return
the token's end marker, NULL if not available.
fy_token_style_start_mark
const struct fy_mark *fy_token_style_start_mark(struct fy_token *fyt)
this one is the start marker with style โ it includes the style indicators ๐
Parameters
- fyt (
struct fy_token *) โ the token to get its style start marker
Description
returns the token's start marker if it exists, including the style indicators. and yeah, again, it's permissible for some token types to have no start marker because they're without content.
Return
the token's style start marker, NULL if not available.
fy_token_style_end_mark
const struct fy_mark *fy_token_style_end_mark(struct fy_token *fyt)
the matching style end marker โ the other half of the fit โจ
Parameters
- fyt (
struct fy_token *) โ the token to get its style end marker
Description
returns the token's end marker if it exists, including the style indicators. and once more for the people in the back: it's permissible for some token types to have no end marker because they're without content.
Return
the token's style end marker, NULL if not available.
fy_scan
struct fy_token *fy_scan(struct fy_parser *fyp)
okay this one is low key iconic โ it's the raw scanner door ๐ฅ
Parameters
- fyp (
struct fy_parser *) โ the parser to get the next token from
Description
returns the next scanner token. heads up though: this is a very low level interface โ it's meant for users who want or need to implement their own YAML parser. so if that's not you, bestie, maybe step back ๐ญ
โ ๏ธ the token you get back is expected to be disposed of using fy_scan_token_free(). do not just leave it lying around.
Return
the next token, or NULL if there are no more tokens available.
fy_scan_token_free
void fy_scan_token_free(struct fy_parser *fyp, struct fy_token *fyt)
clean up your mess ๐ (respectfully)
Parameters
- fyp (
struct fy_parser *) โ the parser of which the token was returned byfy_scan() - fyt (
struct fy_token *) โ the token to free
Description
frees the token that came back from fy_scan(). that's it, that's the whole job ๐ซถ
fy_tag_directive_token_prefix0
const char *fy_tag_directive_token_prefix0(struct fy_token *fyt)
grab the tag directive prefix as a nice zero-terminated string ๐
Parameters
- fyt (
struct fy_token *) โ the tag directive token out of which the prefix pointer will be returned
Description
pulls out the tag directive's prefix contents as a zero terminated string. it's similar to fy_tag_directive_token_prefix(), except the string you get back is zero terminated โ and memory may be allocated to hold it, associated with the token. so it's the โจglowed-upโจ version.
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 chillin' inside a tag directive token, but make it a zero terminated string โจ
Parameters
fyt(struct fy_token*) โ the tag directive token you're pulling the handle pointer out of.
Description
Okay so this one grabs the tag directive's handle contents and hands them to you as a zero terminated string ๐
. It's basically fy_tag_directive_token_handle()'s sibling โ the difference being that what comes back is zero terminated, and memory may get allocated to hold it, and that memory is associated with the token. So like, it's the same vibe but null-safe at the end, iykyk.
Return
A pointer to the zero terminated text representation of the handle token ๐. NULL if something went wrong.
fy_tag_token_handle
const char *fy_tag_token_handle(struct fy_token *fyt, size_t *lenp)
Get the handle that's inside a tag token ๐ท๏ธ
Parameters
fyt(struct fy_token*) โ the tag token the handle pointer comes out of.lenp(size_t*) โ pointer to a variable that'll hold the returned length.
Description
Retrieves the tag handle contents fr fr. It will fail if the token isn't actually a tag token, or if a memory error happens ๐ญ. No cap, those are the two ways it goes sideways.
Return
A pointer to the text representation of the handle token, and lenp gets assigned the character length of said representation. NULL if there's an error.
fy_tag_token_suffix
const char *fy_tag_token_suffix(struct fy_token *fyt, size_t *lenp)
Get the suffix out of a tag token ๐
Parameters
fyt(struct fy_token*) โ the tag token you're grabbing the suffix pointer from.lenp(size_t*) โ pointer to a variable that'll hold the returned length.
Description
Retrieves the tag suffix contents โจ. Fails if the token isn't a tag token, or if a memory error decides to show up ๐ญ.
Return
A pointer to the text representation of the suffix token, with lenp assigned the character length of that representation. NULL in case of an error.
fy_tag_token_short
const char *fy_tag_token_short(struct fy_token *fyt, size_t *lenp)
Get the short tag of a tag token, bestie ๐
Parameters
fyt(struct fy_token*) โ the tag token the short pointer comes out of.lenp(size_t*) โ pointer to a variable that'll hold the returned length.
Description
Retrieves the short tag contents. And like โ the short tag is literally the same one you'll need to emit, so it's giving main character energy ๐ฅ. Fails if the token isn't a tag token, or if a memory error happens.
Return
A pointer to the text representation of the short tag, and lenp gets the character length of that representation. NULL in case of an error.
fy_tag_token_handle0
const char *fy_tag_token_handle0(struct fy_token *fyt)
Get the handle inside a tag token, zero terminated edition ๐ธ
Parameters
fyt(struct fy_token*) โ the tag token from which the handle pointer will be returned.
Description
Retrieves the tag handle contents as a zero terminated string ๐. It's similar to fy_tag_token_handle(), except the returned string is zero terminated and memory may be allocated to hold it, associated with the token. Same energy, just null-terminated at the end, slay.
Return
A pointer to the zero terminated text representation of the handle token. NULL in case of an error.
fy_tag_token_short0
const char *fy_tag_token_short0(struct fy_token *fyt)
Get the short tag of a tag token as a zero terminated string ๐ฆ
Parameters
fyt(struct fy_token*) โ the tag token the short pointer comes out of.
Description
Retrieves the short tag contents โ and again, the short tag is the exact same one that needs to be emitted ๐. Will fail if the token isn't a tag token, or if a memory error happens.
Return
A pointer to the null terminated text representation of the short tag. NULL in case of an error.
fy_tag_token_suffix0
const char *fy_tag_token_suffix0(struct fy_token *fyt)
Get the suffix inside a tag token as a zero terminated string ๐
Parameters
fyt(struct fy_token*) โ the tag token the suffix pointer comes out of.
Description
Retrieves the tag suffix contents as a zero terminated string โจ. Just like fy_tag_token_suffix(), except โ you guessed it โ the returned string is zero terminated and memory may be allocated to hold it, associated with the token. Consistent queen behavior.
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
Retrieves the version stored in a version directive token. Simple as that, no notes ๐ .
Return
A pointer to the version stored in the version directive token, or NULL if there's an error, or if the token isn't a version directive token. (Rude, but fair.)
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
Retrieves the style of a scalar token. That's the whole assignment โจ.
Return
The scalar style of the token, or FYSS_ANY if there's an error. So yeah, FYSS_ANY is doing double duty as the error signal here โ just so you know ๐.
fy_tag_token_tag
const struct fy_tag *fy_tag_token_tag(struct fy_token *fyt)
Get the tag of a tag token ๐ท๏ธ
Parameters
fyt(struct fy_token*) โ the tag token.
Description
Retrieves the tag of a tag token. Iconic, lowkey self-explanatory.
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 the tag of a tag directive token ๐
Parameters
fyt(struct fy_token*) โ the tag directive token.
Description
Retrieves the tag of a tag directive token. Same vibe, different token type ๐ซถ.
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 you want the main token of.
Description
Retrieves the main token of an event โ and like, to be clear, that's the main token, not the tag or the anchor ๐. It may be NULL in the 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 you want the anchor token of.
Description
Retrieves the anchor token if it exists โจ. Heads up bestie โ this is only valid for mapping/sequence start events and scalar events. Don't come for other event types, it's not giving.
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 you want the tag token of.
Description
Retrieves the tag token if it exists. Same rule as the anchor one โ only valid for mapping/sequence start events and scalar events, got it? ๐
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 the event's start marker ๐
Parameters
fye(struct fy_event*) โ the event you want the start marker of.
Description
Returns the event's start marker if it exists โจ. The start marker is the one belonging to the event's main token, fyi.
Return
The event's start marker, NULL if it's not available.
fy_event_end_mark
const struct fy_mark *fy_event_end_mark(struct fy_event *fye)
Get the event's end marker ๐
Parameters
fye(struct fy_event*) โ the event you want the end marker of.
Description
Returns the event's end marker if it exists ๐. The end marker is the one belonging to the event's main token.
Return
The event's end marker, NULL if it's not available.
fy_event_style_start_mark
const struct fy_mark *fy_event_style_start_mark(struct fy_event *fye)
Get the event's start marker โ style edition ๐
Parameters
fye(struct fy_event*) โ the event you want the style start marker of.
Description
Returns the event's style start marker if it exists โจ. The start marker is the one of the event's main token, including the style marks. But โ plot twist โ if the event contains a tag, then the start mark is the start of the tag token ๐. So it's giving slightly different energy depending on what's in the event.
Return
The event's start marker, NULL if it's not available.
fy_event_style_end_mark
const struct fy_mark *fy_event_style_end_mark(struct fy_event *fye)
Get the event's end marker โ style edition ๐
Parameters
fye(struct fy_event*) โ the event you want the end marker of.
Description
Returns the event's style end marker if it exists. The end marker is the one belonging to the event's main token ๐ธ.
Return
The event's end marker, NULL if it's 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 you want the node style of.
Description
Returns the node style (FYNS_*) of an event โจ. It may return FYNS_ANY if the event is implicit. And, important detail: for collection start events, the only possible values are FYNS_ANY, FYNS_FLOW, and FYNS_BLOCK ๐
. A scalar event, on the other hand, may return any of them. So like, know your event type, bestie.
Return
Hmm โ the docs say this returns "the event's end marker, NULL if not available," which is lowkey a copy-paste glitch on their end ๐ญ, but we're reporting it faithfully: that's what it says. (Editor's note: the text literally says "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
Retrieves the version stored in a document start event โจ.
Return
A pointer to the version, or NULL if there's an error, or if the event isn't 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
Retrieves the version stored in a document state object. Yeah, that's it โ she's straightforward and we respect it ๐ธ.
Return
A pointer to the version, or NULL if something went sideways ๐ญ
fy_document_state_start_mark
const struct fy_mark *fy_document_state_start_mark(struct fy_document_state *fyds)
Get the document state's start mark โจ
Parameters
fyds(struct fy_document_state*) โ the document state object
Description
Returns the document state's start mark (if it even has one, bestie). Heads up: purely synthetic documents don't contain one, so don't come for me when you get NULL ๐
Return
The document's start marker, or NULL if it's not available.
fy_document_state_end_mark
const struct fy_mark *fy_document_state_end_mark(struct fy_document_state *fyds)
Get the document state's end mark ๐
Parameters
fyds(struct fy_document_state*) โ the document state object
Description
Returns the document state's end mark (if it exists). Same deal as before: purely synthetic documents do not contain one, no cap ๐ซถ
Return
The document's end marker, or NULL if it's not available.
fy_document_state_version_explicit
bool fy_document_state_version_explicit(struct fy_document_state *fyds)
Was the 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, periodt.
Return
true if the version was set explicitly, false otherwise
fy_document_state_tags_explicit
bool fy_document_state_tags_explicit(struct fy_document_state *fyds)
Were the 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. And yeah, for synthetic documents this method returns false, iykyk.
Return
true if the document had tags set explicitly, false otherwise
fy_document_state_start_implicit
bool fy_document_state_start_implicit(struct fy_document_state *fyds)
Did it start 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 the document was started implicitly, false otherwise
fy_document_state_end_implicit
bool fy_document_state_end_implicit(struct fy_document_state *fyds)
Did it end 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 the document was ended implicitly, false otherwise
fy_document_state_json_mode
bool fy_document_state_json_mode(struct fy_document_state *fyds)
Was the input JSON? ๐ฅ
Parameters
fyds(struct fy_document_state*) โ the document state object
Description
Find out if a document state object's document was created by a JSON input. Note that for synthetic documents this method returns false โ say it with me now ๐ฃ
Return
true if the document was created in JSON mode, 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 stateprevp(void**) โ the previous iterator
Description
This method iterates over all the tag directive 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_document_state_tag_directives
struct fy_tag **fy_document_state_tag_directives(struct fy_document_state *fyds)
Get all the tag directives in a malloc'ed array ๐งบ
Parameters
fyds(struct fy_document_state*) โ the document state
Description
Returns all the tag directives in a dynamically allocated area. Must be free()'d when you're not using it anymore โ like, actually free it, bestie, don't just vibe and forget ๐
Return
An array of fy_tag pointer structures, terminated with a NULL pointer, and NULL on error.
fy_document_state_tag_is_default
bool fy_document_state_tag_is_default(struct fy_document_state *fyds, const struct fy_tag *tag)
Test whether the given tag is a default one ๐ฏ
Parameters
fyds(struct fy_document_state*) โ the document statetag(const struct fy_tag*) โ the tag to check
Description
Test whether a tag is a default (i.e. implicitly set) one.
Return
true if the tag is a default one, false otherwise
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
Retrieves the document state object of a parser. Note that this is only valid during parsing โ like, only while the party's happening ๐
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
Retrieves the document state object of a document. Simple as that ๐
Return
The document state object of the document, NULL otherwise
fy_document_set_document_state
int fy_document_set_document_state(struct fy_document *fyd, struct fy_document_state *fyds)
Set the document state of a document ๐ ๏ธ
Parameters
fyd(struct fy_document*) โ the documentfyds(struct fy_document_state*) โ the document state to use, orNULLfor default
Description
Sets the document state of a document. That's the whole gig ๐ซก
Return
0 if the set operation was successful, -1 otherwise
fy_document_create_from_event
struct fy_document *fy_document_create_from_event(struct fy_parser *fyp, struct fy_event *fye)
Create an empty document using the event โจ
Parameters
fyp(struct fy_parser*) โ the parserfye(struct fy_event*) โ the event
Description
Create an empty document using the FYET_DOCUMENT_START event generated by the parser. Literally what it says ๐
Return
The created empty document, or NULL on error.
fy_document_update_from_event
int fy_document_update_from_event(struct fy_document *fyd, struct fy_parser *fyp, struct fy_event *fye)
Update the document with the event ๐
Parameters
fyd(struct fy_document*) โ the documentfyp(struct fy_parser*) โ the parserfye(struct fy_event*) โ the event
Description
Update the document using the FYET_DOCUMENT_END event generated by the parser ๐
Return
0 on success, -1 on error
fy_node_create_from_event
struct fy_node *fy_node_create_from_event(struct fy_document *fyd, struct fy_parser *fyp, struct fy_event *fye)
Create a node using the event ๐ฑ
Parameters
fyd(struct fy_document*) โ the documentfyp(struct fy_parser*) โ the parserfye(struct fy_event*) โ the event
Description
Create a new node using the supplied event. The allowed events are FYET_SCALAR, FYET_ALIAS, FYET_MAPPING_START & FYET_SEQUENCE_START โ anything else is a no ๐
Return
The newly created node, or NULL on error
fy_node_update_from_event
int fy_node_update_from_event(struct fy_node *fyn, struct fy_parser *fyp, struct fy_event *fye)
Update a node using the event ๐ง
Parameters
fyn(struct fy_node*) โ the nodefyp(struct fy_parser*) โ the parserfye(struct fy_event*) โ the event
Description
Update information of a node created using fy_node_create_from_event(). The allowed events are FYET_MAPPING_END & FYET_SEQUENCE_END ๐
Return
0 on success, -1 on error
fy_node_pair_create_with_key
struct fy_node_pair *fy_node_pair_create_with_key(struct fy_document *fyd, struct fy_node *fyn_parent, struct fy_node *fyn)
Create a new node pair and set its key ๐
Parameters
fyd(struct fy_document*) โ the documentfyn_parent(struct fy_node*) โ the mappingfyn(struct fy_node*) โ the node pair key
Description
Create a new node pair using the supplied fyn_parent mapping and fyn node as a key. Note that the nodes _must_ have been created by fy_node_create_from_event and they are not interchangeable with other node pair methods โ like, do not mix them, fr fr ๐
โโ๏ธ
The node pair will be added to the fyn_parent mapping with a subsequent call to fy_node_pair_update_with_value().
Return
The newly created node pair, or NULL on error
fy_node_pair_update_with_value
int fy_node_pair_update_with_value(struct fy_node_pair *fynp, struct fy_node *fyn)
Update a node pair with a value and add it to the parent mapping ๐
Parameters
fynp(struct fy_node_pair*) โ the node pairfyn(struct fy_node*) โ the node pair value
Description
Update the node pair with the given value and add it to the parent mapping. Note that the fyn node _must_ have been created by fy_node_create_from_event and the node pair created by fy_node_pair_create_with_key(). Do not intermix other node pair manipulation methods, bestie โ I'm begging ๐ญ
Return
0 on success, -1 on error
fy_node_sequence_add_item
int fy_node_sequence_add_item(struct fy_node *fyn_parent, struct fy_node *fyn)
Add an item node to a sequence node ๐งต
Parameters
fyn_parent(struct fy_node*) โ the parent sequence nodefyn(struct fy_node*) โ the node pair item
Description
Add an item to the end of the sequence node fyn_parent. Note that the fyn_parent and fyn nodes _must_ have been created by fy_node_create_from_event. Do not intermix other sequence node manipulation methods โ same rule as before, no exceptions ๐
Return
0 on success, -1 on error
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, bestie.
Return โ The active document state object of the emitter, NULL otherwise.
โ ๏ธ Emitting only. Outside that window? Not it. ๐
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) โ The optional extra arguments.
Description โ Create an emit event to pass to fy_emit_event(). The extra arguments differ according to the event to be created. So yeah, the varargs are giving โchoose your own adventure,โ but with YAML event types. ๐
The extra args go like this, depending on the event:
FYET_STREAM_START- None.
FYET_STREAM_END- None.
FYET_DOCUMENT_STARTint implicitโtrueif document start should be marked implicit,falseif document start should not be marked implicit.const struct fy_version *versโ Pointer to version to use for the document, orNULLfor default.const struct fy_tag * const *tagsโ Pointer to aNULLterminated array of tag pointers (likeargv),NULLif no extra tags are to be used.
FYET_DOCUMENT_ENDint implicitโtrueif document end should be marked implicit,falseif document end should not be marked implicit.
FYET_MAPPING_STARTenum fy_node_style styleโ Style of the mapping (one ofFYNS_ANY,FYNS_BLOCKorFYNS_FLOW).const char *anchorโ Anchor to place at the mapping, orNULLfor none.const char *tagโ Tag to place at the mapping, orNULLfor none.
FYET_MAPPING_END- None.
FYET_SEQUENCE_STARTenum fy_node_style styleโ Style of the sequence (one ofFYNS_ANY,FYNS_BLOCKorFYNS_FLOW).const char *anchorโ Anchor to place at the sequence, orNULLfor none.const char *tagโ Tag to place at the sequence, orNULLfor none.
FYET_SEQUENCE_END- None.
FYET_SCALARenum fy_scalar_style styleโ Style of the scalar, any validFYSS_*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, orFY_NT (-1)forstrlen(value).const char *anchorโ Anchor to place at the scalar, orNULLfor none.const char *tagโ Tag to place at the scalar, orNULLfor none.
FYET_ALIASconst 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 are analogous to fy_emit_event_create(). Same energy, just handed a va_list. ๐ซถ
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. Its only use is error recovery and cleanup. So like, donโt make freeing your whole personality โ itโs an emergency-cleanup kind of function. ๐
fy_parse_event_create
struct fy_event *fy_parse_event_create(struct fy_parser *fyp, enum fy_event_type type, ...)
Create an emit event. Yes, thatโs literally the one-liner. ๐
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 are analogous to fy_parse_event_create(). ๐ฆ
Return โ The created event or NULL in case of an error.
๐ธ PATH EXECUTION ๐ธ
okay so this header is where it gets fun โ it gives you the ypath subsystem, which is basically a JSONPath / XPath-style query language for navigating your YAML document trees ๐ฆ. iykyk, it's a whole vibe.
A ypath expression like /servers/0/host gets parsed first into a compiled struct fy_path_expr, and then it's executed against a starting node in any struct fy_document to produce a result set of matching nodes. Filter predicates and wildcards are also supported โ slay ๐
.
Typical workflow, bestie, follow along:
// 1. Create a path parser
struct fy_path_parser *fypp = fy_path_parser_create(NULL);
// 2. Compile an expression
struct fy_path_expr *expr =
fy_path_parse_expr_from_string(fypp, "/servers/0/host", -1);
// 3. Create an executor and run the expression
struct fy_path_exec *fypx = fy_path_exec_create(NULL);
fy_path_exec_execute(fypx, expr, fy_document_root(fyd));
// 4. Iterate results
void *iter = NULL;
struct fy_node *fyn;
while ((fyn = fy_path_exec_results_iterate(fypx, &iter)) != NULL)
process(fyn);
// 5. Cleanup
fy_path_exec_destroy(fypx);
fy_path_expr_free(expr);
fy_path_parser_destroy(fypp);
For one-shot use, fy_path_expr_build_from_string() wraps steps 1 and 2 into a single call โ so convenient, honestly ๐ซถ.
The executor can be reset and re-used for multiple executions against the same or different documents. The compiled expression is independent of any document and may be executed repeatedly. no cap, it's reusable like that โจ.
๐ 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 mode, so it doesn't output any information messages ๐คซFYPPCF_DISABLE_RECYCLINGโ Disable the recycling optimization โป๏ธFYPPCF_DISABLE_ACCELERATORSโ Disable use of access accelerators (this one saves memory ๐พ)
Description
These flags control the operation of the path parse. periodt.
๐ struct fy_path_parse_cfg ๐
struct fy_path_parse_cfg โ the 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
This is the argument to the fy_path_parser_create() method, which is what performs parsing of a ypath expression. it's giving config-central ๐
.
๐ 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(). If cfg is NULL a default yaml parser is created ๐.
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
Destroys a path parser that you created earlier via fy_path_parser_create(). clean up after yourself bestie ๐งน.
โญ 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 resets a path parser โ including after an error that caused a parser error to be emitted. like a fresh start, we love that for you ๐ธ.
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 usestr(*const char**) โ The ypath source to use.len(size_t) โ The length of the string (or-1if'0'terminated)
Description
Creates a path expression from a string, using the path parser you hand it ๐ซถ.
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 (the one-shot version, icon behavior) โจ
Parameters
pcfg(*const struct fy_path_parse_cfg**) โ The path parser configuration to use, orNULLfor defaultstr(*const char**) โ The ypath source to use.len(size_t) โ The length of the string (or-1if'0'terminated)
Description
Creates 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 beNULL)
Description
Frees a previously returned expression from any of the path parser methods, like fy_path_expr_build_from_string(). and yes, NULL is fine, it handles it ๐
.
๐ 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 dumpdiag(*struct fy_diag**) โ The diagnostic object to useerrlevel(enum fy_error_type) โ The error level which the diagnostic will uselevel(int) โ The nest level; should be set to0banner(*const char**) โ The banner to display on level0
Description
Dumps the expression using the provided error level. perfect for when you're like "what is this even doing" ๐.
๐ฅ fy_path_expr_to_document ๐ฅ
struct fy_document *fy_path_expr_to_document(struct fy_path_expr *expr)
Converts the path expression to a YAML document ๐
Parameters
expr(*struct fy_path_expr**) โ The expression to convert to a document
Description
Converts the expression to a YAML document, which is genuinely so useful for understanding what the expression evaluates to ๐. it's giving debug mode.
Return
The document of the expression, or NULL on error ๐ญ.
๐ 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. periodt.
๐ struct fy_path_exec_cfg ๐
struct fy_path_exec_cfg โ the 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
This is the argument to the fy_path_exec_create() method, which is what 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(). (yes the manpage says cfg here even though the param is xcfg โ we don't make the rules, we just report them ๐)
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
Destroys an executor created earlier via fy_path_exec_create(). (the manpage literally says "Destroy ane executor" โ typo and all, we keep it, that's the lore ๐ซถ)
โญ 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 resets an executor, without releasing it. reuse szn ๐ .
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 useexpr(*struct fy_path_expr**) โ The expression to usefyn_start(*struct fy_node**) โ The node on which the expression will begin.
Description
Executes the expression starting at fyn_start. If execution is successful, the results are available via fy_path_exec_results_iterate() โจ.
โ ๏ธ heads up bestie: it is illegal to modify the state of the document that the results reside in between this call and the results collection. like, do not touch it. seriously. ๐
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 ๐. (successful but empty, we've all been there)
๐ง 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 executorprevp(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 ๐.
๐ฆ DOCUMENT ITERATION ๐ฆ
okay so this header provides struct fy_document_iterator, which traverses a document tree depth-first without using system stack recursion โ no stack overflow era, we love to see it ๐. Two usage modes are supported:
Node iteration โ visit every node in a subtree in document order:
struct fy_document_iterator *fydi = fy_document_iterator_create();
fy_document_iterator_node_start(fydi, fy_document_root(fyd));
struct fy_node *fyn;
while ((fyn = fy_document_iterator_node_next(fydi)) != NULL)
process(fyn);
fy_document_iterator_destroy(fydi);
Event replay โ regenerate the YAML event stream that produced the document, suitable for feeding into a parser, emitter, or composer:
struct fy_document_iterator *fydi =
fy_document_iterator_create_on_document(fyd);
struct fy_event *fye;
while ((fye = fy_document_iterator_generate_next(fydi)) != NULL) {
process_event(fye);
fy_document_iterator_event_free(fydi, fye);
}
fy_document_iterator_destroy(fydi);
The iterator can also be attached to a struct fy_parser via fy_parser_set_document_iterator(), making a parser transparently replay the events of an existing document rather than parsing fresh input. obsessed with the convenience, honestly ๐
Events emitted by the iterator are in the same order as those that originally created the document, so round-trip fidelity is preserved. no cap, the round-trip stays iconic โจ
๐ enum fy_document_iterator_cfg_flags
Document iterator configuration flags ๐ซถ
๐ Definition
enum fy_document_iterator_cfg_flags {
FYDICF_WANT_BODY_EVENTS,
FYDICF_WANT_DOCUMENT_BODY_EVENTS,
FYDICF_WANT_STREAM_DOCUMENT_BODY_EVENTS
};
๐ Constants
FYDICF_WANT_BODY_EVENTSโ Generate body eventsFYDICF_WANT_DOCUMENT_BODY_EVENTSโ Generate document and body eventsFYDICF_WANT_STREAM_DOCUMENT_BODY_EVENTSโ Generate stream, document and body events
๐ฌ Description
These flags control the operation of the document iterator. tiny flags, big main-character energy ๐
๐ง struct fy_document_iterator_cfg
document iterator configuration structure. ๐ซถ
๐ Definition
struct fy_document_iterator_cfg {
enum fy_document_iterator_cfg_flags flags;
struct fy_document *fyd;
struct fy_node *iterate_root;
}
๐งฉ Members
flagsโ The document iterator flagsfydโ The document to iterate on (orNULLifiterate_rootis set)iterate_rootโ The root of iteration (NULLwhenfydis notNULL)
๐ฌ Description
Argument to the fy_document_iterator_create_cfg() method. it's giving config struct realness ๐
๐ฆ fy_document_iterator_create
struct fy_document_iterator *fy_document_iterator_create(void)
Create a document iterator ๐
๐ฏ Parameters
voidโ no arguments
๐ฌ Description
Creates a document iterator, that can trawl through a document without using recursion. no recursion, just vibes โจ
๐ Return
The newly created document iterator or NULL on error
๐ธ fy_document_iterator_create_cfg
struct fy_document_iterator *fy_document_iterator_create_cfg(const struct fy_document_iterator_cfg *cfg)
Create a document iterator using config ๐
๐ฏ Parameters
cfg(const struct fy_document_iterator_cfg*) โ The document iterator to destroy
not me side-eyeing that parameter description ๐ but yes, that is genuinely what it says.
๐ฌ Description
Creates a document iterator, that can trawl through a document without using recursion. The iterator will generate all the events that created the given document starting at iterator root. it literally replays the lore of the document ๐ซถ
๐ Return
The newly created document iterator or NULL on error
๐ฆ fy_document_iterator_create_on_document
struct fy_document_iterator *fy_document_iterator_create_on_document(struct fy_document *fyd)
Create a document iterator on document โจ
๐ฏ Parameters
fyd(struct fy_document*) โ The document to iterate on
๐ฌ Description
Creates a document iterator, starting at the root of the given document. root node first, obviously ๐
๐ Return
The newly created document iterator or NULL on error
๐ fy_document_iterator_create_on_node
struct fy_document_iterator *fy_document_iterator_create_on_node(struct fy_node *fyn)
Create a document iterator on node ๐ฆ
๐ฏ Parameters
fyn(struct fy_node*) โ The node to iterate on
๐ฌ Description
Creates a document iterator, starting at the given node. pick your starting point, bestie ๐ฏ
๐ Return
The newly created document iterator or NULL on error
๐
fy_document_iterator_destroy
void fy_document_iterator_destroy(struct fy_document_iterator *fydi)
Destroy the given document iterator ๐
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to destroy
๐ฌ Description
Destroy a document iterator created earlier via fy_document_iterator_create(). cleanup era, we love to see it ๐งน
๐ fy_document_iterator_event_free
void fy_document_iterator_event_free(struct fy_document_iterator *fydi, struct fy_event *fye)
Free an event that was created by a document iterator ๐ซถ
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator that created the eventfye(struct fy_event*) โ The event
๐ฌ Description
Free (possibly recycling) an event that was created by a document iterator. recycling? we love sustainability โป๏ธ
โญ fy_document_iterator_stream_start
struct fy_event *fy_document_iterator_stream_start(struct fy_document_iterator *fydi)
Create a stream start event using the iterator ๐
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to create the event
๐ฌ Description
Creates a stream start event on the document iterator and advances the internal state of it accordingly. state machine go brrr โ๏ธ
๐ Return
The newly created stream start event, or NULL on error.
๐ fy_document_iterator_stream_end
struct fy_event *fy_document_iterator_stream_end(struct fy_document_iterator *fydi)
Create a stream end event using the iterator ๐
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to create the event
๐ฌ Description
Creates a stream end event on the document iterator and advances the internal state of it accordingly. wrap it up, stream edition ๐ฌ
๐ Return
The newly created stream end event, or NULL on error.
๐ง fy_document_iterator_document_start
struct fy_event *fy_document_iterator_document_start(struct fy_document_iterator *fydi, struct fy_document *fyd)
Create a document start event using the iterator ๐
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to create the eventfyd(struct fy_document*) โ The document containing the document state that is used in the event
๐ฌ Description
Creates a document start event on the document iterator and advances the internal state of it accordingly. The document must not be released until an error, cleanup or a call to fy_document_iterator_document_end(). do not release it early, bestie โ that's a whole mess ๐ญ
๐ Return
The newly created document start event, or NULL on error.
๐ฌ fy_document_iterator_document_end
struct fy_event *fy_document_iterator_document_end(struct fy_document_iterator *fydi)
Create a document end event using the iterator ๐
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to create the event
๐ฌ Description
Creates a document end event on the document iterator and advances the internal state of it accordingly. The document that was used earlier in the call of fy_document_iterator_document_start() can now be released. okay NOW you may release it, periodt ๐
๐ Return
The newly created document end event, or NULL on error.
๐ fy_document_iterator_body_next
struct fy_event *fy_document_iterator_body_next(struct fy_document_iterator *fydi)
Create document body events until the end ๐
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to create the event
๐ฌ Description
Creates the next document body, depth first until the end of the document. The events are created depth first and are in same exact sequence that the original events that created the document.
That means that the finite event stream that generated the document is losslesly preserved in such a way that the document tree representation is functionally equivalent. the lore is preserved, fr fr ๐
Repeated calls to this function will generate a stream of SCALAR, ALIAS, SEQUENCE START, SEQUENCE END, MAPPING START and MAPPING END events, returning NULL at the end of the body event stream.
๐ Return
The newly created document body event or NULL at an error, or an end of the event stream. Use fy_document_iterator_get_error() to check if an error occured. vibe check the error state if something smells off ๐
๐ฆ fy_document_iterator_node_start
void fy_document_iterator_node_start(struct fy_document_iterator *fydi, struct fy_node *fyn)
Start a document node iteration run using a starting point ๐ฏ
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to run withfyn(struct fy_node*) โ The iterator root for the iteration
๐ฌ Description
Starts an iteration run starting at the given node. set the starting point and let it cook ๐ณ
๐ fy_document_iterator_node_next
struct fy_node *fy_document_iterator_node_next(struct fy_document_iterator *fydi)
Return the next node in the iteration sequence ๐ง
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to use for the iteration
๐ฌ Description
Returns a pointer to the next node iterating using as a start the node given at fy_document_iterator_node_start(). The first node returned will be that, followed by all the remaing nodes in the subtree. first the root, then the whole subtree โ iconic traversal behavior ๐ณ
๐ Return
The next node in the iteration sequence or NULL at the end, or if an error occured.
โญ fy_document_iterator_generate_next
struct fy_event *fy_document_iterator_generate_next(struct fy_document_iterator *fydi)
Create events from document iterator โจ
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to create the event
๐ฌ Description
This is a method that will handle the complex state of generating stream, document and body events on the given iterator. the multitasking icon of this API ๐
When generation is complete a NULL event will be generated.
๐ Return
The newly created event or NULL at an error, or an end of the event stream. Use fy_document_iterator_get_error() to check if an error occured. again: check the error state, bestie ๐
๐ fy_document_iterator_get_error
bool fy_document_iterator_get_error(struct fy_document_iterator *fydi)
Get the error state of the document iterator ๐จ
๐ฏ Parameters
fydi(struct fy_document_iterator*) โ The document iterator to use for checking itโs error state.
๐ฌ Description
Returns the error state of the iterator. If itโs in error state, return true and reset the iterator to the state just after creation. error state detected? reset and pretend it never happened, main character move ๐
๐ Return
true if it was in an error state, false otherwise. ๐
๐ enum fy_parser_event_generator_flags ๐
ok so this enum is literally just a vibe check for which events the generator should make. three options, no notes ๐
enum fy_parser_event_generator_flags {
FYPEGF_GENERATE_DOCUMENT_EVENTS,
FYPEGF_GENERATE_STREAM_EVENTS,
FYPEGF_GENERATE_ALL_EVENTS
};
the constants ๐
FYPEGF_GENERATE_DOCUMENT_EVENTSโ generate document eventsFYPEGF_GENERATE_STREAM_EVENTSโ generate stream eventsFYPEGF_GENERATE_ALL_EVENTSโ generate all events
๐ ๏ธ fy_parser_set_document_iterator
int fy_parser_set_document_iterator(struct fy_parser *fyp, enum fy_parser_event_generator_flags flags, struct fy_document_iterator *fydi)
Associate a parser with a document iterator
Parameters ๐ธ
fyp(struct fy_parser*) โ The parserflags(enum fy_parser_event_generator_flags) โ The event generation flagsfydi(struct fy_document_iterator*) โ The document iterator to associate
Description ๐
okay so you're basically setting up a situationship between a parser and a document iterator โ instead of the parser doing the parsing itself, the events get generated by the document iterator instead. iconic delegation, ngl.
Return โจ
0 on success, -1 on error
๐ฆ DOCUMENT BUILDER ๐ฆ
This header provides struct fy_document_builder, which accumulates YAML parser events and assembles them into a struct fy_document tree. it's giving arts-and-crafts but for YAML ๐จ
The builder supports two operating modes:
Pull mode โ the builder drives a parser internally:
struct fy_document_builder *fydb =
fy_document_builder_create_on_parser(fyp);
struct fy_document *fyd;
while ((fyd = fy_document_builder_load_document(fydb, fyp)) != NULL) {
process(fyd);
fy_document_destroy(fyd);
}
fy_document_builder_destroy(fydb);
Push mode โ the caller feeds events one at a time and takes ownership when the document is complete:
fy_document_builder_set_in_stream(fydb);
struct fy_event *fye;
while ((fye = get_next_event()) != NULL) {
fy_document_builder_process_event(fydb, fye);
if (fy_document_builder_is_document_complete(fydb)) {
struct fy_document *fyd =
fy_document_builder_take_document(fydb);
process(fyd);
fy_document_destroy(fyd);
}
}
Push mode is the move when events arrive asynchronously or from a source other than a libfyaml parser โ like a document iterator or a network stream. main character energy for sure ๐ฆ
fy_parse_load_document_with_builder() provides the simplest interface: literally one single call that returns the next complete document from a parser. ate and left no crumbs ๐
๐งฑ struct fy_document_builder_cfg
document builder configuration structure.
Definition
struct fy_document_builder_cfg {
struct fy_parse_cfg parse_cfg;
void *userdata;
struct fy_diag *diag;
}
Members ๐
parse_cfgโ Parser configurationuserdataโ Opaque user data pointerdiagโ Optional diagnostic interface to use
Description ๐
Argument to the fy_document_builder_create() method
๐ฃ fy_document_builder_create
struct fy_document_builder *fy_document_builder_create(const struct fy_document_builder_cfg *cfg)
Create a document builder
Parameters ๐
cfg(const struct fy_document_builder_cfg*) โ The configuration for the document builder
Description โจ
Creates a document builder with its configuration cfg. The document builder may be destroyed by a corresponding call to fy_document_builder_destroy().
Return ๐ซถ
A pointer to the document builder or NULL in case of an error.
๐ง fy_document_builder_create_on_parser
struct fy_document_builder *fy_document_builder_create_on_parser(struct fy_parser *fyp)
Create a document builder pulling state from the parser
Parameters ๐ซ
fyp(struct fy_parser*) โ The parser to associate with
Description ๐ธ
Creates a document builder pulling state from the given parser
Return โญ
A pointer to the document builder or NULL in case of an error.
๐ fy_document_builder_reset
void fy_document_builder_reset(struct fy_document_builder *fydb)
Reset a document builder
Parameters ๐
fydb(struct fy_document_builder*) โ The document builder
Description ๐
Resets a document builder without destroying it โ a little factory reset, but it keeps the builder alive. we love a soft launch.
๐ fy_document_builder_destroy
void fy_document_builder_destroy(struct fy_document_builder *fydb)
Destroy a document builder
Parameters ๐ญ
fydb(struct fy_document_builder*) โ The document builder
Description ๐ฅ
Destroy a document builder. it's over bestie, say bye.
๐ fy_document_builder_get_document
struct fy_document *fy_document_builder_get_document(struct fy_document_builder *fydb)
Get the document of a builder
Parameters ๐ฆ
fydb(struct fy_document_builder*) โ The document builder
Description ๐
Retrieve the document of a document builder. heads up though โ this document may be incomplete. If you need to take ownership use fy_document_builder_take_document(). don't be out here acting like it's finished, it's not ๐ค
Return ๐
The document that the builder built, or NULL in case of an error
๐ fy_document_builder_is_in_stream
bool fy_document_builder_is_in_stream(struct fy_document_builder *fydb)
Test document builder in stream
Parameters ๐งต
fydb(struct fy_document_builder*) โ The document builder
Description โจ
Find out if the document builder is in 'stream' state โ i.e. after stream start but before stream end events are generated. the in-between era, the liminal space, the "we're so back but also not yet" moment.
Return ๐ซถ
true if in stream, false otherwise
๐ fy_document_builder_is_in_document
bool fy_document_builder_is_in_document(struct fy_document_builder *fydb)
Test document builder in document
Parameters ๐
fydb(struct fy_document_builder*) โ The document builder
Description ๐ธ
Find out if the document builder is in 'document' state โ i.e. after document start but before document end events are generated.
Return โญ
true if in document, false otherwise
โ
fy_document_builder_is_document_complete
bool fy_document_builder_is_document_complete(struct fy_document_builder *fydb)
Test document builder complete
Parameters ๐
fydb(struct fy_document_builder*) โ The document builder
Description ๐ซ
Find out if the document of the builder is complete. and if it is complete, then a call to fy_document_builder_take_document() will transfer ownership of the document to the caller. that's the glow-up moment right there.
Return ๐
true if document complete, false otherwise
๐ซด fy_document_builder_take_document
struct fy_document *fy_document_builder_take_document(struct fy_document_builder *fydb)
Take ownership the document of a builder
Parameters ๐
fydb(struct fy_document_builder*) โ The document builder
Description ๐
Take ownership of the document of a document builder. the document builder's document must be complete โ like, non-negotiable, fr fr.
Return โจ
The document that the builder built, or NULL in case of an error
๐ fy_document_builder_peek_document
struct fy_document *fy_document_builder_peek_document(struct fy_document_builder *fydb)
Peek at the document of a builder
Parameters ๐ธ
fydb(struct fy_document_builder*) โ The document builder
Description ๐ฆ
Peek at the document of a document builder. Ownership still remains with the builder โ so like, look, don't touch ๐
Return ๐
A peek to the document that the builder built, or NULL in case of an error
๐ fy_document_builder_set_in_stream
void fy_document_builder_set_in_stream(struct fy_document_builder *fydb)
Set the builders state in 'stream'
Parameters ๐ง
fydb(struct fy_document_builder*) โ The document builder
Description ๐ซ
Set the document builders state to in 'stream'
๐ fy_document_builder_set_in_document
int fy_document_builder_set_in_document(struct fy_document_builder *fydb, struct fy_document_state *fyds, bool single)
Set the builders state in 'document'
Parameters ๐
fydb(struct fy_document_builder*) โ The document builderfyds(struct fy_document_state*) โ The document statesingle(bool) โ Single document mode
Description ๐ฅ
Set the document builders state to in 'document'
Return โญ
0 on success, -1 on error
๐ฅ fy_document_builder_load_document
struct fy_document *fy_document_builder_load_document(struct fy_document_builder *fydb, struct fy_parser *fyp)
Create a document from parser events
Parameters ๐
fydb(struct fy_document_builder*) โ The document builderfyp(struct fy_parser*) โ The parser
Description ๐
Load a document by pumping the parser for events and then processing them with the builder. pump it, process it, slay it.
Return ๐ซถ
The document that results from the parser, or NULL in case of an error (or EOF)
๐๏ธ fy_parse_load_document_with_builder
struct fy_document *fy_parse_load_document_with_builder(struct fy_parser *fyp)
Parse a document via built-in builder
Parameters โจ
fyp(struct fy_parser*) โ The parser
Description ๐ธ
Load a document by pumping the parser for events and then processing them with the in-parser builder. the builder's already in there, you don't gotta bring your own ๐
Return ๐
The document that results from the parser, or NULL in case of an error (or EOF)
โก fy_document_builder_process_event
int fy_document_builder_process_event(struct fy_document_builder *fydb, struct fy_event *fye)
Process an event with a builder
Parameters ๐ฆ
fydb(struct fy_document_builder*) โ The document builderfye(struct fy_event*) โ The event
Description ๐ซ
Pump an event to a document builder for processing.
Return โญ
0 on success, -1 on error
๐ผ COMPOSER ๐ผ
This header provides two complementary interfaces for processing YAML event streams with awareness of the current position in the document hierarchy โ and the best part? no commitment to building a full in-memory tree required. we're just vibing through the events, not moving in ๐ง
Simple callback interface โ fy_parse_compose() calls a user function for each event, passing both the event and the current struct fy_path so the callback can make intelligent decisions without maintaining its own path stack:
enum fy_composer_return my_cb(struct fy_parser *fyp,
struct fy_event *fye,
struct fy_path *path,
void *userdata)
{
if (fy_path_depth(path) > 3)
return FYCR_OK_START_SKIP;
process(fye);
return FYCR_OK_CONTINUE;
}
fy_parse_compose(fyp, my_cb, ctx);
Object-based interface โ struct fy_composer is literally the same mechanism but wrapped in a reusable object, bestie ๐
. It's got ops callbacks, optional document builder integration, and helpers for navigating the path hierarchy. Same energy, cuter packaging.
Path inspection helpers โ functions like fy_path_in_mapping(), fy_path_depth(), fy_path_component_is_sequence(), plus those user-data attach/retrieve pairs, let your callbacks annotate and query the live path stack with zero external bookkeeping. No mental notes app needed, we love to see it ๐ซถ.
Callbacks control event processing by returning one of:
FYCR_OK_CONTINUEโ consume the event and continueFYCR_OK_STOPโ consume the event and stopFYCR_OK_START_SKIPโ start skipping the current subtreeFYCR_OK_STOP_SKIPโ stop an active skip and resume processingFYCR_ERRORโ abort with an error
๐ enum fy_composer_return
enum fy_composer_return โ the returns of the composer callback, aka the vibe check for your whole event loop โจ
Definition
enum fy_composer_return {
FYCR_OK_CONTINUE,
FYCR_OK_STOP,
FYCR_OK_START_SKIP,
FYCR_OK_STOP_SKIP,
FYCR_ERROR
};
Constants
FYCR_OK_CONTINUEโ continue processing, event processed ๐FYCR_OK_STOPโ stop processing, event processedFYCR_OK_START_SKIPโ start skip object(s), event processedFYCR_OK_STOP_SKIPโ stop skipping of objects, event processedFYCR_ERRORโ error, stop processing ๐
๐ธ fy_composer_return_is_ok
bool fy_composer_return_is_ok(enum fy_composer_return ret)
Check if the return code is OK. Literally just "is this fine or not" ๐ง
Parameters
ret(enum fy_composer_return) โ the composer return to check
Description
Convenience method for checking if it's OK to continue.
Return
true if non error or skip condition.
๐ฆ typedef fy_parse_composer_cb
enum fy_composer_return fy_parse_composer_cb(struct fy_parser *fyp,
struct fy_event *fye,
struct fy_path *path,
void *userdata)
Composer callback method โ the main character of this whole section, no cap ๐
Parameters
fyp(struct fy_parser*) โ The parserfye(struct fy_event*) โ The eventpath(struct fy_path*) โ The path that the parser is processinguserdata(void*) โ The user data of thefy_parse_compose()method
Description
This method is called by the fy_parse_compose() method when an event must be processed.
Return
fy_composer_return code telling the parser what to do.
๐ fy_parse_compose
int fy_parse_compose(struct fy_parser *fyp, fy_parse_composer_cb cb,
void *userdata)
Parse using a compose callback. It's giving โจ alternative timeline โจ.
Parameters
fyp(struct fy_parser*) โ The parsercb(fy_parse_composer_cb) โ The callback that will be calleduserdata(void*) โ user pointer to pass to the callback
Description
Alternative parsing method using a composer callback.
The parser will construct a path argument that is used by the callback to make intelligent decisions about creating a document and/or DOM. Big brain behavior fr fr ๐ง
Return
0 if no error occured, -1 on error.
๐ fy_path_component_is_mapping
bool fy_path_component_is_mapping(struct fy_path_component *fypc)
Check if the component is a mapping ๐
Parameters
fypc(struct fy_path_component*) โ The path component to check
Return
true if the path component is a mapping, false otherwise.
โญ fy_path_component_is_sequence
bool fy_path_component_is_sequence(struct fy_path_component *fypc)
Check if the component is a sequence ๐
Parameters
fypc(struct fy_path_component*) โ The path component to check
Return
true if the path component is a sequence, false otherwise.
๐ fy_path_component_sequence_get_index
int fy_path_component_sequence_get_index(struct fy_path_component *fypc)
Get the index of sequence path component โ like, which slot are we in, bestie? ๐ข
Parameters
fypc(struct fy_path_component*) โ The sequence path component to return it's index value
Return
>= 0 the sequence index, -1 if the component is either not in the proper mode, or not a sequence.
๐ fy_path_component_mapping_get_scalar_key
struct fy_token *fy_path_component_mapping_get_scalar_key(struct fy_path_component *fypc)
Get the scalar key of a mapping ๐
Parameters
fypc(struct fy_path_component*) โ The mapping path component to return it's scalar key
Return
a non NULL scalar or alias token if the mapping contains a scalar key, NULL in case of an error, or if the component has a complex key.
๐ธ fy_path_component_mapping_get_scalar_key_tag
struct fy_token *fy_path_component_mapping_get_scalar_key_tag(struct fy_path_component *fypc)
Get the scalar key's tag of a mapping ๐ท๏ธ
Parameters
fypc(struct fy_path_component*) โ The mapping path component to return it's scalar key's tag
Return
a non NULL tag token if the mapping contains a scalar key with a tag or NULL in case of an error, or if the component has a complex key.
๐ฆ fy_path_component_mapping_get_complex_key
struct fy_document *fy_path_component_mapping_get_complex_key(struct fy_path_component *fypc)
Get the complex key of a mapping โ this is the fancy one, iykyk ๐
Parameters
fypc(struct fy_path_component*) โ The mapping path component to return it's complex key
Return
a non NULL document if the mapping contains a complex key, NULL in case of an error, or if the component has a simple key.
โจ fy_path_component_get_text
char *fy_path_component_get_text(struct fy_path_component *fypc)
Get the textual representation of a path component ๐
Parameters
fypc(struct fy_path_component*) โ The path component to get it's textual representation
Description
Given a path component, return a malloc'ed string which contains the textual representation of it.
Note that this method will only return fully completed components and not ones that are in the building process. Mid-build components are not invited to the group chat ๐
Return
The textual representation of the path component, NULL on error, or if the component has not been completely built during the composition of a complex key. The string must be free'ed using free.
โ ๏ธ Yes bestie, you own that memory โ free it or it's a leak, and leaks are not the vibe.
๐ฅ fy_path_depth
int fy_path_depth(struct fy_path *fypp)
Get the depth of a path โ how deep are we in this YAML rabbit hole ๐ณ๏ธ
Parameters
fypp(struct fy_path*) โ The path to query
Return
The depth of the path, or -1 on error.
๐ fy_path_parent
struct fy_path *fy_path_parent(struct fy_path *fypp)
Get the parent of a path ๐ฉโ๐ง
Parameters
fypp(struct fy_path*) โ The path to return it's parent
Description
Paths may contain parents when traversing complex keys. This method returns the immediate parent.
Return
The path parent or NULL on error, if it doesn't exist.
๐ fy_path_get_text
char *fy_path_get_text(struct fy_path *fypp)
Get the textual representation of a path โ๏ธ
Parameters
fypp(struct fy_path*) โ The path to get it's textual representation
Description
Given a path, return a malloc'ed string which contains the textual representation of it.
Note that during processing, complex key paths are simply indicative and not to be used for addressing. Like, they're decorative, not functional, okay? ๐
Return
The textual representation of the path, NULL on error. The string must be free'ed using free.
๐ fy_path_in_root
bool fy_path_in_root(struct fy_path *fypp)
Check if the path is in the root of the document ๐ฑ
Parameters
fypp(struct fy_path*) โ The path
Return
true if the path is located within the root of the document.
๐ fy_path_in_mapping
bool fy_path_in_mapping(struct fy_path *fypp)
Check if the path is in a mapping ๐บ๏ธ
Parameters
fypp(struct fy_path*) โ The path
Return
true if the path is located within a mapping.
๐ฆ fy_path_in_sequence
bool fy_path_in_sequence(struct fy_path *fypp)
Check if the path is in a sequence ๐
Parameters
fypp(struct fy_path*) โ The path
Return
true if the path is located within a sequence.
๐ fy_path_in_mapping_key
bool fy_path_in_mapping_key(struct fy_path *fypp)
Check if the path is in a mapping key state ๐
Parameters
fypp(struct fy_path*) โ The path
Return
true if the path is located within a mapping key state.
๐ fy_path_in_mapping_value
bool fy_path_in_mapping_value(struct fy_path *fypp)
Check if the path is in a mapping value state ๐
Parameters
fypp(struct fy_path*) โ The path
Return
true if the path is located within a mapping value state.
๐ธ fy_path_in_collection_root
bool fy_path_in_collection_root(struct fy_path *fypp)
Check if the path is in a collection root ๐๏ธ
Parameters
fypp(struct fy_path*) โ The path
Description
A collection root state is when the path points to a sequence or mapping but the state does not allow setting keys, values or adding items.
This occurs on MAPPING/SEQUENCE START/END events.
Return
true if the path is located within a collection root state.
๐ซถ fy_path_get_root_user_data
void *fy_path_get_root_user_data(struct fy_path *fypp)
Return the userdata associated with the path root ๐ฆ
Parameters
fypp(struct fy_path*) โ The path
Return
The user data associated with the root of the path, or NULL if no path.
๐ fy_path_set_root_user_data
void fy_path_set_root_user_data(struct fy_path *fypp, void *data)
Set the user data associated with the root ๐งธ
Parameters
fypp(struct fy_path*) โ The pathdata(void*) โ The data to set as root data
Description
Note, no error condition if not a path. Chill, it just doesn't do anything ๐
๐ fy_path_component_get_mapping_user_data
void *fy_path_component_get_mapping_user_data(struct fy_path_component *fypc)
Return the userdata associated with the mapping ๐ฌ
Parameters
fypc(struct fy_path_component*) โ The path component
Return โ the user data that's chillin' with that mapping, or NULL if it's not a mapping at all, or if the user data itself is NULL ๐ซถ
โจ fy_path_component_get_mapping_key_user_data โจ
void *fy_path_component_get_mapping_key_user_data(struct fy_path_component *fypc)
Returns the userdata that's attached to the mapping key, bestie ๐
Parameters
fypc(struct fy_path_component *) โ the path component
Return โ the user data hanging out with the mapping key, or NULL if it's not a mapping or the user data is NULL ๐
๐ fy_path_component_get_sequence_user_data ๐
void *fy_path_component_get_sequence_user_data(struct fy_path_component *fypc)
Returns the userdata that's attached to the sequence ๐ธ
Parameters
fypc(struct fy_path_component *) โ the path component
Return โ the user data chilling with the sequence, or NULL if it's not a sequence or the user data is NULL โจ
๐ฆ fy_path_component_set_mapping_user_data ๐ฆ
void fy_path_component_set_mapping_user_data(struct fy_path_component *fypc, void *data)
Sets the user data associated with a mapping ๐
Parameters
fypc(struct fy_path_component *) โ the path componentdata(void *) โ the data to set as mapping data
Description
Heads up: there's no error condition if it's not a mapping. It just... does its thing ๐
๐ฅ fy_path_component_set_mapping_key_user_data ๐ฅ
void fy_path_component_set_mapping_key_user_data(struct fy_path_component *fypc, void *data)
Sets the user data associated with a mapping key ๐
Parameters
fypc(struct fy_path_component *) โ the path componentdata(void *) โ the data to set as mapping key data
Description
Again, no error condition if you're not in a mapping key state. Zero drama, zero complaints ๐
๐ fy_path_component_set_sequence_user_data ๐
void fy_path_component_set_sequence_user_data(struct fy_path_component *fypc, void *data)
Sets the user data associated with a sequence ๐ธ
Parameters
fypc(struct fy_path_component *) โ the path componentdata(void *) โ the data to set as sequence data
Description
Same deal: no error condition if it's not a sequence ๐ซถ
โญ fy_path_get_parent_user_data โญ
void *fy_path_get_parent_user_data(struct fy_path *path)
Returns the userdata of the parent collection ๐
Parameters
path(struct fy_path *) โ the path
Return โ the user data belonging to the parent collection of the path, or NULL if there's no path ๐ญ
๐ fy_path_set_parent_user_data ๐
void fy_path_set_parent_user_data(struct fy_path *path, void *data)
Sets the user data associated with the parent collection ๐
Parameters
path(struct fy_path *) โ the pathdata(void *) โ the data to set as parent collection data
Description
And yeah โ no error condition if there's no path. It's giving "unbothered" โจ
๐ fy_path_get_last_user_data ๐
void *fy_path_get_last_user_data(struct fy_path *path)
Returns the userdata of the last collection ๐ฅ
Parameters
path(struct fy_path *) โ the path
Return โ the user data belonging to the last collection of the path, or NULL if there's no path ๐
๐ง fy_path_set_last_user_data ๐ง
void fy_path_set_last_user_data(struct fy_path *path, void *data)
Sets the user data associated with the last collection ๐
Parameters
path(struct fy_path *) โ the pathdata(void *) โ the data to set as last collection data
Description
Once more for the people in the back: no error condition if there's no path ๐
๐ fy_path_last_component ๐
struct fy_path_component *fy_path_last_component(struct fy_path *fypp)
Gets the very last component of a path โ like, the final girl of the path hierarchy ๐
Parameters
fypp(struct fy_path *) โ the path
Description
Returns the last component of a path.
Return โ the last path component (which, yes, may be a collection root component), or NULL if it doesn't exist ๐ญ
๐ฆ fy_path_last_not_collection_root_component ๐ฆ
struct fy_path_component *fy_path_last_not_collection_root_component(struct fy_path *fypp)
Gets the last non collection root component of a path ๐ธ
Parameters
fypp(struct fy_path *) โ the path
Description
Returns the last non collection root component of a path. And heads up โ this may not be the last component that fy_path_last_component() hands you ๐
The difference shows up on MAPPING/SEQUENCE START/END events, where the last component is present but not usable as an object parent. Awkward, but that's the vibe ๐
Return โ the last non collection root component, or NULL if it doesn't exist โจ
๐ struct fy_composer_ops ๐
struct fy_composer_ops โ the composer operation callbacks, i.e. the main character energy of the composer ๐
Definition
struct fy_composer_ops {
enum fy_composer_return (*process_event)(struct fy_composer *fyc, struct fy_path *path, struct fy_event *fye);
struct fy_document_builder *(*create_document_builder)(struct fy_composer *fyc);
}
Members
process_eventโ callback for processing a single YAML event with path context ๐ฅcreate_document_builderโ callback for creating a document builder instance ๐ ๏ธ
Description
These are the callbacks the composer uses to process events and create document builders ๐
๐ฆ struct fy_composer_cfg ๐ฆ
struct fy_composer_cfg โ the composer configuration structure, the whole setup โจ
Definition
struct fy_composer_cfg {
const struct fy_composer_ops *ops;
void *userdata;
struct fy_diag *diag;
}
Members
opsโ pointer to composer operation callbacks ๐userdataโ opaque user data pointer that gets passed to callbacks ๐ซdiagโ optional diagnostic interface to use;NULLmeans default ๐ธ
Description
Configuration structure for creating a composer instance. Iconic, honestly ๐
โญ fy_composer_create โญ
struct fy_composer *fy_composer_create(struct fy_composer_cfg *cfg)
Creates a composer โจ
Parameters
cfg(struct fy_composer_cfg *) โ the configuration for the composer
Description
Creates a composer with the given configuration. The composer processes YAML events using callback methods and keeps path information around so it can do intelligent document composition ๐ง โจ The composer may be destroyed by a corresponding call to fy_composer_destroy().
Return โ a pointer to the composer, or NULL in case of an error ๐ญ
๐ fy_composer_destroy ๐
void fy_composer_destroy(struct fy_composer *fyc)
Destroys the given composer ๐ซถ
Parameters
fyc(struct fy_composer *) โ the composer to destroy
Description
Destroys a composer that you created earlier via fy_composer_create(). Closure, bestie ๐
๐ฅ fy_composer_process_event ๐ฅ
enum fy_composer_return fy_composer_process_event(struct fy_composer *fyc, struct fy_event *fye)
Runs a YAML event through the composer ๐ฌ
Parameters
fyc(struct fy_composer *) โ the composerfye(struct fy_event *) โ the event to process
Description
Processes a YAML event by calling the configured process_event callback with path context. The composer maintains the current path and hands it to the callback so it can make intelligent processing decisions ๐
Return โ a fy_composer_return code saying how to proceed (continue, stop, skip, or error) ๐ซ
๐ธ fy_composer_get_cfg ๐ธ
struct fy_composer_cfg *fy_composer_get_cfg(struct fy_composer *fyc)
Gets the configuration of a composer ๐
Parameters
fyc(struct fy_composer *) โ the composer
Return โ the configuration of the composer โจ
๐ fy_composer_get_cfg_userdata ๐
void *fy_composer_get_cfg_userdata(struct fy_composer *fyc)
Gets the userdata from the composer configuration ๐ซถ
Parameters
fyc(struct fy_composer *) โ the composer
Description
Retrieves that opaque userdata pointer from the composer's configuration ๐ซ
Return โ the userdata pointer from the configuration โญ
๐ง fy_composer_get_diag ๐ง
struct fy_diag *fy_composer_get_diag(struct fy_composer *fyc)
Gets the diagnostic object of a composer ๐ฉบ
Parameters
fyc(struct fy_composer *) โ the composer to get the diagnostic object
Description
Returns a pointer to the diagnostic object of a composer object. Important though: the returned diag object has a reference taken, so you should fy_diag_unref() it when you're done with it. Don't leave it hanging, that's a leak and it's not cute ๐
Return โ a pointer to a ref'ed diagnostic object, or NULL in case of an error ๐ญ
๐ fy_composer_get_path ๐
struct fy_path *fy_composer_get_path(struct fy_composer *fyc)
Gets the current path of the composer ๐
Parameters
fyc(struct fy_composer *) โ the composer
Description
Retrieves the current path being processed by the composer. The path represents the location in the YAML document structure where the composer is currently positioned โ like a little "you are here" map ๐บ๏ธ
Return โ the current path, or NULL if no path is active ๐
๐ fy_composer_get_root_path ๐
struct fy_path *fy_composer_get_root_path(struct fy_composer *fyc)
Gets the root path of the composer ๐
Parameters
fyc(struct fy_composer *) โ the composer
Description
Retrieves the root path of the composer's path hierarchy โ the origin story ๐ฑ
Return โ the root path, or NULL if no root exists ๐ญ
๐ fy_composer_get_next_path ๐
struct fy_path *fy_composer_get_next_path(struct fy_composer *fyc, struct fy_path *fypp)
Gets the next path in the composer's path list โก๏ธ
Parameters
fyc(struct fy_composer *) โ the composerfypp(struct fy_path *) โ the previous path, orNULLto get the first path
Description
Iterates through the composer's path list. Pass NULL to get the first path, or pass the previous path to get the next one. It's a whole scroll session, fr fr ๐
Return โ the next path in the list, or NULL if no more paths exist ๐
๐ COPYRIGHT ๐
2019-2026, Pantelis Antoniou โ respect the author, no cap ๐๐
and that's a wrap onLIBFYAML-CORE(3)bestie!! ๐ this was theMar 15, 2026edition of the page, go forth and compose your YAML with main character energy ๐ฆโจ๐
๐ฆ where this page comes from
- nixpkgs unstable: libfyaml 0.9.6
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms