Skip to content

Instantly share code, notes, and snippets.

@jonathanBieler
Created April 23, 2017 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanBieler/1fd7aa08d2cd6d4dc02b0f24aac3d0d6 to your computer and use it in GitHub Desktop.
Save jonathanBieler/1fd7aa08d2cd6d4dc02b0f24aac3d0d6 to your computer and use it in GitHub Desktop.
do_collect(ex::Expr) = any( ex.head .== [:call, :(=)])
dont_collect(ex::Expr) = any( ex.head .== [:line])
function get_vars2(ex::Expr,out,assigned)
ex.head == :(=) && push!(assigned,ex.args[1])
# println(ex)
if do_collect(ex)
for i = 2:length(ex.args)
get_vars2(ex.args[i],out,assigned)
end
elseif !dont_collect(ex)
for i = 1:length(ex.args)
get_vars2(ex.args[i],out,assigned)
end
end
end
function get_vars2(ex::Expr)
out = Symbol[]
assigned = Symbol[]
get_vars2(ex,out,assigned)
unique(out)
end
get_vars2(s::Symbol,out,assigned) = !any(s .== assigned) && push!(out,s)
get_vars2(s::Any,out,assigned) = nothing
get_vars2(ex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment