Expand macros in syn parse tree

Is there a crate that can selectively expand macros in a parse tree generated by syn?

This is impossible, as syn doesn't know how to resolve a macro name — it only has tokens. The same is true for the compiler in general.

Makes sense.

Are there perhaps any tricks to accomplish the same using the compiler? I do know about cargo expand, but it expands everything, and I need to leave certain macros unexpanded.

I think you can use caro expand only expanding certain macros. Keep in mind that the resulting code isn't guaranteed to compile, as there's more to code than just the tokens (namely where the token is from).

And just to restate — this isn't something that can be done as part of a proc macro. It's merely for human consumption.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.