Skip to content

Instantly share code, notes, and snippets.

@simonster
Last active January 4, 2016 15:29
Show Gist options
  • Select an option

  • Save simonster/8640960 to your computer and use it in GitHub Desktop.

Select an option

Save simonster/8640960 to your computer and use it in GitHub Desktop.
@reexport macro
flatten_dot(s::Symbol) = (s,)
flatten_dot(ex::Expr) = tuple(flatten_dot(ex.args[1])..., ex.args[2].args[1])
macro reexport(syms...)
if length(syms) == 1 && isa(syms[1], Expr) && syms[1].head != :.
syms[1].head == :tuple || error("@reexport: invalid syntax")
syms = syms[1].args
end
modules = (Symbol...)[begin
if isa(arg, Symbol) || (isa(arg, Expr) && arg.head == :.)
flatten_dot(arg)
else
error("@reexport: invalid module $arg")
end
end for arg in syms]
esc(Expr(:toplevel, [Expr(:using, m...) for m in modules]...,
[:(eval(Expr(:export, names($(m[end]))...))) for m in modules]...))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment