tags as ordered maps; Geoff refactorings
This commit is contained in:
parent
cdebc952e4
commit
29134ef169
|
@ -109,11 +109,13 @@ end
|
|||
|
||||
local function parse_lua_parameters (tags,tok)
|
||||
tags.formal_args = tools.get_parameters(tok)
|
||||
tags.class = 'function'
|
||||
tags:add('class','function')
|
||||
end
|
||||
|
||||
local function parse_lua_function_header (tags,tok)
|
||||
tags.name = tools.get_fun_name(tok)
|
||||
if not tags.name then
|
||||
tags:add('name',tools.get_fun_name(tok))
|
||||
end
|
||||
if not tags.name then return 'function has no name' end
|
||||
parse_lua_parameters(tags,tok)
|
||||
end
|
||||
|
@ -148,32 +150,40 @@ function Lua:item_follows(t,v,tok)
|
|||
tnext(tok) -- skip '('
|
||||
case = 2
|
||||
parser = function(tags,tok)
|
||||
tags.name = name
|
||||
tags:add('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
|
||||
tags:add('class','table')
|
||||
tags:add('name',name)
|
||||
parse_lua_table (tags,tok)
|
||||
end
|
||||
else -- case [4]
|
||||
case = 4
|
||||
parser = function(tags)
|
||||
tags.class = 'field'
|
||||
tags.name = name
|
||||
tags:add('class','field')
|
||||
tags:add('name',name)
|
||||
end
|
||||
end
|
||||
elseif t == 'keyword' and v == 'return' then -- case [5]
|
||||
elseif t == 'keyword' and v == 'return' then
|
||||
t, v = tnext(tok)
|
||||
if t == 'keyword' and v == 'function' then
|
||||
-- return function(a, b, c)
|
||||
tnext(tok) -- skip '('
|
||||
case = 2
|
||||
parser = parse_lua_parameters
|
||||
elseif t == '{' then
|
||||
-- return {...}
|
||||
case = 5
|
||||
if tnext(tok) ~= '{' then
|
||||
return nil
|
||||
end
|
||||
parser = function(tags,tok)
|
||||
tags.class = 'table'
|
||||
tags:add('class','table')
|
||||
parse_lua_table(tags,tok)
|
||||
end
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
return parser, is_local, case
|
||||
end
|
||||
|
|
|
@ -63,6 +63,24 @@ function parse_colon_tags (text)
|
|||
return preamble,tag_items
|
||||
end
|
||||
|
||||
local Tags = {}
|
||||
Tags.__index = Tags
|
||||
|
||||
function Tags.new (t)
|
||||
t._order = List()
|
||||
return setmetatable(t,Tags)
|
||||
end
|
||||
|
||||
function Tags:add (tag,value)
|
||||
self[tag] = value
|
||||
--print('adding',tag,value)
|
||||
self._order:append(tag)
|
||||
end
|
||||
|
||||
function Tags:iter ()
|
||||
return self._order:iter()
|
||||
end
|
||||
|
||||
-- This takes the collected comment block, and uses the docstyle to
|
||||
-- extract tags and values. Assume that the summary ends in a period or a question
|
||||
-- mark, and everything else in the preamble is the description.
|
||||
|
@ -86,7 +104,7 @@ local function extract_tags (s)
|
|||
summary = preamble
|
||||
end
|
||||
end -- and strip(description) ?
|
||||
local tags = {summary=summary and strip(summary) or '',description=description or ''}
|
||||
local tags = Tags.new{summary=summary and strip(summary) or '',description=description or ''}
|
||||
for _,item in ipairs(tag_items) do
|
||||
local tag, value, modifiers = Item.check_tag(tags,unpack(item))
|
||||
value = strip(value)
|
||||
|
@ -95,14 +113,14 @@ local function extract_tags (s)
|
|||
local old_value = tags[tag]
|
||||
|
||||
if not old_value then -- first element
|
||||
tags[tag] = value
|
||||
tags:add(tag,value)
|
||||
elseif type(old_value)=='table' and old_value.append then -- append to existing list
|
||||
old_value :append (value)
|
||||
else -- upgrade string->list
|
||||
tags[tag] = List{old_value, value}
|
||||
tags:add(tag,List{old_value, value})
|
||||
end
|
||||
end
|
||||
return Map(tags)
|
||||
return tags --Map(tags)
|
||||
end
|
||||
|
||||
local _xpcall = xpcall
|
||||
|
@ -149,8 +167,8 @@ local function parse_file(fname, lang, package, args)
|
|||
end
|
||||
|
||||
local function add_module(tags,module_found,old_style)
|
||||
tags.name = module_found
|
||||
tags.class = 'module'
|
||||
tags:add('name',module_found)
|
||||
tags:add('class','module')
|
||||
local item = F:new_item(tags,lineno())
|
||||
item.old_style = old_style
|
||||
module_item = item
|
||||
|
@ -228,7 +246,7 @@ local function parse_file(fname, lang, package, args)
|
|||
if tags.name then
|
||||
if not tags.class then
|
||||
F:warning("no type specified, assuming function: '"..tags.name.."'")
|
||||
tags.class = 'function'
|
||||
tags:add('class','function')
|
||||
end
|
||||
item_follows, is_local = false, false
|
||||
elseif lang:is_module_modifier (tags) then
|
||||
|
|
Loading…
Reference in New Issue