1 line
44 KiB
Lua
1 line
44 KiB
Lua
|
function a(U)for V,W in pairs(U)do U[W]=true end return U end function b(U)local V=0 for W in pairs(U)do V=V+1 end return V end function c(U,V,W)if U.Print then return U.Print()end V=V or 0 local X=(b(U)>1)local Y=string.rep(' ',V+1)local Z="{"..(X and'\n'or'')for ab,bb in pairs(U)do if type(bb)~='function'and not W(ab)then Z=Z..(X and Y or'')if type(ab)=='number'then elseif type(ab)=='string'and ab:match("^[A-Za-z_][A-Za-z0-9_]*$")then Z=Z..ab.." = "elseif type(ab)=='string'then Z=Z.."[\""..ab.."\"] = "else Z=Z.."["..tostring(ab).."] = "end if type(bb)=='string'then Z=Z.."\""..bb.."\""elseif type(bb)=='number'then Z=Z..bb elseif type(bb)=='table'then Z=Z..c(bb,V+(X and 1 or 0),W)else Z=Z..tostring(bb)end if next(U,ab)then Z=Z..","end if X then Z=Z..'\n'end end end Z=Z..(X and string.rep(' ',V)or'').."}"return Z end function d(U,V)V=V or function()return false end return c(U,0,V)end local k=a{' ','\n','\t','\r'}local l={['\r']='\\r',['\n']='\\n',['\t']='\\t',['"']='\\"',["'"]="\\'",['\\']='\\'}local m={['r']='\r',['n']='\n',['t']='\t',['"']='"',["'"]="'",['\\']='\\'}local n=a{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'}local o=a{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','0','1','2','3','4','5','6','7','8','9'}local p=a{'0','1','2','3','4','5','6','7','8','9'}local q=a{'0','1','2','3','4','5','6','7','8','9','A','a','B','b','C','c','D','d','E','e','F','f'}local r=a{'+','-','*','/','^','%',',','{','}','[',']','(',')',';','#','.',':'}local s=a{'~','=','>','<'}local t=a{'and','break','do','else','elseif','end','false','for','function','goto','if','in','local','nil','not','or','repeat','return','then','true','until','while',}local u=a{'else','elseif','until','end'}local v=a{'-','not','#'}local w=a{'+','-','*','/','%','^','#','..','.',':','>','<','<=','>=','~=','==','and','or'}local x=a{}local y={['+']={6,6};['-']={6,6};['*']={7,7};['/']={7,7};['%']={7,7};['^']={10,9};['..']={5,4};['==']={3,3};['~=']={3,3};['>']={3,3};['<']={3,3};['>=']={3,3};['<=']={3,3};['and']={2,2};['or']={1,1};}local z=8 function e(U)local V=1 local W=#U local X={}local function Y(hb)hb=V+(hb or 0)if hb<=W then return U:sub(hb,hb)else return''end end local function Z()if V<=W then local hb=U:sub(V,V)V=V+1 return hb else return''end end local ab=error local function bb(hb)local ib=1 local jb=1 local kb=1 while ib<=V do if U:sub(ib,ib)=='\n'then jb=jb+1 kb=1 else kb=kb+1 end ib=ib+1 end for lb,mb in pairs(X)do print(mb.Type.."<"..mb.Source..">")end ab("file<"..jb..":"..kb..">: "..hb)end local function cb(hb)while true do local ib=Z()if ib==''then bb("Unfinished long string.")elseif ib==']'then local jb=true for kb=1,hb do if Y()=='='then V=V+1 else jb=false break end end if jb and Z()==']'then return end end end end local function db()local hb=V while Y()=='='do V=V+1 end if Y()=='['then V=V+1 return V-hb-1 else V=hb return nil end end local eb=1 local fb=1 local function gb(hb)local ib={Type=hb;LeadingWhite=U:sub(eb,fb-1);Source=U:sub(fb,V-1);}table.insert(X,ib)eb=V fb=V return ib end while true do eb=V while true do local jb=Y()if jb==''then break elseif jb=='-'then if Y(1)=='-'then V=V+2 if Y()=='['then V=V+1 local kb=db()if kb then cb(kb)else while true do local lb=Z()if lb==''or lb=='\n'then break end end end else while true do local kb=Z()if kb==''or kb=='\n'then break end end end else break end elseif k[jb]then V=V+1 else break end end local hb=U:sub(eb,V-1)fb=V local ib=Z()if ib==''then gb('Eof')break elseif ib=='\''or ib=='\"'then while true do local jb=Z()if jb=='\\'then local kb=Z()local lb=m[kb]if not lb then bb("Invalid Escape Sequence `"..kb.."`.")end elseif jb==ib then break end end gb('String')elseif n[ib]then while o[Y()]do V=V+1 end if t[U:sub(fb,V-1)]then gb('Keyword')else gb('Ident')end elseif p[ib]
|