crash avoided when there's no module doc comment: a warning is issued
This commit is contained in:
parent
109a794109
commit
5fdf0f484d
24
ldoc.lua
24
ldoc.lua
|
@ -246,7 +246,7 @@ local function parse_file(fname,lang)
|
||||||
|
|
||||||
function F:warning (msg,kind)
|
function F:warning (msg,kind)
|
||||||
kind = kind or 'warning'
|
kind = kind or 'warning'
|
||||||
io.stderr:write(kind..' '..file..':'..lineno()..' '..msg,'\n')
|
io.stderr:write(kind..' '..fname..':'..lineno()..' '..msg,'\n')
|
||||||
end
|
end
|
||||||
|
|
||||||
function F:error (msg)
|
function F:error (msg)
|
||||||
|
@ -254,6 +254,13 @@ local function parse_file(fname,lang)
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function add_module(tags,module_found,old_style)
|
||||||
|
tags.name = module_found
|
||||||
|
tags.class = 'module'
|
||||||
|
local item = F:new_item(tags,lineno())
|
||||||
|
item.old_style = old_style
|
||||||
|
end
|
||||||
|
|
||||||
local t,v = tok()
|
local t,v = tok()
|
||||||
while t do
|
while t do
|
||||||
if t == 'comment' then
|
if t == 'comment' then
|
||||||
|
@ -283,25 +290,26 @@ local function parse_file(fname,lang)
|
||||||
tags = extract_tags(comment)
|
tags = extract_tags(comment)
|
||||||
if doc.project_level(tags.class) then
|
if doc.project_level(tags.class) then
|
||||||
module_found = tags.name
|
module_found = tags.name
|
||||||
|
elseif not module_found then
|
||||||
|
module_found = tools.this_module_name(args.package,fname)
|
||||||
|
add_module({summary=''},module_found,true)
|
||||||
|
F:warning 'no module comment found'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- some hackery necessary to find the module() call
|
-- some hackery necessary to find the module() call
|
||||||
if not module_found then
|
if not module_found and ldoc_comment then
|
||||||
local old_style
|
local old_style
|
||||||
module_found,t,v = lang:find_module(tok,t,v)
|
module_found,t,v = lang:find_module(tok,t,v)
|
||||||
-- right, we can add the module object ...
|
-- right, we can add the module object ...
|
||||||
old_style = module_found ~= nil
|
old_style = module_found ~= nil
|
||||||
if not module_found or module_found == '...' then
|
if not module_found or module_found == '...' then
|
||||||
if not t then return end -- run out of file!
|
if not t then quit(fname..": end of file") end -- run out of file!
|
||||||
-- we have to guess the module name
|
-- we have to guess the module name
|
||||||
module_found = tools.this_module_name(args.package,fname)
|
module_found = tools.this_module_name(args.package,fname)
|
||||||
end
|
end
|
||||||
if not tags then tags = extract_tags(comment) end
|
if not tags then tags = extract_tags(comment) end
|
||||||
tags.name = module_found
|
add_module(tags,module_found,old_style)
|
||||||
tags.class = 'module'
|
|
||||||
local item = F:new_item(tags,lineno())
|
|
||||||
item.old_style = old_style
|
|
||||||
tags = nil
|
tags = nil
|
||||||
-- if we did bump into a doc comment, then we can continue parsing it
|
-- if we did bump into a doc comment, then we can continue parsing it
|
||||||
end
|
end
|
||||||
|
@ -314,7 +322,7 @@ local function parse_file(fname,lang)
|
||||||
tags.formal_args = tools.get_parameters(toks)
|
tags.formal_args = tools.get_parameters(toks)
|
||||||
tags.class = 'function'
|
tags.class = 'function'
|
||||||
end
|
end
|
||||||
if tags.name then --pretty.dump(tags)
|
if tags.name then
|
||||||
F:new_item(tags,lineno()).inferred = fun_follows
|
F:new_item(tags,lineno()).inferred = fun_follows
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
-- this module has a comment.
|
||||||
|
-- But it's not a doc comment!
|
||||||
|
|
||||||
|
--- A problem function.
|
||||||
|
-- @param p a parameter
|
||||||
|
function problem.fun(p)
|
||||||
|
return 42
|
||||||
|
end
|
Loading…
Reference in New Issue