27.175
Bearbeitungen
Keine Bearbeitungszusammenfassung Markierung: Zurückgesetzt |
Keine Bearbeitungszusammenfassung Markierung: Zurückgesetzt |
||
| Zeile 139: | Zeile 139: | ||
function p.attrListParser(attr_list, recursion) | function p.attrListParser(attr_list, recursion) | ||
-- Kommandozeile zum Debuggen: | |||
-- mw.logObject(p.attrListParser(";A;{;B;C;};D;")) | |||
local attr_list_parsed = {} | local attr_list_parsed = {} | ||
local loop_count = 0 | local loop_count = 0 | ||
attr_list = str.strip(attr_list or "") | attr_list = str.strip(attr_list or "") | ||
while loop_count < 100 and attr_list ~= "" do -- Schleifenbegrenzung | while loop_count < 100 and attr_list ~= "" do -- Schleifenbegrenzung | ||
loop_count = loop_count + 1 | loop_count = loop_count + 1 | ||
local semicolon = string.find(attr_list, ";") | local semicolon = string.find(attr_list, ";") | ||
local brace_open = string.find(attr_list, "\{") | local brace_open = string.find(attr_list, "\{") | ||
local brace_close = string.find(attr_list, "\}") | local brace_close = string.find(attr_list, "\}") | ||
if brace_open ~= brace_close or | if (brace_open ~= nil and brace_close == nil) or -- Klammer nicht paarweise | ||
(brace_open == nil and brace_close ~= nil) or -- oder | |||
(brace_open or 0) >= (brace_close or 1) then -- in falscher Reihenfolge | (brace_open or 0) >= (brace_close or 1) then -- in falscher Reihenfolge | ||
attr_list = "" | attr_list = "" -- => Abbruch | ||
elseif semicolon == nil and -- letzer Eintrag | elseif semicolon == nil and -- letzer Eintrag | ||
brace_open == nil and brace_close == nil then | brace_open == nil and brace_close == nil then | ||
| Zeile 164: | Zeile 166: | ||
elseif brace_open ~= nil and brace_close ~= nil and -- eingebettete Klammerung | elseif brace_open ~= nil and brace_close ~= nil and -- eingebettete Klammerung | ||
brace_open < brace_close then | brace_open < brace_close then | ||
if not recursion then -- Rekursionsschutz, nur 2 Ebenen | if not recursion then -- Rekursionsschutz, nur 2 Ebenen bzw. 1 Selbstaufruf | ||
local attr_sublist = -- Klammerinhalt | local attr_sublist = -- Klammerinhalt | ||
string.sub(attr_list, brace_open + 1, brace_close - 1) | string.sub(attr_list, brace_open + 1, brace_close - 1) | ||
attr_sublist = p.attrListParser(attr_sublist, true) -- sich selbst aufrufen | attr_sublist = p.attrListParser(attr_sublist, true) -- sich selbst aufrufen mit recursion = true | ||
if #attr_sublist > 0 then | if #attr_sublist > 0 then | ||
table.insert(attr_list_parsed, attr_sublist) | table.insert(attr_list_parsed, attr_sublist) | ||
| Zeile 178: | Zeile 180: | ||
attr_list = str.strip(attr_list) | attr_list = str.strip(attr_list) | ||
end | end | ||
return attr_list_parsed | return attr_list_parsed | ||
end | end | ||
return p | return p | ||