From 8395d6d9d7db624e0794d72aaa701cf23baa12eb Mon Sep 17 00:00:00 2001 From: Steve Donovan Date: Mon, 26 Aug 2013 14:22:52 +0200 Subject: [PATCH] inline error comments starting to work --- ldoc/doc.lua | 18 ++++++++++++++++-- tests/styles/multiple.lua | 13 ++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/ldoc/doc.lua b/ldoc/doc.lua index 32e902b..656b5f7 100644 --- a/ldoc/doc.lua +++ b/ldoc/doc.lua @@ -138,8 +138,11 @@ function doc.expand_annotation_item (tags, last_item) tags:add('name',item_name..'-'..tag..acount) acount = acount + 1 return true + elseif tag == 'return' then + last_item:set_tag(tag,value) end end + return false end -- we process each file, resulting in a File object, which has a list of Item objects. @@ -422,12 +425,21 @@ function Item:trailing_warning (kind,tag,rest) end end +local function is_list (l) + return getmetatable(l) == List +end + function Item:set_tag (tag,value) local ttype = known_tags[tag] local args = self.file.args if ttype == TAG_MULTI or ttype == TAG_MULTI_LINE then -- value is always a List! - if getmetatable(value) ~= List then + local ovalue = self.tags[tag] + if is_list(ovalue) then + ovalue:append(value) + value = ovalue + end + if not is_list(value) then value = List{value} end if ttype ~= TAG_MULTI_LINE and args and args.not_luadoc then @@ -833,11 +845,14 @@ function Item:build_return_groups() local g = integer_keys(mods) if g ~= lastg then group = List() + group.g = g groups:append(group) lastg = g end group:append({text=ret, type = mods.type or '',mods = mods}) end + -- order by groups to force error groups to the end + table.sort(groups,function(g1,g2) return g1.g < g2.g end) self.retgroups = groups -- cool, now see if there are any treturns that have tfields to associate with local fields = self.tags.field @@ -881,7 +896,6 @@ function doc.error_macro(tags,value,modifiers) if grp > 0 then -- cool, create new group g = tostring(grp+1) text:append(value) - print(text) end end end diff --git a/tests/styles/multiple.lua b/tests/styles/multiple.lua index 355d788..bd935fb 100644 --- a/tests/styles/multiple.lua +++ b/tests/styles/multiple.lua @@ -22,9 +22,20 @@ function mul2 () end -- @error bad format function mul3 () end +---- +-- function with inline return and errors +-- @string name +function mul4 (name) + if type(name) ~= 'string' then + --- @error not a string + return nil, 'not a string' + end + --- @treturn string converted to uppercase + return name:upper() +end ----- -- function that raises an error. -- @string filename -- @treturn string result -- @raise 'file not found' -function mul4(filename) end +function mul5(filename) end