I want to use the Rust parser (libsyntax) to parse a Rust file and extract information like function names out of it. I started digging in the docs and code, so my first goal is a program that prints all function names of freestanding functions in a .rs
file.
The program should expand all macros before it prints the function names, so functions declared via macro aren't missed. That's why I can't write some crappy little parser by myself to do the job.
I have to admit that I'm not yet perfectly good at programming Rust, so I apologize in advance for any stupid statements in this question.
How I understood it I need to do the following steps:
- Parse the file via the
Parser
struct - Expand macros with
MacroExpander
- ???
- Use a
Visitor
to walk the AST and extract the information I need (eg. viavisit_fn
)
So here are my questions:
- How do I use
MacroExpander
? - How do I walk the expanded AST with a custom visitor?
I had the idea of using a custom lint check instead of a fully fledged parser. I'm investigating this option.
If it matters, I'm using rustc 0.13.0-nightly (f168c12c5 2014-10-25 20:57:10 +0000)