Skip to content

Instantly share code, notes, and snippets.

@KristofferC
Created May 8, 2017 19:16
Show Gist options
  • Save KristofferC/ef5ac6bc327b3c857be1d84dec498cbf to your computer and use it in GitHub Desktop.
Save KristofferC/ef5ac6bc327b3c857be1d84dec498cbf to your computer and use it in GitHub Desktop.
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