-------------------------------------------------------------------------------
--- @release $Id: standard.lua,v 1.39 2007/12/21 17:50:48 tomas Exp $
+-- @release $Id$
-------------------------------------------------------------------------------
local assert, pairs, tostring, type = assert, pairs, tostring, type
return currentmodule
end
+-- Patterns for constant recognition
+local constant_patterns = {
+ "^()%s*([A-Z][A-Z0-9_]*)%s*=",
+ "^%s*(local%s)%s*([A-Z][A-Z0-9_]*)%s*=",
+}
+
+-------------------------------------------------------------------------------
+-- Checks if the line contains a constant definition
+-- @param line string with line text
+-- @return constant information or nil if no constant definition found
+
+local function check_constant (line)
+ line = util.trim(line)
+
+ local info = table.foreachi(constant_patterns, function (_, pattern)
+ local r, _, l, id = string.find(line, pattern)
+ if r ~= nil then
+ return {
+ name = id,
+ private = (l == "local"),
+ }
+ end
+ end)
+
+ -- TODO: remove these assert's?
+ if info ~= nil then
+ assert(info.name, "constant name undefined")
+ end
+
+ return info
+end
+
-------------------------------------------------------------------------------
-- Extracts summary information from a description. The first sentence of each
-- doc comment should be a summary sentence, containing a concise but complete
if code ~= nil then
local func_info = check_function(code)
local module_name = check_module(code)
+ local const_info = check_constant(code)
if func_info then
block.class = "function"
block.name = func_info.name
block.param = func_info.param
block.private = func_info.private
+ elseif const_info then
+ block.class = "constant"
+ block.name = const_info.name
+ block.private = const_info.private
elseif module_name then
block.class = "module"
block.name = module_name
doc.modules[modulename].tables[t.name] = t
end
end
+
+ -- make constants table
+ doc.modules[modulename].constants = {}
+ for c in class_iterator(blocks, "constant")() do
+ if c and c.name then
+ table.insert(doc.modules[modulename].constants, c.name)
+ doc.modules[modulename].constants[c.name] = c
+ end
+ end
end
if filepath then