Created
April 23, 2020 06:48
-
-
Save baggepinnen/48472676b8d417409299a03317e91af4 to your computer and use it in GitHub Desktop.
Search all julia files for regexes
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
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