+-- 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
+