Using eval and a macro with `$`

I’ve been working on a macro which uses $ in a special way. But for certain tests, I need to use @eval or eval. Here is a very stupid MWE showin the problem, roughly

julia> macro with_dollar(x)
           if x isa Expr && x.head == :$
               esc(:(y = 100))
           else
               esc(:(y = 200))
           end
       end;

julia> @with_dollar $a
100

julia> @eval (@with_dollar $a)
ERROR: UndefVarError: a not defined

Is there a way to tell @eval to ignore it’s own rules about $? How do other packages handle this?

Can’t you use eval instead of @eval?

Yes, but it gives the same problem

julia> e = quote 
           @with_dollar $a
       end
ERROR: UndefVarError: a not defined

I guess the solution is

julia> e = quote 
           @with_dollar $(Expr(:$, :a))
       end
quote
    #= REPL[8]:2 =#
    #= REPL[8]:2 =# @with_dollar $(Expr(:$, :a))
end

julia> eval(e)
100

Does that seem like the easiest option?