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)
|
local function parse_lua_parameters (tags,tok)
|
||||||
tags.formal_args = tools.get_parameters(tok)
|
tags.formal_args = tools.get_parameters(tok)
|
||||||
tags.class = 'function'
|
tags:add('class','function')
|
||||||
end
|
end
|
||||||
|
|
||||||
local function parse_lua_function_header (tags,tok)
|
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
|
if not tags.name then return 'function has no name' end
|
||||||
parse_lua_parameters(tags,tok)
|
parse_lua_parameters(tags,tok)
|
||||||
end
|
end
|
||||||
|
@ -148,32 +150,40 @@ function Lua:item_follows(t,v,tok)
|
||||||
tnext(tok) -- skip '('
|
tnext(tok) -- skip '('
|
||||||
case = 2
|
case = 2
|
||||||
parser = function(tags,tok)
|
parser = function(tags,tok)
|
||||||
tags.name = name
|
tags:add('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
|
case = 3
|
||||||
parser = function(tags,tok)
|
parser = function(tags,tok)
|
||||||
tags.class = 'table'
|
tags:add('class','table')
|
||||||
tags.name = name
|
tags:add('name',name)
|
||||||
parse_lua_table (tags,tok)
|
parse_lua_table (tags,tok)
|
||||||
end
|
end
|
||||||
else -- case [4]
|
else -- case [4]
|
||||||
case = 4
|
case = 4
|
||||||
parser = function(tags)
|
parser = function(tags)
|
||||||
tags.class = 'field'
|
tags:add('class','field')
|
||||||
tags.name = name
|
tags:add('name',name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif t == 'keyword' and v == 'return' then -- case [5]
|
elseif t == 'keyword' and v == 'return' then
|
||||||
case = 5
|
t, v = tnext(tok)
|
||||||
if tnext(tok) ~= '{' then
|
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
|
||||||
|
parser = function(tags,tok)
|
||||||
|
tags:add('class','table')
|
||||||
|
parse_lua_table(tags,tok)
|
||||||
|
end
|
||||||
|
else
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
parser = function(tags,tok)
|
|
||||||
tags.class = 'table'
|
|
||||||
parse_lua_table(tags,tok)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return parser, is_local, case
|
return parser, is_local, case
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,6 +63,24 @@ function parse_colon_tags (text)
|
||||||
return preamble,tag_items
|
return preamble,tag_items
|
||||||
end
|
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
|
-- 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
|
-- 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.
|
-- mark, and everything else in the preamble is the description.
|
||||||
|
@ -86,7 +104,7 @@ local function extract_tags (s)
|
||||||
summary = preamble
|
summary = preamble
|
||||||
end
|
end
|
||||||
end -- and strip(description) ?
|
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
|
for _,item in ipairs(tag_items) do
|
||||||
local tag, value, modifiers = Item.check_tag(tags,unpack(item))
|
local tag, value, modifiers = Item.check_tag(tags,unpack(item))
|
||||||
value = strip(value)
|
value = strip(value)
|
||||||
|
@ -95,14 +113,14 @@ local function extract_tags (s)
|
||||||
local old_value = tags[tag]
|
local old_value = tags[tag]
|
||||||
|
|
||||||
if not old_value then -- first element
|
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
|
elseif type(old_value)=='table' and old_value.append then -- append to existing list
|
||||||
old_value :append (value)
|
old_value :append (value)
|
||||||
else -- upgrade string->list
|
else -- upgrade string->list
|
||||||
tags[tag] = List{old_value, value}
|
tags:add(tag,List{old_value, value})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return Map(tags)
|
return tags --Map(tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
local _xpcall = xpcall
|
local _xpcall = xpcall
|
||||||
|
@ -149,8 +167,8 @@ local function parse_file(fname, lang, package, args)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_module(tags,module_found,old_style)
|
local function add_module(tags,module_found,old_style)
|
||||||
tags.name = module_found
|
tags:add('name',module_found)
|
||||||
tags.class = 'module'
|
tags:add('class','module')
|
||||||
local item = F:new_item(tags,lineno())
|
local item = F:new_item(tags,lineno())
|
||||||
item.old_style = old_style
|
item.old_style = old_style
|
||||||
module_item = item
|
module_item = item
|
||||||
|
@ -228,7 +246,7 @@ local function parse_file(fname, lang, package, args)
|
||||||
if tags.name then
|
if tags.name then
|
||||||
if not tags.class then
|
if not tags.class then
|
||||||
F:warning("no type specified, assuming function: '"..tags.name.."'")
|
F:warning("no type specified, assuming function: '"..tags.name.."'")
|
||||||
tags.class = 'function'
|
tags:add('class','function')
|
||||||
end
|
end
|
||||||
item_follows, is_local = false, false
|
item_follows, is_local = false, false
|
||||||
elseif lang:is_module_modifier (tags) then
|
elseif lang:is_module_modifier (tags) then
|
||||||
|
|
Loading…
Reference in New Issue