@@ -11,10 +11,11 @@ assoc!(d, k, v) = (d[k] = v; d)
1111"""
1212 @esc x y
1313
14- is the same as
15-
16- x = esc(x)
17- y = esc(y)
14+ is the same as:
15+ ```julia
16+ x = esc(x)
17+ y = esc(y)
18+ ```
1819"""
1920macro esc (xs... )
2021 :($ ([:($ x = esc ($ x)) for x in map (esc, xs)]. .. );)
2627Like the `quote` keyword but doesn't insert line numbers from the construction
2728site. e.g. compare `@q begin end` with `quote end`. Line numbers of interpolated
2829expressions are preserverd.
30+
31+ See also: [`rmlines`](@ref)
2932"""
3033macro q (ex)
3134 Expr (:quote , striplines (ex))
@@ -65,6 +68,8 @@ To work with nested blocks:
6568```julia
6669prewalk(rmlines, ex)
6770```
71+
72+ See also: [`@q`](@ref)
6873"""
6974rmlines (x) = x
7075function rmlines (x:: Expr )
@@ -108,8 +113,9 @@ walk(x::Expr, inner, outer) = outer(Expr(x.head, map(inner, x.args)...))
108113 postwalk(f, expr)
109114
110115Applies `f` to each node in the given expression tree, returning the result.
111- `f` sees expressions *after* they have been transformed by the walk. See also
112- `prewalk`.
116+ `f` sees expressions *after* they have been transformed by the walk.
117+
118+ See also: [`prewalk`](@ref).
113119"""
114120postwalk (f, x) = walk (x, x -> postwalk (f, x), f)
115121
@@ -121,7 +127,7 @@ Applies `f` to each node in the given expression tree, returning the result.
121127walk will be applied to whatever `f` returns.
122128
123129This makes `prewalk` somewhat prone to infinite loops; you probably want to try
124- `postwalk` first.
130+ [ `postwalk`](@ref) first.
125131"""
126132prewalk (f, x) = walk (f (x), x -> prewalk (f, x), identity)
127133
@@ -133,7 +139,9 @@ replace(ex, s, s′) = prewalk(x -> x == s ? s′ : x, ex)
133139Simple expression match; will return `true` if the expression `x` can be found
134140inside `expr`.
135141
136- inexpr(:(2+2), 2) == true
142+ ```julia
143+ inexpr(:(2+2), 2) == true
144+ ```
137145"""
138146function inexpr (ex, x)
139147 result = false
@@ -162,11 +170,13 @@ end
162170
163171Replaces gensyms with unique ids (deterministically).
164172
165- julia> x, y = gensym("x"), gensym("y")
166- (Symbol("##x#363"), Symbol("##y#364"))
173+ ```julia
174+ julia> x, y = gensym("x"), gensym("y")
175+ (Symbol("##x#363"), Symbol("##y#364"))
167176
168- julia> MacroTools.gensym_ids(:(\$ x+\$ y))
169- :(x_1 + y_2)
177+ julia> MacroTools.gensym_ids(:(\$ x+\$ y))
178+ :(x_1 + y_2)
179+ ```
170180"""
171181function gensym_ids (ex)
172182 counter = 0
@@ -184,11 +194,13 @@ end
184194Replaces gensyms with animal names.
185195This makes gensym'd code far easier to follow.
186196
187- julia> x, y = gensym("x"), gensym("y")
188- (Symbol("##x#363"), Symbol("##y#364"))
197+ ```julia
198+ julia> x, y = gensym("x"), gensym("y")
199+ (Symbol("##x#363"), Symbol("##y#364"))
189200
190- julia> MacroTools.alias_gensyms(:(\$ x+\$ y))
191- :(porcupine + gull)
201+ julia> MacroTools.alias_gensyms(:(\$ x+\$ y))
202+ :(porcupine + gull)
203+ ```
192204"""
193205function alias_gensyms (ex)
194206 left = copy (animals)
201213"""
202214More convenient macro expansion, e.g.
203215
204- @expand @time foo()
216+ ```julia
217+ @expand @time foo()
218+ ```
205219"""
206220@static if VERSION <= v " 0.7.0-DEV.484"
207221 macro expand (ex)
@@ -248,7 +262,10 @@ function shortdef1(ex)
248262end
249263shortdef (ex) = prewalk (shortdef1, ex)
250264
251- """ `gatherwheres(:(f(x::T, y::U) where T where U)) => (:(f(x::T, y::U)), (:U, :T))`
265+ """
266+ ```julia
267+ gatherwheres(:(f(x::T, y::U) where T where U)) == (:(f(x::T, y::U)), (:U, :T))
268+ ```
252269"""
253270function gatherwheres (ex)
254271 if @capture (ex, (f_ where {params1__}))
@@ -272,14 +289,16 @@ end
272289and return `Dict(:name=>..., :args=>..., etc.)`. The definition can be rebuilt by
273290calling `MacroTools.combinedef(dict)`, or explicitly with
274291
275- ```
292+ ```julia
276293rtype = get(dict, :rtype, :Any)
277294all_params = [get(dict, :params, [])..., get(dict, :whereparams, [])...]
278295:(function \$ (dict[:name]){\$ (all_params...)}(\$ (dict[:args]...);
279296 \$ (dict[:kwargs]...))::\$ rtype
280297 \$ (dict[:body])
281298 end)
282299```
300+
301+ See also: [`combinedef`](@ref)
283302"""
284303function splitdef (fdef)
285304 error_msg = " Not a function definition: $(repr (fdef)) "
321340"""
322341 combinedef(dict::Dict)
323342
324- `combinedef` is the inverse of `splitdef`. It takes a splitdef-like Dict
325- and returns a function definition. """
343+ `combinedef` is the inverse of [`splitdef`](@ref). It takes a `splitdef`-like Dict
344+ and returns a function definition.
345+ """
326346function combinedef (dict:: Dict )
327347 rtype = get (dict, :rtype , nothing )
328348 params = get (dict, :params , [])
383403"""
384404 combinearg(arg_name, arg_type, is_splat, default)
385405
386- `combinearg` is the inverse of `splitarg`. """
406+ `combinearg` is the inverse of [`splitarg`](@ref).
407+ """
387408function combinearg (arg_name, arg_type, is_splat, default)
388409 a = arg_name=== nothing ? :(:: $arg_type ) : :($ arg_name:: $arg_type )
389410 a2 = is_splat ? Expr (:... , a) : a
@@ -405,13 +426,15 @@ Match function arguments (whether from a definition or a function call) such as
405426`default` are `nothing` when they are absent. For example:
406427
407428```julia
408- > map(splitarg, (:(f(a=2, x::Int=nothing, y, args...))).args[2:end])
429+ julia > map(splitarg, (:(f(a=2, x::Int=nothing, y, args...))).args[2:end])
4094304-element Array{Tuple{Symbol,Symbol,Bool,Any},1}:
410431 (:a, :Any, false, 2)
411432 (:x, :Int, false, :nothing)
412433 (:y, :Any, false, nothing)
413434 (:args, :Any, true, nothing)
414435```
436+
437+ See also: [`combinearg`](@ref)
415438"""
416439function splitarg (arg_expr)
417440 splitvar (arg) =
0 commit comments