Skip to content

Commit 9a3fb2d

Browse files
committed
Merge pull request #13907 from JuliaLang/yyc/gendoc-match
More restricted signature matching in genstdlib.jl
2 parents 69c7576 + 1def889 commit 9a3fb2d

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

doc/genstdlib.jl

+16-12
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ function tryrst(md, remove_decl)
133133
return Markdown.rst(md)
134134
catch e
135135
warn("Error converting docstring:")
136-
# display(md)
136+
# display(md)
137137
println(e)
138138
return
139139
end
140140
end
141141

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

144-
function split_decl_rst(md, decl)
144+
function split_decl_rst(md)
145145
if isrst(md)
146146
rst_text = flatten(md).content[1].code
147147
ls = split(rst_text, "\n")
@@ -158,14 +158,17 @@ function split_decl_rst(md, decl)
158158
end
159159
return decl, join(ls[body_start:end], "\n")
160160
end
161-
return decl, rst_text
162161
else
163162
if isa(md.content[1], Markdown.Code) && md.content[1].language == ""
164-
decl = ".. function:: " * replace(shift!(md.content).code, "\n",
163+
sigs = shift!(md.content)
164+
decl = ".. function:: " * replace(sigs.code, "\n",
165165
"\n ")
166+
body = Markdown.rst(md)
167+
unshift!(md.content, sigs)
168+
return decl, body
166169
end
167-
return decl, Markdown.rst(md)
168170
end
171+
return "", ""
169172
end
170173

171174
# Disable by default since it is hard to eliminate false positives
@@ -239,17 +242,19 @@ function translate(file)
239242
end
240243
end
241244
doc = nothing
245+
decl = nothing
246+
body = nothing
242247
for mdoc in getdoc(mod, funcname)
243-
trst = tryrst(mdoc, false)
244-
trst !== nothing || continue
245-
if contains(replace(trst, r"[\n ][\n ]+", " "),
246-
" " * replace(full, r"[\n ][\n ]+", " "))
248+
mdecl, mbody = split_decl_rst(mdoc)
249+
if contains(replace(mdecl, r"[\n ][\n ]+", " "),
250+
replace(".. function:: " * full,
251+
r"[\n ][\n ]+", " "))
247252
if doc != nothing
248253
error("duplicate $full $l")
249254
end
250255
doc = mdoc
251-
else
252-
#@show trst full
256+
decl = mdecl
257+
body = mbody
253258
end
254259
end
255260
if doc == nothing || torst(doc, false) == nothing
@@ -262,7 +267,6 @@ function translate(file)
262267
delete!(all_docs, doc)
263268
doccing = true
264269
start_func_doc(full)
265-
decl, body = split_decl_rst(doc, l)
266270
println(io, decl)
267271
println(io)
268272
println(io, " .. Docstring generated from Julia source\n")

0 commit comments

Comments
 (0)