Proc macro attribute being parsed several times?

Hello!

I'm trying to write a proc macro that parses some custom DSL and transforms it into good Rust ~ for those familiar, I'm trying to parse some kind of separation logic but it's not important.

The "expressions" I want to parse are *-separated. For example:
emp * (l -> v) (read "emp star l points to v), and a predicate would look like:

#[predicate]
fn dummy(l: &T) {
 emp * (l -> v)
}

Now, Rust is unhappy with my use of -> in the middle of a function, and I my proc_macro_attribute function isn't even call if I write this (:frowning_face:)

I found a workaround, I write emp * #(l -> v) and success, I get a token stream! I do what I have to do, and return the correct token stream, in this case something like:

fn dummy(l: &T) {
   let v = ...;
   __internal::star(
      __internal::emp(),
      __internal::point_to(l, v)
   )
}

Everything parses well and works well, the proc_macro_attribute function exits correctly, but the compilation still fails, pointing at the # character before the (l -> v) saying this:

I looked at the -Z unpretty=expanded output and it shows a program that correctly parses, but somehow it looks like my dummy function is parsed twice, once inside of the macro, and once by the actual rust compiler.

Any idea why this is happening?

Cheers

The input of attribute macros is required to be syntactically valid Rust code. You are not going to get a successful compilation where that is not the case.

1 Like

Yep that sounds about right unfortunately
I'll use a workaround
Thank you!