Module:DetailedList

local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs local string, table, yesno = loader.require('String', 'Table', 'Yesno') local data = require('Module:DetailedList/Data')

local p = {}

local function mergeMultiListSyntax(args, start) -- Check if list format is being used local start = tonumber(start) or 1 local function _tostring(v) if type(v) == 'table' then return table.concat(v) elseif type(v) == 'boolean' or v == nil or type(v) == 'number' or type(v) == 'function' then return tostring(v) else return v		end end --errors checkType(1, args, 'table') checkType(2, start, 'number', true) args[start] = _tostring(args[start]) if args[start]:match('%*') then local list = {} for v in (args[start]):gmatch('%*+[^%*]+') do			v = v:gsub('\n',' ') table.push(list, string.trim(v)) end list[1] = _tostring(list[1]) if not list[1] or list[1] == '' then table.remove(list,1) end return list elseif args[start] and not args[start]:match('%*') and not args[start+1] then return {args[start]} end --else local list, i = {}, start while args[i] do		list[#list+1] = _tostring(args[i]) i = i + 1 end return list end

function p.detailedResourceList( frame ) local args = getArgs(frame) local list = mergeMultiListSyntax(args) return frame:preprocess(p._detailedResourceList(list)) end

function p._detailedResourceList(list) local ret = {} local function addmod(var, mod) return var:match(mod) and var or var..mod end local function resolve(depth1, num1, item1, mod1) mod1 = mod1 or '' if item1:match('/[^/]+/') then item1 = item1:match('/([^/]+)/') mod1 = addmod(mod1, '//') end for _,m in ipairs{'{','}'} do			if item1:match(m) then mod1 = addmod(mod1, m) end end local queryResult = data[item1] if mod1:match('//') and queryResult then mod1 = addmod(mod1, '{') -- wrap span (start) end local mods = ('%s%s'):format(			mod1:match('{') and ' ' or ,			mod1:match('}') and ' ' or 			) table.push(ret, ('%s%s'):format( string._repeat('*',depth1), tostring(num1), item1, mods ))		if mod1:match('//') and queryResult then queryResult = type(queryResult[1]) ~= 'table' and { queryResult } or queryResult for _, entry in ipairs(queryResult) do				local iDepth, iNum, iItem, iMod = entry[1], entry[2], entry[3], entry[4] resolve(depth1+iDepth, num1*iNum, iItem, iMod) end ret[#ret] = ret[#ret]..' ' -- wrap span (end) end end for _,line in ipairs(list) do		local asterisks = line:match('^%*+') local depth = asterisks and #asterisks or 0 local item, num, itemname, queryResult local modifiers = '' if line:match('^[%*%s]*/[^/]+/') then item = line:match('^[%*%s]*/([^/]+)/') modifiers = addmod(modifiers, '//') else item = line:match('^[%*%s]*(.*)') end for _,m in ipairs{'{','}'} do			if line:match(m) then modifiers = addmod(modifiers, m) end end item = string.trim(item) if item:match('^%d+ .*') then num, itemname = item:match('^(%d+) ([^%{%}]*)') num = tonumber(num) or 1 else num, itemname = 1, item:gsub('{',):gsub('}',) end itemname = string.trim(itemname) resolve(depth, num, itemname, modifiers) end return table.concat(ret, '\n') end

return p