|
1 | 1 | export @esc, isexpr, isline, iscall, rmlines, unblock, block, inexpr, namify, isdef,
|
2 |
| - longdef, shortdef, @expand, makeif, prettify, splitdef, splitarg |
| 2 | + longdef, shortdef, @expand, makeif, prettify, splitarg |
3 | 3 |
|
4 | 4 | """
|
5 | 5 | assoc!(d, k, v)
|
@@ -261,89 +261,6 @@ function gatherwheres(ex)
|
261 | 261 | end
|
262 | 262 | end
|
263 | 263 |
|
264 |
| -""" splitdef(fdef) |
265 |
| -
|
266 |
| -Match any function definition |
267 |
| -
|
268 |
| -```julia |
269 |
| -function name{params}(args; kwargs)::rtype where {whereparams} |
270 |
| - body |
271 |
| -end |
272 |
| -``` |
273 |
| -
|
274 |
| -and return `Dict(:name=>..., :args=>..., etc.)`. The definition can be rebuilt by |
275 |
| -calling `MacroTools.combinedef(dict)`, or explicitly with |
276 |
| -
|
277 |
| -``` |
278 |
| -rtype = get(dict, :rtype, :Any) |
279 |
| -all_params = [get(dict, :params, [])..., get(dict, :whereparams, [])...] |
280 |
| -:(function \$(dict[:name]){\$(all_params...)}(\$(dict[:args]...); |
281 |
| - \$(dict[:kwargs]...))::\$rtype |
282 |
| - \$(dict[:body]) |
283 |
| - end) |
284 |
| -``` |
285 |
| -""" |
286 |
| -function splitdef(fdef) |
287 |
| - error_msg = "Not a function definition: $(repr(fdef))" |
288 |
| - @assert(@capture(longdef1(fdef), |
289 |
| - function (fcall_ | fcall_) body_ end), |
290 |
| - "Not a function definition: $fdef") |
291 |
| - fcall_nowhere, whereparams = gatherwheres(fcall) |
292 |
| - @assert(@capture(fcall_nowhere, ((func_(args__; kwargs__)) | |
293 |
| - (func_(args__; kwargs__)::rtype_) | |
294 |
| - (func_(args__)) | |
295 |
| - (func_(args__)::rtype_))), |
296 |
| - error_msg) |
297 |
| - @assert(@capture(func, (fname_{params__} | fname_)), error_msg) |
298 |
| - di = Dict(:name=>fname, :args=>args, |
299 |
| - :kwargs=>(kwargs===nothing ? [] : kwargs), :body=>body) |
300 |
| - if rtype !== nothing; di[:rtype] = rtype end |
301 |
| - if whereparams !== nothing; di[:whereparams] = whereparams end |
302 |
| - if params !== nothing; di[:params] = params end |
303 |
| - di |
304 |
| -end |
305 |
| - |
306 |
| -""" |
307 |
| - combinedef(dict::Dict) |
308 |
| -
|
309 |
| -`combinedef` is the inverse of `splitdef`. It takes a splitdef-like Dict |
310 |
| -and returns a function definition. """ |
311 |
| -function combinedef(dict::Dict) |
312 |
| - rtype = get(dict, :rtype, nothing) |
313 |
| - params = get(dict, :params, []) |
314 |
| - wparams = get(dict, :whereparams, []) |
315 |
| - body = block(dict[:body]) |
316 |
| - name = dict[:name] |
317 |
| - name_param = isempty(params) ? name : :($name{$(params...)}) |
318 |
| - # We need the `if` to handle parametric inner/outer constructors like |
319 |
| - # SomeType{X}(x::X) where X = SomeType{X}(x, x+2) |
320 |
| - if isempty(wparams) |
321 |
| - if rtype==nothing |
322 |
| - @q(function $name_param($(dict[:args]...); |
323 |
| - $(dict[:kwargs]...)) |
324 |
| - $(body.args...) |
325 |
| - end) |
326 |
| - else |
327 |
| - @q(function $name_param($(dict[:args]...); |
328 |
| - $(dict[:kwargs]...))::$rtype |
329 |
| - $(body.args...) |
330 |
| - end) |
331 |
| - end |
332 |
| - else |
333 |
| - if rtype==nothing |
334 |
| - @q(function $name_param($(dict[:args]...); |
335 |
| - $(dict[:kwargs]...)) where {$(wparams...)} |
336 |
| - $(body.args...) |
337 |
| - end) |
338 |
| - else |
339 |
| - @q(function $name_param($(dict[:args]...); |
340 |
| - $(dict[:kwargs]...))::$rtype where {$(wparams...)} |
341 |
| - $(body.args...) |
342 |
| - end) |
343 |
| - end |
344 |
| - end |
345 |
| -end |
346 |
| - |
347 | 264 | """
|
348 | 265 | combinearg(arg_name, arg_type, is_splat, default)
|
349 | 266 |
|
|
0 commit comments