Строка 5: |
Строка 5: |
| | | |
| -- Dependencies: | | -- Dependencies: |
− | local concat = table.concat | + | local concat, sort = table.concat, table.sort |
| local wrap, yield = coroutine.wrap, coroutine.yield | | local wrap, yield = coroutine.wrap, coroutine.yield |
| local string = mw.ustring or string | | local string = mw.ustring or string |
Строка 12: |
Строка 12: |
| local lpeg, rex = lpeg, rex_pcre | | local lpeg, rex = lpeg, rex_pcre |
| local P, C, Cc, Cp, S, V = lpeg.P, lpeg.C, lpeg.Cc, lpeg.Cp, lpeg.S, lpeg.V | | local P, C, Cc, Cp, S, V = lpeg.P, lpeg.C, lpeg.Cc, lpeg.Cp, lpeg.S, lpeg.V |
− | local any, never, spaces, escape, slash = P(1), P(0), lpeg.locale ().space ^ 0, P'\\', P'/' | + | local any, never, spaces, escape, slash = P(1), P(false), lpeg.locale ().space ^ 0, P'\\', P'/' |
| local open, close, comma, equals = P'(', P')', P',', P'=' | | local open, close, comma, equals = P'(', P')', P',', P'=' |
| local ask = mw.smw.ask | | local ask = mw.smw.ask |
Строка 116: |
Строка 116: |
| * ( spaces * V'arg' * ( spaces * comma * spaces * V'arg' ) ^ 0 ) | | * ( spaces * V'arg' * ( spaces * comma * spaces * V'arg' ) ^ 0 ) |
| * spaces * close / function (func, ...) | | * spaces * close / function (func, ...) |
− | mw.log 'In call rule.'
| |
| local args = {...} | | local args = {...} |
| return function (string) | | return function (string) |
Строка 123: |
Строка 122: |
| substituted [i] = arg == 's' and string or arg | | substituted [i] = arg == 's' and string or arg |
| end | | end |
− | return func (string, unpack (substituted)) | + | return func (unpack (substituted)) |
| end | | end |
| end, | | end, |
| func = (function() | | func = (function() |
− | -- Only allowed functions: | + | -- Only allowed functions. Their names must be ordered from longest to shortest: |
| + | local names = {} |
| + | for name, _ in pairs (allowed) do |
| + | names [#names + 1] = name |
| + | end |
| + | sort (names, function (a, b) |
| + | return #a > #b |
| + | end) |
| local choice = never | | local choice = never |
− | mw.log 'In func rule'
| + | for _, name in pairs (names) do |
− | for name, func in pairs (allowed) do | + | choice = choice + P (name) * Cc (allowed [name]) |
− | mw.log ('In func rule. name = ' .. tostring (name))
| |
− | choice = choice + P (name) * Cc (func) | |
| end | | end |
| return choice | | return choice |
− | end)(), | + | end) (), |
| arg = V's' + V'call' + V'string' + V'regex' + V'func', | | arg = V's' + V'call' + V'string' + V'regex' + V'func', |
| s = C (s), | | s = C (s), |
Строка 142: |
Строка 146: |
| local sanitised = rex.gsub (pattern, '\\\\u([0-9A-F]{2,4})', '\\x{%1}', nil, convert_flags'ig') | | local sanitised = rex.gsub (pattern, '\\\\u([0-9A-F]{2,4})', '\\x{%1}', nil, convert_flags'ig') |
| return sanitised | | return sanitised |
− | end) * slash * C (S'gim' ^ 0) | + | end) * slash * C (S'gim' ^ 0 + '') |
| } | | } |
| | | |
Строка 219: |
Строка 223: |
| end, | | end, |
| test2 = function () | | test2 = function () |
− | return wikify (test, code, '') | + | return wikify (test, '') |
− | end | + | end, |
| + | test3 = function (arg) |
| + | return transform:match (arg) |
| + | end, allowed = allowed |
| } -- return | | } -- return |