Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.6
Compat 0.30.0
1 change: 1 addition & 0 deletions src/MacroTools.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__precompile__(true)
module MacroTools

using Compat
export @match, @capture

include("match.jl")
Expand Down
13 changes: 7 additions & 6 deletions src/macro.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down