Module:ArgRest and Module:ArgRest/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
enclose the pipe capture in a separate thingamajig |
enclose pipe capturing in separate capture group |
||
Line 17: | Line 17: | ||
assert(secondParam, "second parameter missing") |
assert(secondParam, "second parameter missing") |
||
-- Helper for replaceTripleBraces: reads through "default" to find aliases and the actual default |
|||
⚫ | |||
local function recurseOverBraces(str2, i) |
|||
⚫ | |||
local alias, _, default = str2:match("([^{}<>|]+)(|?)(.*)") |
|||
⚫ | |||
if default and default:match("{{%b{}}}") then |
|||
return frame:getParent().args[alias:gsub("%d+", tostring(i))] or recurseOverBraces(default:match("{{(%b{})}}"):sub(1, -2), i) |
|||
⚫ | |||
return frame:getParent().args[alias:gsub("%d+", tostring(i))] or default or "{{{" .. alias .. "}}}" |
|||
end |
|||
end |
|||
⚫ | |||
---- Since %b{} doesn't allow fine control, we must do a second search within the matched string |
|||
local parameter, _, default = str:match("([^{}<>|]+)(|?)(.*)") |
|||
if _ == "" then default = nil elseif default:match("{{%b{}}}") then |
|||
default = recurseOverBraces(default:match("{{(%b{})}}"):sub(1, -2), i) |
|||
end |
|||
return frame:getParent().args[parameter:gsub("%d+", tostring(i))] or default or "{{{" .. parameter .. "}}}" |
return frame:getParent().args[parameter:gsub("%d+", tostring(i))] or default or "{{{" .. parameter .. "}}}" |
||
end |
end |
||
⚫ | |||
for i = start, math.huge do |
for i = start, math.huge do |
||
-- Check if the parameter is defined |
-- Check if the parameter is defined. TODO: make this check for aliases |
||
if not frame:getParent().args[secondParam:gsub('%d+', tostring(i))] then |
if not frame:getParent().args[secondParam:gsub('%d+', tostring(i))] then |
||
break |
break |
||
end |
end |
||
-- local processed = wikitext:gsub("{{{([^{}<>|]+)(|?([^{}<>|]*))}}}", function(a, b, c) return replaceTripleBraces(a, b, c, i) end) |
|||
local processed = wikitext:gsub("{ |
local processed = wikitext:gsub("%{%{(%b{})%}%}", function(a) return replaceTripleBraces(a:sub(1, -2), i) end) --matches everything in triple braces |
||
result = result .. processed |
result = result .. processed |
||
end |
end |