diff --git a/REQUIRE b/REQUIRE index 137767a..5c0d3d8 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,2 @@ julia 0.6 +Compat 0.30.0 diff --git a/src/MacroTools.jl b/src/MacroTools.jl index 430ae3c..80a96af 100644 --- a/src/MacroTools.jl +++ b/src/MacroTools.jl @@ -1,6 +1,7 @@ __precompile__(true) module MacroTools +using Compat export @match, @capture include("match.jl") diff --git a/src/macro.jl b/src/macro.jl index 9545107..45bbcff 100644 --- a/src/macro.jl +++ b/src/macro.jl @@ -1,21 +1,22 @@ -allbindings(pat, bs) = - isbinding(pat) || (isslurp(pat) && pat ≠ :__) ? push!(bs, bname(pat)) : +function allbindings(pat, bs) + if isa(pat, QuoteNode) + return allbindings(pat.value, bs) + end + return isbinding(pat) || (isslurp(pat) && pat ≠ :__) ? push!(bs, bname(pat)) : isa(pat, TypeBind) ? push!(bs, pat.name) : isa(pat, OrBind) ? (allbindings(pat.pat1, bs); allbindings(pat.pat2, bs)) : istb(pat) ? push!(bs, tbname(pat)) : isexpr(pat, :$) ? bs : isa(pat, Expr) ? map(pat -> allbindings(pat, bs), [pat.head, pat.args...]) : bs +end allbindings(pat) = (bs = Any[]; allbindings(pat, bs); bs) function bindinglet(bs, body) - ex = :(let $(esc(:env)) = env + ex = :(let $(esc(:env)) = env, $((:($(esc(b)) = get(env, $(Expr(:quote, b)), nothing)) for b in bs)...) $body end) - for b in bs - push!(ex.args, :($(esc(b)) = get(env, $(Expr(:quote, b)), nothing))) - end return ex end diff --git a/src/utils.jl b/src/utils.jl index 3cf8437..f6e1fd3 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -120,7 +120,7 @@ function inexpr(ex, x) return result end -global const animals = split(readstring(joinpath(dirname(@__FILE__), "..", "animals.txt"))) +const animals = split(read(joinpath(dirname(@__FILE__), "..", "animals.txt"), String)) isgensym(s::Symbol) = contains(string(s), "#") isgensym(s) = false @@ -140,7 +140,7 @@ function alias_gensyms(ex) end # Helper function, from Compat. Use Base.macroexpand in 0.7 -macroexpandmodule(mod::Module, x::ANY) = eval(mod, :(macroexpand($(QuoteNode(x))))) +macroexpandmodule(mod::Module, @nospecialize(x)) = eval(mod, :(macroexpand($(QuoteNode(x))))) """ More convenient macro expansion, e.g.