Module:Syntax

local p  = {} function p.test local str = local list = {} local ret = '' for i, s in ipairs(mw.text.split(str, '\n')) do   local l = mw.text.trim(s) -- Empty line/whitespace. if #l == 0 then list[#list+1] = s   -- Comment detection (# prefix). elseif ({       ['#'] = 1,        ['%'] = 1,        ['['] = 1    })[string.sub(l, 1, 1)] or string.sub(l, 1, 2) == '//' then list[#list+1] = ' ' .. l .. ' '   -- Error detection: --- # inside or after statement --- punctuation prefix elseif string.find(l, '#') or string.sub(l, 1, 1):match('%p') then list[#list+1] = ' ' .. l .. ' '   -- Parsing ImportJS strings. else -- Split text by symbol. local t1 = mw.text.split(l, '%p+') local t2 = mw.text.split(l, '[^%p]+') local t = {} -- String extraction. for it, st in ipairs(t1) do           t[2*it-1] = st        end -- Symbol extraction. table.remove(t2,  1) table.remove(t2, #t2) for iy, sy in ipairs(t2) do           t[ 2*iy ] = sy        end -- Combination of 'dev:' prefix. if t[1] == 'dev' and t[2] == ':' then t[1]   = 'dev' .. table.remove(t, 2) end -- Combination of '.js' suffix. if t[#t-1] == '.' and t[#t] == 'js' then t[#t-1] = '.'  .. table.remove(t, #t) end -- Pattern loop. local ptn = { me1 = '^dev:', br0 = '.js$', sy0 = '%p+', st0 = '[%p]+' }       -- Pattern matching conditionals. local b = {} for ii, si in ipairs(t) do           for c, p in ipairs(ptn) do                -- Pattern test. b[ii] = string.match(si, p) ~= nil if string.sub(si, 1, 1) == '^' then b[ii] = b[ii] and ii == 1 elseif string.sub(p, -1) == '$' then b[ii] = b[ii] and ii == #t end -- Conditional class highlighting. if b[ii] then t[ii] = ' ' .. si .. ' '               end end end list[#list+1] = table.concat(t) end end ret = table.concat(list, ' ') return ret end return p