Re: Parsing YAML into key:value tree nodes with C library

David Todd <[email protected]> Sat, 21 Aug 2021 16:39:33 -0400
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============3230498367755081177==
Content-Type: multipart/alternative;
 boundary="------------DC9D41C2BDB7A49CEF7F6316"
Content-Language: en-US

This is a multi-part message in MIME format.
--------------DC9D41C2BDB7A49CEF7F6316
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Thanks for the information, Ingy!=C2=A0 I should have realized that the l=
ist=20
isn't used much just by the lack of traffic, but I didn't know where to=20
look.

And thanks to the pointer to libfyaml.=C2=A0 I hadn't seen that package (=
or,=20
at least hadn't noted it) in by browsing, but just looking at the=20
excellent Readme.md, it looks like it's well documented and functional.=C2=
=A0=20
I'll give it a try.

David


On 8/21/21 8:33 AM, Ingy dot Net wrote:
> Greetings,
>
> This mailing list isn't used for much anymore, save high level=20
> announcements from time to time.
>
> A couple things:
>
>   * Check out https://github.com/pantoniou/libfyaml/
>     <https://github.com/pantoniou/libfyaml/> which is more full
>     featured and under active development.
>   * Join https://matrix.to/#/#chat:yaml.io
>     <https://matrix.to/#/#chat:yaml.io> which is the new best way to
>     engage with the YAML community.
>       o #yaml IRC is still around on the libera.chat IRC network.
>
> Cheers, Ingy
>
>
> On Mon, Aug 16, 2021 at 12:19 PM Felix Krause <[email protected]=20
> <mailto:[email protected]>> wrote:
>
>     Hi David,
>
>     libyaml does contain such an API:
>     https://github.com/yaml/libyaml/blob/master/include/yaml.h#L1457
>     <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 =E2=80=93 you iterate them via
>
>     |for (yaml_node_item_t *cur =3D node->data.sequence.start; cur !=3D=

>     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
>     <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
>     [email protected]
>     <mailto:[email protected]>
>     https://lists.sourceforge.net/lists/listinfo/yaml-core
>     <https://lists.sourceforge.net/lists/listinfo/yaml-core>
>


--------------DC9D41C2BDB7A49CEF7F6316
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html>
  <head>
    <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF=
-8">
  </head>
  <body>
    Thanks for the information, Ingy!=C2=A0 I should have realized that t=
he
    list isn't used much just by the lack of traffic, but I didn't know
    where to look.<br>
    <br>
    And thanks to the pointer to libfyaml.=C2=A0 I hadn't seen that packa=
ge
    (or, at least hadn't noted it) in by browsing, but just looking at
    the excellent Readme.md, it looks like it's well documented and
    functional.=C2=A0 I'll give it a try.<br>
    <br>
    David<br>
    <br>
    <br>
    <div class=3D"moz-cite-prefix">On 8/21/21 8:33 AM, Ingy dot Net wrote=
:<br>
    </div>
    <blockquote type=3D"cite"
cite=3D"mid:CAHJtQJ5qAvmB-=3DfRCq81QopD8kTAC8Pc=3DHGvBfeULfnhwDtGQQ@mail.=
gmail.com">
      <meta http-equiv=3D"content-type" content=3D"text/html; charset=3DU=
TF-8">
      <div dir=3D"ltr">Greetings,
        <div><br>
        </div>
        <div>This mailing list isn't used for much anymore, save high
          level announcements from time to time.</div>
        <div><br>
        </div>
        <div>A couple things:<br>
          <ul>
            <li>Check out=C2=A0<a
                href=3D"https://github.com/pantoniou/libfyaml/"
                moz-do-not-send=3D"true">https://github.com/pantoniou/lib=
fyaml/</a>
              which is more full featured and under active development.</=
li>
            <li>Join=C2=A0<a href=3D"https://matrix.to/#/#chat:yaml.io"
                moz-do-not-send=3D"true">https://matrix.to/#/#chat:yaml.i=
o</a>
              which is the new best way to engage with the YAML
              community.</li>
            <ul>
              <li>#yaml IRC is still around on the libera.chat IRC
                network.</li>
            </ul>
          </ul>
        </div>
        <div>Cheers, Ingy</div>
        <div><br>
        </div>
      </div>
      <br>
      <div class=3D"gmail_quote">
        <div dir=3D"ltr" class=3D"gmail_attr">On Mon, Aug 16, 2021 at 12:=
19
          PM Felix Krause &lt;<a href=3D"mailto:[email protected]"
            moz-do-not-send=3D"true">[email protected]</a>&gt; wrote:<br>
        </div>
        <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">=

          <div>
            <div style=3D"font-family:sans-serif">
              <div style=3D"white-space:normal">
                <p dir=3D"auto">Hi David,</p>
                <p dir=3D"auto">libyaml does contain such an API: <a
                    href=3D"https://github.com/yaml/libyaml/blob/master/i=
nclude/yaml.h#L1457"
                    style=3D"color:rgb(57,131,196)" target=3D"_blank"
                    moz-do-not-send=3D"true">https://github.com/yaml/liby=
aml/blob/master/include/yaml.h#L1457</a></p>
                <p dir=3D"auto">This gives you a <code
style=3D"background-color:rgb(247,247,247);border-radius:3px;margin:0px;p=
adding:0px
                    0.4em" bgcolor=3D"#F7F7F7">yaml_document_t</code> wit=
h
                  a root node accessible via <code
style=3D"background-color:rgb(247,247,247);border-radius:3px;margin:0px;p=
adding:0px
                    0.4em" bgcolor=3D"#F7F7F7">yaml_document_get_root_nod=
e</code>.
                  The API is not well-documented but basically nodes can
                  refer to sub-nodes via an <code
style=3D"background-color:rgb(247,247,247);border-radius:3px;margin:0px;p=
adding:0px
                    0.4em" bgcolor=3D"#F7F7F7">int</code> index and you
                  use <code
style=3D"background-color:rgb(247,247,247);border-radius:3px;margin:0px;p=
adding:0px
                    0.4em" bgcolor=3D"#F7F7F7">yaml_document_get_node</co=
de>
                  to retrieve subnodes.</p>
                <p dir=3D"auto">mapping and sequence nodes store their
                  children in a stack structure =E2=80=93 you iterate the=
m via</p>
                <pre style=3D"background-color:rgb(247,247,247);border-ra=
dius:5px;margin-left:15px;margin-right:15px;max-width:90vw;overflow-x:aut=
o;padding:5px" bgcolor=3D"#F7F7F7"><code style=3D"background-color:rgb(24=
7,247,247);border-radius:3px;margin:0px;padding:0px" bgcolor=3D"#F7F7F7">=
for (yaml_node_item_t *cur =3D node-&gt;data.sequence.start; cur !=3D nod=
e-&gt;data.sequence.top; ++cur) {
   // ...
}
</code></pre>
                <p dir=3D"auto">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.</p>=

                <hr style=3D"background:linear-gradient(to
                  right,rgb(204,204,204),rgb(51,51,51),rgb(204,204,204))
                  rgb(51,51,51);border:0px;height:1px" height=3D"1">
                <p dir=3D"auto">If you want a more convenient API, I did
                  write this utility in the past: <a
                    href=3D"https://github.com/flyx/libyaml_constructor"
                    style=3D"color:rgb(57,131,196)" target=3D"_blank"
                    moz-do-not-send=3D"true">https://github.com/flyx/liby=
aml_constructor</a></p>
                <p dir=3D"auto">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.</p>
                <p dir=3D"auto">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.</p>
                <p dir=3D"auto">Cheers,<br>
                  Felix</p>
              </div>
            </div>
          </div>
          _______________________________________________<br>
          Yaml-core mailing list<br>
          <a href=3D"mailto:[email protected]"
            target=3D"_blank" moz-do-not-send=3D"true">[email protected]=
urceforge.net</a><br>
          <a
            href=3D"https://lists.sourceforge.net/lists/listinfo/yaml-cor=
e"
            rel=3D"noreferrer" target=3D"_blank" moz-do-not-send=3D"true"=
>https://lists.sourceforge.net/lists/listinfo/yaml-core</a><br>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </body>
</html>

--------------DC9D41C2BDB7A49CEF7F6316--


--===============3230498367755081177==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============3230498367755081177==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core

--===============3230498367755081177==--