Advertisement
NathaanTFM

luainlua

Aug 9th, 2023 (edited)
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.73 KB | None | 0 0
  1. do local a;local b=_G.getmetatable;local c=_G.table;local d=_G.pairs;local e=_G.ipairs;local f=_G.type;local g=_G.string;local h=_G.setmetatable;local i=_G.select;local j=_G.tostring;local k=_G.next;local function l(...)return{n=i('#',...),...}end;local m=unpack or c.unpack;local function unpack(n,o,p)if o==nil then o=1 end;if p==nil then p=n.n end;if p==nil then p=#n end;return m(n,o,p)end;a=(function(q)local r={}return function(s,...)if r[s]~=nil then return unpack(r[s])elseif q[s]~=nil then r[s]=l(q[s](...))q[s]=nil;return unpack(r[s])else error("module '"..s.."' not found")end end end)({['generator']=function(...)local t=a("utils")local u=t.print;local v=t.dump;local function w()local self={}self.buffer=""local x=0;local y;local function z(A)self.buffer=self.buffer..g.gsub(A,"\n","\n"..g.rep(" ",x))end;local function B(C)C=x+C*4;if g.sub(self.buffer,-x-1)=="\n"..g.rep(" ",x)then self.buffer=g.sub(self.buffer,0,-x-1)self.buffer=self.buffer..g.rep(" ",C)end;x=C end;local function D(E)z("(")for o,s in e(E.positional)do if o~=1 then z(", ")end;z(s)end;if E.vararg then if#E.positional>0 then z(", ")end;z("...")end;z(")")end;local function F(G)for o,C in e(G)do if o~=1 then z(", ")end;y(C)end end;local function H(I)B(1)for J,K in e(I)do self.add_statement(K)end;B(-1)end;local function L(M)z("function")D(M.params)z("\n")H(M.body)z("end")end;local function N(M)z(M.name)end;local function O(M)if k(M.fields)==nil then z("{}")return end;z("{\n")B(1)for o,P in e(M.fields)do if o~=1 then z(",\n")end;if P.type=="name"then z(P.name.." = ")elseif P.type=="expr"then z("[")y(P.expr)z("] = ")end;y(P.value)end;z("\n")B(-1)z("}")end;local function Q(M)z(M.uop)if#M.uop>1 then z(" ")end;z("(")y(M.value)z(")")end;local function R(M)z("(")y(M.left)z(" "..M.op.." ")y(M.right)z(")")end;local function S(M)y(M.value)z("(")F(M.args)z(")")end;local function T(M)y(M.value)z(":")z(M.name)z("(")F(M.args)z(")")end;local function U(M)y(M.value)if M.name~=nil then z("."..M.name)else z("[")y(M.expr)z("]")end end;local function V(M)z(v(M.value))end;local function W(M)z("...")end;y=function(M)if M.type=="function"then L(M)elseif M.type=="name"then N(M)elseif M.type=="table"then O(M)elseif M.type=="unary"then Q(M)elseif M.type=="binary"then R(M)elseif M.type=="call"then S(M)elseif M.type=="invoke"then T(M)elseif M.type=="index"then U(M)elseif M.type=="constant"then V(M)elseif M.type=="vararg"then W(M)else error("cannot dump expr '"..M.type.."'")end end;local function X(K)for o,Y in e(K.targets)do if o~=1 then z(", ")end;y(Y)end;z(" = ")F(K.values)z("\n")end;local function Z(K)z("local ")for o,Y in e(K.targets)do if o~=1 then z(", ")end;z(Y)end;if K.values~=nil then z(" = ")F(K.values)end;z("\n")end;local function _(K)z("function ")for o,a0 in e(K.name)do if o==#K.name and K.vararg then z(":")elseif o~=1 then z(".")end;z(a0)end;D(K.params)z("\n")H(K.body)z("end\n")end;local function a1(K)z("local function ")z(K.name)D(K.params)z("\n")H(K.body)z("end\n")end;local function a2(K)z("if ")y(K.cond)z(" then\n")H(K.body)for o,elt in e(K.elseifs)do z("elseif ")y(elt.cond)z(" then\n")H(elt.body)end;if K.elsebody~=nil then z("else\n")H(K.elsebody)end;z("end\n")end;local function a3(K)y(K.expr)z("\n")end;local function a4(K)z("return ")F(K.values)z("\n")end;local function a5(K)z("do\n")H(K.body)z("end\n")end;local function a6(K)z("while ")y(K.cond)z(" do\n")H(K.body)z("end\n")end;local function a7(K)z("break\n")end;local function a8(K)z("for ")z(K.target)z(" = ")y(K.start)z(", ")y(K.stop)if K.step~=nil then z(", ")y(K.step)end;z(" do\n")H(K.body)z("end\n")end;local function a9(K)z("for ")for o,Y in e(K.targets)do if o~=1 then z(", ")end;z(Y)end;z(" in ")F(K.values)z(" do\n")H(K.body)z("end\n")end;local function aa(K)z("repeat\n")H(K.body)z("until")y(K.cond)z("\n")end;self.add_expression=function(M)y(M)end;self.add_statement=function(K)if K.type=="assign"then X(K)elseif K.type=="local_assign"then Z(K)elseif K.type=="function"then _(K)elseif K.type=="local_function"then a1(K)elseif K.type=="if"then a2(K)elseif K.type=="expr"then a3(K)elseif K.type=="return"then a4(K)elseif K.type=="do"then a5(K)elseif K.type=="while"then a6(K)elseif K.type=="break"then a7(K)elseif K.type=="forin"then a9(K)elseif K.type=="fornum"then a8(K)elseif K.type=="repeat"then aa(K)else error("cannot add stmt '"..K.type.."'")end end;return self end;return w end,['interpreter']=function(...)local t=a("utils")local ab=t.contains;local ac=t.get_identifier;local v=t.dump;local u=t.print;local ad=a("generator")()local function ae(M)ad.buffer=""ad.add_expression(M)return ad.buffer end;local function af(K)ad.buffer=""ad.add_statement(K)return ad.buffer end;local ag;local function ah(I,E,ai,aj,ak)local al={unpack(ai)}local am=nil;local an,ao;local ap={stmt=nil}if aj==nil then aj=_ENV or _G end;local function aq(elt)return(f(elt)=="table"or f(elt)=="userdata")and b(elt)~=nil end;local function ar(as)error(ap.stmt._chunk..":"..ap.stmt._row..": "..as,0)end;local function at(au,C,av,M)local aw=f(C)for J,elt in d(av)do if elt==aw then return end end;local as="attempt to "..au.." a "..aw.." value"if M~=nil then as=as.." ("..ae(M)..")"end;ar(as)end;local function ax(ay,az,aA,aB)if aq(ay)or aq(az)then return end;at("perform arithmetic on",ay,{"number"},aA)at("perform arithmetic on",az,{"number"},aB)end;local function aC(ay,az)if aq(ay)or aq(az)then return end;local aD=f(ay)local aE=f(az)if aD~=aE then ar("attempt to compare "..aD.." with "..aE)elseif aD~="string"and aD~="number"then ar("attempt to compare two "..aD.." values")end end;local function aF()u()u("-- debug_locals --")for aG,a0 in e(al)do u("-> block "..aG)for aH,aI in d(a0.locals)do u("    ",aH,v(aI.value):sub(1,40))end;u()end;u()end;local function aJ()local aK=al[#al]local aL={locals={}}c.insert(al,aL)end;local function aM()c.remove(al)end;local function aN(s)for o=#al,1,-1 do local aL=al[o]if aL.locals[s]~=nil then return aL.locals[s]end end;return nil end;local function aO(s)local aP=aN(s)if aP~=nil then return aP.value else return aj[s]end end;local function aQ(s,C)local aP=aN(s)if aP~=nil then aP.value=C else aj[s]=C end end;local function aR(s,C)local aL=al[#al]aL.locals[s]={value=C}end;local function aS(G)local n={}n.n=0;if G~=nil then for o,C in e(G)do if o==#G then local aT=l(an(C))for p=1,aT.n do n[o+p-1]=aT[p]end;n.n=o+aT.n-1 else local aU=an(C)n[o]=aU end end end;return n end;an=function(M)if M.type=="index"then local C=an(M.value)if ak and not aq(C)then at("index",C,{"table","string"},M.value)end;if M.name~=nil then return C[M.name]else local M=an(M.expr)return C[M]end elseif M.type=="name"then return aO(M.name)elseif M.type=="unary"then local C=an(M.value)if M.uop=="-"then if ak and not aq(C)then at("perform arithmetic on",C,{"number"},M.value)end;return-C elseif M.uop=="#"then if ak and not aq(C)then at("get length of",C,{"string","table"},M.value)end;return#C elseif M.uop=="not"then return not C end;error("uop: "..M.uop)elseif M.type=="binary"then local ay=an(M.left)if M.op=="and"then if ay then return an(M.right)else return ay end elseif M.op=="or"then if not ay then return an(M.right)else return ay end end;local az=an(M.right)if M.op=="+"then if ak then ax(ay,az,M.left,M.right)end;return ay+az elseif M.op=="-"then if ak then ax(ay,az,M.left,M.right)end;return ay-az elseif M.op=="*"then if ak then ax(ay,az,M.left,M.right)end;return ay*az elseif M.op=="%"then if ak then ax(ay,az,M.left,M.right)end;return ay%az elseif M.op=="^"then if ak then ax(ay,az,M.left,M.right)end;return ay^az elseif M.op=="/"then if ak then ax(ay,az,M.left,M.right)end;return ay/az elseif M.op==".."then if ak and not aq(ay)and not aq(az)then at("concatenate",ay,{"string","number"},M.left)at("concatenate",az,{"string","number"},M.right)end;return ay..az elseif M.op=="=="then return ay==az elseif M.op=="<"then if ak then aC(ay,az)end;return ay<az elseif M.op=="<="then if ak then aC(ay,az)end;return ay<=az elseif M.op=="~="then return ay~=az elseif M.op==">"then if ak then aC(ay,az)end;return ay>az elseif M.op==">="then if ak then aC(ay,az)end;return ay>=az end;error("op: "..M.op)elseif M.type=="constant"then return M.value elseif M.type=="table"then local aV={}local aG=1;for o,P in e(M.fields)do if o==#M.fields and P.type=="value"then local G=l(an(P.value))for p=1,G.n do aV[aG+p-1]=G[p]end else local C=an(P.value)if P.type=="name"then aV[P.name]=C elseif P.type=="expr"then local M=an(P.expr)aV[M]=C else aV[aG]=C;aG=aG+1 end end end;return aV elseif M.type=="function"then return ag(M.body,M.params,al,aj,ak)elseif M.type=="call"then local aW=an(M.value)local aX=aS(M.args)if ak and not aq(aW)then at("call",aW,{"function"},M.value)end;return aW(unpack(aX))elseif M.type=="invoke"then local C=an(M.value)if ak and not aq(C)then at("index",C,{"table","string"},M.value)end;local aW=C[M.name]if ak and not aq(aW)and f(aW)~="function"then ar("attempt to call method '"..M.name.."' (a "..f(aW).." value)")end;local aX=aS(M.args)return aW(C,unpack(aX))elseif M.type=="vararg"then if am~=nil then return unpack(am)else ar("cannot use '...' outside a vararg function")end else error("cannot evaluate "..M.type)end end;ao=function(K)ap.stmt=K;local code=0;local results=nil;if K.type=="local_assign"then local n=aS(K.values)for o,Y in e(K.targets)do aR(K.targets[o],n[o])end elseif K.type=="assign"then local n=aS(K.values)for o,Y in e(K.targets)do if Y.type=="name"then aQ(Y.name,n[o])elseif Y.type=="index"then local C=an(Y.value)if ak and not aq(C)then at("index",C,{"table","string"},Y.value)end;if Y.name~=nil then C[Y.name]=n[o]else local M=an(Y.expr)C[M]=n[o]end else error("cannot assign to "..Y.type)end end elseif K.type=="if"then local aY=an(K.cond)local I=K.elsebody;if aY then I=K.body else for o,elt in e(K.elseifs)do aY=an(elt.cond)if aY then I=elt.body;break end end end;if I~=nil then aJ()for J,aZ in e(I)do code,results=ao(aZ)if code>0 then break end end;aM()end elseif K.type=="while"or K.type=="repeat"then local aY;if K.type=="while"then aY=an(K.cond)else aY=true end;local I=K.body;while aY do aJ()for J,aZ in e(K.body)do code,results=ao(aZ)if code>0 then break end end;aM()if code==1 then break elseif code==2 then code=0;break end;aY=an(K.cond)if K.type=="repeat"then aY=not aY end end elseif K.type=="do"then aJ()for J,aZ in e(K.body)do code,results=ao(aZ)if code>0 then break end end;aM()elseif K.type=="expr"then an(K.expr)elseif K.type=="local_function"then aR(K.name,ag(K.body,K.params,al,aj,ak))elseif K.type=="function"then local E={positional={},vararg=K.params.vararg}if K.method then c.insert(E.positional,"self")end;for aG,a0 in d(K.params.positional)do c.insert(E.positional,a0)end;local aW=ag(K.body,E,al,aj,ak)if#K.name==1 then aQ(K.name[1],aW)else local n=aO(K.name[1])for o=2,#K.name-1 do n=n[K.name[o]]end;n[K.name[#K.name]]=aW end elseif K.type=="return"then code=1;results=aS(K.values)elseif K.type=="fornum"then local a_=an(K.start)local b0=an(K.stop)local b1=1;if K.step~=nil then b1=an(K.step)end;if ak then if f(a_)~="number"then ar("'for' initial value must be a number")elseif f(b0)~="number"then ar("'for' limit must be a number")elseif f(b1)~="number"then ar("'for' step must be a number")end end;for o=a_,b0,b1 do aJ()aR(K.target,o)for J,aZ in e(K.body)do code,results=ao(aZ)if code>0 then break end end;aM()if code==1 then break elseif code==2 then code=0;break end end elseif K.type=="forin"then local G=aS(K.values)local b2,aI,b3=unpack(G)while true do local n=l(b2(aI,b3))b3=n[1]if b3==nil then break end;aJ()for o,Y in e(K.targets)do aR(K.targets[o],n[o])end;for J,aZ in e(K.body)do code,results=ao(aZ)if code>0 then break end end;aM()if code==1 then break elseif code==2 then code=0;break end end elseif K.type=="break"then code=2 else error("cannot evaluate statement '"..K.type.."'")end;return code,results end;local function b4(...)local n=l(...)aJ()if E~=nil then for o,b5 in e(E.positional)do aR(b5,n[o])end;if E.vararg then am={}am.n=0;for o=#E.positional+1,n.n do am.n=am.n+1;am[am.n]=n[o]end end end;for J,K in e(I)do code,results=ao(K)if code==1 then break elseif code>1 then error("unexpected code "..code)end end;aM()if code==1 then return unpack(results)end end;return b4 end;ag=function(I,E,ai,aj)if ai==nil then ai={{locals={}}}else ai={unpack(ai)}end;return function(...)local b6=ah(I,E,ai,aj,not not _G.DEBUG_INTERPRETER)return b6(...)end end;local function b7(I,aj)return ag(I,nil,nil,aj)end;return b7 end,['lexer']=function(...)local t=a("utils")local ab=t.contains;local ac=t.get_identifier;local v=t.dump;local u=t.print;local b8={'function','elseif','repeat','return','break','false','local','until','while','else','then','true','and','end','for','nil','not','do','if','in','or'}local b9={'...','..','~=','==','<=','>=','+','-','*','/','%','^','<','>','#','=','.','(',')','[',']','{','}',',',';',':'}local ba={}local bb={}bb.__tostring=function()return"LuaLexer: "..ac(elt)end;local function bc(bd,be,bf)if f(bf)~="string"then bf="[string]"end;local self={}h(self,bb)local bg=1;local bh=g.sub(be,1,1)local bi={}local function bj(bk)local bl,bm=self.get_row_col()u("Current: "..self.dump())error(bf..":"..bl..": "..bk,0)end;local function bn(bo)if bo==nil then bo=1 end;bg=bg+bo;bh=g.sub(be,bg,bg)end;local function bp(bq)return g.sub(be,bg,bg+bq-1)end;local function br(bs)bg=bs;bh=g.sub(be,bg,bg)end;local function bt()while true do local Y=g.find(be,"[^\n\r\t ]",bg)if Y==nil then Y=#be+1 end;if Y~=bg then br(Y)else if bp(2)~="--"then break else local bu=g.match(be,"^--%[(=*)%[",bg)if bu~=nil then Y=g.find(be,"%]"..bu.."%]",bg)if Y==nil then bj("long comment not closed")end;br(Y+#bu+2)else Y=g.find(be,"\n",bg,true)if Y==nil then Y=#be end;br(Y+1)end end end end end;local function bv()local bw=""for J,bx in d(b9)do if#bw~=#bx then bw=bp(#bx)end;if bw==bx then bn(#bx)return bx end end;return nil end;local function by()local s=g.match(be,"^[a-zA-Z_][a-zA-Z0-9_]*",bg)if s~=nil then bn(#s)return s end;return nil end;local function bz()if bh~="\\"then bj("invalid string escape")end;bn(1)local bA=g.match(be,"^([0-9]+)",bg)if bA~=nil then local C=tonumber(bA)if C>255 then bj("escape sequence too large")end;bn(#bA)return g.char(C)end;local bB=bh;if bB==""then bj("eof while parsing string escape")end;bn(1)if bB=="a"then return"\a"elseif bB=="b"then return"\b"elseif bB=="f"then return"\f"elseif bB=="n"then return"\n"elseif bB=="r"then return"\r"elseif bB=="t"then return"\t"elseif bB=="v"then return"\v"else return bB end end;local function bC()local bu=g.match(be,"^%[(=*)%[",bg)if bu==nil then return nil end;bn(2+#bu)if bh=="\n"then bn(1)end;local bD="]"..bu.."]"local bk=""while true do if bh==""then bj("eof while reading string")elseif bh=="]"then if bp(#bD)==bD then bn(#bD)break else bk=bk..bh;bn(1)end else bk=bk..bh;bn(1)end end;return bk end;local function bE()if bh~='"'and bh~="'"then return nil end;local bF=bh;bn(1)local bk=""while true do if bh=="\\"then bk=bk..bz()elseif bh==bF then bn(1)break elseif bh==""then bj("eof while reading string")elseif bh=="\n"then bj("unexpected newline in string")else bk=bk..bh;bn(1)end end;return bk end;local function bG()local bk=bE()if bk==nil then bk=bC()end;return bk end;local function bH()local C=g.match(be,"^0[xX][0-9a-fA-F]+",bg)if C~=nil then assert(tonumber(C)~=nil,"failed to read number")bn(#C)return tonumber(C)end;C=g.match(be,"^([0-9]*%.[0-9]+)",bg)if C==nil then C=g.match(be,"^([0-9]+)",bg)end;if C==nil then return nil end;bn(#C)local bI=g.match(be,"^([eE]%-?[0-9]+)",bg)if bI~=nil then bn(#bI)C=C..bI end;assert(tonumber(C)~=nil,"failed to read number")return tonumber(C)end;local function bJ()self.eof=false;self.keyword=nil;self.name=nil;self.number=nil;self.string=nil;self.token=nil end;self.next=function()bt()bi[1]=bi[2]bi[2]=bg;bJ()if bh==""then self.eof=true;return end;local s=by()if s~=nil then if ab(b8,s)then self.keyword=s else self.name=s end;return end;local bK=bH()if bK~=nil then self.number=bK;return end;local bk=bG()if bk~=nil then self.string=bk;return end;local bx=bv()if bx~=nil then self.token=bx;return end;bj("unexpected \""..bp(1).."\"")end;self.dump=function()if self.eof==true then return"end-of-file"elseif self.keyword~=nil then return"keyword "..v(self.keyword)..""elseif self.name~=nil then return"name "..v(self.name)..""elseif self.string~=nil then return"string "..v(self.string)..""elseif self.number~=nil then return"number "..v(self.number)..""elseif self.token~=nil then return"token "..v(self.token)..""else return"unknown"end end;local bL=1;local bM=1;local bN=1;self.get_row_col=function()while bN<bg do local Y=g.find(be,"\n",bN,true)if Y==nil or Y>bg then break else bL=bL+1;bN=Y+1 end end;return bL,bM end;self.restore=function()if bi[1]==nil then bj("cannot restore")end;br(bi[1])bi={}self.next()end;self.next()return self end;h(ba,{__call=bc,__tostring=function(elt)return"LuaLexer"end})return ba end,['loadstring']=function(...)local bO=a("parser")local b7=a("interpreter")local bP=function(be,bf,aj)local bQ,bR=pcall(function()return bO(be,bf)end)if not bQ then return nil,bR end;local aW=b7(bR.body,aj)return aW end;return bP end,['main']=function(...)local bP=a("loadstring")local bS=_G or _ENV;bS.loadstring=bP;local bT=eventChatCommand;local function bU(bk)return j(bk):gsub("&","&amp;"):gsub("<","&lt;"):gsub(">","&gt;")end;function eventChatCommand(s,bV)if bV:sub(1,5)=="eval "then local be=bV:sub(6)local bQ,bW=pcall(function()local aW,bW=bP(be)if not aW then error(bW,0)end;local aV=aW()end)if not bQ then ui.addPopup(0x4e415421,0,"<text align='center'>Lua error: "..bU(bW),s,50,50,nil,true)end elseif bT~=nil then return bT(s,bV)end end end,['parser']=function(...)local t=a("utils")local ab=t.contains;local ac=t.get_identifier;local v=t.dump;local u=t.print;local ba=a("lexer")local bO={}local bb={}bb.__tostring=function()return"LuaParser: "..ac(elt)end;local function bc(bd,be,bf)if f(bf)~="string"then bf="[string]"end;local self={}h(self,bb)local bX=ba(be,bf)local function bY(bk)local bl,bm=bX.get_row_col()u("Current: "..bX.dump())error(bf..":"..bl..": "..bk,0)end;local bZ={["+"]={10,10},["-"]={10,10},["*"]={11,11},["%"]={11,11},["^"]={14,13},["/"]={11,11},[".."]={9,8},["=="]={3,3},["<"]={3,3},["<="]={3,3},["~="]={3,3},[">"]={3,3},[">="]={3,3},["and"]={2,2},["or"]={1,1}}local b_={["not"]=12,["-"]=12,["#"]=12}local c0,c1;local function c2(bx)if bX.token~=bx then bY("expected '"..bx.."', got "..bX.dump())end;bX.next()end;local function c3(c4)if bX.keyword~=c4 then bY("expected '"..c4 .."', got "..bX.dump())end;bX.next()end;local function c5()local s=bX.name;if s==nil then bY("expected name, got "..bX.dump())end;bX.next()return s end;local function c6()if bX.token=='['then bX.next()local M=c0()c2(']')c2('=')local C=c0()return{type="expr",expr=M,value=C}elseif bX.name~=nil then local s=bX.name;bX.next()if bX.token=='='then bX.next()local C=c0()return{type="name",name=s,value=C}else bX.restore()end end;local C=c0()return{type="value",value=C}end;local function c7()c2('{')local c8={}if bX.token~='}'then while true do local P=c6()c.insert(c8,P)if bX.token~=','and bX.token~=';'then break else bX.next()if bX.token=='}'then break end end end end;c2('}')return{type="table",fields=c8}end;local function c9()c2('(')local E={positional={},vararg=false}if bX.token~=')'then while true do if bX.name~=nil then c.insert(E.positional,bX.name)bX.next()elseif bX.token=="..."then E.vararg=true;bX.next()else bY("cannot read param")end;if bX.token==","then bX.next()else break end end end;c2(')')return E end;local function ca()return bX.keyword=="end"or bX.keyword=="else"or bX.keyword=="elseif"or bX.keyword=="until"end;local function cb()local I={}while not ca()do local K=c1()if K==nil then bY("unexpected "..bX.dump())end;c.insert(I,K)end;return I end;local function cc()local I=cb()c3("end")return I end;local function cd()c3("function")local E=c9()local I=cc()return{type="function",params=E,body=I}end;local function ce()local G={}while true do local M=c0()c.insert(G,M)if bX.token==","then bX.next()else break end end;return G end;local function cf()if bX.token=='('then local aX={}bX.next()if bX.token~=')'then aX=ce()end;c2(')')return aX elseif bX.token=='{'then local aX={}c.insert(aX,c7())return aX elseif bX.string~=nil then local aX={}c.insert(aX,{type="constant",value=bX.string})bX.next()return aX else return nil end end;local function cg()local aV;if bX.token=="("then bX.next()aV=c0()c2(')')elseif bX.name~=nil then aV={type="name",name=bX.name}bX.next()else bY("expected '(' or name")end;while true do if bX.token=="."then bX.next()local s=c5()aV={type="index",value=aV,name=s}elseif bX.token=="["then bX.next()local M=c0()aV={type="index",value=aV,expr=M}c2(']')elseif bX.token==":"then bX.next()local s=c5()local aX=cf()if aX==nil then bY("expected call args")end;aV={type="invoke",value=aV,name=s,args=aX}else local aX=cf()if aX~=nil then aV={type="call",value=aV,args=aX}else break end end end;return aV end;local function ch()local aV=nil;if bX.number~=nil then aV={type="constant",value=tonumber(bX.number)}bX.next()elseif bX.string~=nil then aV={type="constant",value=bX.string}bX.next()elseif bX.keyword=="nil"then aV={type="constant",value=nil}bX.next()elseif bX.keyword=="true"then aV={type="constant",value=true}bX.next()elseif bX.keyword=="false"then aV={type="constant",value=false}bX.next()elseif bX.token=="..."then aV={type="vararg"}bX.next()elseif bX.token=="{"then aV=c7()elseif bX.keyword=="function"then aV=cd()elseif bX.name~=nil or bX.token=='('then aV=cg()end;if aV==nil then bY("expected expression, got "..bX.dump())end;return aV end;c0=function(ci)if ci==nil then ci=0 end;local ay;local cj=bX.keyword or bX.token;if b_[cj]~=nil then bX.next()ay={type="unary",uop=cj,value=c0(b_[cj])}else ay=ch()end;local au=bX.keyword or bX.token;while bZ[au]~=nil and bZ[au][1]>ci do bX.next()local az=c0(bZ[au][2])ay={type="binary",left=ay,op=au,right=az}au=bX.keyword or bX.token end;return ay end;local function ck()assert(bX.keyword=="function")bX.next()local s=c5()local E=c9()local I=cc()return{type="local_function",name=s,params=E,body=I}end;local function cl()local cm={}while true do c.insert(cm,c5())if bX.token==","then bX.next()else break end end;local G=nil;if bX.token=="="then bX.next()G=ce()end;return{type="local_assign",targets=cm,values=G}end;local function cn()if bX.keyword~="function"then return nil end;bX.next()local s={}c.insert(s,c5())while bX.token=="."do bX.next()c.insert(s,c5())end;local co=bX.token==':'if co then bX.next()c.insert(s,c5())end;local E=c9()local I=cc()return{type="function",name=s,method=co,params=E,body=I}end;local function cp()if bX.keyword~="local"then return nil end;bX.next()if bX.keyword=="function"then return ck()elseif bX.name~=nil then return cl()else bY("exported 'function' or name")end end;local function cq()if bX.keyword~="if"then return nil end;bX.next()local aY=c0()c3("then")local I=cb()local cr={}local cs=nil;while bX.keyword=="elseif"do bX.next()local aY=c0()c3("then")local ct=cb()c.insert(cr,{cond=aY,body=ct})end;if bX.keyword=="else"then bX.next()cs=cb()end;c3("end")return{type="if",cond=aY,body=I,elseifs=cr,elsebody=cs}end;local function cu()if bX.keyword~="while"then return nil end;bX.next()local aY=c0()c3("do")local I=cc()return{type="while",cond=aY,body=I}end;local function cv()if bX.keyword~="repeat"then return nil end;bX.next()local I=cb()c3("until")local aY=c0()return{type="repeat",cond=aY,body=I}end;local function cw()if bX.keyword~="break"then return nil end;bX.next()return{type="break"}end;local function cx(M)return M.type=="index"or M.type=="name"end;local function cy()if bX.name==nil and bX.token~='('then return nil end;local M=cg()if bX.token==","or bX.token=="="then local cm={}if not cx(M)then bY("cannot assign to expr")end;c.insert(cm,M)while bX.token==","do bX.next()M=cg()if not cx(M)then bY("cannot assign to expr")end;c.insert(cm,M)end;c2("=")local G=ce()return{type="assign",targets=cm,values=G}else return{type="expr",expr=M}end end;local function cz()if bX.keyword~="return"then return nil end;bX.next()local G={}if not ca()and bX.token~=";"then G=ce()end;return{type="return",values=G}end;local function cA()if bX.keyword~="do"then return nil end;bX.next()local I=cc()return{type="do",body=I}end;local function cB()if bX.keyword~="for"then return nil end;bX.next()local Y=c5()if bX.token=="="then bX.next()local a_=c0()c2(",")local b0=c0()local b1=nil;if bX.token==","then bX.next()b1=c0()end;c3("do")local I=cc()return{type="fornum",target=Y,start=a_,stop=b0,step=b1,body=I}elseif bX.keyword=="in"or bX.token==","then local cm={Y}while bX.token==","do bX.next()c.insert(cm,c5())end;c3("in")local G=ce()c3("do")local I=cc()return{type="forin",targets=cm,values=G,body=I}end end;c1=function()local bl,bm=bX.get_row_col()local aV=cn()or cp()or cq()or cu()or cz()or cA()or cw()or cB()or cv()or cy()if aV then aV._chunk=bf;aV._row=bl;aV._col=bm;while bX.token==";"do bX.next()end end;return aV end;self.body={}while bX.token==";"do bX.next()end;while not bX.eof do local K=c1()if not K then bY("unexpected "..bX.dump())end;c.insert(self.body,K)end;return self end;h(bO,{__call=bc,__tostring=function(elt)return"LuaParser"end})return bO end,['utils']=function(...)local function ab(cC,cD)for aG,a0 in d(cC)do if a0==cD then return true end end;return false end;local function ac(elt)local cE=b(elt)h(elt,nil)local cF,cG=g.match(j(elt),"^([a-z]+): ([a-fA-F0-9]+)$")h(elt,cE)if cF==f(elt)then return cG end;return"(lost)"end;local cH;local function cI(bk)bk=g.gsub(bk,"\\","\\\\")bk=g.gsub(bk,"'","\\'")bk=g.gsub(bk,"\n","\\n")bk=g.gsub(bk,"\r","\\r")bk=g.gsub(bk,"\t","\\t")local aV="'"aV=aV..bk;aV=aV.."'"return aV end;local function cJ(n,cK)if cK==nil then cK={}end;if ab(cK,n)then return"("..j(n)..")"end;c.insert(cK,n)local aV="{"local cL=false;for aG,a0 in d(n)do if cL then aV=aV..", "else cL=true end;local cM=g.sub(aG,1,1)if g.match(cM,"^[a-zA-Z_][a-zA-Z0-9_]*$")then aV=aV..aG else aV=aV.."["..cH(aG,cK).."]"end;aV=aV.." = "aV=aV..cH(a0,cK)end;aV=aV.."}"return aV end;cH=function(elt,cK)local cN=f(elt)if cN=="string"then return cI(elt,cK)elseif cN=="table"then return cJ(elt,cK)elseif cN=="function"or cN=="thread"then return"("..j(elt)..")"else return j(elt)end end;local function u(...)local aX=l(...)local cO=""for o=1,aX.n do if o~=1 then cO=cO.."  "end;cO=cO..j(aX[o])end;_G.print(cO)end;return{dump=cH,print=u,contains=ab,get_identifier=ac}end})a("main")end
  2.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement