Questions regarding compiler plugins


Hi all,

I’m trying to do some compile-time code generation using compiler plugins. So
far I understand how to get a token stream but I’m struggling with actually
using those tokens and generating Rust expression as a result of macro
expansions. My questions:

  • How do I get the actual literals from libsyntax::parse::token::Lit?
    libsyntax::tokenstream::TokenTree is giving literals in that type, I can’t
    find a way to get actual literal values from those.

  • Generating Rust expressions is really painful using AstBuilder trait
    implementations. I’m wondering if there’s a macro (or something like
    quasiquoters in other languages) to make generating MacResults easier.

Any ideas? Thanks


One thing you should know is that this is all changing soon. I wrote a blog post about it:

That is, soon you’ll be using libmacro to write these kinds of things, rather than libsyntax.