elua: make old documentation generator generate instead of failing

While a rewritten template-based doc generator is pending addition
into a separate repository, at least fix this one so that it works
in case we decide to go back to it, because right now it's just
failing because of out of date code.

The fixes here are based on the revamped documentation generator
that will be introduced.
This commit is contained in:
Daniel Kolesa 2018-09-05 13:12:05 +02:00
parent 107bb9d2ed
commit 1e52108644
2 changed files with 29 additions and 26 deletions

View File

@ -44,11 +44,11 @@ M.Node = util.Object:clone {
end, end,
name_get = function(self) name_get = function(self)
return self.obj:name_get() return self._obj:name_get()
end, end,
short_name_get = function(self) short_name_get = function(self)
return self.obj:short_name_get() return self._obj:short_name_get()
end, end,
namespaces_get = function(self) namespaces_get = function(self)
@ -107,6 +107,11 @@ local add_since = function(str, since)
end end
M.Doc = Node:clone { M.Doc = Node:clone {
-- duplicate ctor to disable assertion
__ctor = function(self, obj)
self._obj = obj
end,
summary_get = function(self) summary_get = function(self)
if not self._obj then if not self._obj then
return nil return nil
@ -1349,26 +1354,24 @@ M.DocTokenizer = util.Object:clone {
ref_resolve = function(self, root) ref_resolve = function(self, root)
-- FIXME: unit -- FIXME: unit
local tp, d1, d2 = self.tok:ref_resolve(eos) local tp, d1, d2 = self.tok:ref_resolve(eos)
local reft = eolian.doc_ref_type local reft = eolian.object_type
local ret = {} local ret = {}
if tp == reft.CLASS or tp == reft.FUNC or tp == reft.EVENT then if tp == reft.CLASS or tp == reft.FUNCTION or tp == reft.EVENT then
if not class_type_str[d1:type_get()] then if not class_type_str[d1:type_get()] then
error("unknown class type for class '" error("unknown class type for class '"
.. d1:name_get() .. "'") .. d1:name_get() .. "'")
end end
elseif tp == reft.ALIAS then elseif tp == reft.TYPEDECL then
elseif tp == reft.STRUCT or tp == reft.STRUCT_FIELD then elseif tp == reft.ENUM_FIELD or tp == reft.STRUCT_FIELD then
-- TODO: point to field -- TODO: point to field
elseif tp == reft.ENUM or tp == reft.ENUM_FIELD then elseif tp == reft.VARIABLE then
-- TODO: point to field
elseif tp == reft.VAR then
else else
error("invalid reference '" .. self:text_get() .. "'") error("invalid reference '" .. self:text_get() .. "'")
end end
for tok in d1:name_get():gmatch("[^%.]+") do for tok in d1:name_get():gmatch("[^%.]+") do
ret[#ret + 1] = tok:lower() ret[#ret + 1] = tok:lower()
end end
if tp == reft.FUNC then if tp == reft.FUNCTION then
ret[#ret + 1] = func_type_str[d2:type_get()] ret[#ret + 1] = func_type_str[d2:type_get()]
ret[#ret + 1] = d2:name_get():lower() ret[#ret + 1] = d2:name_get():lower()
elseif tp == reft.EVENT then elseif tp == reft.EVENT then

View File

@ -87,7 +87,7 @@ local not_verbs = {
local get_class_name = function(cls) local get_class_name = function(cls)
local words = {} local words = {}
local klass = cls:full_name_get() local klass = cls:name_get()
for word in string.gmatch(klass, "%a+") do for word in string.gmatch(klass, "%a+") do
words[#words+1] = word words[#words+1] = word
end end
@ -107,20 +107,20 @@ get_mono_type = function(tp)
tpdecl = tp:typedecl_get() tpdecl = tp:typedecl_get()
if tpt == tp.REGULAR then if tpt == tp.REGULAR then
if tp:full_name_get() == "string" then if tp:name_get() == "string" then
return "System.String" return "System.String"
elseif tp:full_name_get() == "list" then elseif tp:name_get() == "list" then
ntp = tp:base_type_get() ntp = tp:base_type_get()
--assert(btp ~= nil) --assert(btp ~= nil)
--ntp = btp:next_type_get() --ntp = btp:next_type_get()
return "eina.List<" .. get_mono_type(ntp) .. ">" return "eina.List<" .. get_mono_type(ntp) .. ">"
elseif tpdecl then elseif tpdecl then
--print("typedecl type is ", tp:full_name_get()) --print("typedecl type is ", tp:name_get())
tpt = tpdecl:type_get() tpt = tpdecl:type_get()
return get_class_name(tp) --tp:full_name_get() return get_class_name(tp) --tp:name_get()
else else
--print("regular type is ", tp:full_name_get()) --print("regular type is ", tp:name_get())
return tp:full_name_get() return tp:name_get()
end end
elseif tpt == tp.CLASS then elseif tpt == tp.CLASS then
return get_class_name(tp) return get_class_name(tp)
@ -189,7 +189,7 @@ local find_parent_impl
find_parent_impl = function(fulln, cl) find_parent_impl = function(fulln, cl)
for i, pcl in ipairs(cl:inherits_get()) do for i, pcl in ipairs(cl:inherits_get()) do
for j, impl in ipairs(pcl:implements_get()) do for j, impl in ipairs(pcl:implements_get()) do
if impl:full_name_get() == fulln then if impl:name_get() == fulln then
--if get_class_name(impl) == fulln then --if get_class_name(impl) == fulln then
return impl, pcl return impl, pcl
end end
@ -224,7 +224,7 @@ local write_description = function(f, impl, func, cl)
local doc = impl:doc_get(func.METHOD, true) local doc = impl:doc_get(func.METHOD, true)
local docf = impl:fallback_doc_get(true) local docf = impl:fallback_doc_get(true)
if over and (not doc:exists() and (not docf or not docf:exists())) then if over and (not doc:exists() and (not docf or not docf:exists())) then
bdoc = find_parent_briefdoc(impl:full_name_get(), cl) bdoc = find_parent_briefdoc(impl:name_get(), cl)
else else
bdoc = doc:brief_get(docf) bdoc = doc:brief_get(docf)
end end
@ -338,7 +338,7 @@ local gen_func_mono_sig = function(f, ftype)
pars[#pars + 1] = gen_mono_param(par) pars[#pars + 1] = gen_mono_param(par)
end end
for i, par in ipairs(vals) do for i, par in ipairs(vals) do
print('parameter is value for get, so out') --print('parameter is value for get, so out')
pars[#pars + 1] = gen_mono_param(par, true) pars[#pars + 1] = gen_mono_param(par, true)
end end
@ -382,7 +382,7 @@ local build_functable = function(f, tcl, tbl)
table.sort(nt, function(v1, v2) table.sort(nt, function(v1, v2)
local cl1, cl2 = v1[0], v2[0] local cl1, cl2 = v1[0], v2[0]
if cl1 ~= cl2 then if cl1 ~= cl2 then
return cl1:full_name_get() < cl2:full_name_get() return cl1:name_get() < cl2:name_get()
end end
local f1, f2 = v1[1], v2[1] local f1, f2 = v1[1], v2[1]
@ -435,7 +435,7 @@ M.build_inherits = function(cl, t, lvl)
cln = ":" .. 'develop:api' .. ":" cln = ":" .. 'develop:api' .. ":"
.. table.concat(cln, ":") .. table.concat(cln, ":")
lbuf:write_raw("[[", cln, "|", get_class_name(cl), "]]") lbuf:write_raw("[[", cln, "|", get_class_name(cl), "]]")
--lbuf:write_link(cl:nspaces_get(true), cl:full_name_get()) --lbuf:write_link(cl:nspaces_get(true), cl:name_get())
lbuf:write_raw(" ") lbuf:write_raw(" ")
lbuf:write_i("(" .. cl:type_str_get() .. ")") lbuf:write_i("(" .. cl:type_str_get() .. ")")
@ -487,7 +487,7 @@ M.write_inherit_functable = function(f, tcl, tbl)
if cl ~= prevcl then if cl ~= prevcl then
prevcl = cl prevcl = cl
f:write_raw("^ ") f:write_raw("^ ")
f:write_link(cl:nspaces_get(true), cl:full_name_get()) f:write_link(cl:nspaces_get(true), cl:name_get())
f:write_raw(" ^^^") f:write_raw(" ^^^")
f:write_nl() f:write_nl()
end end
@ -535,7 +535,7 @@ M.write_functable = function(f, tcl, tbl)
-- but we get latest doc every time so it's ok for now -- but we get latest doc every time so it's ok for now
local llbuf = writer.Buffer() local llbuf = writer.Buffer()
llbuf:write_raw(" [Overridden from ") llbuf:write_raw(" [Overridden from ")
llbuf:write_link(ocl:nspaces_get(true), ocl:full_name_get()) llbuf:write_link(ocl:nspaces_get(true), ocl:name_get())
llbuf:write_raw("]") llbuf:write_raw("]")
f:write_i(llbuf:finish()) f:write_i(llbuf:finish())
end end
@ -562,12 +562,12 @@ end
M.build_class = function(cl) M.build_class = function(cl)
local cln = cl:nspaces_get() local cln = cl:nspaces_get()
local fulln = cl:full_name_get() local fulln = cl:name_get()
--table.insert(cln, "mono") --table.insert(cln, "mono")
cln[#cln] = cln[#cln] .. "_mono" cln[#cln] = cln[#cln] .. "_mono"
--printgen("Generating (MONO) class: " .. fulln .. " in ns ", unpack(cln)) --printgen("Generating (MONO) class: " .. fulln .. " in ns ", unpack(cln))
local f = writer.Writer(cln, fulln .. " (mono)") local f = writer.Writer(cln, fulln .. " (mono)")
f:write_h(cl:full_name_get() .. " (" .. cl:type_str_get() .. ")", 1) f:write_h(cl:name_get() .. " (" .. cl:type_str_get() .. ")", 1)
f:write_h("Description", 2) f:write_h("Description", 2)
f:write_raw(cl:doc_get():full_get(nil, true)) f:write_raw(cl:doc_get():full_get(nil, true))