From: Ingy d. N. <in...@in...> - 2021-08-21 13:28:54
|
Greetings, This mailing list isn't used for much anymore, save high level announcements from time to time. A couple things: - Check out https://github.com/pantoniou/libfyaml/ which is more full featured and under active development. - Join https://matrix.to/#/#chat:yaml.io which is the new best way to engage with the YAML community. - #yaml IRC is still around on the libera.chat IRC network. Cheers, Ingy On Mon, Aug 16, 2021 at 12:19 PM Felix Krause <ya...@fl...> wrote: > Hi David, > > libyaml does contain such an API: > https://github.com/yaml/libyaml/blob/master/include/yaml.h#L1457 > > This gives you a yaml_document_t with a root node accessible via > yaml_document_get_root_node. The API is not well-documented but basically > nodes can refer to sub-nodes via an int index and you use > yaml_document_get_node to retrieve subnodes. > > mapping and sequence nodes store their children in a stack structure – you > iterate them via > > for (yaml_node_item_t *cur = node->data.sequence.start; cur != node->data.sequence.top; ++cur) { > // ... > } > > Now if you load in a YAML that contains a mapping with scalar key/value > pairs, your root node will be a mapping and the subnodes will be scalars. > ------------------------------ > > If you want a more convenient API, I did write this utility in the past: > https://github.com/flyx/libyaml_constructor > > It is a code generator that reads in a C header containing type > definitions and autogenerates code that loads YAML into those types (using > libyaml). With this, you can define how your YAML structure must look via C > types and some annotations in the given header. > > That tool was a part of a project which I abandoned, hence I never did a > proper release. However it did work quite well for all I can remember. The > compile-time dependency on libclang (to parse your C header) may be a bit > of a hurdle. > > Cheers, > Felix > _______________________________________________ > Yaml-core mailing list > Yam...@li... > https://lists.sourceforge.net/lists/listinfo/yaml-core > |