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
69 | 69 |
return preamble,tag_items
|
70 | 70 |
end
|
71 | 71 |
|
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
|
73 | 74 |
local Tags = {}
|
74 | 75 |
Tags.__index = Tags
|
75 | 76 |
|
|
88 | 89 |
return tags
|
89 | 90 |
end
|
90 | 91 |
|
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
|
92 | 104 |
rawset(self,tag,value)
|
93 | |
self._order:append(tag)
|
|
105 |
if not ovalue then
|
|
106 |
self._order:append(tag)
|
|
107 |
end
|
94 | 108 |
end
|
95 | 109 |
|
96 | 110 |
function Tags:iter ()
|
|
127 | 141 |
if not value:match '\n[^\n]+\n' then
|
128 | 142 |
value = strip(value)
|
129 | 143 |
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)
|
141 | 146 |
end
|
142 | 147 |
return tags --Map(tags)
|
143 | 148 |
end
|
148 | 148 |
ldoc.alias(name,{'param',modifiers={type=type}})
|
149 | 149 |
end
|
150 | 150 |
|
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'}
|
160 | 155 |
end)
|
161 | |
|
162 | 156 |
|
163 | 157 |
ldoc.tparam_alias 'string'
|
164 | 158 |
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
|