[RFC 00/29] RFC: Generate object-model code based on relax-ng files

Shi Lei shi_lei at massclouds.com
Wed Apr 22 05:51:10 UTC 2020


... ...
>The key question is just how difficult will it be to write a tool that
>can parse the C header files, and magic comments, to output suitable
>XML parser/formatter functions ? There's no easy way to answer that
>without someone trying it.
>
>
>Regards,
>Daniel
>--
>|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
>|: https://libvirt.org -o- https://fstop138.berrange.com :|
>|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
> 

Thanks for your reply in detail. I get your point.

My intention of doing this is to test an idea: only using one language or notation
to depict object-models in libvirt; and then calling a series of tools to translate it into
various representations, such as c-language structures/parse/format, rng-files, other
language bindings, part of test-framwork, part of document, etc.

I knew this idea is too ideal and too big, so I just tried to generate some c-code based
on rng-files as a beginning point.

During the process, I found that the descriptive power of relax-ng was weak. Of cause, it
is not designed for this aim. I had to introduce extra DIRECTIVES to enhance it, which
made it not concise.

I have also considered of using json-schema rather than relax-ng. Json-schema has more
descriptive power than relax-ng. And json-schema has combining schemas and conditional
schemas, which can be used to define data constrains and reduce error-checking code in
parsefunctions. But using json-schema cannot solve the problems that you have mentioned
and rewriting rng file with json-schema is another big job.

As you suggested, parsing C-structs plus some magic comments may be a good starting point.
But parsing C is much more difficult than parsing xml or json. I think this job should base on
some present tools or other basis. We can first refer to Clang or other light compiler front-end.
Maybe we can utilize some output of the middle stage of these compilers.

Regards,
Shi Lei




More information about the libvir-list mailing list