Skip to content
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

Expand macro expression #957

Closed
edgarogh opened this issue Jan 18, 2021 · 3 comments
Closed

Expand macro expression #957

edgarogh opened this issue Jan 18, 2021 · 3 comments

Comments

@edgarogh
Copy link

I'm making an expression/function macro that takes a string literal, transforms it, and returns a new string literal. The problem I'm having is that string-literal-returning macros like concat!, env!, stringify! (and I might forget some) cannot be given as a parameter to my macro due to the order in which macros are expanded (they're passed as macro expressions, not expanded). I spent quite a bit of time in the doc and didn't find any way to expand a ExprMacro into the expanded macro's TokenStream, so I can use this in place.

Is there such a feature ? If no, is it planned, or impossible to do ?

@dtolnay
Copy link
Owner

dtolnay commented Jan 19, 2021

I wouldn't want this to be built into syn, which is only supposed to be a parser. However it would be reasonable to address in a different crate.

@dtolnay dtolnay closed this as completed Jan 19, 2021
@malobre
Copy link

malobre commented May 15, 2022

@edgarogh Did you find a crate that could do this ?

Edit: For anyone interested there's also the unstable proc_macro_expand feature.

@Nemo157
Copy link

Nemo157 commented Jul 28, 2022

You can proxy your proc-macro through a macro-rules-macro using https://docs.rs/with_builtin_macros to support a subset of the std macros. I have an example using it and also extended that with optional support for the proc-macro-expand feature too in Nullus157/stylish-rs#5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants