Codebase list lua-ldoc / 3c72ea1
ldoc.alias can specify a function which must return tag, value, modifiers like Item:check_tag. The alias error works with return groups steve donovan 10 years ago
4 changed file(s) with 48 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
404404 self.tags = {}
405405 self.formal_args = tags.formal_args
406406 tags.formal_args = nil
407 local iter = tags.iter or Map.Iter
407 local iter = tags.iter or Map.iter
408408 for tag in iter(tags) do
409409 self:set_tag(tag,tags[tag])
410410 end
493493 end
494494 end
495495 else -- has to be a function
496 alias(tags,value,modifiers)
496 return alias(tags,value,modifiers)
497497 end
498498 end
499499 local ttype = known_tags[tag]
792792 for i,ret in ipairs(self.ret) do
793793 local mods = retmod[i]
794794 local g = integer_keys(mods)
795 print(g,lastg)
796795 if g ~= lastg then
797796 group = List()
798797 groups:append(group)
800799 end
801800 group:append({text=ret, type = mods.type or ''})
802801 end
803 print(groups)
804802 self.retgroups = groups
805803 end
806804
6969 return preamble,tag_items
7070 end
7171
72 -- Tags are stored as an ordered map
72 -- Tags are stored as an ordered multi map from strings to strings
73 -- If the same key is used, then the value becomes a list
7374 local Tags = {}
7475 Tags.__index = Tags
7576
8889 return tags
8990 end
9091
91 function Tags:add (tag,value)
92 function Tags:add (tag,value,modifiers)
93 if modifiers then -- how modifiers are encoded
94 value = {value,modifiers=modifiers}
95 end
96 local ovalue = rawget(self,tag)
97 if ovalue then -- previous value?
98 if getmetatable(ovalue) ~= List then
99 ovalue = List{ovalue}
100 end
101 ovalue:append(value)
102 value = ovalue
103 end
92104 rawset(self,tag,value)
93 self._order:append(tag)
105 if not ovalue then
106 self._order:append(tag)
107 end
94108 end
95109
96110 function Tags:iter ()
127141 if not value:match '\n[^\n]+\n' then
128142 value = strip(value)
129143 end
130
131 if modifiers then value = { value, modifiers=modifiers } end
132 local old_value = tags[tag]
133
134 if not old_value then -- first element
135 tags:add(tag,value)
136 elseif type(old_value)=='table' and old_value.append then -- append to existing list
137 old_value :append (value)
138 else -- upgrade string->list
139 tags:add(tag,List{old_value, value})
140 end
144
145 tags:add(tag,value,modifiers)
141146 end
142147 return tags --Map(tags)
143148 end
148148 ldoc.alias(name,{'param',modifiers={type=type}})
149149 end
150150
151 ldoc.alias ('error',function(tags,value,modifiers)
152 local t = List{'nil','error message'}
153 local oret = tags['return']
154 if not oret or type(oret) == 'string' then
155 if oret then t:insert(1,oret) end
156 tags:add('return',t)
157 else
158 tags['return']:extend(t)
159 end
151 ldoc.alias ('error',function(tags,value)
152 local g = '2'
153 tags:add('return','',{[g]=true,type='nil'})
154 return 'return', value, {[g]=true,type='string'}
160155 end)
161
162156
163157 ldoc.tparam_alias 'string'
164158 ldoc.tparam_alias 'number'
0 ------
1 -- Various ways of indicating errors
2 -- @module multiple
3
4 -----
5 -- function with return groups.
6 -- @treturn[1] string result
7 -- @return[2] nil
8 -- @return[2] error message
9 function mul1 () end
10
11 -----
12 -- function with return and error tag
13 -- @return result
14 -- @error message
15 function mul2 () end
16
17 -----
18 -- function that raises an error.
19 -- @string filename
20 -- @treturn string result
21 -- @raise 'file not found'
22 function mul3(filename) end