2011-04-13 13:02:40 +02:00
|
|
|
------
|
|
|
|
-- Defining the ldoc document model.
|
|
|
|
|
|
|
|
|
2012-10-28 18:51:00 +01:00
|
|
|
local class = require 'pl.class'
|
|
|
|
local utils = require 'pl.utils'
|
|
|
|
local List = require 'pl.List'
|
2012-12-29 11:04:39 +01:00
|
|
|
local Map = require 'pl.Map'
|
2016-06-27 16:25:56 +02:00
|
|
|
local text = require 'pl.text'
|
2011-04-13 13:02:40 +02:00
|
|
|
|
|
|
|
local doc = {}
|
2011-09-20 12:59:34 +02:00
|
|
|
local global = require 'ldoc.builtin.globals'
|
2011-06-14 10:54:51 +02:00
|
|
|
local tools = require 'ldoc.tools'
|
2011-04-13 13:02:40 +02:00
|
|
|
local split_dotted_name = tools.split_dotted_name
|
|
|
|
|
2012-12-31 16:02:40 +01:00
|
|
|
local TAG_MULTI,TAG_ID,TAG_SINGLE,TAG_TYPE,TAG_FLAG,TAG_MULTI_LINE = 'M','id','S','T','N','ML'
|
2012-12-10 13:45:54 +01:00
|
|
|
|
2011-04-13 13:02:40 +02:00
|
|
|
-- these are the basic tags known to ldoc. They come in several varieties:
|
2012-12-10 13:45:54 +01:00
|
|
|
-- - 'M' tags with multiple values like 'param' (TAG_MULTI)
|
2014-10-12 18:35:19 +02:00
|
|
|
-- - 'ML' tags which have a single multi-lined value like 'usage' (TAG_MULTI_LINE)
|
2012-12-10 13:45:54 +01:00
|
|
|
-- - 'id' tags which are identifiers, like 'name' (TAG_ID)
|
|
|
|
-- - 'S' tags with a single value, like 'release' (TAG_SINGLE)
|
|
|
|
-- - 'N' tags which have no associated value, like 'local` (TAG_FLAG)
|
|
|
|
-- - 'T' tags which represent a type, like 'function' (TAG_TYPE)
|
2011-04-13 13:02:40 +02:00
|
|
|
local known_tags = {
|
2013-08-27 12:47:47 +02:00
|
|
|
param = 'M', see = 'M', comment = 'M', usage = 'ML', ['return'] = 'M', field = 'M', author='M',set='M';
|
2016-04-06 08:50:14 +02:00
|
|
|
class = 'id', name = 'id', pragma = 'id', alias = 'id',
|
2011-08-26 15:34:42 +02:00
|
|
|
copyright = 'S', summary = 'S', description = 'S', release = 'S', license = 'S',
|
2016-04-06 08:50:14 +02:00
|
|
|
fixme = 'S', todo = 'S', warning = 'S', raise = 'S', charset = 'S', within = 'S',
|
2014-10-12 18:35:19 +02:00
|
|
|
['local'] = 'N', export = 'N', private = 'N', constructor = 'N', static = 'N',include = 'S',
|
2012-12-10 13:45:54 +01:00
|
|
|
-- project-level
|
2014-10-12 16:09:09 +02:00
|
|
|
module = 'T', script = 'T', example = 'T', topic = 'T', submodule='T', classmod='T', file='T',
|
2012-12-10 13:45:54 +01:00
|
|
|
-- module-level
|
|
|
|
['function'] = 'T', lfunction = 'T', table = 'T', section = 'T', type = 'T',
|
|
|
|
annotation = 'T', factory = 'T';
|
|
|
|
|
2011-04-13 13:02:40 +02:00
|
|
|
}
|
|
|
|
known_tags._alias = {}
|
|
|
|
known_tags._project_level = {
|
2011-06-06 18:38:02 +02:00
|
|
|
module = true,
|
2011-07-08 15:59:56 +02:00
|
|
|
script = true,
|
2011-07-11 15:40:44 +02:00
|
|
|
example = true,
|
2012-12-10 13:45:54 +01:00
|
|
|
topic = true,
|
2013-08-07 15:19:46 +02:00
|
|
|
submodule = true,
|
|
|
|
classmod = true,
|
2014-10-12 18:35:19 +02:00
|
|
|
file = true,
|
2011-04-13 13:02:40 +02:00
|
|
|
}
|
|
|
|
|
2012-12-29 11:04:39 +01:00
|
|
|
known_tags._code_types = {
|
|
|
|
module = true,
|
2013-08-07 15:19:46 +02:00
|
|
|
script = true,
|
|
|
|
classmod = true,
|
|
|
|
}
|
|
|
|
|
|
|
|
known_tags._presentation_names = {
|
|
|
|
classmod = 'Class',
|
2012-12-29 11:04:39 +01:00
|
|
|
}
|
|
|
|
|
2012-12-31 13:52:00 +01:00
|
|
|
known_tags._module_info = {
|
|
|
|
'copyright','release','license','author'
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:36:28 +02:00
|
|
|
local see_reference_handlers = {}
|
|
|
|
|
2012-12-10 13:45:54 +01:00
|
|
|
|
2011-06-15 16:12:56 +02:00
|
|
|
doc.TAG_MULTI,doc.TAG_ID,doc.TAG_SINGLE,doc.TAG_TYPE,doc.TAG_FLAG =
|
|
|
|
TAG_MULTI,TAG_ID,TAG_SINGLE,TAG_TYPE,TAG_FLAG
|
2011-04-13 13:02:40 +02:00
|
|
|
|
|
|
|
-- add a new tag.
|
|
|
|
function doc.add_tag(tag,type,project_level)
|
2011-06-06 18:38:02 +02:00
|
|
|
if not known_tags[tag] then
|
|
|
|
known_tags[tag] = type
|
|
|
|
known_tags._project_level[tag] = project_level
|
|
|
|
end
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2012-07-30 18:36:28 +02:00
|
|
|
function doc.add_custom_see_handler(pat,action)
|
2012-12-29 11:04:39 +01:00
|
|
|
see_reference_handlers[pat] = action
|
2012-07-30 18:36:28 +02:00
|
|
|
end
|
|
|
|
|
2011-04-13 13:02:40 +02:00
|
|
|
-- add an alias to an existing tag (exposed through ldoc API)
|
|
|
|
function doc.add_alias (a,tag)
|
2011-06-06 18:38:02 +02:00
|
|
|
known_tags._alias[a] = tag
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- get the tag alias value, if it exists.
|
|
|
|
function doc.get_alias(tag)
|
2011-06-06 18:38:02 +02:00
|
|
|
return known_tags._alias[tag]
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- is it a'project level' tag, such as 'module' or 'script'?
|
|
|
|
function doc.project_level(tag)
|
2011-06-06 18:38:02 +02:00
|
|
|
return known_tags._project_level[tag]
|
|
|
|
end
|
|
|
|
|
2012-12-31 13:52:00 +01:00
|
|
|
-- is it a project level tag containing code?
|
2012-12-29 11:04:39 +01:00
|
|
|
function doc.code_tag (tag)
|
|
|
|
return known_tags._code_types[tag]
|
|
|
|
end
|
|
|
|
|
2012-08-22 12:50:57 +02:00
|
|
|
-- is it a section tag?
|
2011-06-06 18:38:02 +02:00
|
|
|
function doc.section_tag (tag)
|
2012-08-22 12:50:57 +02:00
|
|
|
return tag == 'section' or doc.class_tag(tag)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- is it a class tag, like 'type' or 'factory'?
|
|
|
|
function doc.class_tag (tag)
|
|
|
|
return tag == 'type' or tag == 'factory'
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2013-08-07 15:19:46 +02:00
|
|
|
-- how the type wants to be formally presented; e.g. 'module' becomes 'Module'
|
|
|
|
-- but 'classmod' will become 'Class'
|
|
|
|
function doc.presentation_name (tag)
|
|
|
|
local name = known_tags._presentation_names[tag]
|
|
|
|
if not name then
|
|
|
|
name = tag:gsub('(%a)(%a*)',function(f,r)
|
|
|
|
return f:upper()..r
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
return name
|
|
|
|
end
|
|
|
|
|
2012-12-31 13:52:00 +01:00
|
|
|
function doc.module_info_tags ()
|
|
|
|
return List.iter(known_tags._module_info)
|
|
|
|
end
|
|
|
|
|
2013-08-23 13:50:34 +02:00
|
|
|
-- annotation tags can appear anywhere in the code and may contain any of these tags:
|
2011-09-18 20:45:36 +02:00
|
|
|
known_tags._annotation_tags = {
|
|
|
|
fixme = true, todo = true, warning = true
|
|
|
|
}
|
2011-09-17 19:13:47 +02:00
|
|
|
|
|
|
|
local acount = 1
|
|
|
|
|
2011-09-18 20:45:36 +02:00
|
|
|
function doc.expand_annotation_item (tags, last_item)
|
2014-01-06 14:03:09 +01:00
|
|
|
if tags.summary ~= '' or last_item == nil then return false end
|
|
|
|
local item_name = last_item.tags.name
|
2011-09-19 13:34:01 +02:00
|
|
|
for tag, value in pairs(tags) do
|
|
|
|
if known_tags._annotation_tags[tag] then
|
2014-09-15 20:02:28 +02:00
|
|
|
tags.summary = nil
|
2013-05-15 15:30:47 +02:00
|
|
|
tags:add('class','annotation')
|
|
|
|
tags:add('summary',value)
|
|
|
|
tags:add('name',item_name..'-'..tag..acount)
|
2011-09-19 13:34:01 +02:00
|
|
|
acount = acount + 1
|
|
|
|
return true
|
2015-12-23 14:19:21 +01:00
|
|
|
elseif tags.error and tag == 'return' then
|
2013-08-26 14:22:52 +02:00
|
|
|
last_item:set_tag(tag,value)
|
2011-09-19 13:34:01 +02:00
|
|
|
end
|
2011-09-17 19:13:47 +02:00
|
|
|
end
|
2013-08-26 14:22:52 +02:00
|
|
|
return false
|
2011-09-17 19:13:47 +02:00
|
|
|
end
|
|
|
|
|
2011-04-13 13:02:40 +02:00
|
|
|
-- we process each file, resulting in a File object, which has a list of Item objects.
|
|
|
|
-- Items can be modules, scripts ('project level') or functions, tables, etc.
|
|
|
|
-- (In the code 'module' refers to any project level tag.)
|
|
|
|
-- When the File object is finalized, we specialize some items as modules which
|
|
|
|
-- are 'container' types containing functions and tables, etc.
|
|
|
|
|
|
|
|
local File = class()
|
|
|
|
local Item = class()
|
|
|
|
local Module = class(Item) -- a specialized kind of Item
|
|
|
|
|
|
|
|
doc.File = File
|
|
|
|
doc.Item = Item
|
|
|
|
doc.Module = Module
|
|
|
|
|
|
|
|
function File:_init(filename)
|
2011-06-06 18:38:02 +02:00
|
|
|
self.filename = filename
|
|
|
|
self.items = List()
|
|
|
|
self.modules = List()
|
2012-03-13 11:23:55 +01:00
|
|
|
self.sections = List()
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function File:new_item(tags,line)
|
2011-07-11 15:40:44 +02:00
|
|
|
local item = Item(tags,self,line or 1)
|
2011-06-06 18:38:02 +02:00
|
|
|
self.items:append(item)
|
|
|
|
return item
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2011-12-06 18:19:09 +01:00
|
|
|
function File:export_item (name)
|
|
|
|
for item in self.items:iter() do
|
|
|
|
local tags = item.tags
|
|
|
|
if tags.name == name then
|
2013-11-18 13:54:28 +01:00
|
|
|
tags.export = true
|
2011-12-06 18:19:09 +01:00
|
|
|
if tags['local'] then
|
2012-12-21 17:25:06 +01:00
|
|
|
tags['local'] = nil
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
2012-12-22 15:29:42 +01:00
|
|
|
return
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
|
|
|
end
|
2012-12-22 15:29:42 +01:00
|
|
|
-- warn if any of these guys are not found, indicating no
|
|
|
|
-- documentation was given.
|
|
|
|
self:warning('no docs '..tools.quote(name))
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
|
|
|
|
2012-08-22 12:50:57 +02:00
|
|
|
|
|
|
|
local function has_prefix (name,prefix)
|
|
|
|
local i1,i2 = name:find(prefix)
|
|
|
|
return i1 == 1 and i2 == #prefix
|
|
|
|
end
|
|
|
|
|
|
|
|
local function mod_section_type (this_mod)
|
|
|
|
return this_mod and this_mod.section and this_mod.section.type
|
|
|
|
end
|
|
|
|
|
2013-08-01 12:14:57 +02:00
|
|
|
function File:find_module_in_files (name)
|
2012-12-10 13:45:54 +01:00
|
|
|
for f in File.list:iter() do
|
|
|
|
for m in f.modules:iter() do
|
|
|
|
if m.name == name then
|
|
|
|
return m,f.filename
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-27 08:46:37 +01:00
|
|
|
local function init_within_section (mod,name)
|
|
|
|
mod.kinds:add_kind(name, name)
|
|
|
|
mod.enclosing_section = mod.section
|
|
|
|
mod.section = nil
|
|
|
|
return name
|
|
|
|
end
|
|
|
|
|
2011-04-13 13:02:40 +02:00
|
|
|
function File:finish()
|
2011-06-06 18:38:02 +02:00
|
|
|
local this_mod
|
|
|
|
local items = self.items
|
2012-12-10 13:45:54 +01:00
|
|
|
local tagged_inside
|
2014-01-05 13:55:20 +01:00
|
|
|
self.args = self.args or {}
|
2011-06-06 18:38:02 +02:00
|
|
|
for item in items:iter() do
|
2012-08-22 12:50:57 +02:00
|
|
|
if mod_section_type(this_mod) == 'factory' and item.tags then
|
|
|
|
local klass = '@{'..this_mod.section.name..'}'
|
|
|
|
-- Factory constructors return the object type, and methods all have implicit self argument
|
|
|
|
if item.tags.constructor and not item.tags['return'] then
|
|
|
|
item.tags['return'] = List{klass}
|
|
|
|
elseif item.tags.param then
|
|
|
|
item.tags.param:put('self '..klass)
|
|
|
|
end
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
item:finish()
|
2014-01-02 17:45:04 +01:00
|
|
|
-- the default is not to show local functions in the documentation.
|
|
|
|
if not self.args.all and (item.type=='lfunction' or (item.tags and item.tags['local'])) then
|
|
|
|
-- don't add to the module --
|
|
|
|
elseif doc.project_level(item.type) then
|
2011-06-06 18:38:02 +02:00
|
|
|
this_mod = item
|
2012-12-10 13:45:54 +01:00
|
|
|
local package,mname,submodule
|
2014-09-28 18:54:17 +02:00
|
|
|
if item.type == 'module' or item.type == 'classmod' then
|
2011-07-08 15:59:56 +02:00
|
|
|
-- if name is 'package.mod', then mod_name is 'mod'
|
|
|
|
package,mname = split_dotted_name(this_mod.name)
|
2013-01-28 10:23:31 +01:00
|
|
|
if self.args.merge then
|
2013-08-01 12:14:57 +02:00
|
|
|
local mod,mf = self:find_module_in_files(item.name)
|
2013-01-28 10:23:31 +01:00
|
|
|
if mod then
|
|
|
|
print('found master module',mf)
|
|
|
|
this_mod = mod
|
2013-05-06 11:52:36 +02:00
|
|
|
if this_mod.section then
|
|
|
|
print '***closing section from master module***'
|
|
|
|
this_mod.section = nil
|
|
|
|
end
|
2013-01-28 10:23:31 +01:00
|
|
|
submodule = true
|
|
|
|
end
|
|
|
|
end
|
2012-12-10 13:45:54 +01:00
|
|
|
elseif item.type == 'submodule' then
|
|
|
|
local mf
|
|
|
|
submodule = true
|
2013-08-01 12:14:57 +02:00
|
|
|
this_mod,mf = self:find_module_in_files(item.name)
|
2012-12-10 13:45:54 +01:00
|
|
|
if this_mod == nil then
|
|
|
|
self:error("'"..item.name.."' not found for submodule")
|
|
|
|
end
|
|
|
|
tagged_inside = tools.this_module_name(self.base,self.filename)..' Functions'
|
|
|
|
this_mod.kinds:add_kind(tagged_inside, tagged_inside)
|
2011-07-11 15:40:44 +02:00
|
|
|
end
|
|
|
|
if not package then
|
|
|
|
mname = this_mod.name
|
|
|
|
package = ''
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2012-12-10 13:45:54 +01:00
|
|
|
if not submodule then
|
|
|
|
this_mod.package = package
|
|
|
|
this_mod.mod_name = mname
|
2013-11-16 20:03:43 +01:00
|
|
|
this_mod.kinds = doc.ModuleMap() -- the iterator over the module contents
|
2012-12-10 13:45:54 +01:00
|
|
|
self.modules:append(this_mod)
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
elseif doc.section_tag(item.type) then
|
|
|
|
local display_name = item.name
|
|
|
|
if display_name == 'end' then
|
|
|
|
this_mod.section = nil
|
|
|
|
else
|
|
|
|
local summary = item.summary:gsub('%.$','')
|
2014-01-05 13:55:20 +01:00
|
|
|
local lookup_name
|
2012-08-22 12:50:57 +02:00
|
|
|
if doc.class_tag(item.type) then
|
2011-06-06 18:38:02 +02:00
|
|
|
display_name = 'Class '..item.name
|
2014-01-05 13:55:20 +01:00
|
|
|
lookup_name = item.name
|
2011-06-06 18:38:02 +02:00
|
|
|
item.module = this_mod
|
|
|
|
this_mod.items.by_name[item.name] = item
|
2011-04-13 13:02:40 +02:00
|
|
|
else
|
2011-06-06 18:38:02 +02:00
|
|
|
display_name = summary
|
2014-01-05 13:55:20 +01:00
|
|
|
lookup_name = summary
|
2014-06-27 15:50:21 +02:00
|
|
|
item.summary = ''
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
|
|
|
item.display_name = display_name
|
2013-11-27 08:46:37 +01:00
|
|
|
this_mod.section = item
|
2016-10-13 11:00:05 +02:00
|
|
|
-- the purpose of this little hack is to properly distinguish
|
2016-10-13 14:53:00 +02:00
|
|
|
-- between built-in kinds and any user-defined kinds.
|
2016-10-13 11:00:05 +02:00
|
|
|
this_mod.kinds:add_kind(display_name,display_name..' ',nil,item)
|
2013-11-27 08:46:37 +01:00
|
|
|
this_mod.sections:append(item)
|
2014-01-05 13:55:20 +01:00
|
|
|
this_mod.sections.by_name[lookup_name:gsub('%A','_')] = item
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
|
|
|
else
|
2012-08-22 12:50:57 +02:00
|
|
|
local to_be_removed
|
2011-06-06 18:38:02 +02:00
|
|
|
-- add the item to the module's item list
|
|
|
|
if this_mod then
|
|
|
|
-- new-style modules will have qualified names like 'mod.foo'
|
2013-11-16 18:21:50 +01:00
|
|
|
if item.name == nil then
|
|
|
|
self:error("item's name is nil")
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
local mod,fname = split_dotted_name(item.name)
|
|
|
|
-- warning for inferred unqualified names in new style modules
|
|
|
|
-- (retired until we handle methods like Set:unset() properly)
|
|
|
|
if not mod and not this_mod.old_style and item.inferred then
|
|
|
|
--item:warning(item.name .. ' is declared in global scope')
|
|
|
|
end
|
|
|
|
-- the function may be qualified with a module alias...
|
2011-06-16 16:44:46 +02:00
|
|
|
local alias = this_mod.tags.alias
|
|
|
|
if (alias and mod == alias) or mod == 'M' or mod == '_M' then
|
2011-06-06 18:38:02 +02:00
|
|
|
mod = this_mod.mod_name
|
|
|
|
end
|
|
|
|
-- if that's the mod_name, then we want to only use 'foo'
|
|
|
|
if mod == this_mod.mod_name and this_mod.tags.pragma ~= 'nostrip' then
|
|
|
|
item.name = fname
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2012-12-10 13:45:54 +01:00
|
|
|
if tagged_inside then
|
2012-12-29 11:04:39 +01:00
|
|
|
item.tags.within = tagged_inside
|
2012-12-10 13:45:54 +01:00
|
|
|
end
|
2012-12-29 11:04:39 +01:00
|
|
|
if item.tags.within then
|
2013-11-27 08:46:37 +01:00
|
|
|
init_within_section(this_mod,item.tags.within)
|
2012-12-10 13:45:54 +01:00
|
|
|
end
|
|
|
|
|
2011-06-06 18:38:02 +02:00
|
|
|
-- right, this item was within a section or a 'class'
|
2011-06-08 19:12:04 +02:00
|
|
|
local section_description
|
2013-08-07 15:19:46 +02:00
|
|
|
local classmod = this_mod.type == 'classmod'
|
|
|
|
if this_mod.section or classmod then
|
|
|
|
local stype
|
2012-12-10 13:45:54 +01:00
|
|
|
local this_section = this_mod.section
|
2013-08-07 15:19:46 +02:00
|
|
|
if this_section then
|
|
|
|
item.section = this_section.display_name
|
|
|
|
stype = this_section.type
|
|
|
|
end
|
2013-03-05 16:56:30 +01:00
|
|
|
-- if it was a class, then if the name is unqualified then it becomes
|
2013-03-08 12:40:59 +01:00
|
|
|
-- 'Class:foo' (unless flagged as being a constructor, static or not a function)
|
2013-08-07 15:19:46 +02:00
|
|
|
if doc.class_tag(stype) or classmod then
|
2013-11-27 08:46:37 +01:00
|
|
|
if not item.name:match '[:%.]' then -- not qualified name!
|
|
|
|
-- a class is either a @type section or a @classmod module. Is this a _method_?
|
2013-08-07 15:19:46 +02:00
|
|
|
local class = classmod and this_mod.name or this_section.name
|
2013-03-08 12:40:59 +01:00
|
|
|
local static = item.tags.constructor or item.tags.static or item.type ~= 'function'
|
2013-11-28 10:57:13 +01:00
|
|
|
-- methods and metamethods go into their own special sections...
|
|
|
|
if classmod and item.type == 'function' then
|
2013-11-27 08:46:37 +01:00
|
|
|
local inferred_section
|
|
|
|
if item.name:match '^__' then
|
|
|
|
inferred_section = 'Metamethods'
|
|
|
|
elseif not static then
|
|
|
|
inferred_section = 'Methods'
|
|
|
|
end
|
2013-11-28 10:57:13 +01:00
|
|
|
if inferred_section then
|
2013-11-27 08:46:37 +01:00
|
|
|
item.tags.within = init_within_section(this_mod,inferred_section)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- Whether to use '.' or the language's version of ':' (e.g. \ for Moonscript)
|
2016-10-26 09:47:26 +02:00
|
|
|
item.name = class..(not static and this_mod.file.lang.method_call or '.')..item.name
|
2016-10-25 09:06:01 +02:00
|
|
|
end
|
2012-08-22 12:50:57 +02:00
|
|
|
if stype == 'factory' then
|
|
|
|
if item.tags.private then to_be_removed = true
|
|
|
|
elseif item.type == 'lfunction' then
|
|
|
|
item.type = 'function'
|
|
|
|
end
|
|
|
|
if item.tags.constructor then
|
|
|
|
item.section = item.type
|
|
|
|
end
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2013-08-07 15:19:46 +02:00
|
|
|
if this_section then
|
2014-06-27 15:50:21 +02:00
|
|
|
--section_description = this_section.summary..' '..(this_section.description or '')
|
|
|
|
--this_section.summary = ''
|
2013-08-07 15:19:46 +02:00
|
|
|
elseif item.tags.within then
|
2014-05-25 13:58:25 +02:00
|
|
|
item.section = item.tags.within
|
2013-08-07 15:19:46 +02:00
|
|
|
else
|
2013-11-27 08:46:37 +01:00
|
|
|
if item.type == 'function' or item.type == 'lfunction' then
|
|
|
|
section_description = "Methods"
|
|
|
|
end
|
2013-08-07 15:19:46 +02:00
|
|
|
item.section = item.type
|
|
|
|
end
|
2013-11-27 08:46:37 +01:00
|
|
|
elseif item.tags.within then -- ad-hoc section...
|
2014-10-12 16:45:09 +02:00
|
|
|
item.section = item.tags.within
|
2011-06-06 18:38:02 +02:00
|
|
|
else -- otherwise, just goes into the default sections (Functions,Tables,etc)
|
2013-11-27 08:46:37 +01:00
|
|
|
item.section = item.type;
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
|
|
|
|
item.module = this_mod
|
2012-08-22 12:50:57 +02:00
|
|
|
if not to_be_removed then
|
|
|
|
local these_items = this_mod.items
|
|
|
|
these_items.by_name[item.name] = item
|
|
|
|
these_items:append(item)
|
|
|
|
this_mod.kinds:add(item,these_items,section_description)
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
|
2012-12-29 11:04:39 +01:00
|
|
|
-- restore current section after a 'within'
|
2013-11-27 08:46:37 +01:00
|
|
|
if this_mod.enclosing_section then
|
|
|
|
this_mod.section = this_mod.enclosing_section
|
|
|
|
this_mod.enclosing_section = nil
|
|
|
|
end
|
2012-12-29 11:04:39 +01:00
|
|
|
|
2011-06-06 18:38:02 +02:00
|
|
|
else
|
|
|
|
-- must be a free-standing function (sometimes a problem...)
|
|
|
|
end
|
|
|
|
end
|
2016-10-26 09:47:26 +02:00
|
|
|
item.names_hierarchy = require('pl.utils').split(
|
|
|
|
item.name,
|
|
|
|
'[.:]'
|
|
|
|
)
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2011-07-12 14:14:55 +02:00
|
|
|
-- some serious hackery. We force sections into this 'module',
|
|
|
|
-- and ensure that there is a dummy item so that the section
|
|
|
|
-- is not empty.
|
|
|
|
|
|
|
|
function File:add_document_section(title)
|
2013-03-28 12:06:42 +01:00
|
|
|
local section = title:gsub('%W','_')
|
2011-07-12 14:14:55 +02:00
|
|
|
self:new_item {
|
|
|
|
name = section,
|
|
|
|
class = 'section',
|
|
|
|
summary = title
|
|
|
|
}
|
|
|
|
self:new_item {
|
|
|
|
name = 'dumbo',
|
|
|
|
class = 'function',
|
|
|
|
}
|
|
|
|
return section
|
|
|
|
end
|
|
|
|
|
2011-06-13 15:42:42 +02:00
|
|
|
function Item:_init(tags,file,line)
|
|
|
|
self.file = file
|
|
|
|
self.lineno = line
|
2011-06-06 18:38:02 +02:00
|
|
|
self.summary = tags.summary
|
|
|
|
self.description = tags.description
|
|
|
|
tags.summary = nil
|
|
|
|
tags.description = nil
|
|
|
|
self.tags = {}
|
|
|
|
self.formal_args = tags.formal_args
|
|
|
|
tags.formal_args = nil
|
2013-08-24 15:19:45 +02:00
|
|
|
local iter = tags.iter or Map.iter
|
2012-12-29 11:04:39 +01:00
|
|
|
for tag in iter(tags) do
|
|
|
|
self:set_tag(tag,tags[tag])
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
2012-12-29 11:04:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Item:add_to_description (rest)
|
2013-03-07 12:49:39 +01:00
|
|
|
if type(rest) == 'string' then
|
|
|
|
self.description = (self.description or '') .. rest
|
|
|
|
end
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
|
|
|
|
2013-05-09 13:28:39 +02:00
|
|
|
function Item:trailing_warning (kind,tag,rest)
|
|
|
|
if type(rest)=='string' and #rest > 0 then
|
2013-11-16 18:21:50 +01:00
|
|
|
Item.warning(self,kind.." tag: '"..tag..'" has trailing text ; use not_luadoc=true if you want description to continue between tags\n"'..rest..'"')
|
2013-05-09 13:28:39 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-26 14:22:52 +02:00
|
|
|
local function is_list (l)
|
|
|
|
return getmetatable(l) == List
|
|
|
|
end
|
|
|
|
|
2011-12-06 18:19:09 +01:00
|
|
|
function Item:set_tag (tag,value)
|
|
|
|
local ttype = known_tags[tag]
|
2013-05-09 13:28:39 +02:00
|
|
|
local args = self.file.args
|
2012-12-29 11:04:39 +01:00
|
|
|
|
2012-12-31 16:02:40 +01:00
|
|
|
if ttype == TAG_MULTI or ttype == TAG_MULTI_LINE then -- value is always a List!
|
2013-08-26 14:22:52 +02:00
|
|
|
local ovalue = self.tags[tag]
|
2013-08-27 12:47:47 +02:00
|
|
|
if ovalue then -- already defined, must be a list
|
|
|
|
--print(tag,ovalue,value)
|
|
|
|
if is_list(value) then
|
|
|
|
ovalue:extend(value)
|
|
|
|
else
|
|
|
|
ovalue:append(value)
|
|
|
|
end
|
2013-08-26 14:22:52 +02:00
|
|
|
value = ovalue
|
|
|
|
end
|
2013-08-27 12:47:47 +02:00
|
|
|
-- these multiple values are always represented as lists
|
2013-08-26 14:22:52 +02:00
|
|
|
if not is_list(value) then
|
2011-12-06 18:19:09 +01:00
|
|
|
value = List{value}
|
|
|
|
end
|
2013-05-15 15:30:47 +02:00
|
|
|
if ttype ~= TAG_MULTI_LINE and args and args.not_luadoc then
|
2012-12-31 16:02:40 +01:00
|
|
|
local last = value[#value]
|
|
|
|
if type(last) == 'string' and last:match '\n' then
|
|
|
|
local line,rest = last:match('([^\n]+)(.*)')
|
|
|
|
value[#value] = line
|
|
|
|
self:add_to_description(rest)
|
|
|
|
end
|
2012-12-29 11:04:39 +01:00
|
|
|
end
|
2011-12-06 18:19:09 +01:00
|
|
|
self.tags[tag] = value
|
|
|
|
elseif ttype == TAG_ID then
|
2013-03-08 12:40:59 +01:00
|
|
|
local modifiers
|
2013-03-07 12:39:41 +01:00
|
|
|
if type(value) == 'table' then
|
|
|
|
if value.append then -- it was a List!
|
|
|
|
-- such tags are _not_ multiple, e.g. name
|
2013-09-26 15:34:53 +02:00
|
|
|
if tag == 'class' and value:contains 'example' then
|
|
|
|
self:error("cannot use 'example' tag for functions or tables. Use 'usage'")
|
|
|
|
else
|
|
|
|
self:error("'"..tag.."' cannot have multiple values; "..tostring(value))
|
|
|
|
end
|
2013-03-07 12:39:41 +01:00
|
|
|
end
|
|
|
|
value = value[1]
|
2013-03-08 12:40:59 +01:00
|
|
|
modifiers = value.modifiers
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2013-04-16 10:11:05 +02:00
|
|
|
if value == nil then self:error("Tag without value: "..tag) end
|
2013-03-07 12:39:41 +01:00
|
|
|
local id, rest = tools.extract_identifier(value)
|
|
|
|
self.tags[tag] = id
|
2013-05-15 15:30:47 +02:00
|
|
|
if args and args.not_luadoc then
|
2013-05-09 13:28:39 +02:00
|
|
|
self:add_to_description(rest)
|
|
|
|
else
|
|
|
|
self:trailing_warning('id',tag,rest)
|
|
|
|
end
|
2011-12-06 18:19:09 +01:00
|
|
|
elseif ttype == TAG_SINGLE then
|
|
|
|
self.tags[tag] = value
|
|
|
|
elseif ttype == TAG_FLAG then
|
|
|
|
self.tags[tag] = true
|
2013-05-09 13:28:39 +02:00
|
|
|
if args.not_luadoc then
|
|
|
|
self:add_to_description(value)
|
|
|
|
else
|
|
|
|
self:trailing_warning('flag',tag,value)
|
|
|
|
end
|
2011-12-06 18:19:09 +01:00
|
|
|
else
|
2011-12-09 14:43:37 +01:00
|
|
|
Item.warning(self,"unknown tag: '"..tag.."' "..tostring(ttype))
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- preliminary processing of tags. We check for any aliases, and for tags
|
|
|
|
-- which represent types. This implements the shortcut notation.
|
2011-12-06 18:19:09 +01:00
|
|
|
function Item.check_tag(tags,tag, value, modifiers)
|
|
|
|
local alias = doc.get_alias(tag)
|
|
|
|
if alias then
|
|
|
|
if type(alias) == 'string' then
|
|
|
|
tag = alias
|
2013-08-24 13:21:41 +02:00
|
|
|
elseif type(alias) == 'table' then --{ tag, value=, modifiers = }
|
2011-12-06 18:19:09 +01:00
|
|
|
local avalue,amod
|
|
|
|
tag, avalue, amod = alias[1],alias.value,alias.modifiers
|
|
|
|
if avalue then value = avalue..' '..value end
|
|
|
|
if amod then
|
|
|
|
modifiers = modifiers or {}
|
2016-06-27 19:45:26 +02:00
|
|
|
local value_tokens = utils.split(value)
|
2011-12-06 18:19:09 +01:00
|
|
|
for m,v in pairs(amod) do
|
2016-06-27 19:45:26 +02:00
|
|
|
local idx = tonumber(v:match('^%$(%d+)'))
|
2011-12-06 18:19:09 +01:00
|
|
|
if idx then
|
2012-03-17 11:17:22 +01:00
|
|
|
v, value = value:match('(%S+)(.*)')
|
2016-06-27 19:45:26 +02:00
|
|
|
-- v = value_tokens[idx]
|
|
|
|
-- value_tokens[idx] = ''
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
|
|
|
modifiers[m] = v
|
|
|
|
end
|
2016-06-27 19:45:26 +02:00
|
|
|
-- value = table.concat(value_tokens, ' ')
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
2013-08-26 13:37:41 +02:00
|
|
|
else -- has to be a function that at least returns tag, value
|
2013-08-24 15:19:45 +02:00
|
|
|
return alias(tags,value,modifiers)
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
local ttype = known_tags[tag]
|
|
|
|
if ttype == TAG_TYPE then
|
2012-12-29 11:04:39 +01:00
|
|
|
tags:add('class',tag)
|
2011-06-06 18:38:02 +02:00
|
|
|
tag = 'name'
|
|
|
|
end
|
2011-12-06 18:19:09 +01:00
|
|
|
return tag, value, modifiers
|
|
|
|
end
|
|
|
|
|
|
|
|
-- any tag (except name and classs) may have associated modifiers,
|
|
|
|
-- in the form @tag[m1,...] where m1 is either name1=value1 or name1.
|
|
|
|
-- At this stage, these are encoded
|
|
|
|
-- in the tag value table and need to be extracted.
|
|
|
|
|
|
|
|
local function extract_value_modifier (p)
|
2012-12-21 17:25:06 +01:00
|
|
|
if type(p)~='table' then
|
2011-12-06 18:19:09 +01:00
|
|
|
return p, { }
|
|
|
|
else
|
2012-12-21 17:25:06 +01:00
|
|
|
return p[1], p.modifiers or { }
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function extract_tag_modifiers (tags)
|
2012-03-23 13:21:43 +01:00
|
|
|
local modifiers, mods = {}
|
2011-12-06 18:19:09 +01:00
|
|
|
for tag, value in pairs(tags) do
|
2012-12-21 17:25:06 +01:00
|
|
|
if type(value)=='table' and value.append then -- i.e. it is a List!
|
2011-12-06 18:19:09 +01:00
|
|
|
local tmods = {}
|
|
|
|
for i, v in ipairs(value) do
|
|
|
|
v, mods = extract_value_modifier(v)
|
|
|
|
tmods[i] = mods
|
|
|
|
value[i] = v
|
|
|
|
end
|
|
|
|
modifiers[tag] = tmods
|
|
|
|
else
|
|
|
|
value, mods = extract_value_modifier(value)
|
|
|
|
modifiers[tag] = mods
|
|
|
|
tags[tag] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return modifiers
|
|
|
|
end
|
|
|
|
|
|
|
|
local function read_del (tags,name)
|
|
|
|
local ret = tags[name]
|
|
|
|
tags[name] = nil
|
|
|
|
return ret
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2013-03-18 14:51:28 +01:00
|
|
|
local build_arg_list, split_iden -- forward declaration
|
|
|
|
|
2013-08-26 13:37:41 +02:00
|
|
|
function Item:split_param (line)
|
|
|
|
local name, comment = line:match('%s*([%w_%.:]+)(.*)')
|
|
|
|
if not name then
|
|
|
|
self:error("bad param name format '"..line.."'. Are you missing a parameter name?")
|
|
|
|
end
|
|
|
|
return name, comment
|
|
|
|
end
|
2011-04-13 13:02:40 +02:00
|
|
|
|
|
|
|
function Item:finish()
|
2011-06-06 18:38:02 +02:00
|
|
|
local tags = self.tags
|
2012-03-02 12:19:34 +01:00
|
|
|
local quote = tools.quote
|
2011-12-06 18:19:09 +01:00
|
|
|
self.name = read_del(tags,'name')
|
|
|
|
self.type = read_del(tags,'class')
|
|
|
|
self.modifiers = extract_tag_modifiers(tags)
|
|
|
|
self.usage = read_del(tags,'usage')
|
2013-05-27 14:47:26 +02:00
|
|
|
tags.see = read_del(tags,'see')
|
2013-08-21 15:52:53 +02:00
|
|
|
if tags.see then
|
|
|
|
tags.see = tools.identifier_list(tags.see)
|
|
|
|
end
|
2016-06-27 16:25:56 +02:00
|
|
|
if self.usage then
|
|
|
|
for i = 1,#self.usage do
|
|
|
|
local usage = self.usage[i]:gsub('^%s*\n','')
|
|
|
|
self.usage[i] = text.dedent(usage)
|
|
|
|
end
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
if doc.project_level(self.type) then
|
|
|
|
-- we are a module, so become one!
|
|
|
|
self.items = List()
|
2012-03-13 11:23:55 +01:00
|
|
|
self.sections = List()
|
2011-06-06 18:38:02 +02:00
|
|
|
self.items.by_name = {}
|
2012-03-13 11:23:55 +01:00
|
|
|
self.sections.by_name = {}
|
2011-06-06 18:38:02 +02:00
|
|
|
setmetatable(self,Module)
|
|
|
|
elseif not doc.section_tag(self.type) then
|
|
|
|
-- params are either a function's arguments, or a table's fields, etc.
|
|
|
|
if self.type == 'function' then
|
2011-12-06 18:19:09 +01:00
|
|
|
self.parameter = 'param'
|
|
|
|
self.ret = read_del(tags,'return')
|
|
|
|
self.raise = read_del(tags,'raise')
|
|
|
|
if tags['local'] then
|
|
|
|
self.type = 'lfunction'
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
|
|
|
else
|
2011-12-06 18:19:09 +01:00
|
|
|
self.parameter = 'field'
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2012-10-28 18:51:00 +01:00
|
|
|
local field = self.parameter
|
|
|
|
local params = read_del(tags,field)
|
2012-12-13 18:17:32 +01:00
|
|
|
-- use of macros like @string (which is short for '@tparam string')
|
|
|
|
-- can lead to param tags associated with a table.
|
2012-12-21 18:13:40 +01:00
|
|
|
if self.parameter == 'field' and tags.param then
|
|
|
|
local tparams = read_del(tags,'param')
|
|
|
|
if params then
|
|
|
|
params:extend(tparams)
|
|
|
|
List(self.modifiers.field):extend(self.modifiers.param)
|
|
|
|
else
|
|
|
|
params = tparams
|
|
|
|
self.modifiers.field = self.modifiers.param
|
|
|
|
end
|
2012-12-13 14:01:33 +01:00
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
local param_names, comments = List(), List()
|
2011-12-06 18:19:09 +01:00
|
|
|
if params then
|
|
|
|
for line in params:iter() do
|
2013-08-26 13:37:41 +02:00
|
|
|
local name, comment = self:split_param(line)
|
2013-03-18 14:51:28 +01:00
|
|
|
param_names:append(name)
|
2011-12-06 18:19:09 +01:00
|
|
|
comments:append(comment)
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2012-12-31 13:52:00 +01:00
|
|
|
self.modifiers['return'] = self.modifiers['return'] or List()
|
|
|
|
self.modifiers[field] = self.modifiers[field] or List()
|
2013-03-18 14:51:28 +01:00
|
|
|
-- we use the formal arguments (if available) as the authoritative list.
|
|
|
|
-- If there are both params and formal args, then they must match;
|
|
|
|
-- (A formal argument of ... may match any number of params at the end, however.)
|
|
|
|
-- If there are formal args and no params, we see if the args have any suitable comments.
|
|
|
|
-- Params may have subfields.
|
|
|
|
local fargs, formal = self.formal_args
|
|
|
|
if fargs then
|
|
|
|
if #param_names == 0 then
|
|
|
|
--docs may be embedded in argument comments; in either case, use formal arg names
|
2013-08-26 13:37:41 +02:00
|
|
|
local ret
|
|
|
|
formal,comments,ret = self:parse_formal_arguments(fargs)
|
|
|
|
if ret and not self.ret then self.ret = ret end
|
|
|
|
elseif #fargs > 0 then -- consistency check!
|
2012-03-02 12:19:34 +01:00
|
|
|
local varargs = fargs[#fargs] == '...'
|
2013-03-18 14:51:28 +01:00
|
|
|
if varargs then table.remove(fargs) end
|
2013-11-18 13:54:28 +01:00
|
|
|
if tags.export then
|
|
|
|
if fargs[1] == 'self' then
|
|
|
|
table.remove(fargs,1)
|
|
|
|
else
|
|
|
|
tags.static = true
|
|
|
|
end
|
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
local k = 0
|
|
|
|
for _,pname in ipairs(param_names) do
|
|
|
|
local _,field = split_iden(pname)
|
|
|
|
if not field then
|
|
|
|
k = k + 1
|
|
|
|
if k > #fargs then
|
|
|
|
if not varargs then
|
|
|
|
self:warning("extra param with no formal argument: "..quote(pname))
|
2011-12-09 14:43:37 +01:00
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
elseif pname ~= fargs[k] then
|
|
|
|
self:warning("param and formal argument name mismatch: "..quote(pname).." "..quote(fargs[k]))
|
2011-12-09 14:43:37 +01:00
|
|
|
end
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
if k < #fargs then
|
2013-08-26 13:37:41 +02:00
|
|
|
for i = k+1,#fargs do if fargs[i] ~= '...' then
|
|
|
|
self:warning("undocumented formal argument: "..quote(fargs[i]))
|
|
|
|
end end
|
2012-03-01 19:08:55 +01:00
|
|
|
end
|
2013-09-26 16:05:45 +02:00
|
|
|
end -- #fargs > 0
|
|
|
|
-- formal arguments may come with types, inferred by the
|
|
|
|
-- appropriate code in ldoc.lang
|
|
|
|
if fargs.types then
|
|
|
|
self.modifiers[field] = List()
|
|
|
|
for t in fargs.types:iter() do
|
|
|
|
self:add_type(field,t)
|
|
|
|
end
|
|
|
|
if fargs.return_type then
|
|
|
|
if not self.ret then -- type, but no comment; no worries
|
|
|
|
self.ret = List{''}
|
2013-09-20 13:33:06 +02:00
|
|
|
end
|
2013-09-26 16:05:45 +02:00
|
|
|
self.modifiers['return'] = List()
|
|
|
|
self:add_type('return',fargs.return_type)
|
2013-09-20 13:33:06 +02:00
|
|
|
end
|
2013-09-26 16:05:45 +02:00
|
|
|
end
|
2013-08-26 13:37:41 +02:00
|
|
|
end -- fargs
|
2011-12-06 18:19:09 +01:00
|
|
|
|
|
|
|
-- the comments are associated with each parameter by
|
|
|
|
-- adding name-value pairs to the params list (this is
|
|
|
|
-- also done for any associated modifiers)
|
2013-03-18 14:51:28 +01:00
|
|
|
-- (At this point we patch up any subparameter references)
|
2012-10-28 18:51:00 +01:00
|
|
|
local pmods = self.modifiers[field]
|
2013-03-18 14:51:28 +01:00
|
|
|
local params, fields = List()
|
|
|
|
local original_names = formal and formal or param_names
|
|
|
|
local names = List()
|
|
|
|
self.subparams = {}
|
2014-04-23 13:19:16 +02:00
|
|
|
params.map = {}
|
|
|
|
|
2013-03-18 14:51:28 +01:00
|
|
|
for i,name in ipairs(original_names) do
|
2013-06-06 18:59:11 +02:00
|
|
|
if type(name) ~= 'string' then
|
|
|
|
self:error("declared table cannot have array entries")
|
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
local pname,field = split_iden(name)
|
|
|
|
if field then
|
|
|
|
if not fields then
|
|
|
|
fields = List()
|
|
|
|
self.subparams[pname] = fields
|
|
|
|
end
|
|
|
|
fields:append(name)
|
|
|
|
else
|
|
|
|
names:append(name)
|
|
|
|
params:append(name)
|
|
|
|
fields = nil
|
|
|
|
end
|
|
|
|
|
2014-04-23 13:19:16 +02:00
|
|
|
params.map[name] = comments[i]
|
2011-12-06 18:19:09 +01:00
|
|
|
if pmods then
|
|
|
|
pmods[name] = pmods[i]
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
self.params = params
|
|
|
|
self.args = build_arg_list (names,pmods)
|
|
|
|
end
|
2013-08-24 13:21:41 +02:00
|
|
|
if self.ret then
|
|
|
|
self:build_return_groups()
|
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
end
|
2011-12-06 18:19:09 +01:00
|
|
|
|
2013-09-20 13:33:06 +02:00
|
|
|
function Item:add_type(field,type)
|
|
|
|
self.modifiers[field]:append {type = type}
|
|
|
|
end
|
|
|
|
|
2013-03-18 14:51:28 +01:00
|
|
|
-- ldoc allows comments in the formal arg list to be used, if they aren't specified with @param
|
|
|
|
-- Further, these comments may start with a type followed by a colon, and are then equivalent
|
|
|
|
-- to a @tparam
|
|
|
|
function Item:parse_argument_comment (comment,field)
|
|
|
|
if comment then
|
|
|
|
comment = comment:gsub('^%-+%s*','')
|
|
|
|
local type,rest = comment:match '([^:]+):(.*)'
|
|
|
|
if type then
|
2013-09-20 13:33:06 +02:00
|
|
|
self:add_type(field,type)
|
2013-03-18 14:51:28 +01:00
|
|
|
comment = rest
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return comment or ''
|
|
|
|
end
|
|
|
|
|
2013-08-26 13:37:41 +02:00
|
|
|
function Item:parse_formal_arguments (fargs)
|
|
|
|
local formal, comments, ret = List(), List()
|
|
|
|
if fargs.return_comment then
|
|
|
|
local retc = self:parse_argument_comment(fargs.return_comment,'return')
|
|
|
|
ret = List{retc}
|
|
|
|
end
|
|
|
|
for i, name in ipairs(fargs) do
|
|
|
|
formal:append(name)
|
|
|
|
comments:append(self:parse_argument_comment(fargs.comments[name],self.parameter))
|
|
|
|
end
|
|
|
|
return formal, comments, ret
|
|
|
|
end
|
|
|
|
|
2013-03-18 14:51:28 +01:00
|
|
|
function split_iden (name)
|
|
|
|
if name == '...' then return name end
|
|
|
|
local pname,field = name:match('(.-)%.(.+)')
|
|
|
|
if not pname then
|
|
|
|
return name
|
|
|
|
else
|
|
|
|
return pname,field
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function build_arg_list (names,pmods)
|
|
|
|
-- build up the string representation of the argument list,
|
|
|
|
-- using any opt and optchain modifiers if present.
|
|
|
|
-- For instance, '(a [, b])' if b is marked as optional
|
|
|
|
-- with @param[opt] b
|
|
|
|
local buffer, npending = { }, 0
|
|
|
|
local function acc(x) table.insert(buffer, x) end
|
2014-10-12 16:45:09 +02:00
|
|
|
-- a number of trailing [opt]s will be usually converted to [opt],[optchain],...
|
|
|
|
-- *unless* a person uses convert_opt.
|
|
|
|
if pmods and not doc.ldoc.convert_opt then
|
2013-03-20 13:41:54 +01:00
|
|
|
local m = pmods[#names]
|
2013-03-21 18:52:53 +01:00
|
|
|
if m and m.opt then
|
2013-03-20 13:41:54 +01:00
|
|
|
m.optchain = m.opt
|
|
|
|
for i = #names-1,1,-1 do
|
|
|
|
m = pmods[i]
|
2013-03-21 18:52:53 +01:00
|
|
|
if not m or not m.opt then break end
|
2013-03-20 13:41:54 +01:00
|
|
|
m.optchain = m.opt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
for i = 1, #names do
|
|
|
|
local m = pmods and pmods[i]
|
2013-03-19 14:00:57 +01:00
|
|
|
local opt
|
2013-03-18 14:51:28 +01:00
|
|
|
if m then
|
|
|
|
if not m.optchain then
|
|
|
|
acc ((']'):rep(npending))
|
|
|
|
npending=0
|
2011-12-06 18:19:09 +01:00
|
|
|
end
|
2013-03-20 13:41:54 +01:00
|
|
|
opt = m.optchain or m.opt
|
2013-03-19 14:00:57 +01:00
|
|
|
if opt then
|
2013-08-20 15:26:49 +02:00
|
|
|
acc('[')
|
2013-03-19 14:00:57 +01:00
|
|
|
npending=npending+1
|
|
|
|
end
|
2011-10-04 14:54:08 +02:00
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
if i>1 then acc (', ') end
|
|
|
|
acc(names[i])
|
2013-03-19 14:00:57 +01:00
|
|
|
if opt and opt ~= true then acc('='..opt) end
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2013-03-18 14:51:28 +01:00
|
|
|
acc ((']'):rep(npending))
|
|
|
|
return '('..table.concat(buffer)..')'
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2013-08-26 13:37:41 +02:00
|
|
|
------ retrieving information about parameters -----
|
|
|
|
-- The template leans on these guys heavily....
|
|
|
|
|
2013-08-22 10:12:04 +02:00
|
|
|
function Item:param_modifiers (p)
|
2011-12-06 18:19:09 +01:00
|
|
|
local mods = self.modifiers[self.parameter]
|
|
|
|
if not mods then return '' end
|
2013-08-22 10:12:04 +02:00
|
|
|
return rawget(mods,p)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Item:type_of_param(p)
|
|
|
|
local mparam = self:param_modifiers(p)
|
2011-12-06 18:19:09 +01:00
|
|
|
return mparam and mparam.type or ''
|
|
|
|
end
|
|
|
|
|
2014-10-12 16:45:09 +02:00
|
|
|
-- default value for param; if optional but no default, it's just `true`.
|
2013-08-22 10:12:04 +02:00
|
|
|
function Item:default_of_param(p)
|
|
|
|
local m = self:param_modifiers(p)
|
|
|
|
if not m then return nil end
|
|
|
|
local opt = m.optchain or m.opt
|
|
|
|
return opt
|
|
|
|
end
|
|
|
|
|
2013-11-16 18:21:50 +01:00
|
|
|
function Item:readonly(p)
|
|
|
|
local m = self:param_modifiers(p)
|
|
|
|
if not m then return nil end
|
|
|
|
return m.readonly
|
|
|
|
end
|
|
|
|
|
2013-08-26 09:59:10 +02:00
|
|
|
function Item:subparam(p)
|
|
|
|
local subp = rawget(self.subparams,p)
|
|
|
|
if subp then
|
|
|
|
return subp,p
|
|
|
|
else
|
|
|
|
return {p},nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Item:display_name_of(p)
|
|
|
|
local pname,field = split_iden(p)
|
|
|
|
if field then
|
|
|
|
return field
|
|
|
|
else
|
|
|
|
return pname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-------- return values and types -------
|
|
|
|
|
2011-12-06 18:19:09 +01:00
|
|
|
function Item:type_of_ret(idx)
|
|
|
|
local rparam = self.modifiers['return'][idx]
|
|
|
|
return rparam and rparam.type or ''
|
|
|
|
end
|
|
|
|
|
2013-08-24 13:21:41 +02:00
|
|
|
local function integer_keys(t)
|
2013-08-26 13:37:41 +02:00
|
|
|
if type(t) ~= 'table' then return 0 end
|
2013-08-24 13:21:41 +02:00
|
|
|
for k in pairs(t) do
|
|
|
|
local num = tonumber(k)
|
|
|
|
if num then return num end
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2013-08-25 10:47:45 +02:00
|
|
|
function Item:return_type(r)
|
|
|
|
if not r.type then return '' end
|
|
|
|
return r.type, r.ctypes
|
|
|
|
end
|
|
|
|
|
2013-08-27 12:47:47 +02:00
|
|
|
local struct_return_type = '*'
|
|
|
|
|
2013-08-24 13:21:41 +02:00
|
|
|
function Item:build_return_groups()
|
2014-11-19 19:55:45 +01:00
|
|
|
local quote = tools.quote
|
2013-08-25 10:47:45 +02:00
|
|
|
local modifiers = self.modifiers
|
|
|
|
local retmod = modifiers['return']
|
2013-08-24 13:21:41 +02:00
|
|
|
local groups = List()
|
|
|
|
local lastg, group
|
|
|
|
for i,ret in ipairs(self.ret) do
|
|
|
|
local mods = retmod[i]
|
|
|
|
local g = integer_keys(mods)
|
|
|
|
if g ~= lastg then
|
|
|
|
group = List()
|
2013-08-26 14:22:52 +02:00
|
|
|
group.g = g
|
2013-08-24 13:21:41 +02:00
|
|
|
groups:append(group)
|
|
|
|
lastg = g
|
|
|
|
end
|
2013-08-27 12:47:47 +02:00
|
|
|
--require 'pl.pretty'.dump(ret)
|
2013-09-26 15:34:53 +02:00
|
|
|
if not mods then
|
|
|
|
self:error(quote(self.name)..' had no return?')
|
|
|
|
end
|
|
|
|
group:append({text=ret, type = mods and (mods.type or '') or '',mods = mods})
|
2013-08-24 13:21:41 +02:00
|
|
|
end
|
2013-08-26 14:22:52 +02:00
|
|
|
-- order by groups to force error groups to the end
|
|
|
|
table.sort(groups,function(g1,g2) return g1.g < g2.g end)
|
2013-08-24 13:21:41 +02:00
|
|
|
self.retgroups = groups
|
2013-08-27 12:47:47 +02:00
|
|
|
--require 'pl.pretty'.dump(groups)
|
2013-08-25 10:47:45 +02:00
|
|
|
-- cool, now see if there are any treturns that have tfields to associate with
|
|
|
|
local fields = self.tags.field
|
|
|
|
if fields then
|
|
|
|
local fcomments = List()
|
|
|
|
for i,f in ipairs(fields) do
|
2013-08-26 13:37:41 +02:00
|
|
|
local name, comment = self:split_param(f)
|
2013-08-25 10:47:45 +02:00
|
|
|
fields[i] = name
|
2013-08-27 12:47:47 +02:00
|
|
|
fcomments[i] = comment
|
2013-08-25 10:47:45 +02:00
|
|
|
end
|
|
|
|
local fmods = modifiers.field
|
|
|
|
for group in groups:iter() do for r in group:iter() do
|
2013-08-27 12:47:47 +02:00
|
|
|
if r.mods and r.mods.type then
|
|
|
|
local ctypes, T = List(), r.mods.type
|
|
|
|
for i,f in ipairs(fields) do if fmods[i][T] then
|
2013-08-25 10:47:45 +02:00
|
|
|
ctypes:append {name=f,type=fmods[i].type,comment=fcomments[i]}
|
2013-08-27 12:47:47 +02:00
|
|
|
end end
|
2013-08-25 10:47:45 +02:00
|
|
|
r.ctypes = ctypes
|
2013-08-27 12:47:47 +02:00
|
|
|
--require 'pl.pretty'.dump(ctypes)
|
2013-08-25 10:47:45 +02:00
|
|
|
end
|
|
|
|
end end
|
|
|
|
end
|
2013-08-24 13:21:41 +02:00
|
|
|
end
|
|
|
|
|
2013-08-27 12:47:47 +02:00
|
|
|
local ecount = 0
|
|
|
|
|
2013-08-26 09:59:10 +02:00
|
|
|
-- this alias macro implements @error.
|
|
|
|
-- Alias macros need to return the same results as Item:check_tags...
|
|
|
|
function doc.error_macro(tags,value,modifiers)
|
2013-08-27 12:47:47 +02:00
|
|
|
local merge_groups = doc.ldoc.merge_error_groups
|
2013-08-26 13:37:41 +02:00
|
|
|
local g = '2' -- our default group id
|
|
|
|
-- Were we given an explicit group modifier?
|
2013-08-26 09:59:10 +02:00
|
|
|
local key = integer_keys(modifiers)
|
2013-08-26 13:37:41 +02:00
|
|
|
if key > 0 then
|
|
|
|
g = tostring(key)
|
|
|
|
else
|
|
|
|
local l = tags:get 'return'
|
|
|
|
if l then -- there were returns already......
|
|
|
|
-- maximum group of _existing_ error return
|
2013-08-27 12:47:47 +02:00
|
|
|
local grp, lastr = 0
|
2013-08-26 13:37:41 +02:00
|
|
|
for r in l:iter() do if type(r) == 'table' then
|
2013-08-27 12:47:47 +02:00
|
|
|
local rg = r.modifiers._err
|
|
|
|
if rg then
|
|
|
|
lastr = r
|
|
|
|
grp = math.max(grp,rg)
|
|
|
|
end
|
2013-08-26 13:37:41 +02:00
|
|
|
end end
|
|
|
|
if grp > 0 then -- cool, create new group
|
2013-08-27 12:47:47 +02:00
|
|
|
if not merge_groups then
|
|
|
|
g = tostring(grp+1)
|
|
|
|
else
|
|
|
|
local mods, text, T = lastr.modifiers
|
|
|
|
local new = function(text)
|
|
|
|
return mods._collected..' '..text,{type='string',[T]=true}
|
|
|
|
end
|
|
|
|
if not mods._collected then
|
|
|
|
text = lastr[1]
|
|
|
|
lastr[1] = merge_groups
|
|
|
|
T = '@'..ecount
|
|
|
|
mods.type = T
|
|
|
|
mods._collected = 1
|
|
|
|
ecount = ecount + 1
|
|
|
|
tags:add('field',new(text))
|
|
|
|
else
|
|
|
|
T = mods.type
|
|
|
|
end
|
|
|
|
mods._collected = mods._collected + 1
|
|
|
|
return 'field',new(value)
|
|
|
|
end
|
2013-08-26 13:37:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-08-26 09:59:10 +02:00
|
|
|
tags:add('return','',{[g]=true,type='nil'})
|
2013-08-26 13:37:41 +02:00
|
|
|
-- note that this 'return' is tagged with _err!
|
|
|
|
return 'return', value, {[g]=true,_err=tonumber(g),type='string'}
|
2013-03-18 14:51:28 +01:00
|
|
|
end
|
|
|
|
|
2013-08-26 13:37:41 +02:00
|
|
|
---------- bothering the user --------------------
|
2013-03-18 14:51:28 +01:00
|
|
|
|
2011-04-13 13:02:40 +02:00
|
|
|
function Item:warning(msg)
|
2011-12-09 14:43:37 +01:00
|
|
|
local file = self.file and self.file.filename
|
2013-02-13 13:15:29 +01:00
|
|
|
if type(file) == 'table' then require 'pl.pretty'.dump(file); file = '?' end
|
2011-12-09 14:43:37 +01:00
|
|
|
file = file or '?'
|
|
|
|
io.stderr:write(file,':',self.lineno or '1',': ',self.name or '?',': ',msg,'\n')
|
2016-04-10 18:02:09 +02:00
|
|
|
Item.had_warning = true
|
2011-06-19 17:52:02 +02:00
|
|
|
return nil
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2011-06-13 15:42:42 +02:00
|
|
|
function Item:error(msg)
|
|
|
|
self:warning(msg)
|
|
|
|
os.exit(1)
|
|
|
|
end
|
|
|
|
|
2011-08-28 15:37:06 +02:00
|
|
|
Module.warning, Module.error = Item.warning, Item.error
|
|
|
|
|
2013-03-18 14:51:28 +01:00
|
|
|
-------- Resolving References -----------------
|
|
|
|
|
2011-07-05 18:19:49 +02:00
|
|
|
function Module:hunt_for_reference (packmod, modules)
|
|
|
|
local mod_ref
|
2011-07-11 15:40:44 +02:00
|
|
|
local package = self.package or ''
|
2011-07-05 18:19:49 +02:00
|
|
|
repeat -- same package?
|
|
|
|
local nmod = package..'.'..packmod
|
|
|
|
mod_ref = modules.by_name[nmod]
|
|
|
|
if mod_ref then break end -- cool
|
|
|
|
package = split_dotted_name(package)
|
|
|
|
until not package
|
|
|
|
return mod_ref
|
|
|
|
end
|
|
|
|
|
2012-07-30 18:36:28 +02:00
|
|
|
local err = io.stderr
|
|
|
|
|
|
|
|
local function custom_see_references (s)
|
2013-11-17 18:48:35 +01:00
|
|
|
for pat, action in pairs(see_reference_handlers) do
|
|
|
|
if s:match(pat) then
|
|
|
|
local label, href = action(s:match(pat))
|
|
|
|
if not label then print('custom rule failed',s,pat,href) end
|
|
|
|
return {href = href, label = label}
|
|
|
|
end
|
|
|
|
end
|
2012-07-30 18:36:28 +02:00
|
|
|
end
|
|
|
|
|
2011-07-05 18:19:49 +02:00
|
|
|
local function reference (s, mod_ref, item_ref)
|
|
|
|
local name = item_ref and item_ref.name or ''
|
|
|
|
-- this is deeply hacky; classes have 'Class ' prepended.
|
2014-01-05 13:55:20 +01:00
|
|
|
--~ if item_ref and doc.class_tag(item_ref.type) then
|
|
|
|
--~ name = 'Class_'..name
|
|
|
|
--~ end
|
2011-07-11 15:40:44 +02:00
|
|
|
return {mod = mod_ref, name = name, label=s}
|
2011-07-05 18:19:49 +02:00
|
|
|
end
|
|
|
|
|
2013-11-17 18:48:35 +01:00
|
|
|
function Module:lookup_class_item (packmod, s)
|
2014-01-05 13:55:20 +01:00
|
|
|
local klass = packmod --"Class_"..packmod
|
|
|
|
local qs = klass..':'..s
|
|
|
|
local klass_section = self.sections.by_name[klass]
|
|
|
|
if not klass_section then return nil end -- no such class
|
|
|
|
for item in self.items:iter() do
|
|
|
|
--print('item',qs,item.name)
|
|
|
|
if s == item.name or qs == item.name then
|
|
|
|
return reference(s,self,item)
|
2013-11-17 18:48:35 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2013-08-21 14:52:09 +02:00
|
|
|
function Module:process_see_reference (s,modules,istype)
|
2013-09-27 15:37:46 +02:00
|
|
|
if s == nil then return nil end
|
2011-07-05 18:19:49 +02:00
|
|
|
local mod_ref,fun_ref,name,packmod
|
2012-07-30 18:36:28 +02:00
|
|
|
local ref = custom_see_references(s)
|
|
|
|
if ref then return ref end
|
2012-01-09 13:07:24 +01:00
|
|
|
if not s:match '^[%w_%.%:%-]+$' or not s:match '[%w_]$' then
|
2011-12-06 18:19:09 +01:00
|
|
|
return nil, "malformed see reference: '"..s..'"'
|
|
|
|
end
|
2013-11-16 19:36:53 +01:00
|
|
|
|
|
|
|
-- `istype` means that we are looking up strictly in a _type_ context, so then only
|
|
|
|
-- allow `classmod` module references.
|
2013-08-21 14:52:09 +02:00
|
|
|
local function ismod(item)
|
|
|
|
if item == nil then return false end
|
|
|
|
if not istype then return true
|
|
|
|
else
|
|
|
|
return item.type == 'classmod'
|
|
|
|
end
|
|
|
|
end
|
2013-11-16 19:36:53 +01:00
|
|
|
|
|
|
|
-- it is _entirely_ possible that someone does not want auto references for standard Lua libraries!
|
|
|
|
local lua_manual_ref
|
|
|
|
local ldoc = tools.item_ldoc(self)
|
|
|
|
if ldoc and ldoc.no_lua_ref then
|
|
|
|
lua_manual_ref = function(s) return false end
|
|
|
|
else
|
|
|
|
lua_manual_ref = global.lua_manual_ref
|
|
|
|
end
|
2014-06-22 17:14:08 +02:00
|
|
|
-- pure C projects use global lookup (no namespaces)
|
2014-10-01 16:02:38 +02:00
|
|
|
if ldoc and ldoc.global_lookup == nil then
|
2014-06-22 17:14:08 +02:00
|
|
|
local using_c = ldoc.parse_extra and ldoc.parse_extra.C
|
|
|
|
ldoc.global_lookup = using_c or false
|
|
|
|
end
|
2013-11-16 19:36:53 +01:00
|
|
|
|
2011-07-05 18:19:49 +02:00
|
|
|
-- is this a fully qualified module name?
|
|
|
|
local mod_ref = modules.by_name[s]
|
2013-08-21 14:52:09 +02:00
|
|
|
if ismod(mod_ref) then return reference(s, mod_ref,nil) end
|
2011-07-05 18:19:49 +02:00
|
|
|
-- module reference?
|
|
|
|
mod_ref = self:hunt_for_reference(s, modules)
|
2013-08-21 14:52:09 +02:00
|
|
|
if ismod(mod_ref) then return mod_ref end
|
2011-07-08 15:59:56 +02:00
|
|
|
-- 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
|
|
|
|
-- otherwise, start splitting!
|
2011-07-05 18:19:49 +02:00
|
|
|
local packmod,name = split_dotted_name(s) -- e.g. 'pl.utils','split'
|
|
|
|
if packmod then -- qualified name
|
|
|
|
mod_ref = modules.by_name[packmod] -- fully qualified mod name?
|
|
|
|
if not mod_ref then
|
|
|
|
mod_ref = self:hunt_for_reference(packmod, modules)
|
|
|
|
if not mod_ref then
|
2013-11-17 18:48:35 +01:00
|
|
|
local ref = self:lookup_class_item(packmod,s)
|
|
|
|
if ref then return ref end
|
2014-01-05 13:55:20 +01:00
|
|
|
local mod, klass = split_dotted_name(packmod)
|
|
|
|
mod_ref = modules.by_name[mod]
|
|
|
|
if mod_ref then
|
|
|
|
ref = mod_ref:lookup_class_item(klass,name)
|
|
|
|
if ref then return ref end
|
|
|
|
end
|
2013-11-17 18:48:35 +01:00
|
|
|
ref = lua_manual_ref(s)
|
2011-07-05 18:19:49 +02:00
|
|
|
if ref then return ref end
|
|
|
|
return nil,"module not found: "..packmod
|
|
|
|
end
|
|
|
|
end
|
2013-11-28 10:57:13 +01:00
|
|
|
fun_ref = mod_ref:get_fun_ref(name)
|
2011-07-05 18:19:49 +02:00
|
|
|
if fun_ref then
|
|
|
|
return reference(s,mod_ref,fun_ref)
|
|
|
|
else
|
2012-03-13 11:23:55 +01:00
|
|
|
fun_ref = mod_ref.sections.by_name[name]
|
|
|
|
if not fun_ref then
|
|
|
|
return nil,"function or section not found: "..s.." in "..mod_ref.name
|
|
|
|
else
|
|
|
|
return reference(fun_ref.name:gsub('_',' '),mod_ref,fun_ref)
|
|
|
|
end
|
2011-07-05 18:19:49 +02:00
|
|
|
end
|
|
|
|
else -- plain jane name; module in this package, function in this module
|
2014-10-01 16:02:38 +02:00
|
|
|
if ldoc and ldoc.global_lookup then
|
2014-06-20 15:11:40 +02:00
|
|
|
for m in modules:iter() do
|
|
|
|
fun_ref = m:get_fun_ref(s)
|
|
|
|
if fun_ref then return reference(s,m,fun_ref) end
|
|
|
|
end
|
|
|
|
return nil,"function: "..s.." not found globally"
|
|
|
|
end
|
2011-07-05 18:19:49 +02:00
|
|
|
mod_ref = modules.by_name[self.package..'.'..s]
|
2013-08-21 14:52:09 +02:00
|
|
|
if ismod(mod_ref) then return reference(s, mod_ref,nil) end
|
2013-11-28 10:57:13 +01:00
|
|
|
fun_ref = self:get_fun_ref(s)
|
2013-11-17 18:48:35 +01:00
|
|
|
if fun_ref then return reference(s,self,fun_ref)
|
2011-07-05 18:19:49 +02:00
|
|
|
else
|
2013-11-16 19:36:53 +01:00
|
|
|
local ref = lua_manual_ref (s)
|
2011-07-05 18:19:49 +02:00
|
|
|
if ref then return ref end
|
|
|
|
return nil, "function not found: "..s.." in this module"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-28 10:57:13 +01:00
|
|
|
function Module:get_fun_ref(s)
|
|
|
|
local fun_ref = self.items.by_name[s]
|
|
|
|
-- did not get an exact match, so try to match by the unqualified fun name
|
|
|
|
if not fun_ref then
|
|
|
|
local patt = '[.:]'..s..'$'
|
|
|
|
for qname,ref in pairs(self.items.by_name) do
|
|
|
|
if qname:match(patt) then
|
|
|
|
fun_ref = ref
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return fun_ref
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-04-13 13:02:40 +02:00
|
|
|
-- resolving @see references. A word may be either a function in this module,
|
|
|
|
-- or a module in this package. A MOD.NAME reference is within this package.
|
|
|
|
-- Otherwise, the full qualified name must be used.
|
|
|
|
-- First, check whether it is already a fully qualified module name.
|
|
|
|
-- Then split it and see if the module part is a qualified module
|
|
|
|
-- and try look up the name part in that module.
|
|
|
|
-- If this isn't successful then try prepending the current package to the reference,
|
|
|
|
-- and try to to resolve this.
|
|
|
|
function Module:resolve_references(modules)
|
2011-06-06 18:38:02 +02:00
|
|
|
local found = List()
|
2015-10-16 22:34:31 +02:00
|
|
|
-- Resolve see references in item. Can be Module or Item type.
|
|
|
|
local function resolve_item_references(item)
|
2011-06-06 18:38:02 +02:00
|
|
|
local see = item.tags.see
|
|
|
|
if see then -- this guy has @see references
|
|
|
|
item.see = List()
|
|
|
|
for s in see:iter() do
|
2011-07-05 18:19:49 +02:00
|
|
|
local href, err = self:process_see_reference(s,modules)
|
|
|
|
if href then
|
2011-06-19 17:52:02 +02:00
|
|
|
item.see:append (href)
|
2011-06-06 18:38:02 +02:00
|
|
|
found:append{item,s}
|
2011-07-05 18:19:49 +02:00
|
|
|
elseif err then
|
|
|
|
item:warning(err)
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-16 22:34:31 +02:00
|
|
|
|
|
|
|
resolve_item_references(self); -- Resolve module-level see references.
|
|
|
|
for item in self.items:iter() do
|
|
|
|
resolve_item_references(item); -- Resolve item-level see references.
|
|
|
|
end
|
2011-06-06 18:38:02 +02:00
|
|
|
-- mark as found, so we don't waste time re-searching
|
|
|
|
for f in found:iter() do
|
|
|
|
f[1].tags.see:remove_value(f[2])
|
|
|
|
end
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2011-08-26 15:34:42 +02:00
|
|
|
function Item:dump_tags (taglist)
|
|
|
|
for tag, value in pairs(self.tags) do
|
|
|
|
if not taglist or taglist[tag] then
|
2011-12-09 14:43:37 +01:00
|
|
|
Item.warning(self,tag..' '..tostring(value))
|
2011-08-26 15:34:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Module:dump_tags (taglist)
|
|
|
|
Item.dump_tags(self,taglist)
|
|
|
|
for item in self.items:iter() do
|
|
|
|
item:dump_tags(taglist)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-11 15:40:44 +02:00
|
|
|
--------- dumping out modules and items -------------
|
|
|
|
|
2012-12-29 11:04:39 +01:00
|
|
|
local function dump_tags (tags)
|
|
|
|
if next(tags) then
|
|
|
|
print 'tags:'
|
|
|
|
for tag, value in pairs(tags) do
|
|
|
|
print('\t',tag,value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-24 15:51:38 +02:00
|
|
|
-- ANSI colour codes for making important stuff BOLD
|
|
|
|
-- (but not on Windows)
|
|
|
|
local bold,default = '\x1B[1m','\x1B[0m'
|
|
|
|
if utils.dir_separator == '\\' then
|
|
|
|
bold,default = '',''
|
|
|
|
end
|
|
|
|
|
2011-04-13 18:45:41 +02:00
|
|
|
function Module:dump(verbose)
|
2013-07-23 10:40:07 +02:00
|
|
|
if not doc.project_level(self.type) then return end
|
2011-06-06 18:38:02 +02:00
|
|
|
print '----'
|
2016-06-24 15:51:38 +02:00
|
|
|
print(self.type..':',bold..self.name,self.summary..default)
|
2011-06-06 18:38:02 +02:00
|
|
|
if self.description then print(self.description) end
|
2012-12-29 11:04:39 +01:00
|
|
|
dump_tags (self.tags)
|
2011-06-06 18:38:02 +02:00
|
|
|
for item in self.items:iter() do
|
|
|
|
item:dump(verbose)
|
|
|
|
end
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2011-06-15 16:33:13 +02:00
|
|
|
-- make a text dump of the contents of this File object.
|
|
|
|
-- The level of detail is controlled by the 'verbose' parameter.
|
|
|
|
-- Primarily intended as a debugging tool.
|
|
|
|
function File:dump(verbose)
|
|
|
|
for mod in self.modules:iter() do
|
|
|
|
mod:dump(verbose)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-13 13:02:40 +02:00
|
|
|
function Item:dump(verbose)
|
2011-06-06 18:38:02 +02:00
|
|
|
local tags = self.tags
|
|
|
|
local name = self.name
|
|
|
|
if self.type == 'function' then
|
|
|
|
name = name .. self.args
|
|
|
|
end
|
|
|
|
if verbose then
|
2011-06-09 15:07:27 +02:00
|
|
|
print()
|
2016-06-24 15:51:38 +02:00
|
|
|
io.write(bold)
|
2011-06-06 18:38:02 +02:00
|
|
|
print(self.type,name)
|
2016-06-24 15:51:38 +02:00
|
|
|
io.write(default)
|
2011-06-06 18:38:02 +02:00
|
|
|
print(self.summary)
|
2012-03-17 11:17:22 +01:00
|
|
|
if self.description and self.description:match '%S' then
|
|
|
|
print 'description:'
|
|
|
|
print(self.description)
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2016-06-03 09:28:00 +02:00
|
|
|
if self.params and #self.params > 0 then
|
2012-03-17 11:17:22 +01:00
|
|
|
print 'parameters:'
|
|
|
|
for _,p in ipairs(self.params) do
|
2014-04-23 13:19:16 +02:00
|
|
|
print('',p,self.params.map[p])
|
2012-03-17 11:17:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if self.ret and #self.ret > 0 then
|
|
|
|
print 'returns:'
|
|
|
|
for _,r in ipairs(self.ret) do
|
|
|
|
print('',r)
|
|
|
|
end
|
|
|
|
end
|
2012-12-29 11:04:39 +01:00
|
|
|
dump_tags(self.tags)
|
2011-06-06 18:38:02 +02:00
|
|
|
else
|
2016-06-24 15:51:38 +02:00
|
|
|
print('* '..bold..name..default..' - '..self.summary)
|
2011-06-06 18:38:02 +02:00
|
|
|
end
|
2011-04-13 13:02:40 +02:00
|
|
|
end
|
|
|
|
|
2011-07-11 15:40:44 +02:00
|
|
|
function doc.filter_objects_through_function(filter, module_list)
|
2011-12-06 18:19:09 +01:00
|
|
|
local quit, quote = utils.quit, tools.quote
|
2011-07-11 15:40:44 +02:00
|
|
|
if filter == 'dump' then filter = 'pl.pretty.dump' end
|
|
|
|
local mod,name = tools.split_dotted_name(filter)
|
|
|
|
local ok,P = pcall(require,mod)
|
|
|
|
if not ok then quit("cannot find module "..quote(mod)) end
|
|
|
|
local ok,f = pcall(function() return P[name] end)
|
|
|
|
if not ok or type(f) ~= 'function' then quit("dump module: no function "..quote(name)) end
|
|
|
|
|
|
|
|
-- clean up some redundant and cyclical references--
|
|
|
|
module_list.by_name = nil
|
|
|
|
for mod in module_list:iter() do
|
|
|
|
mod.kinds = nil
|
|
|
|
mod.file = mod.file.filename
|
|
|
|
for item in mod.items:iter() do
|
|
|
|
item.module = nil
|
|
|
|
item.file = nil
|
|
|
|
item.formal_args = nil
|
|
|
|
item.tags['return'] = nil
|
|
|
|
item.see = nil
|
|
|
|
end
|
|
|
|
mod.items.by_name = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local ok,err = pcall(f,module_list)
|
|
|
|
if not ok then quit("dump failed: "..err) end
|
|
|
|
end
|
|
|
|
|
2011-04-13 13:02:40 +02:00
|
|
|
return doc
|