Skip to content

Commit

Permalink
handle signatures better
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeInnes committed Jun 27, 2015
1 parent 5e375cd commit 362ac82
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions doc/genstdlib.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using .Markdown
using Base.Markdown: MD

cd(dirname(@__FILE__))

Expand All @@ -8,6 +9,22 @@ ident(mod, x) = "$mod.$(isop(x) ? "(:($x))" : x)"

getdoc(mod, x) = try eval(parse("@doc $(ident(mod, x))")) catch e end

flat_content(md) = md
flat_content(xs::Vector) = reduce((xs, x) -> vcat(xs,flat_content(x)), [], xs)
flat_content(md::MD) = flat_content(md.content)
flatten(md::MD) = MD(flat_content(md))

issig(md) = isa(md, Markdown.Code) && length(split(md.code, "\n")) == 1

function splitsig(md)
md = flatten(md)
sig = nothing
if !isempty(md.content) && issig(md.content[1])
sig = shift!(md.content)
end
return md, sig
end

function translate(file)
@assert isfile(file)
ls = split(readall(file), "\n")[1:end-1]
Expand All @@ -24,18 +41,20 @@ function translate(file)
func = match(r".. function:: (@?[^\(\s\{]+)", l)
func == nothing && (warn("bad function $l"); continue)
func = func.captures[1]
doc = getdoc(mod, func)

if getdoc(mod, func) == nothing
if doc == nothing
info("no docs for $(ident(mod, func))")
println(io, l)
doccing = false
continue
end

doc, sig = splitsig(doc)
doccing = true
println(io, l)
println(io, sig == nothing ? l : ".. function:: $(sig.code)")
println(io)
for l in split(Markdown.rst(getdoc(mod, func)), "\n")
for l in split(Markdown.rst(doc), "\n")
println(io, " ", l)
end
println(io)
Expand Down

0 comments on commit 362ac82

Please sign in to comment.