Created
April 23, 2017 21:55
-
-
Save jonathanBieler/1fd7aa08d2cd6d4dc02b0f24aac3d0d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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