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'
|
globals.set_manual_url 'http://www.lua.org/manual/5.1/manual.html'
|
||||||
end
|
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 tables = globals.tables
|
||||||
|
|
||||||
local function function_ref (name)
|
local function function_ref (name,tbl)
|
||||||
return {href = fun_ref..name, label = name}
|
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
|
end
|
||||||
|
|
||||||
local function module_ref (name)
|
local function module_ref (tbl)
|
||||||
return {href = manual..tables[name], label = name}
|
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
|
end
|
||||||
|
|
||||||
function globals.lua_manual_ref (name)
|
function globals.lua_manual_ref (name)
|
||||||
local tbl,fname = tools.split_dotted_name(name)
|
local tbl,fname = tools.split_dotted_name(name)
|
||||||
|
local ref
|
||||||
if not tbl then -- plain symbol
|
if not tbl then -- plain symbol
|
||||||
if functions[name] then
|
ref = function_ref(name)
|
||||||
return function_ref(name)
|
if ref then return ref end
|
||||||
end
|
ref = module_ref(name)
|
||||||
if tables[name] then
|
if ref then return ref end
|
||||||
return module_ref(name)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
if tables[tbl] then
|
ref = function_ref(fname,tbl)
|
||||||
return function_ref(name)
|
if ref then return ref end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
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}
|
return {mod = mod_ref, name = name, label=s}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Module:process_see_reference (s,modules)
|
function Module:process_see_reference (s,modules,istype)
|
||||||
local mod_ref,fun_ref,name,packmod
|
local mod_ref,fun_ref,name,packmod
|
||||||
local ref = custom_see_references(s)
|
local ref = custom_see_references(s)
|
||||||
if ref then return ref end
|
if ref then return ref end
|
||||||
if not s:match '^[%w_%.%:%-]+$' or not s:match '[%w_]$' then
|
if not s:match '^[%w_%.%:%-]+$' or not s:match '[%w_]$' then
|
||||||
return nil, "malformed see reference: '"..s..'"'
|
return nil, "malformed see reference: '"..s..'"'
|
||||||
end
|
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?
|
-- is this a fully qualified module name?
|
||||||
local mod_ref = modules.by_name[s]
|
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?
|
-- module reference?
|
||||||
mod_ref = self:hunt_for_reference(s, modules)
|
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)
|
-- method reference? (These are of form CLASS.NAME)
|
||||||
fun_ref = self.items.by_name[s]
|
fun_ref = self.items.by_name[s]
|
||||||
if fun_ref then return reference(s,self,fun_ref) end
|
if fun_ref then return reference(s,self,fun_ref) end
|
||||||
|
@ -871,7 +878,7 @@ function Module:process_see_reference (s,modules)
|
||||||
end
|
end
|
||||||
else -- plain jane name; module in this package, function in this module
|
else -- plain jane name; module in this package, function in this module
|
||||||
mod_ref = modules.by_name[self.package..'.'..s]
|
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]
|
fun_ref = self.items.by_name[s]
|
||||||
if fun_ref then return reference(s, self,fun_ref)
|
if fun_ref then return reference(s, self,fun_ref)
|
||||||
else
|
else
|
||||||
|
|
|
@ -180,7 +180,7 @@ function html.generate_output(ldoc, args, project)
|
||||||
end
|
end
|
||||||
local types = {}
|
local types = {}
|
||||||
for name in tp:gmatch("[^|]+") do
|
for name in tp:gmatch("[^|]+") do
|
||||||
local ref,err = markup.process_reference(name)
|
local ref,err = markup.process_reference(name,true)
|
||||||
if ref then
|
if ref then
|
||||||
types[#types+1] = ('<a class="type" href="%s">%s</a>'):format(ldoc.href(ref),ref.label or name)
|
types[#types+1] = ('<a class="type" href="%s">%s</a>'):format(ldoc.href(ref),ref.label or name)
|
||||||
else
|
else
|
||||||
|
|
|
@ -285,21 +285,21 @@ function markup.create (ldoc, format, pretty)
|
||||||
global_context = ldoc.package and ldoc.package .. '.'
|
global_context = ldoc.package and ldoc.package .. '.'
|
||||||
prettify.set_prettifier(pretty)
|
prettify.set_prettifier(pretty)
|
||||||
|
|
||||||
markup.process_reference = function(name)
|
markup.process_reference = function(name,istype)
|
||||||
if local_context == 'none.' and not name:match '%.' then
|
if local_context == 'none.' and not name:match '%.' then
|
||||||
return nil,'not found'
|
return nil,'not found'
|
||||||
end
|
end
|
||||||
local mod = ldoc.single or ldoc.module or ldoc.modules[1]
|
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 ref then return ref end
|
||||||
if global_context then
|
if global_context then
|
||||||
local qname = global_context .. name
|
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
|
if ref then return ref end
|
||||||
end
|
end
|
||||||
if local_context then
|
if local_context then
|
||||||
local qname = local_context .. name
|
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
|
if ref then return ref end
|
||||||
end
|
end
|
||||||
-- note that we'll return the original error!
|
-- note that we'll return the original error!
|
||||||
|
|
Loading…
Reference in New Issue