Last active
January 4, 2016 15:29
-
-
Save simonster/8640960 to your computer and use it in GitHub Desktop.
@reexport macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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