Skip to content

Instantly share code, notes, and snippets.

@baggepinnen
Created April 23, 2020 06:48
Show Gist options
  • Save baggepinnen/48472676b8d417409299a03317e91af4 to your computer and use it in GitHub Desktop.
Save baggepinnen/48472676b8d417409299a03317e91af4 to your computer and use it in GitHub Desktop.
Search all julia files for regexes
using Printf, Base.Iterators
root = "/home/$(ENV["USER"])/.julia/dev/"
# root = "/home/$(ENV["USER"])/.julia/packages/"
const regs = [
r"(\w+)\s?->\w+\(\1\)[,\b]", # Finds x->f(x)
r"\w+\s?==\s?(true|false)", # Finds x == true
]
function findem(root, regs; extension=".jl", pad=80)
for (root, dirs, files) in walkdir(root)
for file in files
splitext(file)[2] == extension || continue
fullpath = joinpath(root, file)
for (ln, line) in enumerate(eachline(fullpath))
for reg in regs
for m in eachmatch(reg, line)
println(rpad(fullpath * ":$ln ", pad), m.match)
end
end
end
end
end
end
findem(root,regs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment