Search code examples
javascriptcnode.jsnode-ffi

C parser in Javascript


I'd like to parse C header files in Javascript. Is there any such library available? Otherwise, any tips to help me get started?

Update: My ultimate goal is to automatically build interfaces for node-ffi. The parser doesn't necessarily have to be in Javascript as long as it can spit out a format understandable by Javascript. If it's very hard to develop by myself, I'll probably have to go with an off the shelf solution...?


Solution

  • You should check out clang.

    For a simple command-line invocation, you can try this:

    clang -cc1 -ast-dump-xml myfile.h
    

    Or you can build your own tool using clang reasonably-well-documented parser library, which will build an AST for you, and let you walk it as you see fit (perhaps for output in JSON).