Proc macro attribute unexpected token

Hi! Lets assume I'm creating a matrix(tensor) arithmetic DSL, and I would like to do this through an attribute proc macro. I would like to apply this proc macro at the function level, with the intention of writing with the DSL as the entire function (and parsing it into valid rust in the macro)

I'm testing with the following, in the DSL (proc macro) crate I have (for testing):

#[proc_macro_attribute]
pub fn func(_args: TokenStream, _input: TokenStream) -> TokenStream{
    //...parse DSL input
    let mut output = quote!{
        fn test() {

           //will be valid rust
        }
    };
    output.into()

In my "user" crate I have two examples

The first compiles fine

#[DSL::func]
fn mul() { //assume this will be a matrix multiplication 
    let a = vec![2,2];
    let b = vec![2,2];
    a * b
} //gets replaced with dummy code above no issues

Now if instead of a mul, I want to do an an element wise multiplication, and I would like the DSL to represent this using .* as the operator. e.g.:

#[DSL::func]
fn test() {
    let a = vec![2,2];
    let b = vec![2,2];
    a .* b
}
// results in:
error: unexpected token: `*`
 a .* b
    ^

Now sure I understand this is an error in normal Rust, but I'm confused why this error is being emitted since the proc macro is returning completely different output (and removes the offending line). I'm assuming there is some compiler pass to figure out what the attribute applies to?

I can do this using a function like proc macro, is that my best (only) option?

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.