Skip to content

Commit

Permalink
doc system fix: when using __doc__ and define==false, extract just
Browse files Browse the repository at this point in the history
the `__doc__` pieces to avoid repeating the rest of the surrounding
code (which might include method definitions).
  • Loading branch information
JeffBezanson committed Jan 22, 2016
1 parent 9748c18 commit 85d8d2b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -519,21 +519,30 @@ more than one expression is marked then the same docstring is applied to each ex
"""
:(Base.@__doc__)

function __doc__!(meta, def::Expr)
function __doc__!(meta, def::Expr, define=true)
if isexpr(def, :block, 2) && isexpr(def.args[1], :meta, 1) && def.args[1].args[1] === :doc
# Convert `Expr(:block, Expr(:meta, :doc), ...)` created by `@__doc__` to an `@doc`.
def.head = :macrocall
def.args = [symbol("@doc"), meta, def.args[end]]
true
def.args = [symbol("@doc"), meta, def.args[end], define]
(true, def)
else
found = false
ret = Expr(:block)
for each in def.args
found |= __doc__!(meta, each)
f, ex = __doc__!(meta, each)
if f
found = true
push!(ret.args, ex)
end
end
if length(ret.args)==1
return (found, ret.args[1])
else
return (found, ret)
end
found
end
end
__doc__!(meta, def) = false
__doc__!(meta, def, define=true) = (false, def)

# Predicates and helpers for `docm` expression selection:

Expand Down Expand Up @@ -594,7 +603,7 @@ function docm(meta, ex, define = true)
# Errors generated by calling `macroexpand` are passed back to the call site.
isexpr(x, :error) ? esc(x) :
# When documenting macro-generated code we look for embedded `@__doc__` calls.
__doc__!(meta, x) ? esc(x) :
(temp = __doc__!(meta, x, define); temp[1]) ? esc(define ? x : temp[2]) :
# Any "basic" expression such as a bare function or module name or numeric literal.
isbasicdoc(x) ? namedoc(meta, nothing, x) :

Expand Down

0 comments on commit 85d8d2b

Please sign in to comment.