-- CFB schedule table conversion
-- {{subst:#invoke:CFB schedule/convert|table|...}}
local p = {}
local function splitargs(s)
s = '♣MARK♣' .. s
i = 0
while mw.ustring.find(s, '♣MARK♣') and (i < 100) do
i = i + 1
s=mw.ustring.gsub(s,'(♣MARK♣)%s*%|%s*([^%|{}%[%]=%s]*)%s*=%s*', '♦♦%2 = %1')
s=mw.ustring.gsub(s,'(♣MARK♣)([^%|{}%[%]=]*)', '%2%1')
s=mw.ustring.gsub(s,'(♣MARK♣)(%{%{[^%{%}]*%}%})', '%2%1')
s=mw.ustring.gsub(s,'(♣MARK♣)(%[%[[^%[%]]*%]%])', '%2%1')
s=mw.ustring.gsub(s,'(♣MARK♣)(%[[^%[%]]*%])', '%2%1')
s=mw.ustring.gsub(s,'♣MARK♣$', '')
end
local res = {}
for t in mw.text.gsplit(s, '%s*♦♦%s*') do
local k = mw.text.gsub(t, '^([^=]-)%s*=%s*(.-)%s*$', '%1')
local v = mw.text.gsub(t, '^([^=]-)%s*=%s*(.-)%s*$', '%2')
if k ~= t then
res[k] = v
end
end
return res
end
local function parseHeader(frame, s)
return frame:expandTemplate('CFB Schedule Start', splitargs(s))
end
local function parseFooter(frame, s)
return frame:expandTemplate('CFB Schedule End', splitargs(s))
end
local function parseEntry(frame, s)
return frame:expandTemplate('CFB Schedule Entry', splitargs(s))
end
function p.table(frame)
local res = ''
for t in mw.text.gsplit(frame.args[1] or '', '{{[_%s]*CFB[_%s]*Schedule[_%s]*') do
local s = t:match( '^%s*(.-)%s*$' )
if mw.ustring.sub(s,-2) == '}}' then
s = mw.ustring.sub(s,1,-3)
if mw.ustring.sub(s,1,5) == 'Entry' then
res = res .. parseEntry(frame,mw.ustring.sub(s,6))
elseif mw.ustring.sub(s,1,5) == 'Start' then
res = res .. parseHeader(frame,mw.ustring.sub(s,6))
elseif mw.ustring.sub(s,1,3) == 'End' then
res = res .. parseFooter(frame,mw.ustring.sub(s,4))
else
res = res .. t
end
else
res = res .. t
end
end
return res
end
return p