cleaned up some runaway table field detection code, which caused crashes with table items with no declared fields
This commit is contained in:
parent
86dd93e67c
commit
a606f6305e
|
@ -129,10 +129,11 @@ end
|
|||
-- Depending on the case successfully detected, returns a function which
|
||||
-- will be called later to fill in inferred item tags
|
||||
function Lua:item_follows(t,v,tok)
|
||||
local parser
|
||||
local parser, case
|
||||
local is_local = t == 'keyword' and v == 'local'
|
||||
if is_local then t,v = tnext(tok) end
|
||||
if t == 'keyword' and v == 'function' then -- case [1]
|
||||
case = 1
|
||||
parser = parse_lua_function_header
|
||||
elseif t == 'iden' then
|
||||
local name,t,v = tools.get_fun_name(tok,v)
|
||||
|
@ -140,39 +141,37 @@ function Lua:item_follows(t,v,tok)
|
|||
t,v = tnext(tok)
|
||||
if t == 'keyword' and v == 'function' then -- case [2]
|
||||
tnext(tok) -- skip '('
|
||||
case = 2
|
||||
parser = function(tags,tok)
|
||||
tags.name = name
|
||||
parse_lua_parameters(tags,tok)
|
||||
end
|
||||
elseif t == '{' then -- case [3]
|
||||
case = 3
|
||||
parser = function(tags,tok)
|
||||
tags.class = 'table'
|
||||
tags.name = name
|
||||
parse_lua_table (tags,tok)
|
||||
end
|
||||
else -- case [4]
|
||||
case = 4
|
||||
parser = function(tags)
|
||||
tags.class = 'field'
|
||||
tags.name = name
|
||||
end
|
||||
end
|
||||
end
|
||||
return parser, is_local
|
||||
return parser, is_local, case
|
||||
end
|
||||
|
||||
|
||||
-- this is called, whether the tag was inferred or not.
|
||||
-- Currently tries to fill in the fields of a table from comments
|
||||
function Lua:parse_extra (tags,tok)
|
||||
if tags.class == 'table' and not tags.field then
|
||||
local res, stat
|
||||
if t ~= '{' then
|
||||
stat,t,v = pcall(tok)
|
||||
if not stat then return nil end
|
||||
res,t,v = self:search_for_token(tok,'{','{',tok())
|
||||
if not res then return nil,t,v end
|
||||
end
|
||||
parse_lua_table (tags,tok)
|
||||
-- we only call the function returned by the item_follows above if there
|
||||
-- is not already a name and a type.
|
||||
-- Otherwise, this is called. Currrently only tries to fill in the fields
|
||||
-- of a table from a table definition as identified above
|
||||
function Lua:parse_extra (tags,tok,case)
|
||||
if tags.class == 'table' and not tags.field and case == 3 then
|
||||
parse_lua_table(tags,tok)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -147,13 +147,15 @@ local function parse_file(fname,lang, package)
|
|||
t,v = tok()
|
||||
end
|
||||
end
|
||||
|
||||
if not t then break end -- no more file!
|
||||
|
||||
if t == 'space' then t,v = tnext(tok) end
|
||||
|
||||
local item_follows, tags, is_local
|
||||
local item_follows, tags, is_local, case
|
||||
if ldoc_comment or first_comment then
|
||||
comment = table.concat(comment)
|
||||
|
||||
if not ldoc_comment and first_comment then
|
||||
F:warning("first comment must be a doc comment!")
|
||||
break
|
||||
|
@ -161,7 +163,7 @@ local function parse_file(fname,lang, package)
|
|||
if first_comment then
|
||||
first_comment = false
|
||||
else
|
||||
item_follows, is_local = lang:item_follows(t,v,tok)
|
||||
item_follows, is_local, case = lang:item_follows(t,v,tok)
|
||||
end
|
||||
if item_follows or comment:find '@'then
|
||||
tags = extract_tags(comment)
|
||||
|
@ -215,7 +217,7 @@ local function parse_file(fname,lang, package)
|
|||
if item_follows then -- parse the item definition
|
||||
item_follows(tags,tok)
|
||||
else
|
||||
lang:parse_extra(tags,tok)
|
||||
lang:parse_extra(tags,tok,case)
|
||||
end
|
||||
end
|
||||
-- local functions treated specially
|
||||
|
|
|
@ -261,7 +261,7 @@ function M.get_parameters (tok,endtoken,delim)
|
|||
args.comments = {}
|
||||
local ltl = lexer.get_separated_list(tok,endtoken,delim)
|
||||
|
||||
if #ltl[1] == 0 then return args end -- no arguments
|
||||
if not ltl or #ltl[1] == 0 then return args end -- no arguments
|
||||
|
||||
local function set_comment (idx,tok)
|
||||
local text = value_of(tok):gsub('%s*$','')
|
||||
|
|
Loading…
Reference in New Issue