词条 | Module:Sandbox/Wnt/Expression |
释义 | --- this began long ago when a first test program for the Mandelbrot set went pear-shaped local p={} function chunk(text) local text=mw.ustring.gsub(text,"(%d%s*)E(%s*[%d%+%-])","%1 E %2") -- force space around E notation to avoid going nuts later local debuglog="" local chunks={type={}} local prowl=mw.ustring.gmatch(text,"(%S+)") local firstbit local num=1 local op=2 local var=3 local warning=4 local defs={num={"^([%d%.]*)(.*)$"},op={"^(E?)(.*)$","^([%(%)%*%+%-%?%%/!^]?)(.*)$"},var={"^(%a*)(.*)$"}} t=prowl() while t do local ot=t for i,j in pairs(defs) do for _,v in pairs(j) do firstbit,t=mw.ustring.match(t,v) debuglog=debuglog.."<"..tostring(firstbit)..","..tostring(t)..">"..tostring(i).."i"..tostring(j).."j"..tostring(t).."t"..tostring(v).."v" assert(t,debuglog) -- should always deliver a null string even if the target isn't there if firstbit ~= "" then table.insert(chunks,firstbit) table.insert(chunks.type,i) end end end if t==ot then firstbit,t=mw.ustring.match(t,"^(.)(.*)$") table.insert(chunks,'ignored:'..firstbit) table.insert(chunks.type,warning) end if t=="" then t=prowl() end -- if you run out of bits between spaces, pull a new interspace bit. end return chunks end function p.main(frame) local args=frame.args or {} local parent=frame.getParent(frame) or {} local pargs=parent.args or {} local expr=args.expr or pargs.expr or "" -- (Handle nothing in with nothing out?) local chunks=chunk(expr) return #chunks,"types"..table.concat(chunks.type,",").."values"..table.concat(chunks,",") -- check 1: getting the input sorted out into chunks end return p |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。