Package list lua-ldoc / d9d749f
fix issue #79: will not allow a module as a type. Plus, add reference lookup for lfs and lpeg Steve Donovan 8 years ago
4 changed file(s) with 52 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
7272 globals.set_manual_url 'http://www.lua.org/manual/5.1/manual.html'
7373 end
7474
75 -- external libs tracked by LDoc using LDoc style
76 local xlibs = {
77 lfs='lfs.html', lpeg='lpeg.html',
78 }
79 local xlib_url = 'http://stevedonovan.github.io/lua-stdlibs/modules/'
80
7581 local tables = globals.tables
7682
77 local function function_ref (name)
78 return {href = fun_ref..name, label = name}
83 local function function_ref (name,tbl)
84 local href
85 tbl = tbl or ''
86 if tables[tbl] then
87 name = tbl..'.'..name
88 href = fun_ref..name
89 elseif xlibs[tbl] then
90 href = xlib_url..xlibs[tbl]..'#'..name
91 name = tbl..'.'..name
92 else
93 return nil
94 end
95 return {href = href, label = name}
7996 end
8097
81 local function module_ref (name)
82 return {href = manual..tables[name], label = name}
98 local function module_ref (tbl)
99 local href
100 if tables[tbl] ~= nil then
101 href = manual..tables[tbl]
102 elseif xlibs[tbl] then
103 href = xlib_url..xlibs[tbl]
104 else
105 return nil
106 end
107 return {href = href, label = tbl}
83108 end
84109
85110 function globals.lua_manual_ref (name)
86111 local tbl,fname = tools.split_dotted_name(name)
112 local ref
87113 if not tbl then -- plain symbol
88 if functions[name] then
89 return function_ref(name)
90 end
91 if tables[name] then
92 return module_ref(name)
93 end
114 ref = function_ref(name)
115 if ref then return ref end
116 ref = module_ref(name)
117 if ref then return ref end
94118 else
95 if tables[tbl] then
96 return function_ref(name)
97 end
119 ref = function_ref(fname,tbl)
120 if ref then return ref end
98121 end
99122 return nil
100123 end
829829 return {mod = mod_ref, name = name, label=s}
830830 end
831831
832 function Module:process_see_reference (s,modules)
832 function Module:process_see_reference (s,modules,istype)
833833 local mod_ref,fun_ref,name,packmod
834834 local ref = custom_see_references(s)
835835 if ref then return ref end
836836 if not s:match '^[%w_%.%:%-]+$' or not s:match '[%w_]$' then
837837 return nil, "malformed see reference: '"..s..'"'
838838 end
839 local function ismod(item)
840 if item == nil then return false end
841 if not istype then return true
842 else
843 return item.type == 'classmod'
844 end
845 end
839846 -- is this a fully qualified module name?
840847 local mod_ref = modules.by_name[s]
841 if mod_ref then return reference(s, mod_ref,nil) end
848 if ismod(mod_ref) then return reference(s, mod_ref,nil) end
842849 -- module reference?
843850 mod_ref = self:hunt_for_reference(s, modules)
844 if mod_ref then return mod_ref end
851 if ismod(mod_ref) then return mod_ref end
845852 -- method reference? (These are of form CLASS.NAME)
846853 fun_ref = self.items.by_name[s]
847854 if fun_ref then return reference(s,self,fun_ref) end
870877 end
871878 else -- plain jane name; module in this package, function in this module
872879 mod_ref = modules.by_name[self.package..'.'..s]
873 if mod_ref then return reference(s, mod_ref,nil) end
880 if ismod(mod_ref) then return reference(s, mod_ref,nil) end
874881 fun_ref = self.items.by_name[s]
875882 if fun_ref then return reference(s, self,fun_ref)
876883 else
179179 end
180180 local types = {}
181181 for name in tp:gmatch("[^|]+") do
182 local ref,err = markup.process_reference(name)
182 local ref,err = markup.process_reference(name,true)
183183 if ref then
184184 types[#types+1] = ('<a class="type" href="%s">%s</a>'):format(ldoc.href(ref),ref.label or name)
185185 else
284284 global_context = ldoc.package and ldoc.package .. '.'
285285 prettify.set_prettifier(pretty)
286286
287 markup.process_reference = function(name)
287 markup.process_reference = function(name,istype)
288288 if local_context == 'none.' and not name:match '%.' then
289289 return nil,'not found'
290290 end
291291 local mod = ldoc.single or ldoc.module or ldoc.modules[1]
292 local ref,err = mod:process_see_reference(name, ldoc.modules)
292 local ref,err = mod:process_see_reference(name, ldoc.modules, istype)
293293 if ref then return ref end
294294 if global_context then
295295 local qname = global_context .. name
296 ref = mod:process_see_reference(qname, ldoc.modules)
296 ref = mod:process_see_reference(qname, ldoc.modules, istype)
297297 if ref then return ref end
298298 end
299299 if local_context then
300300 local qname = local_context .. name
301 ref = mod:process_see_reference(qname, ldoc.modules)
301 ref = mod:process_see_reference(qname, ldoc.modules, istype)
302302 if ref then return ref end
303303 end
304304 -- note that we'll return the original error!