KoboldAI-Client/extern/lualibs/lulpeg.lua

139 lines
52 KiB
Lua
Raw Normal View History

2021-12-22 01:35:57 +01:00
-- LuLPEG @a10d246290254ab5c206ed9df1394db9275166ab | /lulpeg.lua | https://github.com/pygy/LuLPeg | License: Public-domain-equivalent except for /src/re.lua, which is MIT-licensed | Minified using https://www.npmjs.com/package/luamin/v/1.0.4 and then the following regex replacement was used on the output: /(\([^()]+?\))(\([^()]+?or[^()]+?\)\([^()]+?\))/ was replaced with "\1;\2" (without the quotes)
-- Copyright (C) 2013 Lua.org, PUC-Rio.
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local _ENV,a,b,c,d=_ENV or _G,{},{},true,require;local function require(...)local e=...if a[e]then return a[e]elseif b[e]then a[e]=b[e](e)return a[e]else return d(e)end end;do local _ENV=_ENV;b['util']=function(...)local getmetatable,setmetatable,load,loadstring,next,pairs,pcall,print,rawget,rawset,select,tostring,type,unpack=getmetatable,setmetatable,load,loadstring,next,pairs,pcall,print,rawget,rawset,select,tostring,type,unpack;local f,g,h=require"math",require"string",require"table"local i,j,k,l,m=f.max,g.match,g.gsub,h.concat,h.insert;local n=require"compat"local function o()end;local p,q,r;if pcall and not n.lua52 and not c then local function s(t,u)error("illegal global read: "..tostring(u),2)end;local function v(t,u,w)error("illegal global write: "..tostring(u)..": "..tostring(w),2)end;local x=setmetatable({},{__index=s,__newindex=v})p=function()pcall(setfenv,3,x)end;function q(y)rawget(x,y)end;function r(y,w)rawset(x,y,w)end else p=o end;local _ENV=p()local z={nop=o,noglobals=p,getglobal=q,setglobal=r}z.unpack=h.unpack or unpack;z.pack=h.pack or function(...)return{n=select('#',...),...}end;if n.lua51 then local A=load;function z.load(B,C,D,x)local E;if type(B)=='string'then E=loadstring(B)else E=A(B,C)end;if x then setfenv(E,x)end;return E end else z.load=load end;if n.luajit and n.jit then function z.max(F)local G=0;for u=1,#F do G=i(G,F[u])end;return G end elseif n.luajit then local H=z.unpack;function z.max(F)local I=#F;if I<=30 or I>10240 then local G=0;for u=1,#F do local J=F[u]if J>G then G=J end end;return G else return i(H(F))end end else local H=z.unpack;local K=1000;function z.max(L)local I=#L;if I==0 then return-1 end;local M=1;local N=K;local G=L[1]repeat if N>I then N=I end;local O=i(H(L,M,N))if O>G then G=O end;M=M+K;N=N+K until M>=I;return G end end;local function P(h,D)local Q=getmetatable(h)or{}if Q.__mode then error("The mode has already been set on table "..tostring(h)..".")end;Q.__mode=D;return setmetatable(h,Q)end;z.setmode=P;function z.weakboth(h)return P(h,"kv")end;function z.weakkey(h)return P(h,"k")end;function z.weakval(h)return P(h,"v")end;function z.strip_mt(h)return setmetatable(h,nil)end;local R;do local S,T=0,{}function R(w)if not T[w]then S=S+1;T[w]=S end;return T[w]end end;z.getuniqueid=R;do local U=0;function z.gensym()U=U+1;return"___SYM_"..U end end;function z.passprint(...)print(...)return...end;local V,W,X,Y,Z;local _=2;local function a0(w,a1)a1=a1 or 0;Z={}local a2={}V(w,a2,a1,a1)local a3=l(a2,"")return a3 end;z.val_to_str=a0;function V(w,a2,a1,a4)a4=a4 or 1;if"string"==type(w)then w=k(w,"\n","\n"..(" "):rep(a1*_+a4))if j(k(w,"[^'\"]",""),'^"+$')then a2[#a2+1]=l{"'","",w,"'"}else a2[#a2+1]=l{'"',k(w,'"','\\"'),'"'}end elseif"cdata"==type(w)then Y(w,a2,a1)elseif"table"==type(w)then if Z[w]then a2[#a2+1]=Z[w]else Z[w]=tostring(w)X(w,a2,a1)end else a2[#a2+1]=tostring(w)end end;function W(y,a2,a1)if"string"==type(y)and j(y,"^[_%a][_%a%d]*$")then a2[#a2+1]=k(y,"\n",(" "):rep(a1*_+1).."\n")else a2[#a2+1]="[ "V(y,a2,a1)a2[#a2+1]=" ]"end end;function Y(w,a2,a1)a2[#a2+1]=(" "):rep(a1*_)a2[#a2+1]="["print(#a2)for u=0,#w do if u%16==0 and u~=0 then a2[#a2+1]="\n"a2[#a2+1]=(" "):rep(a1*_+2)end;a2[#a2+1]=w[u]and 1 or 0;a2[#a2+1]=u~=#w and", "or""end;print(#a2,a2[1],a2[2])a2[#a2+1]="]"end;function X(a5,a2,a1)a2[#a2+1]=Z[a5]a2[#a2+1]="{\n"for y,w in pairs(a5)do local a4=1;a2[#a2+1]=(" "):rep((a1+1)*_)W(y,a2,a1+1)if a2[#a2]==" ]"and a2[#a2-2]=="[ "then a4=8+#a2[#a2-1]end;a2[#a2+1]=" = "V(w,a2,a1+1,a4)a2[#a2+1]="\n"end;a2[#a2+1]=(" "):rep(a1*_)a2[#a2+1]="}"end;function z.expose(w)print(a0(w))return w end;function z.map(F,a6,...)if type(F)=="function"then F,a6=a6,F end;local a3={}for u=1,#F do a3[u]=a6(F[u],...)end;return a3 end;function z.selfmap(F,a6,...)if type(F)=="function"then F,a6=a6,F end;for u=1,#F do F[u]=a6(F[u],...)end;return F end;local function a7(a5,a6,...)if type(a5)=="function"then a5,a6=a6,a5 end;local a3={}for y,w in next,a5 do a3[y]=a6(w,...)end;return a3 end;z.map_all=a7;local function a8(F,a6,a2)local a9=1;if not a2 then a2=F[1]a9=2 end;for u=a9,#F do a2=a6(a2,F[u])en
local compile, expose, type, LL = ...
return function (pt, ccache)
local matcher, this_aux = compile(pt.pattern, ccache), pt.aux
return function (sbj, si, caps, ci, state)
local ref_ci = ci
local kind, bounds, openclose, aux
= caps.kind, caps.bounds, caps.openclose, caps.aux
kind [ci] = "XXXX"
bounds [ci] = si
openclose [ci] = 0
caps.aux [ci] = (this_aux or false)
local success
success, si, ci
= matcher(sbj, si, caps, ci + 1, state)
if success then
if ci == ref_ci + 1 then
caps.openclose[ref_ci] = si
else
kind [ci] = "XXXX"
bounds [ci] = si
openclose [ci] = ref_ci - ci
aux [ci] = this_aux or false
ci = ci + 1
end
else
ci = ci - 1
end
return success, si, ci
end
end]=]):gsub("XXXX",w),w.." compiler")(aL,aE,type,aG)end;aK["Carg"]=function(aM,aN)local b5=aM.aux;return function(aY,aZ,b0,aQ,b6)if b6.args.n<b5 then error("reference to absent argument #"..b5)end;b0.kind[aQ]="value"b0.bounds[aQ]=aZ;if b6.args[b5]==nil then b0.openclose[aQ]=1/0;b0.aux[aQ]=1/0 else b0.openclose[aQ]=aZ;b0.aux[aQ]=b6.args[b5]end;return true,aZ,aQ+1 end end;for t,w in pairs{"Cb","Cc","Cp"}do aK[w]=load(([=[
return function (pt, ccache)
local this_aux = pt.aux
return function (sbj, si, caps, ci, state)
caps.kind [ci] = "XXXX"
caps.bounds [ci] = si
caps.openclose [ci] = si
caps.aux [ci] = this_aux or false
return true, si, ci + 1
end
end]=]):gsub("XXXX",w),w.." compiler")(aE)end;aK["/zero"]=function(aM,aN)local a_=aL(aM.pattern,aN)return function(aY,aZ,b0,aQ,b6)local success,b7=a_(aY,aZ,b0,aQ,b6)aP(b0.aux,aQ)return success,b7,aQ end end;local function b8(u,...)return u,aD(...)end;aK["Cmt"]=function(aM,aN)local a_,a6=aL(aM.pattern,aN),aM.aux;return function(aY,aZ,b0,aQ,b6)local success,b9,ba=a_(aY,aZ,b0,aQ,b6)if not success then aP(b0.aux,aQ)return false,aZ,aQ end;local b2,b3;if ba==aQ then b2,b3=b8(a6(aY,b9,aA(aY,aZ,b9-1)))else aP(b0.aux,ba)aP(b0.kind,ba)local bb,t,bc=aH(b0,aY,aQ)b2,b3=b8(a6(aY,b9,H(bb,1,bc)))end;if not b2 then return false,aZ,aQ end;if b2==true then b2=b9 end;if type(b2)=="number"and aZ<=b2 and b2<=#aY+1 then local bd,be,bf,bg=b0.kind,b0.bounds,b0.openclose,b0.aux;for u=1,b3.n do bd[aQ]="value"be[aQ]=aZ;if b3[u]==nil then b0.openclose[aQ]=1/0;b0.aux[aQ]=1/0 else b0.openclose[aQ]=b2;b0.aux[aQ]=b3[u]end;aQ=aQ+1 end elseif type(b2)=="number"then error"Index out of bounds returned by match-time capture."else error("Match time capture must return a number, a boolean or nil".." as first argument, or nothing at all.")end;return true,b2,aQ end end;aK["string"]=function(aM,aN)local bh=aM.aux;local S=#bh;return function(aY,aZ,b0,aQ,b6)local bi=aZ-1;for u=1,S do local bj;bj=az(aY,bi+u)if bj~=bh[u]then return false,aZ,aQ end end;return true,aZ+S,aQ end end;aK["char"]=function(aM,aN)return load(([=[
local s_byte, s_char = ...
return function(sbj, si, caps, ci, state)
local c, nsi = s_byte(sbj, si), si + 1
if c ~= __C0__ then
return false, si, ci
end
return true, nsi, ci
end]=]):gsub("__C0__",tostring(aM.aux)))(az,("").char)end;local function bk(aY,aZ,b0,aQ,b6)return true,aZ,aQ end;aK["true"]=function(aM)return bk end;local function bl(aY,aZ,b0,aQ,b6)return false,aZ,aQ end;aK["false"]=function(aM)return bl end;local function bm(aY,aZ,b0,aQ,b6)return aZ>#aY,aZ,aQ end;aK["eos"]=function(aM)return bm end;local function bn(aY,aZ,b0,aQ,b6)local bo,t=az(aY,aZ),aZ+1;if bo then return true,aZ+1,aQ else return false,aZ,aQ end end;aK["one"]=function(aM)return bn end;aK["any"]=function(aM)local S=aM.aux;if S==1 then return bn else S=aM.aux-1;return function(aY,aZ,b0,aQ,b6)local b5=aZ+S;if b5<=#aY then return true,b5+1,aQ else return false,aZ,aQ end end end end;do local function bp(at)for y,w in pairs(at.aux)do if not aI(w)then error(("rule 'A' is not a pattern"):gsub("A",tostring(y)))end end end;aK["grammar"]=function(aM,aN)bp(aM)local bq=a7(aM.aux,aL,aN)local br=bq[1]return function(aY,aZ,b0,aQ,b6)m(b6.grammars,bq)local success,b7,aQ=br(aY,aZ,b0,aQ,b6)aB(b6.grammars)return success,b7,aQ end end end;local bs={kind={},bounds={},openclose={},aux={}}aK["behind"]=function(aM,aN)local a_,S=aL(aM.pattern,aN),aM.aux;return function(aY,aZ,b0,aQ,b6)if aZ<=S then return false,aZ,aQ end;local success=a_(aY,aZ-S,bs,aQ,b6)bs.aux={}return success,aZ,aQ end end;aK["range"]=function(aM)local bt=aM.aux;return function(aY,aZ,b0,aQ,b6)local bo,b7=az(aY,aZ),aZ+1;for u=1,#bt do local bu=bt[u]if bo and bu[bo]then return true,b7,aQ end end;return false,aZ,aQ end end;aK["set"]=function(aM)local g=aM.aux;return function(aY,aZ,b0,aQ,b6)local bo,b7=az(aY,aZ),aZ+1;if g[bo]then return true,b7,aQ else return false,aZ,aQ end end end;aK["range"]=aK.set;aK["ref"]=function(aM,aN)local bv=aM.aux;local aq;return function(aY,aZ,b0,aQ,b6)if not aq then if#b6.grammars==0 then error(("rule 'XXXX' used outside a grammar"):gsub("XXXX",tostring(bv)))elseif not b6.grammars[#b6.grammars][bv]then error(("rule 'XXXX' undefined in given grammar"):gsub("XXXX",tostring(bv)))end;aq=b6.grammars[#b6.grammars][bv]end;local success,b7,bw=aq(aY,aZ,b0,aQ,b6)return success,b7,bw end end;local bx=[=[
success, si, ci = XXXX(sbj, si, caps, ci, state)
if success then
return true, si, ci
else
end]=]local function by(bd,aM,aN)if aM[2].pkind==bd then return aL(aM[1],aN),by(bd,aM[2],aN)else return aL(aM[1],aN),aL(aM[2],aN)end end;aK["choice"]=function(aM,aN)local bz={by("choice",aM,aN)}local bA,bB={},{}for u=1,#bz do local f="ch"..u;bA[#bA+1]=f;bB[#bA]=bx:gsub("XXXX",f)end;bA[#bA+1]="clear_captures"bz[#bA]=aP;local bC=l{"local ",l(bA,", "),[=[ = ...
return function (sbj, si, caps, ci, state)
local aux, success = caps.aux, false
]=],l(bB,"\n"),[=[--
return false, si, ci
end]=]}return load(bC,"Choice")(H(bz))end;local bD=[=[
success, si, ci = XXXX(sbj, si, caps, ci, state)
if not success then
return false, ref_si, ref_ci
end]=]aK["sequence"]=function(aM,aN)local bE={by("sequence",aM,aN)}local bA,bB={},{}for u=1,#bE do local f="seq"..u;bA[#bA+1]=f;bB[#bA]=bD:gsub("XXXX",f)end;bA[#bA+1]="clear_captures"bE[#bA]=aP;local bC=l{"local ",l(bA,", "),[=[ = ...
return function (sbj, si, caps, ci, state)
local ref_si, ref_ci, success = si, ci
]=],l(bB,"\n"),[=[
return true, si, ci
end]=]}return load(bC,"Sequence")(H(bE))end;aK["at most"]=function(aM,aN)local a_,b5=aL(aM.pattern,aN),aM.aux;b5=-b5;return function(aY,aZ,b0,aQ,b6)local success=true;for u=1,b5 do success,aZ,aQ=a_(aY,aZ,b0,aQ,b6)if not success then break end end;return true,aZ,aQ end end;aK["at least"]=function(aM,aN)local a_,b5=aL(aM.pattern,aN),aM.aux;if b5==0 then return function(aY,aZ,b0,aQ,b6)local bF,bG;while true do local success;bF,bG=aZ,aQ;success,aZ,aQ=a_(aY,aZ,b0,aQ,b6)if not success then aZ,aQ=bF,bG;break end end;return true,aZ,aQ end elseif b5==1 then return function(aY,aZ,b0,aQ,b6)local bF,bG;local success=true;success,aZ,aQ=a_(aY,aZ,b0,aQ,b6)if not success then return false,aZ,aQ end;while true do local success;bF,bG=aZ,aQ;success,aZ,aQ=a_(aY,aZ,b0,aQ,b6)if not success then aZ,aQ=bF,bG;break end end;return true,aZ,aQ end else return function(aY,aZ,b0,aQ,b6)local bF,bG;local success=true;for t=1,b5 do success,aZ,aQ=a_(aY,aZ,b0,aQ,b6)if not success then return false,aZ,aQ end end;while true do local success;bF,bG=aZ,aQ;success,aZ,aQ=a_(aY,aZ,b0,aQ,b6)if not success then aZ,aQ=bF,bG;break end end;return true,aZ,aQ end end end;aK["unm"]=function(aM,aN)if aM.pkind=="any"and aM.aux==1 then return bm end;local a_=aL(aM.pattern,aN)return function(aY,aZ,b0,aQ,b6)local success,t,t=a_(aY,aZ,b0,aQ,b6)return not success,aZ,aQ end end;aK["lookahead"]=function(aM,aN)local a_=aL(aM.pattern,aN)return function(aY,aZ,b0,aQ,b6)local success,t,t=a_(aY,aZ,b0,aQ,b6)return success,aZ,aQ end end end end end;do local _ENV=_ENV;b['datastructures']=function(...)local getmetatable,pairs,setmetatable,type=getmetatable,pairs,setmetatable,type;local f,h,ay=require"math",require"table",require"util"local n=require"compat"local bH;if n.luajit then bH=require"ffi"end;local _ENV=ay.noglobals()local bI,load,bJ=ay.extend,ay.load,ay.max;local i,l,m,bK=f.max,h.concat,h.insert,h.sort;local bL={}local bM,bN,bO;local bP={}local function bQ(bR)local av=setmetatable(load(l{"return{ [0]=false",(", false"):rep(bR)," }"})(),bP)return av end;if n.jit then local bS,bT={v={}}function bP.__index(g,u)if u==nil or u>g.upper then return nil end;return g.v[u]end;function bP.__len(g)return g.upper end;function bP.__newindex(g,u,w)g.v[u]=w end;bT=bH.metatype('struct { int upper; bool v[?]; }',bP)function bM(h)if type(h)=="number"then local a3=bT(h+1)a3.upper=h;return a3 end;local bR=bJ(h)bS.upper=bR;if bR>255 then error"bool_set overflow"end;local av=bT(bR+1)av.upper=bR;for u=1,#h do av[h[u]]=true end;return av end;function bN(g)return type(g)=="cdata"and bH.istype(g,bT)end;bO=bN else function bM(h)if type(h)=="number"then return bQ(h)end;local av=bQ(bJ(h))for u=1,#h do av[h[u]]=true end;return av end;function bN(g)return false end;function bO(g)return getmetatable(g)==bP end end;local function bU(bV,bW)bW=bV<=bW and bW or-1;local av=bM(bW)for u=bV,bW do av[u]=true end;return av end;local bX,bY={},{}local function bZ(g,b_)if type(g)=="number"then b_[g]=true;return b_ else return g end end;local function c0(am,an)bX[am]=nil;bY[an]=nil end;local function c1(am,an)local bR=i(type(am)=="number"and am or#am,type(an)=="number"and an or#an)local c2,c3=bZ(am,bX),bZ(an,bY)local a3=bM(bR)for u=0,bR do a3[u]=c2[u]or c3[u]or false end;c0(am,an)return a3 end;local function c4(am,an)local a3={}for u=0,255 do a3[u]=am[u]and not an[u]end;return a3 end;local function c5(g)local c6={}for u=0,255 do c6[#c6+1]=g[u]==true and u or nil end;return l(c6,", ")end;bL.binary={set={new=bM,union=c1,difference=c4,tostring=c5},Range=bU,isboolset=bN,isbyteset=bO,isset=bO}local c7={}local function c8(h)local av=setmetatable({},c7)for u=1,#h do av[h[u]]=true end;return av end;local function c9(am,a3)for y in pairs(am)do a3[y]=true end;return a3 end;local function ca(am,an)am,an=type(am)=="number"and c8{am}or am,type(an)=="number"and c8{an}or an;local a3=c8{}c9(am,a3)c9(an,a3)return a3 end;local function cb(am,an)local c6={}am,an=type(am)=="number"and c8{am}or am,type(an)=="number"and c8{an}or an;for cc in pairs(am)do if am[cc]and not an[cc]then c6[#c6+1]=cc end end;return c8(c6)end;local function cd(g)l
"V( ",
(type(pt.aux) == "string" and "\""..pt.aux.."\"")
or tostring(pt.aux)
, " )"
]],range=[[
"R( ",
escape(t_concat(map(
pt.as_is,
function(e) return '"'..e..'"' end)
, ", "))
," )"
]]}do ea[y]=load(([==[
local k, map, t_concat, to_char, escape, set_repr = ...
return function (pt, offset, prefix)
print(t_concat{offset,prefix,XXXX})
end
]==]):gsub("XXXX",w),y.." printer")(y,aC,l,cW,e8,e9)end;for y,w in pairs{["behind"]=[[ LL_pprint(pt.pattern, offset, "B ") ]],["at least"]=[[ LL_pprint(pt.pattern, offset, pt.aux.." ^ ") ]],["at most"]=[[ LL_pprint(pt.pattern, offset, pt.aux.." ^ ") ]],unm=[[LL_pprint(pt.pattern, offset, "- ")]],lookahead=[[LL_pprint(pt.pattern, offset, "# ")]],choice=[[
print(offset..prefix.."+")
local ch, i = {}, 1
while pt.pkind == "choice" do
ch[i], pt, i = pt[1], pt[2], i + 1
end
ch[i] = pt
map(ch, LL_pprint, offset.." :", "")
]],sequence=[=[
print(offset..prefix.."*")
local acc, p2 = {}
offset = offset .. " |"
while true do
if pt.pkind ~= "sequence" then -- last element
if pt.pkind == "char" then
acc[#acc + 1] = pt.aux
print(offset..'P( "'..s.char(u.unpack(acc))..'" )')
else
if #acc ~= 0 then
print(offset..'P( "'..s.char(u.unpack(acc))..'" )')
end
LL_pprint(pt, offset, "")
end
break
elseif pt[1].pkind == "char" then
acc[#acc + 1] = pt[1].aux
elseif #acc ~= 0 then
print(offset..'P( "'..s.char(u.unpack(acc))..'" )')
acc = {}
LL_pprint(pt[1], offset, "")
else
LL_pprint(pt[1], offset, "")
end
pt = pt[2]
end
]=],grammar=[[
print(offset..prefix.."Grammar")
for k, pt in pairs(pt.aux) do
local prefix = ( type(k)~="string"
and tostring(k)
or "\""..k.."\"" )
LL_pprint(pt, offset.." ", prefix .. " = ")
end
]]}do ea[y]=load(([[
local map, LL_pprint, pkind, s, u, flatten = ...
return function (pt, offset, prefix)
XXXX
end
]]):gsub("XXXX",w),y.." printer")(aC,eb,type,g,ay,by)end;for t,ee in pairs{"C","Cs","Ct"}do ea[ee]=function(aM,ab,ec)print(ab..ec..ee)eb(aM.pattern,ab.." ","")end end;for t,ee in pairs{"Cg","Clb","Cf","Cmt","div_number","/zero","div_function","div_table"}do ea[ee]=function(aM,ab,ec)print(ab..ec..ee.." "..tostring(aM.aux or""))eb(aM.pattern,ab.." ","")end end;ea["div_string"]=function(aM,ab,ec)print(ab..ec..'/string "'..tostring(aM.aux or"")..'"')eb(aM.pattern,ab.." ","")end;for t,ee in pairs{"Carg","Cp"}do ea[ee]=function(aM,ab,ec)print(ab..ec..ee.."( "..tostring(aM.aux).." )")end end;ea["Cb"]=function(aM,ab,ec)print(ab..ec.."Cb( \""..aM.aux.."\" )")end;ea["Cc"]=function(aM,ab,ec)print(ab..ec.."Cc("..l(aC(aM.aux,tostring),", ").." )")end;local ef={}local eg=" "local function eh(b5)b5=tostring(b5)b5=b5 .."."..(" "):rep(4-#b5)return b5 end;local function ei(b0,aQ,a1,aY,b5)local bf,bd=b0.openclose,b0.kind;a1=a1 or 0;while bd[aQ]and bf[aQ]>=0 do if b0.openclose[aQ]>0 then print(l({eh(b5),eg:rep(a1),b0.kind[aQ],": start = ",tostring(b0.bounds[aQ])," finish = ",tostring(b0.openclose[aQ]),b0.aux[aQ]and" aux = "or"",b0.aux[aQ]and(type(b0.aux[aQ])=="string"and'"'..tostring(b0.aux[aQ])..'"'or tostring(b0.aux[aQ]))or""," \t",aA(aY,b0.bounds[aQ],b0.openclose[aQ]-1)}))if type(b0.aux[aQ])=="table"then aE(b0.aux[aQ])end else local bd=b0.kind[aQ]local br=b0.bounds[aQ]print(l({eh(b5),eg:rep(a1),bd,": start = ",br,b0.aux[aQ]and" aux = "or"",b0.aux[aQ]and(type(b0.aux[aQ])=="string"and'"'..tostring(b0.aux[aQ])..'"'or tostring(b0.aux[aQ]))or""}))aQ,b5=ei(b0,aQ+1,a1+1,aY,b5+1)print(l({eh(b5),eg:rep(a1),"/",bd," finish = ",tostring(b0.bounds[aQ])," \t",aA(aY,br,(b0.bounds[aQ]or 1)-1)}))end;b5=b5+1;aQ=aQ+1 end;return aQ,b5 end;function aG.cprint(b0,aQ,aY)aQ=aQ or 1;print"\nCapture Printer:\n================"ei(b0,aQ,0,aY,1)print"================\n/Cprinter\n"end;return{pprint=aG.pprint,cprint=aG.cprint}end end end;do local _ENV=_ENV;b['analyzer']=function(...)local ay=require"util"local o,ej=ay.nop,ay.weakkey;local ek,el,em=ej{},ej{},ej{}return{hasV=o,hasCmt=o,length=o,hasCapture=o}end end;do local _ENV=_ENV;b['locale']=function(...)local bI=require"util".extend;local _ENV=require"util".noglobals()return function(aF,aG)local en,bh=aG.R,aG.S;local eo={}eo["cntrl"]=en"\0\31"+"\127"eo["digit"]=en"09"eo["lower"]=en"az"eo["print"]=en" ~"eo["space"]=bh" \f\n\r\t\v"eo["upper"]=en"AZ"eo["alpha"]=eo["lower"]+eo["upper"]eo["alnum"]=eo["alpha"]+eo["digit"]eo["graph"]=eo["print"]-eo["space"]eo["punct"]=eo["graph"]-eo["alnum"]eo["xdigit"]=eo["digit"]+en"af"+en"AF"function aG.locale(h)return bI(h or{},eo)end end end end;do local _ENV=_ENV;b['match']=function(...)end end;do local _ENV=_ENV;b['factorizer']=function(...)local ipairs,pairs,print,setmetatable=ipairs,pairs,print,setmetatable;local ay=require"util"local ak,o,ep,ej=ay.id,ay.nop,ay.setify,ay.weakkey;local _ENV=ay.noglobals()local function eq(am,an,er)local ak,es=er.id,er.brk;if am==ak then return true,an elseif an==ak then return true,am elseif am==es then return true,es else return false end end;local et=ep{"unm","lookahead","C","Cf","Cg","Cs","Ct","/zero"}local eu=ep{"behind","at least","at most","Clb","Cmt","div_string","div_number","div_table","div_function"}local ev=ep{"char","set","range"}local ew;ew=setmetatable({},{__mode="k",__index=function(self,aM)local bd,a3=aM.pkind,false;if bd=="Cmt"or bd=="ref"then a3=true elseif et[bd]or eu[bd]then a3=ew[aM.pattern]elseif bd=="choice"or bd=="sequence"then a3=ew[aM[1]]or ew[aM[2]]end;ew[aM]=a3;return a3 end})return function(aF,aG)if aF.options.factorize==false then return{choice=o,sequence=o,lookahead=o,unm=o}end;local ex,aT=aF.constructors,aG.P;local ey,ez=ex.constant.truept,ex.constant.falsept;local eA=aF.set.union;local eB=ep{"char","set"}local eC={["/zero"]="__div",["div_number"]="__div",["div_string"]="__div",["div_table"]="__div",["div_function"]="__div",["at least"]="__exp",["at most"]="__exp",["Clb"]="Cg"}local function eD(am,an)do local eE,a3=eq(am,an,{id=ez,brk=ey})if eE then return a3 end end;local eF,eG=am.pkind,an.pkind;if am==an