Skip to content

Commit 4039d3b

Browse files
committed
walk over directories
1 parent 195b673 commit 4039d3b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/MacroTools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module MacroTools
22

33
using DataStructures, Compat
44
using Compat.Markdown
5-
export @match, @capture
5+
export @match, @capture, sourcewalk, sourcemap
66

77
include("match/match.jl")
88
include("match/types.jl")

src/patch/cst.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,20 @@ function sourcemap(f, src::SourceFile)
117117
patch(src, diff(src.ast, ex))
118118
end
119119

120-
# TODO directories
121120
function sourcemap(f, path::AbstractString)
122-
isfile(path) || error("No file at $f")
121+
isdir(path) && return sourcemap_dir(f, path)
122+
isfile(path) || error("No file at $path")
123123
s = SourceFile(path)
124124
ex = striplines(f(s.ast))
125125
patch!(s, diff(s.ast, ex))
126126
end
127127

128+
function sourcemap_dir(f, path)
129+
for (dir, _, fs) in walkdir(path), file in fs
130+
endswith(file, ".jl") && sourcemap(f, joinpath(dir, file))
131+
end
132+
end
133+
128134
sourcewalk(f, file) = sourcemap(x -> postwalk(f, x), file)
129135

130136
textmap(f, text) = sourcemap(f, SourceFile("", text))

0 commit comments

Comments
 (0)