@@ -11,10 +11,11 @@ assoc!(d, k, v) = (d[k] = v; d)
11
11
"""
12
12
@esc x y
13
13
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
+ ```
18
19
"""
19
20
macro esc (xs... )
20
21
:($ ([:($ x = esc ($ x)) for x in map (esc, xs)]. .. );)
@@ -138,7 +139,9 @@ replace(ex, s, s′) = prewalk(x -> x == s ? s′ : x, ex)
138
139
Simple expression match; will return `true` if the expression `x` can be found
139
140
inside `expr`.
140
141
141
- inexpr(:(2+2), 2) == true
142
+ ```julia
143
+ inexpr(:(2+2), 2) == true
144
+ ```
142
145
"""
143
146
function inexpr (ex, x)
144
147
result = false
@@ -167,11 +170,13 @@ end
167
170
168
171
Replaces gensyms with unique ids (deterministically).
169
172
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"))
172
176
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
+ ```
175
180
"""
176
181
function gensym_ids (ex)
177
182
counter = 0
@@ -189,11 +194,13 @@ end
189
194
Replaces gensyms with animal names.
190
195
This makes gensym'd code far easier to follow.
191
196
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"))
194
200
195
- julia> MacroTools.alias_gensyms(:(\$ x+\$ y))
196
- :(porcupine + gull)
201
+ julia> MacroTools.alias_gensyms(:(\$ x+\$ y))
202
+ :(porcupine + gull)
203
+ ```
197
204
"""
198
205
function alias_gensyms (ex)
199
206
left = copy (animals)
206
213
"""
207
214
More convenient macro expansion, e.g.
208
215
209
- @expand @time foo()
216
+ ```julia
217
+ @expand @time foo()
218
+ ```
210
219
"""
211
220
@static if VERSION <= v " 0.7.0-DEV.484"
212
221
macro expand (ex)
@@ -255,7 +264,10 @@ function shortdef1(ex)
255
264
end
256
265
shortdef (ex) = prewalk (shortdef1, ex)
257
266
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
+ ```
259
271
"""
260
272
function gatherwheres (ex)
261
273
if @capture (ex, (f_ where {params1__}))
279
291
and return `Dict(:name=>..., :args=>..., etc.)`. The definition can be rebuilt by
280
292
calling `MacroTools.combinedef(dict)`, or explicitly with
281
293
282
- ```
294
+ ```julia
283
295
rtype = get(dict, :rtype, :Any)
284
296
all_params = [get(dict, :params, [])..., get(dict, :whereparams, [])...]
285
297
:(function \$ (dict[:name]){\$ (all_params...)}(\$ (dict[:args]...);
@@ -378,7 +390,7 @@ Match function arguments (whether from a definition or a function call) such as
378
390
`default` are `nothing` when they are absent. For example:
379
391
380
392
```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])
382
394
4-element Array{Tuple{Symbol,Symbol,Bool,Any},1}:
383
395
(:a, :Any, false, 2)
384
396
(:x, :Int, false, :nothing)
0 commit comments