I think i forgot to add toplevel
esc(Expr(:toplevel, ex))
Thanks everyone
On Thursday, March 3, 2016 at 6:31:05 PM UTC-8, Julia Tylors wrote:
>
> Hi everyone;
>
> I am writing a macro which uses module:
>
> @f module X
> x= 4
> end
>
> macro f(ex)
> isa(ex,Expr) && (ex.head == :module) || error("@f : syntax error")
> module_name = ex.args[2]
> module_blk = ex.args[3].args
> import_stmts = quote
> import CSS.Leech
> end
> insert!(module_blk,length(module_blk),import_stmts)
> esc(ex)
> end
>
> But it gives the error:
> ERROR: syntax: malformed expression
>
> What is wrong here?
>
> Thanks
>