@@ -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)]. .. );)
@@ -138,7 +139,9 @@ replace(ex, s, s′) = prewalk(x -> x == s ? s′ : x, ex)
138139Simple expression match; will return `true` if the expression `x` can be found
139140inside `expr`.
140141
141- inexpr(:(2+2), 2) == true
142+ ```julia
143+ inexpr(:(2+2), 2) == true
144+ ```
142145"""
143146function inexpr (ex, x)
144147 result = false
@@ -167,11 +170,13 @@ end
167170
168171Replaces gensyms with unique ids (deterministically).
169172
170- julia> x, y = gensym("x"), gensym("y")
171- (Symbol("##x#363"), Symbol("##y#364"))
173+ ```julia
174+ julia> x, y = gensym("x"), gensym("y")
175+ (Symbol("##x#363"), Symbol("##y#364"))
172176
173- julia> MacroTools.gensym_ids(:(\$ x+\$ y))
174- :(x_1 + y_2)
177+ julia> MacroTools.gensym_ids(:(\$ x+\$ y))
178+ :(x_1 + y_2)
179+ ```
175180"""
176181function gensym_ids (ex)
177182 counter = 0
@@ -189,11 +194,13 @@ end
189194Replaces gensyms with animal names.
190195This makes gensym'd code far easier to follow.
191196
192- julia> x, y = gensym("x"), gensym("y")
193- (Symbol("##x#363"), Symbol("##y#364"))
197+ ```julia
198+ julia> x, y = gensym("x"), gensym("y")
199+ (Symbol("##x#363"), Symbol("##y#364"))
194200
195- julia> MacroTools.alias_gensyms(:(\$ x+\$ y))
196- :(porcupine + gull)
201+ julia> MacroTools.alias_gensyms(:(\$ x+\$ y))
202+ :(porcupine + gull)
203+ ```
197204"""
198205function alias_gensyms (ex)
199206 left = copy (animals)
206213"""
207214More convenient macro expansion, e.g.
208215
209- @expand @time foo()
216+ ```julia
217+ @expand @time foo()
218+ ```
210219"""
211220@static if VERSION <= v " 0.7.0-DEV.484"
212221 macro expand (ex)
@@ -255,7 +264,10 @@ function shortdef1(ex)
255264end
256265shortdef (ex) = prewalk (shortdef1, ex)
257266
258- """ `gatherwheres(:(f(x::T, y::U) where T where U)) => (:(f(x::T, y::U)), (:U, :T))`
267+ """
268+ ```julia
269+ gatherwheres(:(f(x::T, y::U) where T where U)) == (:(f(x::T, y::U)), (:U, :T))
270+ ```
259271"""
260272function gatherwheres (ex)
261273 if @capture (ex, (f_ where {params1__}))
279291and return `Dict(:name=>..., :args=>..., etc.)`. The definition can be rebuilt by
280292calling `MacroTools.combinedef(dict)`, or explicitly with
281293
282- ```
294+ ```julia
283295rtype = get(dict, :rtype, :Any)
284296all_params = [get(dict, :params, [])..., get(dict, :whereparams, [])...]
285297:(function \$ (dict[:name]){\$ (all_params...)}(\$ (dict[:args]...);
@@ -378,7 +390,7 @@ Match function arguments (whether from a definition or a function call) such as
378390`default` are `nothing` when they are absent. For example:
379391
380392```julia
381- > map(splitarg, (:(f(a=2, x::Int=nothing, y, args...))).args[2:end])
393+ julia > map(splitarg, (:(f(a=2, x::Int=nothing, y, args...))).args[2:end])
3823944-element Array{Tuple{Symbol,Symbol,Bool,Any},1}:
383395 (:a, :Any, false, 2)
384396 (:x, :Int, false, :nothing)
0 commit comments