Created
May 8, 2017 19:16
-
-
Save KristofferC/ef5ac6bc327b3c857be1d84dec498cbf to your computer and use it in GitHub Desktop.
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
using MacroTools | |
using DataStructures | |
function prockey(key) | |
if isa(key, Symbol) || isa(key, String) | |
return :($(string(key)) => nothing) | |
elseif @capture(key, (a_ : b_) | (a_ => b_) | (a_ = b_)) | |
return :($(string(a))=>$b) | |
end | |
error("Invalid pgf option $key") | |
end | |
function procmap(d) | |
if @capture(d, f_(xs__)) | |
return :($f($(map(procmap, xs)...))) | |
elseif !@capture(d, {xs__}) | |
return d | |
else | |
return :(OrderedDict{Any, Any}($(map(prockey, xs)...))) | |
end | |
end | |
macro pgf(ex) | |
esc(prewalk(procmap, ex)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment