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