the taste of sweet crack

I’ve been gradually pushing on in my free time on gobject-introspection, so I can make the dbus-glib bindings decent. A couple of months ago back I started hacking up a code scanner to generate the introspection xml,using code from gtk-doc, but using perl regexps to parse C just made me feel dirty…

Johan Dahlin pointed me at Sparse, a front-end parser for c developed by some of the kernel guys. The only problem is that it doesn’t have language bindings (or even, seemingly, a stable abi). So I’ve just submitted a patch to sparse that adds an executable ‘c2xml‘. c2xml will dump the parse tree of the input file as a simple xml structure, suitable for manipulation by some python or suchlike. That could then be used to, say, generate c api descriptions, documentation and language bindings or make code navigation or refactoring tools.

I like it!

2 Responses to “the taste of sweet crack”

  1. OpenIDhttp://jdahlin.livejournal.com/ Says:

    Sweet!

    I pondered many time to write language bindings, but this is even better. Once this is done I’ll probably use it by the header parser in PyGTK.

    Thanks for working on this!

  2. OpenIDJosh Says:

    I love that you decided to try Sparse for this. I’ve tried to position Sparse not just as a static analysis tool, but also as a simple front-end for C, useful for all the cases where you have a brilliant idea but stop because you first need to parse C. And you definitely had a brilliant idea; it makes me very happy that Sparse can help you implement it. I look forward to seeing c2xml become part of Sparse soon.