lrs-lang / lib

An experimental standard library
Mozilla Public License 2.0
223 stars 3 forks source link

Write a C parser #12

Open mahkoh opened 8 years ago

mahkoh commented 8 years ago

One of the major problems when using rust or lrs is that bindings have to be written manually. There have been some efforts that used libclang to generate bindings, but libclang doesn't expose enough details to do this properly. Iirc, you cannot access C macros properly with libclang.

To tackle this problem, I wrote a C preprocessor some time ago (in rust). This preprocessor understands all GCC extensions. What's missing is an actual C parser. Note that this C parser doesn't have to be able to parse all C code. It's enough to parse the function definitions and skip the function body.

I'll try to clean the preprocessor up and port it to lrs soonish.

briansmith commented 8 years ago

Why not do this using Clang's parser?

mahkoh commented 8 years ago

Last time I checked, libclang doesn't give you access to the pre-processor state after the parsing. For example:

#define X 1

If this is the file you're parsing libclang gives you nothing.

I also like writing parsers so I don't think I'm going to use libclang even if it has improved in the meantime. I'm not working on this at the moment though.