4 | 4 |
require 'pl'
|
5 | 5 |
|
6 | 6 |
local doc = {}
|
7 | |
|
|
7 |
local global = require 'builtin.globals'
|
8 | 8 |
local tools = require 'ldoc.tools'
|
9 | 9 |
local split_dotted_name = tools.split_dotted_name
|
10 | 10 |
|
|
99 | 99 |
mname = this_mod.name
|
100 | 100 |
package = ''
|
101 | 101 |
else
|
102 | |
package = package .. '.'
|
|
102 |
package = package
|
103 | 103 |
end
|
104 | 104 |
self.modules:append(this_mod)
|
105 | 105 |
this_mod.package = package
|
|
276 | 276 |
if type(name) == 'table' then pretty.dump(name); name = '?' end
|
277 | 277 |
name = name or '?'
|
278 | 278 |
io.stderr:write(name,':',self.lineno or '?',' ',msg,'\n')
|
|
279 |
return nil
|
279 | 280 |
end
|
280 | 281 |
|
281 | 282 |
function Item:error(msg)
|
|
294 | 295 |
function Module:resolve_references(modules)
|
295 | 296 |
local found = List()
|
296 | 297 |
|
|
298 |
local function hunt_for_reference (packmod)
|
|
299 |
local mod_ref
|
|
300 |
local package = self.package
|
|
301 |
repeat -- same package?
|
|
302 |
local nmod = package..'.'..packmod
|
|
303 |
mod_ref = modules.by_name[nmod]
|
|
304 |
if mod_ref then break end -- cool
|
|
305 |
package = split_dotted_name(package)
|
|
306 |
until not package
|
|
307 |
return mod_ref
|
|
308 |
end
|
|
309 |
|
297 | 310 |
local function process_see_reference (item,see,s)
|
298 | 311 |
local mod_ref,fun_ref,name,packmod
|
299 | 312 |
-- is this a fully qualified module name?
|
300 | 313 |
local mod_ref = modules.by_name[s]
|
301 | 314 |
if mod_ref then return mod_ref,nil end
|
|
315 |
-- module reference?
|
|
316 |
mod_ref = hunt_for_reference(s)
|
|
317 |
if mod_ref then return mod_ref end
|
302 | 318 |
local packmod,name = split_dotted_name(s) -- e.g. 'pl.utils','split'
|
303 | 319 |
if packmod then -- qualified name
|
304 | 320 |
mod_ref = modules.by_name[packmod] -- fully qualified mod name?
|
305 | 321 |
if not mod_ref then
|
306 | |
mod_ref = modules.by_name[self.package..packmod]
|
307 | |
end
|
308 | |
if not mod_ref then
|
309 | |
item:warning("module not found: "..packmod)
|
310 | |
return nil
|
|
322 |
mod_ref = hunt_for_reference(packmod)
|
|
323 |
if not mod_ref then
|
|
324 |
local ref = global.lua_manual_ref(s)
|
|
325 |
if ref then return ref end
|
|
326 |
return item:warning("module not found: "..packmod)
|
|
327 |
end
|
311 | 328 |
end
|
312 | 329 |
fun_ref = mod_ref.items.by_name[name]
|
313 | 330 |
if fun_ref then
|
|
316 | 333 |
item:warning("function not found: "..s.." in "..mod_ref.name)
|
317 | 334 |
end
|
318 | 335 |
else -- plain jane name; module in this package, function in this module
|
319 | |
mod_ref = modules.by_name[self.package..s]
|
|
336 |
mod_ref = modules.by_name[self.package..'.'..s]
|
320 | 337 |
if mod_ref then return mod_ref,nil end
|
321 | 338 |
fun_ref = self.items.by_name[s]
|
322 | 339 |
if fun_ref then return self,fun_ref
|
323 | 340 |
else
|
|
341 |
local ref = global.lua_manual_ref (s)
|
|
342 |
if ref then return ref end
|
324 | 343 |
item:warning("function not found: "..s.." in this module")
|
325 | 344 |
end
|
326 | 345 |
end
|
|
333 | 352 |
for s in see:iter() do
|
334 | 353 |
local mod_ref, item_ref = process_see_reference(item,see,s)
|
335 | 354 |
if mod_ref then
|
336 | |
local name = item_ref and item_ref.name or ''
|
337 | |
-- this is deeply hacky; classes have 'Class ' prepended.
|
338 | |
if item_ref and item_ref.type == 'type' then
|
339 | |
name = 'Class_'..name
|
|
355 |
local href
|
|
356 |
if mod_ref.name then
|
|
357 |
local name = item_ref and item_ref.name or ''
|
|
358 |
-- this is deeply hacky; classes have 'Class ' prepended.
|
|
359 |
if item_ref and item_ref.type == 'type' then
|
|
360 |
name = 'Class_'..name
|
|
361 |
end
|
|
362 |
href = {mod=mod_ref.name,name=name,label=s}
|
|
363 |
else
|
|
364 |
href = {href = mod_ref.href,label=s}
|
340 | 365 |
end
|
341 | |
item.see:append {mod=mod_ref.name,name=name,label=s}
|
|
366 |
item.see:append (href)
|
342 | 367 |
found:append{item,s}
|
343 | 368 |
end
|
344 | 369 |
end
|