-
-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing a whole crate with particular cfgs defined #588
Comments
Syn is only a parser, so other aspects of compilation like expanding macros, dealing with target-specific configuration properties, crawling the filesystem, etc are out of scope. https://github.com/TedDriggs/syn-inline-mod looks like it handles some of what you need. |
I see, I'll check that out, thanks! |
@dtolnay is there a crate for expanding macros ? Like in the project you mention: #[cfg(foo)]
mod a; is expanded to #[cfg(foo)]
mod a {
...a contents...
} This gives me an AST for the whole crate, but now I'd like to define some macros, and expand them, e.g., removing all those |
I don't know of such a crate. |
I was thinking about porting the
ctest
crate (used by libc) to syn, mainly because it uses the latest release of thesyntex_syntax
crate which does not supportrepr(transparent)
, and that blocks adding APIs that could benefit fromrepr(transparent)
to libc.I have a couple of questions and am not sure where is the best place to ask them.
The
syntex_syntax
crate has aparse_crate
function, that given a file, continues walking the directory tree parsing modules, it can do a certain level of macro expansion while doing this (e.g.cfg(unix)
, etc. where these macros are defined in the session).I was wondering if
syn
has something similar, or what would be the best way of achieving the same thing.I thought that maybe I could parse a single file, then do a fold on the file that expands some macros, then visit all the modules, resolve their paths in the file-system, and repeat. Something like this seems widely-useful enough that it might be worth it to implement it in
syn
directly instead.E.g. the
ctest
crate defines, for each target-triple, which macros should be expanded, but that sounds manual and brittle. It might be better to somehow hook uprustc_target
and obtain this information from there.The text was updated successfully, but these errors were encountered: