Skip to content

Commit

Permalink
updates to genstdlib.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeInnes committed Aug 14, 2015
1 parent f37376a commit df2e997
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions doc/genstdlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,23 @@ 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

isrst(md) =
length(flatten(md).content) == 1 &&
isa(flatten(md).content[1], Markdown.Code) &&
flatten(md).content[1].language == "rst"

torst(md) = isrst(md) ? flatten(md).content[1].code : Markdown.rst(md)

function remsig(l, doc)
sig = l[15:end]
ls = split(doc, "\n")
contains(ls[2], sig) && (ls = ls[3:end])
while ls[1] == "" shift!(ls) end
startswith(ls[1], " "^11) && (ls = ["::", ls...])
join(ls, "\n")
function tryrst(md)
try
Markdown.rst(md)
catch e
warn("Error converting docstring:")
display(md)
return
end
end

torst(md) = isrst(md) ? flatten(md).content[1].code : tryrst(md)

function translate(file)
@assert isfile(file)
ls = split(readall(file), "\n")[1:end-1]
Expand All @@ -59,10 +49,8 @@ function translate(file)
func = func.captures[1]
doc = getdoc(mod, func)

if doc == nothing || !isrst(doc)
doc == nothing ?
info("no docs for $(ident(mod, func))") :
info("can't convert docs for $(ident(mod, func))")
if doc == nothing || torst(doc) == nothing
info("no docs for $(ident(mod, func))")
println(io, l)
doccing = false
continue
Expand All @@ -71,10 +59,11 @@ function translate(file)
doccing = true
println(io, l)
println(io)
for l in split(remsig(l, torst(doc)), "\n")
println(io, " .. Docstring generated from Julia source")
for l in split(torst(doc), "\n")
ismatch(r"^\s*$", l) ? println(io) : println(io, " ", l)
end
println(io)
isrst(doc) && println(io)
elseif doccing && (startswith(l, " ") || ismatch(r"^\s*$", l))
else
doccing = false
Expand Down

0 comments on commit df2e997

Please sign in to comment.