Skip to content

Instantly share code, notes, and snippets.

@KristofferC
Created May 8, 2017 14:28
Show Gist options
  • Save KristofferC/5e7f40eecb605c72251a109d7a6122ec to your computer and use it in GitHub Desktop.
Save KristofferC/5e7f40eecb605c72251a109d7a6122ec to your computer and use it in GitHub Desktop.
using MacroTools, Lazy
import MacroTools: prewalk
using DataStructures
function prockey(key)
(isa(key, Symbol) || isa(key, String)) && return :($(string(key)) => nothing)
@capture(key, (a_:b_) | (a_=>b_) | (a_=b_)) || error("Invalid pgf option $key")
isa(a, Symbol) && (a = Expr(:quote, a))
:($a=>$b)
end
function procmap(d)
@capture(d, {xs__}) || return d
:(OrderedDict{Any, Any}($(map(prockey, xs)...)))
end
macro pgf(ex)
@>> ex prewalk(procmap) esc
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment