3
-------------------------------------------------------------------------------
4
-- Handlers for several tags
5
-- @release $Id: tags.lua,v 1.8 2007/09/05 12:39:09 tomas Exp $
6
-------------------------------------------------------------------------------
8
local luadoc = require "luadoc"
9
local util = require "luadoc.util"
10
local string = require "string"
11
local table = require "table"
12
local assert, type, tostring = assert, type, tostring
14
module "luadoc.taglet.standard.tags"
16
-------------------------------------------------------------------------------
18
local function author (tag, block, text)
19
block[tag] = block[tag] or {}
21
luadoc.logger:warn("author `name' not defined [["..text.."]]: skipping")
24
table.insert (block[tag], text)
27
-------------------------------------------------------------------------------
28
-- Set the class of a comment block. Classes can be "module", "function",
29
-- "table". The first two classes are automatic, extracted from the source code
31
local function class (tag, block, text)
35
-------------------------------------------------------------------------------
37
local function copyright (tag, block, text)
41
-------------------------------------------------------------------------------
43
local function description (tag, block, text)
47
-------------------------------------------------------------------------------
49
local function filename (tag, block, text)
53
-------------------------------------------------------------------------------
55
local function field (tag, block, text)
56
if block["class"] ~= "table" then
57
luadoc.logger:warn("documenting `field' for block that is not a `table'")
59
block[tag] = block[tag] or {}
61
local _, _, name, desc = string.find(text, "^([_%w%.]+)%s+(.*)")
62
assert(name, "field name not defined")
64
table.insert(block[tag], name)
65
block[tag][name] = desc
68
-------------------------------------------------------------------------------
69
-- Set the name of the comment block. If the block already has a name, issue
70
-- an error and do not change the previous value
72
local function name (tag, block, text)
73
if block[tag] and block[tag] ~= text then
74
luadoc.logger:error(string.format("block name conflict: `%s' -> `%s'", block[tag], text))
80
-------------------------------------------------------------------------------
81
-- Processes a parameter documentation.
82
-- @param tag String with the name of the tag (it must be "param" always).
83
-- @param block Table with previous information about the block.
84
-- @param text String with the current line beeing processed.
86
local function param (tag, block, text)
87
block[tag] = block[tag] or {}
88
-- TODO: make this pattern more flexible, accepting empty descriptions
89
local _, _, name, desc = string.find(text, "^([_%w%.]+)%s+(.*)")
91
luadoc.logger:warn("parameter `name' not defined [["..text.."]]: skipping")
94
local i = table.foreachi(block[tag], function (i, v)
100
luadoc.logger:warn(string.format("documenting undefined parameter `%s'", name))
101
table.insert(block[tag], name)
103
block[tag][name] = desc
106
-------------------------------------------------------------------------------
108
local function release (tag, block, text)
112
-------------------------------------------------------------------------------
114
local function ret (tag, block, text)
116
if type(block[tag]) == "string" then
117
block[tag] = { block[tag], text }
118
elseif type(block[tag]) == "table" then
119
table.insert(block[tag], text)
125
-------------------------------------------------------------------------------
128
local function see (tag, block, text)
129
-- see is always an array
130
block[tag] = block[tag] or {}
132
-- remove trailing "."
133
text = string.gsub(text, "(.*)%.$", "%1")
135
local s = util.split("%s*,%s*", text)
137
table.foreachi(s, function (_, v)
138
table.insert(block[tag], v)
142
-------------------------------------------------------------------------------
145
local function usage (tag, block, text)
146
if type(block[tag]) == "string" then
147
block[tag] = { block[tag], text }
148
elseif type(block[tag]) == "table" then
149
table.insert(block[tag], text)
155
-------------------------------------------------------------------------------
158
handlers["author"] = author
159
handlers["class"] = class
160
handlers["copyright"] = copyright
161
handlers["description"] = description
162
handlers["field"] = field
163
handlers["name"] = name
164
handlers["param"] = param
165
handlers["release"] = release
166
handlers["return"] = ret
167
handlers["see"] = see
168
handlers["usage"] = usage
169
handlers["filename"] = filename
171
-------------------------------------------------------------------------------
173
function handle (tag, block, text)
174
if not handlers[tag] then
175
luadoc.logger:error(string.format("undefined handler for tag `%s'", tag))
178
-- assert(handlers[tag], string.format("undefined handler for tag `%s'", tag))
179
return handlers[tag](tag, block, text)