fix issue #79: will not allow a module as a type. Plus, add reference lookup for lfs and lpeg
This commit is contained in:
parent
dfdac3f977
commit
d9d749fa37
|
@ -73,29 +73,52 @@ else
|
|||
globals.set_manual_url 'http://www.lua.org/manual/5.1/manual.html'
|
||||
end
|
||||
|
||||
-- external libs tracked by LDoc using LDoc style
|
||||
local xlibs = {
|
||||
lfs='lfs.html', lpeg='lpeg.html',
|
||||
}
|
||||
local xlib_url = 'http://stevedonovan.github.io/lua-stdlibs/modules/'
|
||||
|
||||
local tables = globals.tables
|
||||
|
||||
local function function_ref (name)
|
||||
return {href = fun_ref..name, label = name}
|
||||
local function function_ref (name,tbl)
|
||||
local href
|
||||
tbl = tbl or ''
|
||||
if tables[tbl] then
|
||||
name = tbl..'.'..name
|
||||
href = fun_ref..name
|
||||
elseif xlibs[tbl] then
|
||||
href = xlib_url..xlibs[tbl]..'#'..name
|
||||
name = tbl..'.'..name
|
||||
else
|
||||
return nil
|
||||
end
|
||||
return {href = href, label = name}
|
||||
end
|
||||
|
||||
local function module_ref (name)
|
||||
return {href = manual..tables[name], label = name}
|
||||
local function module_ref (tbl)
|
||||
local href
|
||||
if tables[tbl] ~= nil then
|
||||
href = manual..tables[tbl]
|
||||
elseif xlibs[tbl] then
|
||||
href = xlib_url..xlibs[tbl]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
return {href = href, label = tbl}
|
||||
end
|
||||
|
||||
function globals.lua_manual_ref (name)
|
||||
local tbl,fname = tools.split_dotted_name(name)
|
||||
local ref
|
||||
if not tbl then -- plain symbol
|
||||
if functions[name] then
|
||||
return function_ref(name)
|
||||
end
|
||||
if tables[name] then
|
||||
return module_ref(name)
|
||||
end
|
||||
ref = function_ref(name)
|
||||
if ref then return ref end
|
||||
ref = module_ref(name)
|
||||
if ref then return ref end
|
||||
else
|
||||
if tables[tbl] then
|
||||
return function_ref(name)
|
||||
end
|
||||
ref = function_ref(fname,tbl)
|
||||
if ref then return ref end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
|
15
ldoc/doc.lua
15
ldoc/doc.lua
|
@ -830,19 +830,26 @@ local function reference (s, mod_ref, item_ref)
|
|||
return {mod = mod_ref, name = name, label=s}
|
||||
end
|
||||
|
||||
function Module:process_see_reference (s,modules)
|
||||
function Module:process_see_reference (s,modules,istype)
|
||||
local mod_ref,fun_ref,name,packmod
|
||||
local ref = custom_see_references(s)
|
||||
if ref then return ref end
|
||||
if not s:match '^[%w_%.%:%-]+$' or not s:match '[%w_]$' then
|
||||
return nil, "malformed see reference: '"..s..'"'
|
||||
end
|
||||
local function ismod(item)
|
||||
if item == nil then return false end
|
||||
if not istype then return true
|
||||
else
|
||||
return item.type == 'classmod'
|
||||
end
|
||||
end
|
||||
-- is this a fully qualified module name?
|
||||
local mod_ref = modules.by_name[s]
|
||||
if mod_ref then return reference(s, mod_ref,nil) end
|
||||
if ismod(mod_ref) then return reference(s, mod_ref,nil) end
|
||||
-- module reference?
|
||||
mod_ref = self:hunt_for_reference(s, modules)
|
||||
if mod_ref then return mod_ref end
|
||||
if ismod(mod_ref) then return mod_ref end
|
||||
-- method reference? (These are of form CLASS.NAME)
|
||||
fun_ref = self.items.by_name[s]
|
||||
if fun_ref then return reference(s,self,fun_ref) end
|
||||
|
@ -871,7 +878,7 @@ function Module:process_see_reference (s,modules)
|
|||
end
|
||||
else -- plain jane name; module in this package, function in this module
|
||||
mod_ref = modules.by_name[self.package..'.'..s]
|
||||
if mod_ref then return reference(s, mod_ref,nil) end
|
||||
if ismod(mod_ref) then return reference(s, mod_ref,nil) end
|
||||
fun_ref = self.items.by_name[s]
|
||||
if fun_ref then return reference(s, self,fun_ref)
|
||||
else
|
||||
|
|
|
@ -180,7 +180,7 @@ function html.generate_output(ldoc, args, project)
|
|||
end
|
||||
local types = {}
|
||||
for name in tp:gmatch("[^|]+") do
|
||||
local ref,err = markup.process_reference(name)
|
||||
local ref,err = markup.process_reference(name,true)
|
||||
if ref then
|
||||
types[#types+1] = ('<a class="type" href="%s">%s</a>'):format(ldoc.href(ref),ref.label or name)
|
||||
else
|
||||
|
|
|
@ -285,21 +285,21 @@ function markup.create (ldoc, format, pretty)
|
|||
global_context = ldoc.package and ldoc.package .. '.'
|
||||
prettify.set_prettifier(pretty)
|
||||
|
||||
markup.process_reference = function(name)
|
||||
markup.process_reference = function(name,istype)
|
||||
if local_context == 'none.' and not name:match '%.' then
|
||||
return nil,'not found'
|
||||
end
|
||||
local mod = ldoc.single or ldoc.module or ldoc.modules[1]
|
||||
local ref,err = mod:process_see_reference(name, ldoc.modules)
|
||||
local ref,err = mod:process_see_reference(name, ldoc.modules, istype)
|
||||
if ref then return ref end
|
||||
if global_context then
|
||||
local qname = global_context .. name
|
||||
ref = mod:process_see_reference(qname, ldoc.modules)
|
||||
ref = mod:process_see_reference(qname, ldoc.modules, istype)
|
||||
if ref then return ref end
|
||||
end
|
||||
if local_context then
|
||||
local qname = local_context .. name
|
||||
ref = mod:process_see_reference(qname, ldoc.modules)
|
||||
ref = mod:process_see_reference(qname, ldoc.modules, istype)
|
||||
if ref then return ref end
|
||||
end
|
||||
-- note that we'll return the original error!
|
||||
|
|
Loading…
Reference in New Issue