Module:Sandbox/MonkeysHK

local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs local string, table, yesno = loader.require('String', 'Table', 'Yesno') local data = require('Module:Sandbox/MonkeysHK/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 p._detailedResourceList(list) end

function p._detailedResourceList(list) local ret = {} local function resolve(depth1, num1, item1, mod1) mod1 = mod1 or '' 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('//') then local queryResult = data[item1] if 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 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]*/([^/])/') table.push(modifiers, '//') else item = line:match('^[%*%s]*(.*)') end for _,m in ipairs{'{','}'} do			if line:match(m) then table.push(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, itemmame = 1, item end resolve(depth, num, itemname, table.concat(modifiers)) end return table.concat(ret, '\n') end

return p