just-bash 2.14.2 → 2.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/bin/chunks/{awk2-VTJMI54B.js → awk2-RSUCURL4.js} +1 -1
- package/dist/bin/chunks/{chunk-L2JBII6Z.js → chunk-2HVFB2TU.js} +72 -72
- package/dist/bin/{shell/chunks/chunk-ZO5PSLKR.js → chunks/chunk-ARI4VLCN.js} +1 -1
- package/dist/bin/chunks/chunk-AX6NCIX6.js +140 -0
- package/dist/bin/{shell/chunks/chunk-NLBRLRWD.js → chunks/chunk-BGGF3ELU.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-VHUYNUT7.js → chunks/chunk-DU4S5MUI.js} +1 -1
- package/dist/bin/chunks/chunk-EFPTD2CS.js +36 -0
- package/dist/bin/chunks/{chunk-SXB55JOI.js → chunk-EONWONZV.js} +1 -1
- package/dist/bin/chunks/{chunk-SDLWFYVT.js → chunk-EWDHVLQL.js} +11 -11
- package/dist/bin/{shell/chunks/chunk-SE4C7FJY.js → chunks/chunk-JDNI5HBX.js} +13 -13
- package/dist/bin/chunks/chunk-KCMUAACL.js +19 -0
- package/dist/bin/{shell/chunks/chunk-XKPFI566.js → chunks/chunk-L6XUBS6H.js} +17 -17
- package/dist/bin/{shell/chunks/chunk-A3HQTYHR.js → chunks/chunk-OXHVTSNH.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-RMQC3GS7.js → chunks/chunk-PNI5NMXP.js} +1 -1
- package/dist/bin/chunks/chunk-PXVBSPBE.js +2 -0
- package/dist/bin/{shell/chunks/chunk-YFPDB4PH.js → chunks/chunk-RA3TG4UK.js} +1 -1
- package/dist/bin/chunks/{chunk-GZHFXDDO.js → chunk-RBQGQWGV.js} +1 -1
- package/dist/bin/chunks/{chunk-THNL3XFF.js → chunk-S3QAKT3R.js} +1 -1
- package/dist/bin/chunks/{chunk-G43H2WGH.js → chunk-TTNNO45C.js} +1 -1
- package/dist/bin/chunks/chunk-UFJFAFSS.js +28 -0
- package/dist/bin/chunks/chunk-WLBA7L7U.js +23 -0
- package/dist/bin/chunks/{chunk-HJEHIH4P.js → chunk-WUYP7DID.js} +2 -2
- package/dist/bin/chunks/chunk-ZUDPEMHG.js +63 -0
- package/dist/bin/chunks/{diff-LE7GMFZD.js → diff-5NUI5BHG.js} +1 -1
- package/dist/bin/{shell/chunks/expansion-2RO5M3QC.js → chunks/expansion-QUT3FT7V.js} +1 -1
- package/dist/bin/{shell/chunks/expr-4CJYC4LY.js → chunks/expr-G4EF4POQ.js} +1 -1
- package/dist/bin/{shell/chunks/file-D5YKS5NV.js → chunks/file-MMSHRWCJ.js} +1 -1
- package/dist/bin/chunks/find-7CVMEZBO.js +2 -0
- package/dist/bin/{shell/chunks/flag-coverage-NSXW5TJP.js → chunks/flag-coverage-IK7WVGOO.js} +1 -1
- package/dist/bin/chunks/{grep-OZJTRD4D.js → grep-7BJ7HFBM.js} +1 -1
- package/dist/bin/chunks/{html-to-markdown-WVZA3MCP.js → html-to-markdown-V6PK6S5U.js} +1 -1
- package/dist/bin/{shell/chunks/jq-FIV5Q5T4.js → chunks/jq-DVZM2CEN.js} +1 -1
- package/dist/bin/{shell/chunks/js-exec-DYEFS64P.js → chunks/js-exec-RWEELTC2.js} +4 -4
- package/dist/bin/chunks/js-exec-worker.js +3 -2
- package/dist/bin/chunks/{ls-G2PXHSNX.js → ls-WONXDVOX.js} +1 -1
- package/dist/bin/chunks/{printf-P3QVL4IO.js → printf-NA7DYZBO.js} +1 -1
- package/dist/bin/chunks/{python3-3423HR2R.js → python3-V2HDKCNM.js} +2 -2
- package/dist/bin/chunks/rg-LA2FQFMS.js +2 -0
- package/dist/bin/chunks/{sed-HALRQZKY.js → sed-WWXBUNG3.js} +1 -1
- package/dist/bin/chunks/{sqlite3-CVNFMP3Z.js → sqlite3-JPU62KSL.js} +1 -1
- package/dist/bin/chunks/sqlite3-worker.js +1728 -0
- package/dist/bin/chunks/tar-GTGFEWDS.js +2 -0
- package/dist/bin/chunks/worker.js +1 -0
- package/dist/bin/chunks/{xan-MOZFJGMY.js → xan-MM3YYGD7.js} +1 -1
- package/dist/bin/chunks/xan-view-6J5MMMQB.js +2 -0
- package/dist/bin/chunks/{yq-Q47JUWL6.js → yq-CWUVVSHY.js} +1 -1
- package/dist/bin/just-bash.js +238 -238
- package/dist/bin/shell/chunks/{awk2-VTJMI54B.js → awk2-RSUCURL4.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-L2JBII6Z.js → chunk-2HVFB2TU.js} +72 -72
- package/dist/bin/{chunks/chunk-ZO5PSLKR.js → shell/chunks/chunk-ARI4VLCN.js} +1 -1
- package/dist/bin/shell/chunks/chunk-AX6NCIX6.js +140 -0
- package/dist/bin/{chunks/chunk-NLBRLRWD.js → shell/chunks/chunk-BGGF3ELU.js} +1 -1
- package/dist/bin/{chunks/chunk-VHUYNUT7.js → shell/chunks/chunk-DU4S5MUI.js} +1 -1
- package/dist/bin/shell/chunks/chunk-EFPTD2CS.js +36 -0
- package/dist/bin/shell/chunks/{chunk-SXB55JOI.js → chunk-EONWONZV.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-SDLWFYVT.js → chunk-EWDHVLQL.js} +11 -11
- package/dist/bin/shell/chunks/chunk-HC7WB764.js +2 -0
- package/dist/bin/{chunks/chunk-SE4C7FJY.js → shell/chunks/chunk-JDNI5HBX.js} +13 -13
- package/dist/bin/shell/chunks/chunk-KCMUAACL.js +19 -0
- package/dist/bin/{chunks/chunk-XKPFI566.js → shell/chunks/chunk-L6XUBS6H.js} +17 -17
- package/dist/bin/{chunks/chunk-A3HQTYHR.js → shell/chunks/chunk-OXHVTSNH.js} +1 -1
- package/dist/bin/{chunks/chunk-RMQC3GS7.js → shell/chunks/chunk-PNI5NMXP.js} +1 -1
- package/dist/bin/{chunks/chunk-YFPDB4PH.js → shell/chunks/chunk-RA3TG4UK.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-GZHFXDDO.js → chunk-RBQGQWGV.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-THNL3XFF.js → chunk-S3QAKT3R.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-G43H2WGH.js → chunk-TTNNO45C.js} +1 -1
- package/dist/bin/shell/chunks/chunk-UFJFAFSS.js +28 -0
- package/dist/bin/shell/chunks/chunk-WLBA7L7U.js +23 -0
- package/dist/bin/shell/chunks/{chunk-HJEHIH4P.js → chunk-WUYP7DID.js} +2 -2
- package/dist/bin/shell/chunks/chunk-ZUDPEMHG.js +63 -0
- package/dist/bin/shell/chunks/{diff-LE7GMFZD.js → diff-5NUI5BHG.js} +1 -1
- package/dist/bin/{chunks/expansion-2RO5M3QC.js → shell/chunks/expansion-QUT3FT7V.js} +1 -1
- package/dist/bin/{chunks/expr-4CJYC4LY.js → shell/chunks/expr-G4EF4POQ.js} +1 -1
- package/dist/bin/{chunks/file-D5YKS5NV.js → shell/chunks/file-MMSHRWCJ.js} +1 -1
- package/dist/bin/shell/chunks/find-7CVMEZBO.js +2 -0
- package/dist/bin/{chunks/flag-coverage-NSXW5TJP.js → shell/chunks/flag-coverage-IK7WVGOO.js} +1 -1
- package/dist/bin/shell/chunks/{grep-OZJTRD4D.js → grep-7BJ7HFBM.js} +1 -1
- package/dist/bin/shell/chunks/{html-to-markdown-WVZA3MCP.js → html-to-markdown-V6PK6S5U.js} +1 -1
- package/dist/bin/{chunks/jq-FIV5Q5T4.js → shell/chunks/jq-DVZM2CEN.js} +1 -1
- package/dist/bin/{chunks/js-exec-CAD5RWEY.js → shell/chunks/js-exec-AKWY6BP5.js} +4 -4
- package/dist/bin/shell/chunks/{ls-G2PXHSNX.js → ls-WONXDVOX.js} +1 -1
- package/dist/bin/shell/chunks/{printf-P3QVL4IO.js → printf-NA7DYZBO.js} +1 -1
- package/dist/bin/shell/chunks/{python3-D3QLNTTN.js → python3-TG6BXZCZ.js} +2 -2
- package/dist/bin/shell/chunks/rg-LA2FQFMS.js +2 -0
- package/dist/bin/shell/chunks/{sed-HALRQZKY.js → sed-WWXBUNG3.js} +1 -1
- package/dist/bin/shell/chunks/{sqlite3-CVNFMP3Z.js → sqlite3-JPU62KSL.js} +1 -1
- package/dist/bin/shell/chunks/tar-GTGFEWDS.js +2 -0
- package/dist/bin/shell/chunks/{xan-MOZFJGMY.js → xan-MM3YYGD7.js} +1 -1
- package/dist/bin/shell/chunks/xan-view-6J5MMMQB.js +2 -0
- package/dist/bin/shell/chunks/{yq-Q47JUWL6.js → yq-CWUVVSHY.js} +1 -1
- package/dist/bin/shell/shell.js +225 -225
- package/dist/bundle/browser.js +603 -603
- package/dist/bundle/chunks/{awk2-POPGKRAI.js → awk2-JFGEGLFP.js} +1 -1
- package/dist/bundle/chunks/{chunk-FEIOJCZD.js → chunk-43RSSTFA.js} +1 -1
- package/dist/bundle/chunks/chunk-5KI4QWT5.js +139 -0
- package/dist/bundle/chunks/{chunk-YFG2CMIF.js → chunk-5PYKJV42.js} +1 -1
- package/dist/bundle/chunks/{chunk-XORM457F.js → chunk-75FNCC7W.js} +72 -72
- package/dist/bundle/chunks/{chunk-YS3AZT3J.js → chunk-B53Y5JFV.js} +1 -1
- package/dist/bundle/chunks/{chunk-J642UCRS.js → chunk-BAQA74XA.js} +1 -1
- package/dist/bundle/chunks/{chunk-OARHFVLG.js → chunk-D6EWIDSU.js} +11 -11
- package/dist/bundle/chunks/{chunk-F55TLFGB.js → chunk-DBKNVD4L.js} +1 -1
- package/dist/bundle/chunks/{chunk-LPQPILI2.js → chunk-GJTDUJ5Q.js} +1 -1
- package/dist/bundle/chunks/chunk-HL6NGDO2.js +22 -0
- package/dist/bundle/chunks/chunk-KX3P26DQ.js +1 -0
- package/dist/bundle/chunks/{chunk-NYQYO467.js → chunk-MIMEPCXY.js} +2 -2
- package/dist/bundle/chunks/{chunk-BBXLRYSX.js → chunk-NRZWEENR.js} +1 -1
- package/dist/bundle/chunks/{chunk-VLGZJRPG.js → chunk-PYDZ2LCK.js} +1 -1
- package/dist/bundle/chunks/{chunk-YCFVLTST.js → chunk-RQ254MFG.js} +1 -1
- package/dist/bundle/chunks/{chunk-OL3S66CO.js → chunk-VBEY5J6R.js} +1 -1
- package/dist/bundle/chunks/chunk-XIZSGUXJ.js +62 -0
- package/dist/bundle/chunks/chunk-XKWWSDBF.js +35 -0
- package/dist/bundle/chunks/{chunk-YNYSPYQ5.js → chunk-YSHZL3MF.js} +13 -13
- package/dist/bundle/chunks/{expansion-ENLSRCXJ.js → expansion-UGGADTZC.js} +1 -1
- package/dist/bundle/chunks/{expr-5T3UU5KE.js → expr-DNFUYZGY.js} +1 -1
- package/dist/bundle/chunks/{file-ZIGAJ4YS.js → file-IGDTDPLG.js} +1 -1
- package/dist/bundle/chunks/find-KNMMLVJD.js +1 -0
- package/dist/bundle/chunks/{flag-coverage-QT4N2Z44.js → flag-coverage-QFOIESUP.js} +1 -1
- package/dist/bundle/chunks/{grep-3AIAIJVR.js → grep-2UMHPO7Y.js} +1 -1
- package/dist/bundle/chunks/{jq-ODXZBPLY.js → jq-LCDWFF5Y.js} +1 -1
- package/dist/bundle/chunks/{js-exec-M6UR76J5.js → js-exec-VXN6TZ7U.js} +4 -4
- package/dist/bundle/chunks/js-exec-worker.js +3 -2
- package/dist/bundle/chunks/{python3-AUFTPCU6.js → python3-DNGS4G3E.js} +2 -2
- package/dist/bundle/chunks/rg-RYV2N6B5.js +1 -0
- package/dist/bundle/chunks/{sed-VFTTATXJ.js → sed-OFX3F4FE.js} +1 -1
- package/dist/bundle/chunks/{sqlite3-56UMWEY3.js → sqlite3-TE5AIOTF.js} +1 -1
- package/dist/bundle/chunks/sqlite3-worker.js +1728 -0
- package/dist/bundle/chunks/tar-LYLTEJV3.js +1 -0
- package/dist/bundle/chunks/worker.js +1 -0
- package/dist/bundle/chunks/{xan-BXDXYEIB.js → xan-X2BIJPJV.js} +1 -1
- package/dist/bundle/chunks/xan-view-OW2TB7Z3.js +1 -0
- package/dist/bundle/chunks/{yq-MJMAR36V.js → yq-M7NFNNED.js} +1 -1
- package/dist/bundle/index.cjs +807 -807
- package/dist/bundle/index.js +174 -174
- package/dist/commands/js-exec/{worker.d.ts → js-exec-worker.d.ts} +2 -2
- package/dist/commands/sqlite3/sqlite3.d.ts +1 -0
- package/dist/commands/sqlite3/worker.js +1728 -0
- package/dist/network/dns-pin.d.ts +43 -0
- package/package.json +8 -9
- package/dist/bin/chunks/chunk-B3RU2PUI.js +0 -140
- package/dist/bin/chunks/chunk-CM4532DS.js +0 -36
- package/dist/bin/chunks/chunk-MXVNCVD6.js +0 -30
- package/dist/bin/chunks/chunk-MY5PY2PL.js +0 -2
- package/dist/bin/chunks/chunk-N5OTVT4F.js +0 -23
- package/dist/bin/chunks/chunk-P6GNZPVW.js +0 -19
- package/dist/bin/chunks/chunk-VRUXUVWB.js +0 -63
- package/dist/bin/chunks/find-GAYRV4IF.js +0 -2
- package/dist/bin/chunks/rg-C6KMBFNG.js +0 -2
- package/dist/bin/chunks/tar-DNUNEW4Z.js +0 -2
- package/dist/bin/chunks/xan-view-5SZBYPLG.js +0 -2
- package/dist/bin/shell/chunks/chunk-B3RU2PUI.js +0 -140
- package/dist/bin/shell/chunks/chunk-CM4532DS.js +0 -36
- package/dist/bin/shell/chunks/chunk-D64U2VGQ.js +0 -2
- package/dist/bin/shell/chunks/chunk-MXVNCVD6.js +0 -30
- package/dist/bin/shell/chunks/chunk-N5OTVT4F.js +0 -23
- package/dist/bin/shell/chunks/chunk-P6GNZPVW.js +0 -19
- package/dist/bin/shell/chunks/chunk-VRUXUVWB.js +0 -63
- package/dist/bin/shell/chunks/find-GAYRV4IF.js +0 -2
- package/dist/bin/shell/chunks/rg-C6KMBFNG.js +0 -2
- package/dist/bin/shell/chunks/tar-DNUNEW4Z.js +0 -2
- package/dist/bin/shell/chunks/xan-view-5SZBYPLG.js +0 -2
- package/dist/bundle/chunks/chunk-BRGMQKJV.js +0 -62
- package/dist/bundle/chunks/chunk-CR5AFCPT.js +0 -22
- package/dist/bundle/chunks/chunk-HWBSOZZR.js +0 -35
- package/dist/bundle/chunks/chunk-UNYNJIFU.js +0 -139
- package/dist/bundle/chunks/chunk-XHM67O4N.js +0 -1
- package/dist/bundle/chunks/find-TPUOAIUQ.js +0 -1
- package/dist/bundle/chunks/rg-FOQSCCX3.js +0 -1
- package/dist/bundle/chunks/tar-ANUBEFJY.js +0 -1
- package/dist/bundle/chunks/xan-view-ECQUO7AJ.js +0 -1
- /package/dist/bin/chunks/{chunk-QSDVMMYI.js → chunk-4CFAYBLV.js} +0 -0
- /package/dist/bin/chunks/{chunk-ND23BJUM.js → chunk-LCDPWJBA.js} +0 -0
- /package/dist/bin/shell/chunks/{chunk-QSDVMMYI.js → chunk-4CFAYBLV.js} +0 -0
- /package/dist/bin/shell/chunks/{chunk-ND23BJUM.js → chunk-LCDPWJBA.js} +0 -0
- /package/dist/bundle/chunks/{chunk-SYMJJMQ4.js → chunk-PXTK5WE2.js} +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as de}from"./chunk-4PRVMER6.js";import{a as D,b as _}from"./chunk-MO4RPBN2.js";import{a as x}from"./chunk-YU6OGPZR.js";import{a as
|
|
3
|
-
`,OFMT:"%.6g",NR:0,NF:0,FNR:0,FILENAME:"",RSTART:0,RLENGTH:-1,SUBSEP:"",fields:[],line:"",vars:Object.create(null),arrays:Object.create(null),arrayAliases:new Map,ARGC:0,ARGV:Object.create(null),ENVIRON:Object.create(null),functions:new Map,fieldSep:t,maxIterations:n,maxRecursionDepth:i,maxOutputSize:s,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,inEndBlock:!1,output:"",openedFiles:new Set,fs:a,cwd:o,exec:l,coverage:u,requireDefenseContext:N}}function Ee(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":return t!==0?e/t:0;case"%":return t!==0?e%t:0;case"^":case"**":return e**t;default:return 0}}function M(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function k(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}async function z(e,t){if(e.type==="regex")return e.pattern;let n=k(await t.evalExpr(e));return n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)),n}async function ye(e,t){return e?e.type==="variable"?e.name:e.type==="field"?`$${Math.floor(M(await t.evalExpr(e.index)))}`:"$0":"$0"}function
|
|
4
|
-
`,s+=2):a==="t"?(i+=" ",s+=2):(i+=a,s+=2)}else e[s]==="&"?(i+=t,s++):(i+=e[s],s++);return i}async function Qe(e,t,n){return e.length===0?"":k(await n.evalExpr(e[0])).toLowerCase()}async function Je(e,t,n){return e.length===0?"":k(await n.evalExpr(e[0])).toUpperCase()}async function Ze(e,t,n){if(e.length===0)return"";let i=k(await n.evalExpr(e[0])),s=[];for(let a=1;a<e.length;a++)s.push(await n.evalExpr(e[a]));return j(i,s)}async function Ye(e,t,n){return e.length===0?0:Math.floor(M(await n.evalExpr(e[0])))}async function et(e,t,n){return e.length===0?0:Math.sqrt(M(await n.evalExpr(e[0])))}async function tt(e,t,n){return e.length===0?0:Math.sin(M(await n.evalExpr(e[0])))}async function nt(e,t,n){return e.length===0?0:Math.cos(M(await n.evalExpr(e[0])))}async function rt(e,t,n){let i=e.length>0?M(await n.evalExpr(e[0])):0,s=e.length>1?M(await n.evalExpr(e[1])):0;return Math.atan2(i,s)}async function it(e,t,n){return e.length===0?0:Math.log(M(await n.evalExpr(e[0])))}async function st(e,t,n){return e.length===0?1:Math.exp(M(await n.evalExpr(e[0])))}function at(e,t,n){return t.random?t.random():Math.random()}async function ot(e,t,n){let i=e.length>0?M(await n.evalExpr(e[0])):Date.now();return t.vars._srand_seed=i,i}function lt(e,t){return()=>{throw new Error(`${e}() is not supported - ${t}`)}}function se(e){return()=>{throw new Error(`function '${e}()' is not implemented`)}}var U=1e4;function j(e,t){let n=0,i="",s=0;for(;s<e.length;)if(e[s]==="%"&&s+1<e.length){let a=s+1,o="",l="",u="",N,
|
|
5
|
-
`;break;case"t":i+=" ";break;case"r":i+="\r";break;case"\\":i+="\\";break;default:i+=a}s+=2}else i+=e[s++];return i}var Re=new Map([["length",$e],["substr",We],["index",Ve],["split",Ke],["sub",Xe],["gsub",qe],["match",ze],["gensub",je],["tolower",Qe],["toupper",Je],["sprintf",Ze],["int",Ye],["sqrt",et],["sin",tt],["cos",nt],["atan2",rt],["log",it],["exp",st],["rand",at],["srand",ot],["system",lt("system","shell execution not allowed in sandboxed environment")],["close",()=>0],["fflush",()=>0],["systime",se("systime")],["mktime",se("mktime")],["strftime",se("strftime")]]);function b(e){return typeof e=="number"?e!==0:!(e===""||e==="0")}function g(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function
|
|
6
|
-
`),l.length>0&&l[l.length-1]===""&&l.pop(),e.vars[a]=JSON.stringify(l),e.vars[o]=-1,u=-1}catch(C){if(C instanceof x)throw C;return-1}else l=JSON.parse(e.vars[a]),u=e.vars[o];let N=u+1;if(N>=l.length)return 0;let
|
|
7
|
-
`),u.length>0&&u[u.length-1]===""&&u.pop(),e.vars[o]=JSON.stringify(u),e.vars[l]=-1,N=-1}catch(O){if(O instanceof x)throw O;return-1}else u=JSON.parse(e.vars[o]),N=e.vars[l];let v=N+1;if(v>=u.length)return 0;let C=u[v];return e.vars[l]=v,t?W(e,t,C):$(e,C),1}async function kt(e,t){if(L(e,"tuple evaluation"),t.length===0)return"";for(let n=0;n<t.length-1;n++)await m(e,"tuple intermediate element",()=>f(e,t[n]));return m(e,"tuple final element",()=>f(e,t[t.length-1]))}be(V);function ue(e){if(e.maxOutputSize>0&&e.output.length>e.maxOutputSize)throw new P(`awk: output size limit exceeded (${e.maxOutputSize} bytes)`,"string_length",e.output)}function T(e,t){D(e.requireDefenseContext,"awk",t)}function y(e,t,n){return _(e.requireDefenseContext,"awk",t,n)}async function V(e,t){T(e,"block execution");for(let n of t)if(await y(e,"statement execution",()=>B(e,n)),Ct(e))break}function Ct(e){return e.shouldExit||e.shouldNext||e.shouldNextFile||e.loopBreak||e.loopContinue||e.hasReturn}async function B(e,t){switch(T(e,"single statement execution"),e.coverage?.hit(`awk:stmt:${t.type}`),t.type){case"block":await y(e,"nested block statement",()=>V(e,t.statements));break;case"expr_stmt":await y(e,"expression statement",()=>f(e,t.expression));break;case"print":await y(e,"print statement",()=>bt(e,t.args,t.output));break;case"printf":await y(e,"printf statement",()=>Ot(e,t.format,t.args,t.output));break;case"if":await y(e,"if statement",()=>Lt(e,t));break;case"while":await y(e,"while statement",()=>Mt(e,t));break;case"do_while":await y(e,"do-while statement",()=>Pt(e,t));break;case"for":await y(e,"for statement",()=>Tt(e,t));break;case"for_in":await y(e,"for-in statement",()=>Ft(e,t));break;case"break":e.loopBreak=!0;break;case"continue":e.loopContinue=!0;break;case"next":e.shouldNext=!0;break;case"nextfile":e.shouldNextFile=!0;break;case"exit":e.shouldExit=!0;{let n=t.code;e.exitCode=n?Math.floor(g(await y(e,"exit code expression",()=>f(e,n)))):0}break;case"return":e.hasReturn=!0;{let n=t.value;e.returnValue=n?await y(e,"return expression",()=>f(e,n)):""}break;case"delete":await y(e,"delete statement",()=>Dt(e,t.target));break}}async function bt(e,t,n){T(e,"print execution");let i=[];for(let a of t){let o=await y(e,"print argument evaluation",()=>f(e,a));typeof o=="number"?Number.isInteger(o)&&Math.abs(o)<Number.MAX_SAFE_INTEGER?i.push(String(o)):i.push(j(e.OFMT,[o])):i.push(S(o))}let s=i.join(e.OFS)+e.ORS;n?await y(e,"print redirection write",()=>Oe(e,n.redirect,n.file,s)):(e.output+=s,ue(e))}async function Ot(e,t,n,i){T(e,"printf execution");let s=S(await y(e,"printf format evaluation",()=>f(e,t))),a=[];for(let l of n)a.push(await y(e,"printf argument evaluation",()=>f(e,l)));let o=j(s,a);i?await y(e,"printf redirection write",()=>Oe(e,i.redirect,i.file,o)):(e.output+=o,ue(e))}async function Oe(e,t,n,i){T(e,"file write execution");let s=e.fs;if(!s||!e.cwd){e.output+=i,ue(e);return}let a=S(await y(e,"redirection filename evaluation",()=>f(e,n))),o=s.resolvePath(e.cwd,a);t===">"?e.openedFiles.has(o)?await y(e,"redirection append write",()=>s.appendFile(o,i)):(await y(e,"redirection overwrite write",()=>s.writeFile(o,i)),e.openedFiles.add(o)):(e.openedFiles.has(o)||e.openedFiles.add(o),await y(e,"redirection append mode write",()=>s.appendFile(o,i)))}async function Lt(e,t){if(T(e,"if execution"),b(await y(e,"if condition evaluation",()=>f(e,t.condition))))await y(e,"if consequent execution",()=>B(e,t.consequent));else if(t.alternate){let n=t.alternate;await y(e,"if alternate execution",()=>B(e,n))}}async function Mt(e,t){T(e,"while execution");let n=0;for(;b(await y(e,"while condition evaluation",()=>f(e,t.condition)));){if(n++,n>e.maxIterations)throw new P(`awk: while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await y(e,"while body execution",()=>B(e,t.body)),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function Pt(e,t){T(e,"do-while execution");let n=0;do{if(n++,n>e.maxIterations)throw new P(`awk: do-while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await y(e,"do-while body execution",()=>B(e,t.body)),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}while(b(await y(e,"do-while condition evaluation",()=>f(e,t.condition))))}async function Tt(e,t){T(e,"for execution");let n=t.init,i=t.condition,s=t.update;n&&await y(e,"for init evaluation",()=>f(e,n));let a=0;for(;!i||b(await y(e,"for condition evaluation",()=>f(e,i)));){if(a++,a>e.maxIterations)throw new P(`awk: for loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await y(e,"for body execution",()=>B(e,t.body)),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break;s&&await y(e,"for update evaluation",()=>f(e,s))}}async function Ft(e,t){T(e,"for-in execution");let n=e.arrays[t.array];if(n)for(let i of Object.keys(n)){if(e.vars[t.variable]=i,e.loopContinue=!1,await y(e,"for-in body execution",()=>B(e,t.body)),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function Dt(e,t){if(T(e,"delete execution"),t.type==="array_access"){let n=S(await y(e,"delete key evaluation",()=>f(e,t.key)));Ie(e,t.array,n)}else t.type==="variable"&&ke(e,t.name)}var q=class{ctx;program=null;rangeStates=[];constructor(t){this.ctx=t}assertDefenseContext(t){D(this.ctx.requireDefenseContext,"awk",t)}withDefenseContext(t,n){return _(this.ctx.requireDefenseContext,"awk",t,n)}execute(t){this.assertDefenseContext("program initialization"),this.program=t,this.ctx.output="";for(let n of t.functions)this.ctx.functions.set(n.name,n);this.rangeStates=t.rules.map(()=>!1)}async executeBegin(){if(this.assertDefenseContext("BEGIN execution entry"),!!this.program){for(let t of this.program.rules)if(t.pattern?.type==="begin"&&(await this.withDefenseContext("BEGIN block execution",()=>V(this.ctx,t.action.statements)),this.ctx.shouldExit))break}}async executeLine(t){if(this.assertDefenseContext("line execution entry"),!(!this.program||this.ctx.shouldExit)){$(this.ctx,t),this.ctx.NR++,this.ctx.FNR++,this.ctx.shouldNext=!1;for(let n=0;n<this.program.rules.length&&!(this.ctx.shouldExit||this.ctx.shouldNext||this.ctx.shouldNextFile);n++){let i=this.program.rules[n];i.pattern?.type==="begin"||i.pattern?.type==="end"||await this.withDefenseContext("rule match",()=>this.matchesRule(i,n))&&await this.withDefenseContext("rule block execution",()=>V(this.ctx,i.action.statements))}}}async executeEnd(){if(this.assertDefenseContext("END execution entry"),!!this.program&&!this.ctx.inEndBlock){this.ctx.inEndBlock=!0,this.ctx.shouldExit=!1;for(let t of this.program.rules)if(t.pattern?.type==="end"&&(await this.withDefenseContext("END block execution",()=>V(this.ctx,t.action.statements)),this.ctx.shouldExit))break;this.ctx.inEndBlock=!1}}getOutput(){return this.ctx.output}getExitCode(){return this.ctx.exitCode}getContext(){return this.ctx}async matchesRule(t,n){this.assertDefenseContext("rule matching");let i=t.pattern;if(!i)return!0;switch(i.type){case"begin":case"end":return!1;case"regex_pattern":return K(i.pattern,this.ctx.line);case"expr_pattern":return b(await this.withDefenseContext("expression pattern evaluation",()=>f(this.ctx,i.expression)));case"range":{let s=await this.withDefenseContext("range start pattern",()=>this.matchPattern(i.start)),a=await this.withDefenseContext("range end pattern",()=>this.matchPattern(i.end));return this.rangeStates[n]?(a&&(this.rangeStates[n]=!1),!0):s?(this.rangeStates[n]=!0,a&&(this.rangeStates[n]=!1),!0):!1}default:return!1}}async matchPattern(t){switch(this.assertDefenseContext("pattern matching"),t.type){case"regex_pattern":return K(t.pattern,this.ctx.line);case"expr_pattern":return b(await this.withDefenseContext("nested expression pattern",()=>f(this.ctx,t.expression)));default:return!1}}};var r;(function(e){e.NUMBER="NUMBER",e.STRING="STRING",e.REGEX="REGEX",e.IDENT="IDENT",e.BEGIN="BEGIN",e.END="END",e.IF="IF",e.ELSE="ELSE",e.WHILE="WHILE",e.DO="DO",e.FOR="FOR",e.IN="IN",e.BREAK="BREAK",e.CONTINUE="CONTINUE",e.NEXT="NEXT",e.NEXTFILE="NEXTFILE",e.EXIT="EXIT",e.RETURN="RETURN",e.DELETE="DELETE",e.FUNCTION="FUNCTION",e.PRINT="PRINT",e.PRINTF="PRINTF",e.GETLINE="GETLINE",e.PLUS="PLUS",e.MINUS="MINUS",e.STAR="STAR",e.SLASH="SLASH",e.PERCENT="PERCENT",e.CARET="CARET",e.EQ="EQ",e.NE="NE",e.LT="LT",e.GT="GT",e.LE="LE",e.GE="GE",e.MATCH="MATCH",e.NOT_MATCH="NOT_MATCH",e.AND="AND",e.OR="OR",e.NOT="NOT",e.ASSIGN="ASSIGN",e.PLUS_ASSIGN="PLUS_ASSIGN",e.MINUS_ASSIGN="MINUS_ASSIGN",e.STAR_ASSIGN="STAR_ASSIGN",e.SLASH_ASSIGN="SLASH_ASSIGN",e.PERCENT_ASSIGN="PERCENT_ASSIGN",e.CARET_ASSIGN="CARET_ASSIGN",e.INCREMENT="INCREMENT",e.DECREMENT="DECREMENT",e.QUESTION="QUESTION",e.COLON="COLON",e.COMMA="COMMA",e.SEMICOLON="SEMICOLON",e.NEWLINE="NEWLINE",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.DOLLAR="DOLLAR",e.APPEND="APPEND",e.PIPE="PIPE",e.EOF="EOF"})(r||(r={}));var _t=new Map([["BEGIN",r.BEGIN],["END",r.END],["if",r.IF],["else",r.ELSE],["while",r.WHILE],["do",r.DO],["for",r.FOR],["in",r.IN],["break",r.BREAK],["continue",r.CONTINUE],["next",r.NEXT],["nextfile",r.NEXTFILE],["exit",r.EXIT],["return",r.RETURN],["delete",r.DELETE],["function",r.FUNCTION],["print",r.PRINT],["printf",r.PRINTF],["getline",r.GETLINE]]);function Gt(e){return e.replace(/\[\[:space:\]\]/g,"[ \\t\\n\\r\\f\\v]").replace(/\[\[:blank:\]\]/g,"[ \\t]").replace(/\[\[:alpha:\]\]/g,"[a-zA-Z]").replace(/\[\[:digit:\]\]/g,"[0-9]").replace(/\[\[:alnum:\]\]/g,"[a-zA-Z0-9]").replace(/\[\[:upper:\]\]/g,"[A-Z]").replace(/\[\[:lower:\]\]/g,"[a-z]").replace(/\[\[:punct:\]\]/g,"[!\"#$%&'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~]").replace(/\[\[:xdigit:\]\]/g,"[0-9A-Fa-f]").replace(/\[\[:graph:\]\]/g,"[!-~]").replace(/\[\[:print:\]\]/g,"[ -~]").replace(/\[\[:cntrl:\]\]/g,"[\\x00-\\x1f\\x7f]")}var ee=class{input;pos=0;line=1;column=1;lastTokenType=null;constructor(t){this.input=t}tokenize(){let t=[];for(;this.pos<this.input.length;){let n=this.nextToken();n&&(t.push(n),this.lastTokenType=n.type)}return t.push(this.makeToken(r.EOF,"")),t}makeToken(t,n){return{type:t,value:n,line:this.line,column:this.column}}peek(t=0){return this.input[this.pos+t]||""}advance(){let t=this.input[this.pos++]||"";return t===`
|
|
2
|
+
import{a as de}from"./chunk-4PRVMER6.js";import{a as D,b as _}from"./chunk-MO4RPBN2.js";import{a as x}from"./chunk-YU6OGPZR.js";import{a as v,b as H}from"./chunk-JDNI5HBX.js";import{k as P}from"./chunk-6KZRLMG3.js";import{a as pe,b as fe,c as re}from"./chunk-GTNBSMZR.js";var Ue=1e4,Be=100,He=new H(/\s+/);function ie(e={}){let{fieldSep:t=He,maxIterations:n=Ue,maxRecursionDepth:i=Be,maxOutputSize:s=0,fs:a,cwd:o,exec:l,coverage:u,requireDefenseContext:N}=e;return{FS:" ",OFS:" ",ORS:`
|
|
3
|
+
`,OFMT:"%.6g",NR:0,NF:0,FNR:0,FILENAME:"",RSTART:0,RLENGTH:-1,SUBSEP:"",fields:[],line:"",vars:Object.create(null),arrays:Object.create(null),arrayAliases:new Map,ARGC:0,ARGV:Object.create(null),ENVIRON:Object.create(null),functions:new Map,fieldSep:t,maxIterations:n,maxRecursionDepth:i,maxOutputSize:s,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,inEndBlock:!1,output:"",openedFiles:new Set,fs:a,cwd:o,exec:l,coverage:u,requireDefenseContext:N}}function Ee(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":return t!==0?e/t:0;case"%":return t!==0?e%t:0;case"^":case"**":return e**t;default:return 0}}function M(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function k(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}async function z(e,t){if(e.type==="regex")return e.pattern;let n=k(await t.evalExpr(e));return n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)),n}async function ye(e,t){return e?e.type==="variable"?e.name:e.type==="field"?`$${Math.floor(M(await t.evalExpr(e.index)))}`:"$0":"$0"}function Se(e,t){if(e==="$0")return t.line;if(e.startsWith("$")){let n=parseInt(e.slice(1),10)-1;return t.fields[n]||""}return k(t.vars[e]??"")}function me(e,t,n){if(e==="$0")n.line=t,n.fields=n.FS===" "?t.trim().split(/\s+/).filter(Boolean):n.fieldSep.split(t),n.NF=n.fields.length;else if(e.startsWith("$")){let i=parseInt(e.slice(1),10)-1;for(;n.fields.length<=i;)n.fields.push("");n.fields[i]=t,n.NF=n.fields.length,n.line=n.fields.join(n.OFS)}else n.vars[e]=t}async function $e(e,t,n){return e.length===0?t.line.length:k(await n.evalExpr(e[0])).length}async function We(e,t,n){if(e.length<2)return"";let i=k(await n.evalExpr(e[0])),s=Math.floor(M(await n.evalExpr(e[1])))-1;if(e.length>=3){let a=Math.floor(M(await n.evalExpr(e[2])));return i.substr(Math.max(0,s),a)}return i.substr(Math.max(0,s))}async function Ve(e,t,n){if(e.length<2)return 0;let i=k(await n.evalExpr(e[0])),s=k(await n.evalExpr(e[1])),a=i.indexOf(s);return a===-1?0:a+1}async function Ke(e,t,n){if(e.length<2)return 0;let i=k(await n.evalExpr(e[0])),s=e[1];if(s.type!=="variable")return 0;let a=s.name,o=t.FS;if(e.length>=3){let u=e[2];if(u.type==="regex")o=v(u.pattern);else{let N=k(await n.evalExpr(u));o=N===" "?v("\\s+"):N}}else t.FS===" "&&(o=v("\\s+"));let l=typeof o=="string"?i.split(o):o.split(i);t.arrays[a]=Object.create(null);for(let u=0;u<l.length;u++)t.arrays[a][String(u+1)]=l[u];return l.length}async function Xe(e,t,n){if(e.length<2)return 0;let i=await z(e[0],n),s=k(await n.evalExpr(e[1])),a=await ye(e[2],n),o=Se(a,t);try{let u=v(i).replace(o,we(s)),N=u!==o?1:0;return me(a,u,t),N}catch{return 0}}async function qe(e,t,n){if(e.length<2)return 0;let i=await z(e[0],n),s=k(await n.evalExpr(e[1])),a=await ye(e[2],n),o=Se(a,t);try{let l=v(i,"g"),u=l.match(o),N=u?u.length:0,A=l.replace(o,we(s));return me(a,A,t),N}catch{return 0}}function we(e){return t=>{let n="",i=0;for(;i<e.length;)if(e[i]==="\\"&&i+1<e.length){let s=e[i+1];s==="&"?(n+="&",i+=2):s==="\\"?(n+="\\",i+=2):(n+=e[i+1],i+=2)}else e[i]==="&"?(n+=t,i++):(n+=e[i],i++);return n}}async function ze(e,t,n){if(e.length<2)return t.RSTART=0,t.RLENGTH=-1,0;let i=k(await n.evalExpr(e[0])),s=await z(e[1],n);try{let o=v(s).exec(i);if(o)return t.RSTART=o.index+1,t.RLENGTH=o[0].length,t.RSTART}catch{}return t.RSTART=0,t.RLENGTH=-1,0}async function je(e,t,n){if(e.length<3)return"";let i=await z(e[0],n),s=k(await n.evalExpr(e[1])),a=k(await n.evalExpr(e[2])),o=e.length>=4?k(await n.evalExpr(e[3])):t.line;try{let l=a.toLowerCase()==="g",u=l?0:parseInt(a,10)||1;if(l)return v(i,"g").replace(o,(A,...C)=>Ne(s,A,C.slice(0,-2)));{let N=0;return v(i,"g").replace(o,(C,...O)=>(N++,N===u?Ne(s,C,O.slice(0,-2)):C))}}catch{return o}}function Ne(e,t,n){let i="",s=0;for(;s<e.length;)if(e[s]==="\\"&&s+1<e.length){let a=e[s+1];if(a==="&")i+="&",s+=2;else if(a==="0")i+=t,s+=2;else if(a>="1"&&a<="9"){let o=parseInt(a,10)-1;i+=n[o]||"",s+=2}else a==="n"?(i+=`
|
|
4
|
+
`,s+=2):a==="t"?(i+=" ",s+=2):(i+=a,s+=2)}else e[s]==="&"?(i+=t,s++):(i+=e[s],s++);return i}async function Qe(e,t,n){return e.length===0?"":k(await n.evalExpr(e[0])).toLowerCase()}async function Je(e,t,n){return e.length===0?"":k(await n.evalExpr(e[0])).toUpperCase()}async function Ze(e,t,n){if(e.length===0)return"";let i=k(await n.evalExpr(e[0])),s=[];for(let a=1;a<e.length;a++)s.push(await n.evalExpr(e[a]));return j(i,s)}async function Ye(e,t,n){return e.length===0?0:Math.floor(M(await n.evalExpr(e[0])))}async function et(e,t,n){return e.length===0?0:Math.sqrt(M(await n.evalExpr(e[0])))}async function tt(e,t,n){return e.length===0?0:Math.sin(M(await n.evalExpr(e[0])))}async function nt(e,t,n){return e.length===0?0:Math.cos(M(await n.evalExpr(e[0])))}async function rt(e,t,n){let i=e.length>0?M(await n.evalExpr(e[0])):0,s=e.length>1?M(await n.evalExpr(e[1])):0;return Math.atan2(i,s)}async function it(e,t,n){return e.length===0?0:Math.log(M(await n.evalExpr(e[0])))}async function st(e,t,n){return e.length===0?1:Math.exp(M(await n.evalExpr(e[0])))}function at(e,t,n){return t.random?t.random():Math.random()}async function ot(e,t,n){let i=e.length>0?M(await n.evalExpr(e[0])):Date.now();return t.vars._srand_seed=i,i}function lt(e,t){return()=>{throw new Error(`${e}() is not supported - ${t}`)}}function se(e){return()=>{throw new Error(`function '${e}()' is not implemented`)}}var U=1e4;function j(e,t){let n=0,i="",s=0;for(;s<e.length;)if(e[s]==="%"&&s+1<e.length){let a=s+1,o="",l="",u="",N,A=a;for(;a<e.length&&/\d/.test(e[a]);)a++;a>A&&e[a]==="$"?(N=parseInt(e.substring(A,a),10)-1,a++):a=A;let C=()=>{if(a<e.length){if(a+1<e.length&&(e[a]==="h"&&e[a+1]==="h"||e[a]==="l"&&e[a+1]==="l")){a+=2;return}/[lzjh]/.test(e[a])&&a++}};for(;a<e.length&&/[-+ #0]/.test(e[a]);)o+=e[a++];if(e[a]==="*"){let d=t[n++],R=d!==void 0?Math.floor(Number(d)):0;R<0?(o+="-",l=String(Math.min(-R,U))):l=String(Math.min(R,U)),a++}else for(;a<e.length&&/\d/.test(e[a]);)l+=e[a++];if(l&&parseInt(l,10)>U&&(l=String(U)),e[a]==="."){if(a++,e[a]==="*"){let d=t[n++];u=String(Math.min(d!==void 0?Math.floor(Number(d)):0,U)),a++}else for(;a<e.length&&/\d/.test(e[a]);)u+=e[a++];u&&parseInt(u,10)>U&&(u=String(U))}C();let O=e[a],w=t[N!==void 0?N:n];switch(O){case"s":{let d=w!==void 0?String(w):"";if(u&&(d=d.substring(0,parseInt(u,10))),l){let R=parseInt(l,10);o.includes("-")?d=d.padEnd(R):d=d.padStart(R)}i+=d,N===void 0&&n++;break}case"d":case"i":{let d=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(d)&&(d=0);let R=d<0,h=Math.abs(d).toString();if(u){let F=parseInt(u,10);h=h.padStart(F,"0")}let c="";R?c="-":o.includes("+")?c="+":o.includes(" ")&&(c=" ");let E=c+h;if(l){let F=parseInt(l,10);o.includes("-")?E=E.padEnd(F):o.includes("0")&&!u?E=c+h.padStart(F-c.length,"0"):E=E.padStart(F)}i+=E,N===void 0&&n++;break}case"f":{let d=w!==void 0?Number(w):0;Number.isNaN(d)&&(d=0);let R=u?parseInt(u,10):6,h=d.toFixed(R);if(l){let c=parseInt(l,10);o.includes("-")?h=h.padEnd(c):h=h.padStart(c)}i+=h,N===void 0&&n++;break}case"e":case"E":{let d=w!==void 0?Number(w):0;Number.isNaN(d)&&(d=0);let R=u?parseInt(u,10):6,h=d.toExponential(R);if(O==="E"&&(h=h.toUpperCase()),l){let c=parseInt(l,10);o.includes("-")?h=h.padEnd(c):h=h.padStart(c)}i+=h,N===void 0&&n++;break}case"g":case"G":{let d=w!==void 0?Number(w):0;Number.isNaN(d)&&(d=0);let R=u?parseInt(u,10):6,h=d!==0?Math.floor(Math.log10(Math.abs(d))):0,c;if(d===0?c="0":h<-4||h>=R?(c=d.toExponential(R-1),O==="G"&&(c=c.toUpperCase())):c=d.toPrecision(R),c.includes(".")&&(c=c.replace(/\.?0+$/,"").replace(/\.?0+e/,"e")),c.includes("e")&&(c=c.replace(/\.?0+e/,"e")),l){let E=parseInt(l,10);o.includes("-")?c=c.padEnd(E):c=c.padStart(E)}i+=c,N===void 0&&n++;break}case"x":case"X":{let d=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(d)&&(d=0);let R=Math.abs(d).toString(16);if(O==="X"&&(R=R.toUpperCase()),u){let E=parseInt(u,10);R=R.padStart(E,"0")}let h=d<0?"-":"",c=h+R;if(l){let E=parseInt(l,10);o.includes("-")?c=c.padEnd(E):o.includes("0")&&!u?c=h+R.padStart(E-h.length,"0"):c=c.padStart(E)}i+=c,N===void 0&&n++;break}case"o":{let d=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(d)&&(d=0);let R=Math.abs(d).toString(8);if(u){let E=parseInt(u,10);R=R.padStart(E,"0")}let h=d<0?"-":"",c=h+R;if(l){let E=parseInt(l,10);o.includes("-")?c=c.padEnd(E):o.includes("0")&&!u?c=h+R.padStart(E-h.length,"0"):c=c.padStart(E)}i+=c,N===void 0&&n++;break}case"c":{typeof w=="number"?i+=String.fromCharCode(w):i+=String(w??"").charAt(0)||"",N===void 0&&n++;break}case"%":i+="%";break;default:i+=e.substring(s,a+1)}s=a+1}else if(e[s]==="\\"&&s+1<e.length){let a=e[s+1];switch(a){case"n":i+=`
|
|
5
|
+
`;break;case"t":i+=" ";break;case"r":i+="\r";break;case"\\":i+="\\";break;default:i+=a}s+=2}else i+=e[s++];return i}var Re=new Map([["length",$e],["substr",We],["index",Ve],["split",Ke],["sub",Xe],["gsub",qe],["match",ze],["gensub",je],["tolower",Qe],["toupper",Je],["sprintf",Ze],["int",Ye],["sqrt",et],["sin",tt],["cos",nt],["atan2",rt],["log",it],["exp",st],["rand",at],["srand",ot],["system",lt("system","shell execution not allowed in sandboxed environment")],["close",()=>0],["fflush",()=>0],["systime",se("systime")],["mktime",se("mktime")],["strftime",se("strftime")]]);function b(e){return typeof e=="number"?e!==0:!(e===""||e==="0")}function g(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function m(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}function ae(e){if(typeof e=="number")return!0;let t=String(e).trim();return t===""?!1:!Number.isNaN(Number(t))}function K(e,t){try{return v(e).test(t)}catch{return!1}}function ge(e,t){return t===""?[]:e.FS===" "?t.trim().split(/\s+/).filter(Boolean):e.fieldSep.split(t)}function Q(e,t){return t===0?e.line:t<0||t>e.fields.length?"":e.fields[t-1]??""}function oe(e,t,n){if(t===0)e.line=m(n),e.fields=ge(e,e.line),e.NF=e.fields.length;else if(t>0){for(;e.fields.length<t;)e.fields.push("");e.fields[t-1]=m(n),e.NF=e.fields.length,e.line=e.fields.join(e.OFS)}}function $(e,t){e.line=t,e.fields=ge(e,t),e.NF=e.fields.length}function Ae(e,t){if(e.FS=t,t===" ")e.fieldSep=new H(/\s+/);else try{e.fieldSep=v(t)}catch{e.fieldSep=v(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"))}}function J(e,t){switch(t){case"FS":return e.FS;case"OFS":return e.OFS;case"ORS":return e.ORS;case"OFMT":return e.OFMT;case"NR":return e.NR;case"NF":return e.NF;case"FNR":return e.FNR;case"FILENAME":return e.FILENAME;case"RSTART":return e.RSTART;case"RLENGTH":return e.RLENGTH;case"SUBSEP":return e.SUBSEP;case"ARGC":return e.ARGC}return e.vars[t]??""}function W(e,t,n){switch(t){case"FS":Ae(e,m(n));return;case"OFS":e.OFS=m(n);return;case"ORS":e.ORS=m(n);return;case"OFMT":e.OFMT=m(n);return;case"NR":e.NR=Math.floor(g(n));return;case"NF":{let i=Math.floor(g(n));if(i<e.NF)e.fields=e.fields.slice(0,i),e.line=e.fields.join(e.OFS);else if(i>e.NF){for(;e.fields.length<i;)e.fields.push("");e.line=e.fields.join(e.OFS)}e.NF=i;return}case"FNR":e.FNR=Math.floor(g(n));return;case"FILENAME":e.FILENAME=m(n);return;case"RSTART":e.RSTART=Math.floor(g(n));return;case"RLENGTH":e.RLENGTH=Math.floor(g(n));return;case"SUBSEP":e.SUBSEP=m(n);return}e.vars[t]=n}function X(e,t){let n=t,i=new Set,s=e.arrayAliases.get(n);for(;s!==void 0&&!i.has(n);)i.add(n),n=s,s=e.arrayAliases.get(n);return n}function Z(e,t,n){if(t==="ARGV")return e.ARGV[n]??"";if(t==="ENVIRON")return e.ENVIRON[n]??"";let i=X(e,t);return e.arrays[i]?.[n]??""}function le(e,t,n,i){let s=X(e,t);e.arrays[s]||(e.arrays[s]=Object.create(null)),e.arrays[s][n]=i}function ve(e,t,n){if(t==="ARGV")return e.ARGV[n]!==void 0;if(t==="ENVIRON")return e.ENVIRON[n]!==void 0;let i=X(e,t);return e.arrays[i]?.[n]!==void 0}function Ie(e,t,n){let i=X(e,t);e.arrays[i]&&delete e.arrays[i][n]}function ke(e,t){let n=X(e,t);delete e.arrays[n]}var Ce=null;function be(e){Ce=e}function L(e,t){D(e.requireDefenseContext,"awk",t)}function S(e,t,n){return _(e.requireDefenseContext,"awk",t,n)}async function f(e,t){switch(L(e,"expression evaluation"),e.coverage?.hit(`awk:expr:${t.type}`),t.type){case"number":return t.value;case"string":return t.value;case"regex":return K(t.pattern,e.line)?1:0;case"field":return ut(e,t);case"variable":return J(e,t.name);case"array_access":return ct(e,t);case"binary":return ht(e,t);case"unary":return dt(e,t);case"ternary":return b(await S(e,"ternary condition evaluation",()=>f(e,t.condition)))?await S(e,"ternary consequent evaluation",()=>f(e,t.consequent)):await S(e,"ternary alternate evaluation",()=>f(e,t.alternate));case"call":return Et(e,t.name,t.args);case"assignment":return yt(e,t);case"pre_increment":return St(e,t.operand);case"pre_decrement":return mt(e,t.operand);case"post_increment":return wt(e,t.operand);case"post_decrement":return Rt(e,t.operand);case"in":return gt(e,t.key,t.array);case"getline":return At(e,t.variable,t.file,t.command);case"tuple":return kt(e,t.elements);default:return""}}async function ut(e,t){L(e,"field reference evaluation");let n=Math.floor(g(await S(e,"field index evaluation",()=>f(e,t.index))));return Q(e,n)}async function ct(e,t){L(e,"array access evaluation");let n=m(await S(e,"array key evaluation",()=>f(e,t.key)));return Z(e,t.array,n)}async function ht(e,t){L(e,"binary expression evaluation");let n=t.operator;if(n==="||")return b(await S(e,"logical-or left evaluation",()=>f(e,t.left)))||b(await S(e,"logical-or right evaluation",()=>f(e,t.right)))?1:0;if(n==="&&")return b(await S(e,"logical-and left evaluation",()=>f(e,t.left)))&&b(await S(e,"logical-and right evaluation",()=>f(e,t.right)))?1:0;if(n==="~"){let l=await S(e,"regex left evaluation",()=>f(e,t.left));t.right.type==="regex"&&e.coverage?.hit("awk:expr:regex");let u=t.right.type==="regex"?t.right.pattern:m(await S(e,"regex right evaluation",()=>f(e,t.right)));try{return v(u).test(m(l))?1:0}catch{return 0}}if(n==="!~"){let l=await S(e,"negated-regex left evaluation",()=>f(e,t.left));t.right.type==="regex"&&e.coverage?.hit("awk:expr:regex");let u=t.right.type==="regex"?t.right.pattern:m(await S(e,"negated-regex right evaluation",()=>f(e,t.right)));try{return v(u).test(m(l))?0:1}catch{return 1}}let i=await S(e,"binary left evaluation",()=>f(e,t.left)),s=await S(e,"binary right evaluation",()=>f(e,t.right));if(n===" "){let l=m(i)+m(s);if(e.maxOutputSize>0&&l.length>e.maxOutputSize)throw new P(`awk: string concatenation size limit exceeded (${e.maxOutputSize} bytes)`,"string_length",e.output);return l}if(pt(n))return ft(i,s,n);let a=g(i),o=g(s);return Ee(a,o,n)}function pt(e){return["<","<=",">",">=","==","!="].includes(e)}function ft(e,t,n){let i=ae(e),s=ae(t);if(i&&s){let l=g(e),u=g(t);switch(n){case"<":return l<u?1:0;case"<=":return l<=u?1:0;case">":return l>u?1:0;case">=":return l>=u?1:0;case"==":return l===u?1:0;case"!=":return l!==u?1:0}}let a=m(e),o=m(t);switch(n){case"<":return a<o?1:0;case"<=":return a<=o?1:0;case">":return a>o?1:0;case">=":return a>=o?1:0;case"==":return a===o?1:0;case"!=":return a!==o?1:0}return 0}async function dt(e,t){L(e,"unary expression evaluation");let n=await S(e,"unary operand evaluation",()=>f(e,t.operand));switch(t.operator){case"!":return b(n)?0:1;case"-":return-g(n);case"+":return+g(n);default:return n}}async function Et(e,t,n){L(e,"function call evaluation");let i=Re.get(t);if(i)return i(n,e,{evalExpr:a=>f(e,a)});let s=e.functions.get(t);return s?Nt(e,s,n):""}async function Nt(e,t,n){if(L(e,"user function call"),e.currentRecursionDepth++,e.currentRecursionDepth>e.maxRecursionDepth)throw e.currentRecursionDepth--,new P(`awk: recursion depth exceeded maximum (${e.maxRecursionDepth})`,"recursion",e.output);let i=Object.create(null);for(let l of t.params)i[l]=e.vars[l];let s=[];for(let l=0;l<t.params.length;l++){let u=t.params[l];if(l<n.length){let N=n[l];N.type==="variable"&&(e.arrayAliases.set(u,N.name),s.push(u));let A=await S(e,"user function argument evaluation",()=>f(e,N));e.vars[u]=A}else e.vars[u]=""}e.hasReturn=!1,e.returnValue=void 0;let a=Ce;a&&await S(e,"user function body execution",()=>a(e,t.body.statements));let o=e.returnValue??"";for(let l of t.params)i[l]!==void 0?e.vars[l]=i[l]:delete e.vars[l];for(let l of s)e.arrayAliases.delete(l);return e.hasReturn=!1,e.returnValue=void 0,e.currentRecursionDepth--,o}async function yt(e,t){L(e,"assignment evaluation");let n=await S(e,"assignment value evaluation",()=>f(e,t.value)),i=t.target,s=t.operator,a;if(s==="=")a=n;else{let o;if(i.type==="field"){let N=Math.floor(g(await S(e,"assignment field index",()=>f(e,i.index))));o=Q(e,N)}else if(i.type==="variable")o=J(e,i.name);else{let N=m(await S(e,"assignment array key",()=>f(e,i.key)));o=Z(e,i.array,N)}let l=g(o),u=g(n);switch(s){case"+=":a=l+u;break;case"-=":a=l-u;break;case"*=":a=l*u;break;case"/=":a=u!==0?l/u:0;break;case"%=":a=u!==0?l%u:0;break;case"^=":a=l**u;break;default:a=n}}if(i.type==="field"){let o=Math.floor(g(await S(e,"assignment target field index",()=>f(e,i.index))));oe(e,o,a)}else if(i.type==="variable")W(e,i.name,a);else{let o=m(await S(e,"assignment target array key",()=>f(e,i.key)));le(e,i.array,o,a)}return a}async function Y(e,t,n,i){L(e,"inc/dec evaluation");let s;if(t.type==="field"){let a=Math.floor(g(await S(e,"inc/dec field index",()=>f(e,t.index))));s=g(Q(e,a)),oe(e,a,s+n)}else if(t.type==="variable")s=g(J(e,t.name)),W(e,t.name,s+n);else{let a=m(await S(e,"inc/dec array key",()=>f(e,t.key)));s=g(Z(e,t.array,a)),le(e,t.array,a,s+n)}return i?s+n:s}async function St(e,t){return Y(e,t,1,!0)}async function mt(e,t){return Y(e,t,-1,!0)}async function wt(e,t){return Y(e,t,1,!1)}async function Rt(e,t){return Y(e,t,-1,!1)}async function gt(e,t,n){L(e,"in-expression evaluation");let i;if(t.type==="tuple"){e.coverage?.hit("awk:expr:tuple");let s=[];for(let a of t.elements)s.push(m(await S(e,"tuple key element evaluation",()=>f(e,a))));i=s.join(e.SUBSEP)}else i=m(await S(e,"in-expression key evaluation",()=>f(e,t)));return ve(e,n,i)?1:0}async function At(e,t,n,i){if(L(e,"getline evaluation"),i)return vt(e,t,i);if(n)return It(e,t,n);if(!e.lines||e.lineIndex===void 0)return-1;let s=e.lineIndex+1;if(s>=e.lines.length)return 0;let a=e.lines[s];return t?W(e,t,a):$(e,a),e.NR++,e.lineIndex=s,1}async function vt(e,t,n){let i=e.exec;if(!i)return-1;L(e,"getline command source");let s=m(await S(e,"getline command expression",()=>f(e,n))),a=`__cmd_${s}`,o=`__cmdi_${s}`,l,u;if(e.vars[a]===void 0)try{l=(await S(e,"getline command exec",()=>i(s))).stdout.split(`
|
|
6
|
+
`),l.length>0&&l[l.length-1]===""&&l.pop(),e.vars[a]=JSON.stringify(l),e.vars[o]=-1,u=-1}catch(C){if(C instanceof x)throw C;return-1}else l=JSON.parse(e.vars[a]),u=e.vars[o];let N=u+1;if(N>=l.length)return 0;let A=l[N];return e.vars[o]=N,t?W(e,t,A):$(e,A),1}async function It(e,t,n){let i=e.fs;if(!i||!e.cwd)return-1;L(e,"getline file source");let s=m(await S(e,"getline filename evaluation",()=>f(e,n)));if(s==="/dev/null")return 0;let a=i.resolvePath(e.cwd,s),o=`__fc_${a}`,l=`__fi_${a}`,u,N;if(e.vars[o]===void 0)try{u=(await S(e,"getline file read",()=>i.readFile(a))).split(`
|
|
7
|
+
`),u.length>0&&u[u.length-1]===""&&u.pop(),e.vars[o]=JSON.stringify(u),e.vars[l]=-1,N=-1}catch(O){if(O instanceof x)throw O;return-1}else u=JSON.parse(e.vars[o]),N=e.vars[l];let A=N+1;if(A>=u.length)return 0;let C=u[A];return e.vars[l]=A,t?W(e,t,C):$(e,C),1}async function kt(e,t){if(L(e,"tuple evaluation"),t.length===0)return"";for(let n=0;n<t.length-1;n++)await S(e,"tuple intermediate element",()=>f(e,t[n]));return S(e,"tuple final element",()=>f(e,t[t.length-1]))}be(V);function ue(e){if(e.maxOutputSize>0&&e.output.length>e.maxOutputSize)throw new P(`awk: output size limit exceeded (${e.maxOutputSize} bytes)`,"string_length",e.output)}function T(e,t){D(e.requireDefenseContext,"awk",t)}function y(e,t,n){return _(e.requireDefenseContext,"awk",t,n)}async function V(e,t){T(e,"block execution");for(let n of t)if(await y(e,"statement execution",()=>B(e,n)),Ct(e))break}function Ct(e){return e.shouldExit||e.shouldNext||e.shouldNextFile||e.loopBreak||e.loopContinue||e.hasReturn}async function B(e,t){switch(T(e,"single statement execution"),e.coverage?.hit(`awk:stmt:${t.type}`),t.type){case"block":await y(e,"nested block statement",()=>V(e,t.statements));break;case"expr_stmt":await y(e,"expression statement",()=>f(e,t.expression));break;case"print":await y(e,"print statement",()=>bt(e,t.args,t.output));break;case"printf":await y(e,"printf statement",()=>Ot(e,t.format,t.args,t.output));break;case"if":await y(e,"if statement",()=>Lt(e,t));break;case"while":await y(e,"while statement",()=>Mt(e,t));break;case"do_while":await y(e,"do-while statement",()=>Pt(e,t));break;case"for":await y(e,"for statement",()=>Tt(e,t));break;case"for_in":await y(e,"for-in statement",()=>Ft(e,t));break;case"break":e.loopBreak=!0;break;case"continue":e.loopContinue=!0;break;case"next":e.shouldNext=!0;break;case"nextfile":e.shouldNextFile=!0;break;case"exit":e.shouldExit=!0;{let n=t.code;e.exitCode=n?Math.floor(g(await y(e,"exit code expression",()=>f(e,n)))):0}break;case"return":e.hasReturn=!0;{let n=t.value;e.returnValue=n?await y(e,"return expression",()=>f(e,n)):""}break;case"delete":await y(e,"delete statement",()=>Dt(e,t.target));break}}async function bt(e,t,n){T(e,"print execution");let i=[];for(let a of t){let o=await y(e,"print argument evaluation",()=>f(e,a));typeof o=="number"?Number.isInteger(o)&&Math.abs(o)<Number.MAX_SAFE_INTEGER?i.push(String(o)):i.push(j(e.OFMT,[o])):i.push(m(o))}let s=i.join(e.OFS)+e.ORS;n?await y(e,"print redirection write",()=>Oe(e,n.redirect,n.file,s)):(e.output+=s,ue(e))}async function Ot(e,t,n,i){T(e,"printf execution");let s=m(await y(e,"printf format evaluation",()=>f(e,t))),a=[];for(let l of n)a.push(await y(e,"printf argument evaluation",()=>f(e,l)));let o=j(s,a);i?await y(e,"printf redirection write",()=>Oe(e,i.redirect,i.file,o)):(e.output+=o,ue(e))}async function Oe(e,t,n,i){T(e,"file write execution");let s=e.fs;if(!s||!e.cwd){e.output+=i,ue(e);return}let a=m(await y(e,"redirection filename evaluation",()=>f(e,n))),o=s.resolvePath(e.cwd,a);t===">"?e.openedFiles.has(o)?await y(e,"redirection append write",()=>s.appendFile(o,i)):(await y(e,"redirection overwrite write",()=>s.writeFile(o,i)),e.openedFiles.add(o)):(e.openedFiles.has(o)||e.openedFiles.add(o),await y(e,"redirection append mode write",()=>s.appendFile(o,i)))}async function Lt(e,t){if(T(e,"if execution"),b(await y(e,"if condition evaluation",()=>f(e,t.condition))))await y(e,"if consequent execution",()=>B(e,t.consequent));else if(t.alternate){let n=t.alternate;await y(e,"if alternate execution",()=>B(e,n))}}async function Mt(e,t){T(e,"while execution");let n=0;for(;b(await y(e,"while condition evaluation",()=>f(e,t.condition)));){if(n++,n>e.maxIterations)throw new P(`awk: while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await y(e,"while body execution",()=>B(e,t.body)),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function Pt(e,t){T(e,"do-while execution");let n=0;do{if(n++,n>e.maxIterations)throw new P(`awk: do-while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await y(e,"do-while body execution",()=>B(e,t.body)),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}while(b(await y(e,"do-while condition evaluation",()=>f(e,t.condition))))}async function Tt(e,t){T(e,"for execution");let n=t.init,i=t.condition,s=t.update;n&&await y(e,"for init evaluation",()=>f(e,n));let a=0;for(;!i||b(await y(e,"for condition evaluation",()=>f(e,i)));){if(a++,a>e.maxIterations)throw new P(`awk: for loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await y(e,"for body execution",()=>B(e,t.body)),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break;s&&await y(e,"for update evaluation",()=>f(e,s))}}async function Ft(e,t){T(e,"for-in execution");let n=e.arrays[t.array];if(n)for(let i of Object.keys(n)){if(e.vars[t.variable]=i,e.loopContinue=!1,await y(e,"for-in body execution",()=>B(e,t.body)),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function Dt(e,t){if(T(e,"delete execution"),t.type==="array_access"){let n=m(await y(e,"delete key evaluation",()=>f(e,t.key)));Ie(e,t.array,n)}else t.type==="variable"&&ke(e,t.name)}var q=class{ctx;program=null;rangeStates=[];constructor(t){this.ctx=t}assertDefenseContext(t){D(this.ctx.requireDefenseContext,"awk",t)}withDefenseContext(t,n){return _(this.ctx.requireDefenseContext,"awk",t,n)}execute(t){this.assertDefenseContext("program initialization"),this.program=t,this.ctx.output="";for(let n of t.functions)this.ctx.functions.set(n.name,n);this.rangeStates=t.rules.map(()=>!1)}async executeBegin(){if(this.assertDefenseContext("BEGIN execution entry"),!!this.program){for(let t of this.program.rules)if(t.pattern?.type==="begin"&&(await this.withDefenseContext("BEGIN block execution",()=>V(this.ctx,t.action.statements)),this.ctx.shouldExit))break}}async executeLine(t){if(this.assertDefenseContext("line execution entry"),!(!this.program||this.ctx.shouldExit)){$(this.ctx,t),this.ctx.NR++,this.ctx.FNR++,this.ctx.shouldNext=!1;for(let n=0;n<this.program.rules.length&&!(this.ctx.shouldExit||this.ctx.shouldNext||this.ctx.shouldNextFile);n++){let i=this.program.rules[n];i.pattern?.type==="begin"||i.pattern?.type==="end"||await this.withDefenseContext("rule match",()=>this.matchesRule(i,n))&&await this.withDefenseContext("rule block execution",()=>V(this.ctx,i.action.statements))}}}async executeEnd(){if(this.assertDefenseContext("END execution entry"),!!this.program&&!this.ctx.inEndBlock){this.ctx.inEndBlock=!0,this.ctx.shouldExit=!1;for(let t of this.program.rules)if(t.pattern?.type==="end"&&(await this.withDefenseContext("END block execution",()=>V(this.ctx,t.action.statements)),this.ctx.shouldExit))break;this.ctx.inEndBlock=!1}}getOutput(){return this.ctx.output}getExitCode(){return this.ctx.exitCode}getContext(){return this.ctx}async matchesRule(t,n){this.assertDefenseContext("rule matching");let i=t.pattern;if(!i)return!0;switch(i.type){case"begin":case"end":return!1;case"regex_pattern":return K(i.pattern,this.ctx.line);case"expr_pattern":return b(await this.withDefenseContext("expression pattern evaluation",()=>f(this.ctx,i.expression)));case"range":{let s=await this.withDefenseContext("range start pattern",()=>this.matchPattern(i.start)),a=await this.withDefenseContext("range end pattern",()=>this.matchPattern(i.end));return this.rangeStates[n]?(a&&(this.rangeStates[n]=!1),!0):s?(this.rangeStates[n]=!0,a&&(this.rangeStates[n]=!1),!0):!1}default:return!1}}async matchPattern(t){switch(this.assertDefenseContext("pattern matching"),t.type){case"regex_pattern":return K(t.pattern,this.ctx.line);case"expr_pattern":return b(await this.withDefenseContext("nested expression pattern",()=>f(this.ctx,t.expression)));default:return!1}}};var r;(function(e){e.NUMBER="NUMBER",e.STRING="STRING",e.REGEX="REGEX",e.IDENT="IDENT",e.BEGIN="BEGIN",e.END="END",e.IF="IF",e.ELSE="ELSE",e.WHILE="WHILE",e.DO="DO",e.FOR="FOR",e.IN="IN",e.BREAK="BREAK",e.CONTINUE="CONTINUE",e.NEXT="NEXT",e.NEXTFILE="NEXTFILE",e.EXIT="EXIT",e.RETURN="RETURN",e.DELETE="DELETE",e.FUNCTION="FUNCTION",e.PRINT="PRINT",e.PRINTF="PRINTF",e.GETLINE="GETLINE",e.PLUS="PLUS",e.MINUS="MINUS",e.STAR="STAR",e.SLASH="SLASH",e.PERCENT="PERCENT",e.CARET="CARET",e.EQ="EQ",e.NE="NE",e.LT="LT",e.GT="GT",e.LE="LE",e.GE="GE",e.MATCH="MATCH",e.NOT_MATCH="NOT_MATCH",e.AND="AND",e.OR="OR",e.NOT="NOT",e.ASSIGN="ASSIGN",e.PLUS_ASSIGN="PLUS_ASSIGN",e.MINUS_ASSIGN="MINUS_ASSIGN",e.STAR_ASSIGN="STAR_ASSIGN",e.SLASH_ASSIGN="SLASH_ASSIGN",e.PERCENT_ASSIGN="PERCENT_ASSIGN",e.CARET_ASSIGN="CARET_ASSIGN",e.INCREMENT="INCREMENT",e.DECREMENT="DECREMENT",e.QUESTION="QUESTION",e.COLON="COLON",e.COMMA="COMMA",e.SEMICOLON="SEMICOLON",e.NEWLINE="NEWLINE",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.DOLLAR="DOLLAR",e.APPEND="APPEND",e.PIPE="PIPE",e.EOF="EOF"})(r||(r={}));var _t=new Map([["BEGIN",r.BEGIN],["END",r.END],["if",r.IF],["else",r.ELSE],["while",r.WHILE],["do",r.DO],["for",r.FOR],["in",r.IN],["break",r.BREAK],["continue",r.CONTINUE],["next",r.NEXT],["nextfile",r.NEXTFILE],["exit",r.EXIT],["return",r.RETURN],["delete",r.DELETE],["function",r.FUNCTION],["print",r.PRINT],["printf",r.PRINTF],["getline",r.GETLINE]]);function Gt(e){return e.replace(/\[\[:space:\]\]/g,"[ \\t\\n\\r\\f\\v]").replace(/\[\[:blank:\]\]/g,"[ \\t]").replace(/\[\[:alpha:\]\]/g,"[a-zA-Z]").replace(/\[\[:digit:\]\]/g,"[0-9]").replace(/\[\[:alnum:\]\]/g,"[a-zA-Z0-9]").replace(/\[\[:upper:\]\]/g,"[A-Z]").replace(/\[\[:lower:\]\]/g,"[a-z]").replace(/\[\[:punct:\]\]/g,"[!\"#$%&'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~]").replace(/\[\[:xdigit:\]\]/g,"[0-9A-Fa-f]").replace(/\[\[:graph:\]\]/g,"[!-~]").replace(/\[\[:print:\]\]/g,"[ -~]").replace(/\[\[:cntrl:\]\]/g,"[\\x00-\\x1f\\x7f]")}var xt=new Set([r.COMMA,r.LBRACE,r.AND,r.OR,r.QUESTION,r.COLON,r.DO,r.ELSE,r.IF,r.WHILE]),ee=class{input;pos=0;line=1;column=1;lastTokenType=null;constructor(t){this.input=t}tokenize(){let t=[];for(;this.pos<this.input.length;){let n=this.nextToken();n&&(t.push(n),this.lastTokenType=n.type)}return t.push(this.makeToken(r.EOF,"")),t}makeToken(t,n){return{type:t,value:n,line:this.line,column:this.column}}peek(t=0){return this.input[this.pos+t]||""}advance(){let t=this.input[this.pos++]||"";return t===`
|
|
8
8
|
`?(this.line++,this.column=1):this.column++,t}skipWhitespace(){for(;this.pos<this.input.length;){let t=this.peek();if(t===" "||t===" "||t==="\r")this.advance();else if(t==="\\")if(this.peek(1)===`
|
|
9
9
|
`)this.advance(),this.advance();else break;else if(t==="#")for(;this.pos<this.input.length&&this.peek()!==`
|
|
10
10
|
`;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let t=this.line,n=this.column,i=this.peek();return i===`
|
|
11
|
-
`?(this.advance(),{type:r.NEWLINE,value:`
|
|
11
|
+
`?(this.advance(),this.lastTokenType!==null&&xt.has(this.lastTokenType)?this.nextToken():{type:r.NEWLINE,value:`
|
|
12
12
|
`,line:t,column:n}):i==='"'?this.readString():i==="/"&&this.canBeRegex()?this.readRegex():this.isDigit(i)||i==="."&&this.isDigit(this.peek(1))?this.readNumber():this.isAlpha(i)||i==="_"?this.readIdentifier():this.readOperator()}canBeRegex(){return new Set([null,r.NEWLINE,r.SEMICOLON,r.LBRACE,r.RBRACE,r.LPAREN,r.LBRACKET,r.COMMA,r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN,r.AND,r.OR,r.NOT,r.MATCH,r.NOT_MATCH,r.QUESTION,r.COLON,r.LT,r.GT,r.LE,r.GE,r.EQ,r.NE,r.PLUS,r.MINUS,r.STAR,r.PERCENT,r.CARET,r.PRINT,r.PRINTF,r.IF,r.WHILE,r.DO,r.FOR,r.RETURN]).has(this.lastTokenType)}readString(){let t=this.line,n=this.column;this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!=='"';)if(this.peek()==="\\"){this.advance();let s=this.advance();switch(s){case"n":i+=`
|
|
13
13
|
`;break;case"t":i+=" ";break;case"r":i+="\r";break;case"f":i+="\f";break;case"b":i+="\b";break;case"v":i+="\v";break;case"a":i+="\x07";break;case"\\":i+="\\";break;case'"':i+='"';break;case"/":i+="/";break;case"x":{let a="";for(;a.length<2&&/[0-9a-fA-F]/.test(this.peek());)a+=this.advance();a.length>0?i+=String.fromCharCode(parseInt(a,16)):i+="x";break}default:if(/[0-7]/.test(s)){let a=s;for(;a.length<3&&/[0-7]/.test(this.peek());)a+=this.advance();i+=String.fromCharCode(parseInt(a,8))}else i+=s}}else i+=this.advance();return this.peek()==='"'&&this.advance(),{type:r.STRING,value:i,line:t,column:n}}readRegex(){let t=this.line,n=this.column;this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!=="/";)if(this.peek()==="\\")i+=this.advance(),this.pos<this.input.length&&(i+=this.advance());else{if(this.peek()===`
|
|
14
|
-
`)break;i+=this.advance()}return this.peek()==="/"&&this.advance(),i=Gt(i),{type:r.REGEX,value:i,line:t,column:n}}readNumber(){let t=this.line,n=this.column,i="";for(;this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="."&&this.isDigit(this.peek(1)))for(i+=this.advance();this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(i+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(i+=this.advance());this.isDigit(this.peek());)i+=this.advance();return{type:r.NUMBER,value:parseFloat(i),line:t,column:n}}readIdentifier(){let t=this.line,n=this.column,i="";for(;this.isAlphaNumeric(this.peek())||this.peek()==="_";)i+=this.advance();let s=_t.get(i);return s!==void 0?{type:s,value:i,line:t,column:n}:{type:r.IDENT,value:i,line:t,column:n}}readOperator(){let t=this.line,n=this.column,i=this.advance(),s=this.peek();switch(i){case"+":return s==="+"?(this.advance(),{type:r.INCREMENT,value:"++",line:t,column:n}):s==="="?(this.advance(),{type:r.PLUS_ASSIGN,value:"+=",line:t,column:n}):{type:r.PLUS,value:"+",line:t,column:n};case"-":return s==="-"?(this.advance(),{type:r.DECREMENT,value:"--",line:t,column:n}):s==="="?(this.advance(),{type:r.MINUS_ASSIGN,value:"-=",line:t,column:n}):{type:r.MINUS,value:"-",line:t,column:n};case"*":return s==="*"?(this.advance(),{type:r.CARET,value:"**",line:t,column:n}):s==="="?(this.advance(),{type:r.STAR_ASSIGN,value:"*=",line:t,column:n}):{type:r.STAR,value:"*",line:t,column:n};case"/":return s==="="?(this.advance(),{type:r.SLASH_ASSIGN,value:"/=",line:t,column:n}):{type:r.SLASH,value:"/",line:t,column:n};case"%":return s==="="?(this.advance(),{type:r.PERCENT_ASSIGN,value:"%=",line:t,column:n}):{type:r.PERCENT,value:"%",line:t,column:n};case"^":return s==="="?(this.advance(),{type:r.CARET_ASSIGN,value:"^=",line:t,column:n}):{type:r.CARET,value:"^",line:t,column:n};case"=":return s==="="?(this.advance(),{type:r.EQ,value:"==",line:t,column:n}):{type:r.ASSIGN,value:"=",line:t,column:n};case"!":return s==="="?(this.advance(),{type:r.NE,value:"!=",line:t,column:n}):s==="~"?(this.advance(),{type:r.NOT_MATCH,value:"!~",line:t,column:n}):{type:r.NOT,value:"!",line:t,column:n};case"<":return s==="="?(this.advance(),{type:r.LE,value:"<=",line:t,column:n}):{type:r.LT,value:"<",line:t,column:n};case">":return s==="="?(this.advance(),{type:r.GE,value:">=",line:t,column:n}):s===">"?(this.advance(),{type:r.APPEND,value:">>",line:t,column:n}):{type:r.GT,value:">",line:t,column:n};case"&":return s==="&"?(this.advance(),{type:r.AND,value:"&&",line:t,column:n}):{type:r.IDENT,value:"&",line:t,column:n};case"|":return s==="|"?(this.advance(),{type:r.OR,value:"||",line:t,column:n}):{type:r.PIPE,value:"|",line:t,column:n};case"~":return{type:r.MATCH,value:"~",line:t,column:n};case"?":return{type:r.QUESTION,value:"?",line:t,column:n};case":":return{type:r.COLON,value:":",line:t,column:n};case",":return{type:r.COMMA,value:",",line:t,column:n};case";":return{type:r.SEMICOLON,value:";",line:t,column:n};case"(":return{type:r.LPAREN,value:"(",line:t,column:n};case")":return{type:r.RPAREN,value:")",line:t,column:n};case"{":return{type:r.LBRACE,value:"{",line:t,column:n};case"}":return{type:r.RBRACE,value:"}",line:t,column:n};case"[":return{type:r.LBRACKET,value:"[",line:t,column:n};case"]":return{type:r.RBRACKET,value:"]",line:t,column:n};case"$":return{type:r.DOLLAR,value:"$",line:t,column:n};default:return{type:r.IDENT,value:i,line:t,column:n}}}isDigit(t){return t>="0"&&t<="9"}isAlpha(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}isAlphaNumeric(t){return this.isDigit(t)||this.isAlpha(t)}};var p={LPAREN:"LPAREN",RPAREN:"RPAREN",QUESTION:"QUESTION",NEWLINE:"NEWLINE",SEMICOLON:"SEMICOLON",RBRACE:"RBRACE",COMMA:"COMMA",PIPE:"PIPE",GT:"GT",APPEND:"APPEND",AND:"AND",OR:"OR",ASSIGN:"ASSIGN",PLUS_ASSIGN:"PLUS_ASSIGN",MINUS_ASSIGN:"MINUS_ASSIGN",STAR_ASSIGN:"STAR_ASSIGN",SLASH_ASSIGN:"SLASH_ASSIGN",PERCENT_ASSIGN:"PERCENT_ASSIGN",CARET_ASSIGN:"CARET_ASSIGN",RBRACKET:"RBRACKET",COLON:"COLON",IN:"IN",PRINT:"PRINT",PRINTF:"PRINTF",IDENT:"IDENT",LT:"LT",LE:"LE",GE:"GE",EQ:"EQ",NE:"NE",MATCH:"MATCH",NOT_MATCH:"NOT_MATCH",NUMBER:"NUMBER",STRING:"STRING",DOLLAR:"DOLLAR",NOT:"NOT",MINUS:"MINUS",PLUS:"PLUS",INCREMENT:"INCREMENT",DECREMENT:"DECREMENT"};function Fe(e){e.expect(p.PRINT);let t=[];if(e.check(p.NEWLINE)||e.check(p.SEMICOLON)||e.check(p.RBRACE)||e.check(p.PIPE)||e.check(p.GT)||e.check(p.APPEND))t.push({type:"field",index:{type:"number",value:0}});else for(t.push(te(e));e.check(p.COMMA);)e.advance(),t.push(te(e));let n;return e.check(p.GT)?(e.advance(),n={redirect:">",file:e.parsePrimary()}):e.check(p.APPEND)&&(e.advance(),n={redirect:">>",file:e.parsePrimary()}),{type:"print",args:t,output:n}}function te(e){return xt(e)?ce(e,!0):ce(e,!1)}function ce(e,t){let n=t?e.parseTernary():Ut(e);if(e.match(p.ASSIGN,p.PLUS_ASSIGN,p.MINUS_ASSIGN,p.STAR_ASSIGN,p.SLASH_ASSIGN,p.PERCENT_ASSIGN,p.CARET_ASSIGN)){let i=e.advance(),s=ce(e,t);if(n.type!=="variable"&&n.type!=="field"&&n.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:new Map([["=","="],["+=","+="],["-=","-="],["*=","*="],["/=","/="],["%=","%="],["^=","^="]]).get(i.value)??"=",target:n,value:s}}return n}function xt(e){let t=0,n=e.pos;for(;n<e.tokens.length;){let i=e.tokens[n];if(i.type===p.LPAREN&&t++,i.type===p.RPAREN&&t--,i.type===p.QUESTION&&t===0)return!0;if(i.type===p.NEWLINE||i.type===p.SEMICOLON||i.type===p.RBRACE||i.type===p.COMMA||i.type===p.PIPE)return!1;n++}return!1}function Ut(e){let t=Le(e);for(;e.check(p.OR);){e.advance();let n=Le(e);t={type:"binary",operator:"||",left:t,right:n}}return t}function Le(e){let t=Me(e);for(;e.check(p.AND);){e.advance();let n=Me(e);t={type:"binary",operator:"&&",left:t,right:n}}return t}function Me(e){let t=Bt(e);if(e.check(p.IN)){e.advance();let n=String(e.expect(p.IDENT).value);return{type:"in",key:t,array:n}}return t}function Bt(e){let t=Pe(e);for(;Ht(e)&&!$t(e);){let n=Pe(e);t={type:"binary",operator:" ",left:t,right:n}}return t}function Pe(e){let t=Te(e);for(;e.match(p.MATCH,p.NOT_MATCH);){let n=e.advance().type===p.MATCH?"~":"!~",i=Te(e);t={type:"binary",operator:n,left:t,right:i}}return t}function Te(e){let t=e.parseAddSub();for(;e.match(p.LT,p.LE,p.GE,p.EQ,p.NE);){let n=e.advance(),i=e.parseAddSub();t={type:"binary",operator:new Map([["<","<"],["<=","<="],[">=",">="],["==","=="],["!=","!="]]).get(n.value)??"==",left:t,right:i}}return t}function Ht(e){return e.match(p.NUMBER,p.STRING,p.IDENT,p.DOLLAR,p.LPAREN,p.NOT,p.MINUS,p.PLUS,p.INCREMENT,p.DECREMENT)}function $t(e){return e.match(p.AND,p.OR,p.QUESTION,p.ASSIGN,p.PLUS_ASSIGN,p.MINUS_ASSIGN,p.STAR_ASSIGN,p.SLASH_ASSIGN,p.PERCENT_ASSIGN,p.CARET_ASSIGN,p.COMMA,p.SEMICOLON,p.NEWLINE,p.RBRACE,p.RPAREN,p.RBRACKET,p.COLON,p.PIPE,p.APPEND,p.GT,p.IN)}function De(e){e.expect(p.PRINTF);let t=e.check(p.LPAREN);t&&(e.advance(),e.skipNewlines());let n=t?e.parseExpression():te(e),i=[];for(;e.check(p.COMMA);)e.advance(),t&&e.skipNewlines(),i.push(t?e.parseExpression():te(e));t&&(e.skipNewlines(),e.expect(p.RPAREN));let s;return e.check(p.GT)?(e.advance(),s={redirect:">",file:e.parsePrimary()}):e.check(p.APPEND)&&(e.advance(),s={redirect:">>",file:e.parsePrimary()}),{type:"printf",format:n,args:i,output:s}}var ne=class{tokens=[];pos=0;parse(t){let n=new ee(t);return this.tokens=n.tokenize(),this.pos=0,this.parseProgram()}setPos(t){this.pos=t}current(){return this.tokens[this.pos]||{type:r.EOF,value:"",line:0,column:0}}advance(){let t=this.current();return this.pos<this.tokens.length&&this.pos++,t}match(...t){return t.includes(this.current().type)}check(t){return this.current().type===t}expect(t,n){if(!this.check(t)){let i=this.current();throw new Error(n||`Expected ${t}, got ${i.type} at line ${i.line}:${i.column}`)}return this.advance()}skipNewlines(){for(;this.check(r.NEWLINE);)this.advance()}skipTerminators(){for(;this.check(r.NEWLINE)||this.check(r.SEMICOLON);)this.advance()}parseProgram(){let t=[],n=[];for(this.skipNewlines();!this.check(r.EOF)&&(this.skipNewlines(),!this.check(r.EOF));)this.check(r.FUNCTION)?t.push(this.parseFunction()):n.push(this.parseRule()),this.skipTerminators();return{functions:t,rules:n}}parseFunction(){this.expect(r.FUNCTION);let t=this.expect(r.IDENT).value;this.expect(r.LPAREN);let n=[];if(!this.check(r.RPAREN))for(n.push(this.expect(r.IDENT).value);this.check(r.COMMA);)this.advance(),n.push(this.expect(r.IDENT).value);this.expect(r.RPAREN),this.skipNewlines();let i=this.parseBlock();return{name:t,params:n,body:i}}parseRule(){let t;if(this.check(r.BEGIN))this.advance(),t={type:"begin"};else if(this.check(r.END))this.advance(),t={type:"end"};else if(this.check(r.LBRACE))t=void 0;else if(this.check(r.REGEX)){let i=this.advance();if(this.check(r.AND)||this.check(r.OR)){let s={type:"binary",operator:"~",left:{type:"field",index:{type:"number",value:0}},right:{type:"regex",pattern:i.value}};t={type:"expr_pattern",expression:this.parseLogicalOrRest(s)}}else{let s={type:"regex_pattern",pattern:i.value};if(this.check(r.COMMA)){this.advance();let a;this.check(r.REGEX)?a={type:"regex_pattern",pattern:this.advance().value}:a={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:s,end:a}}else t=s}}else{let s={type:"expr_pattern",expression:this.parseExpression()};if(this.check(r.COMMA)){this.advance();let a;this.check(r.REGEX)?a={type:"regex_pattern",pattern:this.advance().value}:a={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:s,end:a}}else t=s}this.skipNewlines();let n;return this.check(r.LBRACE)?n=this.parseBlock():n={type:"block",statements:[{type:"print",args:[{type:"field",index:{type:"number",value:0}}]}]},{pattern:t,action:n}}parseBlock(){this.expect(r.LBRACE),this.skipNewlines();let t=[];for(;!this.check(r.RBRACE)&&!this.check(r.EOF);)t.push(this.parseStatement()),this.skipTerminators();return this.expect(r.RBRACE),{type:"block",statements:t}}parseStatement(){if(this.check(r.SEMICOLON)||this.check(r.NEWLINE))return this.advance(),{type:"block",statements:[]};if(this.check(r.LBRACE))return this.parseBlock();if(this.check(r.IF))return this.parseIf();if(this.check(r.WHILE))return this.parseWhile();if(this.check(r.DO))return this.parseDoWhile();if(this.check(r.FOR))return this.parseFor();if(this.check(r.BREAK))return this.advance(),{type:"break"};if(this.check(r.CONTINUE))return this.advance(),{type:"continue"};if(this.check(r.NEXT))return this.advance(),{type:"next"};if(this.check(r.NEXTFILE))return this.advance(),{type:"nextfile"};if(this.check(r.EXIT)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"exit",code:n}}if(this.check(r.RETURN)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"return",value:n}}if(this.check(r.DELETE)){this.advance();let n=this.parsePrimary();if(n.type!=="array_access"&&n.type!=="variable")throw new Error("delete requires array element or array");return{type:"delete",target:n}}return this.check(r.PRINT)?Fe(this):this.check(r.PRINTF)?De(this):{type:"expr_stmt",expression:this.parseExpression()}}parseIf(){this.expect(r.IF),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();this.skipTerminators();let i;return this.check(r.ELSE)&&(this.advance(),this.skipNewlines(),i=this.parseStatement()),{type:"if",condition:t,consequent:n,alternate:i}}parseWhile(){this.expect(r.WHILE),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();return{type:"while",condition:t,body:n}}parseDoWhile(){this.expect(r.DO),this.skipNewlines();let t=this.parseStatement();this.skipNewlines(),this.expect(r.WHILE),this.expect(r.LPAREN);let n=this.parseExpression();return this.expect(r.RPAREN),{type:"do_while",body:t,condition:n}}parseFor(){if(this.expect(r.FOR),this.expect(r.LPAREN),this.check(r.IDENT)){let a=this.advance();if(this.check(r.IN)){this.advance();let o=this.expect(r.IDENT).value;this.expect(r.RPAREN),this.skipNewlines();let l=this.parseStatement();return{type:"for_in",variable:a.value,array:o,body:l}}this.pos--}let t;this.check(r.SEMICOLON)||(t=this.parseExpression()),this.expect(r.SEMICOLON);let n;this.check(r.SEMICOLON)||(n=this.parseExpression()),this.expect(r.SEMICOLON);let i;this.check(r.RPAREN)||(i=this.parseExpression()),this.expect(r.RPAREN),this.skipNewlines();let s=this.parseStatement();return{type:"for",init:t,condition:n,update:i,body:s}}parseExpression(){return this.parseAssignment()}parseAssignment(){let t=this.parseTernary();if(this.match(r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN)){let n=this.advance(),i=this.parseAssignment();if(t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid assignment target");let s=new Set(["=","+=","-=","*=","/=","%=","^="]),a=n.value;if(!s.has(a))throw new Error(`Unknown assignment operator: ${a}`);return{type:"assignment",operator:a,target:t,value:i}}return t}parseTernary(){let t=this.parsePipeGetline();if(this.check(r.QUESTION)){this.advance();let n=this.parseExpression();this.expect(r.COLON);let i=this.parseExpression();t={type:"ternary",condition:t,consequent:n,alternate:i}}return t}parsePipeGetline(){let t=this.parseOr();if(this.check(r.PIPE)){if(this.advance(),!this.check(r.GETLINE))throw new Error("Expected 'getline' after '|' in expression context");this.advance();let n;return this.check(r.IDENT)&&(n=this.advance().value),{type:"getline",command:t,variable:n}}return t}parseOr(){let t=this.parseAnd();for(;this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalOrRest(t){for(t=this.parseLogicalAndRest(t);this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalAndRest(t){for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseAnd(){let t=this.parseIn();for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseIn(){let t=this.parseConcatenation();if(this.check(r.IN)){this.advance();let n=this.expect(r.IDENT).value;return{type:"in",key:t,array:n}}return t}parseConcatenation(){let t=this.parseMatch();for(;this.canStartExpression()&&!this.isConcatTerminator();){let n=this.parseMatch();t={type:"binary",operator:" ",left:t,right:n}}return t}parseMatch(){let t=this.parseComparison();for(;this.match(r.MATCH,r.NOT_MATCH);){let n=this.advance().type===r.MATCH?"~":"!~",i=this.parseComparison();t={type:"binary",operator:n,left:t,right:i}}return t}parseComparison(){let t=this.parseAddSub();for(;this.match(r.LT,r.LE,r.GT,r.GE,r.EQ,r.NE);){let n=this.advance(),i=this.parseAddSub();t={type:"binary",operator:new Map([["<","<"],["<=","<="],[">",">"],[">=",">="],["==","=="],["!=","!="]]).get(n.value)??"==",left:t,right:i}}return t}canStartExpression(){return this.match(r.NUMBER,r.STRING,r.IDENT,r.DOLLAR,r.LPAREN,r.NOT,r.MINUS,r.PLUS,r.INCREMENT,r.DECREMENT)}isConcatTerminator(){return this.match(r.AND,r.OR,r.QUESTION,r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN,r.COMMA,r.SEMICOLON,r.NEWLINE,r.RBRACE,r.RPAREN,r.RBRACKET,r.COLON,r.PIPE,r.APPEND,r.IN)}parseAddSub(){let t=this.parseMulDiv();for(;this.match(r.PLUS,r.MINUS);){let n=this.advance().value,i=this.parseMulDiv();t={type:"binary",operator:n,left:t,right:i}}return t}parseMulDiv(){let t=this.parseUnary();for(;this.match(r.STAR,r.SLASH,r.PERCENT);){let n=this.advance(),i=this.parseUnary();t={type:"binary",operator:new Map([["*","*"],["/","/"],["%","%"]]).get(n.value)??"*",left:t,right:i}}return t}parseUnary(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseUnary();return{type:"unary",operator:t,operand:n}}return this.parsePower()}parsePower(){let t=this.parsePostfix();if(this.check(r.CARET)){this.advance();let n=this.parsePower();t={type:"binary",operator:"^",left:t,right:n}}return t}parsePostfix(){let t=this.parsePrimary();if(this.check(r.INCREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid increment operand");return{type:"post_increment",operand:t}}if(this.check(r.DECREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid decrement operand");return{type:"post_decrement",operand:t}}return t}parseFieldIndex(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseFieldIndex();return{type:"unary",operator:t,operand:n}}return this.parseFieldIndexPower()}parseFieldIndexPower(){let t=this.parseFieldIndexPrimary();if(this.check(r.CARET)){this.advance();let n=this.parseFieldIndexPower();t={type:"binary",operator:"^",left:t,right:n}}return t}parseFieldIndexPrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();return this.expect(r.RPAREN),t}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=this.parseExpression();if(this.check(r.COMMA)){let i=[n];for(;this.check(r.COMMA);)this.advance(),i.push(this.parseExpression());this.expect(r.RBRACKET);let s=i.reduce((a,o)=>({type:"binary",operator:" ",left:{type:"binary",operator:" ",left:a,right:{type:"variable",name:"SUBSEP"}},right:o}));return{type:"array_access",array:t,key:s}}return this.expect(r.RBRACKET),{type:"array_access",array:t,key:n}}return{type:"variable",name:t}}throw new Error(`Unexpected token in field index: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}parsePrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.REGEX))return{type:"regex",pattern:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();if(this.check(r.COMMA)){let n=[t];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"tuple",elements:n}}return this.expect(r.RPAREN),t}if(this.check(r.GETLINE)){this.advance();let t,n;return this.check(r.IDENT)&&(t=this.advance().value),this.check(r.LT)&&(this.advance(),n=this.parsePrimary()),{type:"getline",variable:t,file:n}}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(this.skipNewlines(),!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),this.skipNewlines(),n.push(this.parseExpression());return this.skipNewlines(),this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=[this.parseExpression()];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());this.expect(r.RBRACKET);let i;if(n.length===1)i=n[0];else{i=n[0];for(let s=1;s<n.length;s++)i={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:i,right:{type:"variable",name:"SUBSEP"}},right:n[s]}}return{type:"array_access",array:t,key:i}}return{type:"variable",name:t}}throw new Error(`Unexpected token: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}};var Wt={name:"awk",summary:"pattern scanning and text processing language",usage:"awk [OPTIONS] 'PROGRAM' [FILE...]",options:["-F FS use FS as field separator","-v VAR=VAL assign VAL to variable VAR"," --help display this help and exit"]},Wn={name:"awk",async execute(e,t){D(t.requireDefenseContext,"awk","execution entry");let n=(h,c)=>_(t.requireDefenseContext,"awk",h,c);if(fe(e))return pe(Wt);let i=new H(/\s+/),s=" ",a=Object.create(null),o=0;for(let h=0;h<e.length;h++){let c=e[h];if(c==="-F"&&h+1<e.length)s=he(e[++h]),i=_e(s),o=h+1;else if(c.startsWith("-F"))s=he(c.slice(2)),i=_e(s),o=h+1;else if(c==="-v"&&h+1<e.length){let E=e[++h],F=E.indexOf("=");if(F>0){let G=E.slice(0,F),xe=he(E.slice(F+1));a[G]=xe}o=h+1}else{if(c.startsWith("--"))return re("awk",c);if(c.startsWith("-")&&c.length>1){let E=c[1];if(E!=="F"&&E!=="v")return re("awk",`-${E}`);o=h+1}else if(!c.startsWith("-")){o=h;break}}}if(o>=e.length)return{stdout:"",stderr:`awk: missing program
|
|
15
|
-
`,exitCode:1};let l=e[o],u=e.slice(o+1),N=new ne,
|
|
16
|
-
`,exitCode:1}}let C={readFile:t.fs.readFile.bind(t.fs),writeFile:t.fs.writeFile.bind(t.fs),appendFile:async(h,c)=>{try{let E=await n("appendFile read",()=>t.fs.readFile(h));await n("appendFile write",()=>t.fs.writeFile(h,E+c))}catch(E){if(E instanceof x)throw E;await n("appendFile create",()=>t.fs.writeFile(h,c))}},resolvePath:t.fs.resolvePath.bind(t.fs)},O=t.exec,I=ie({fieldSep:i,maxIterations:t.limits?.maxAwkIterations,maxOutputSize:t.limits?.maxStringLength,fs:C,cwd:t.cwd,exec:O?h=>n("command pipe exec",()=>O(h,{cwd:t.cwd,signal:t.signal})):void 0,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext});I.FS=s,I.vars=Object.assign(Object.create(null),a),I.ARGC=u.length+1,I.ARGV=Object.create(null),I.ARGV[0]="awk";for(let h=0;h<u.length;h++)I.ARGV[String(h+1)]=u[h];I.ENVIRON=de(t.env);let w=new q(I);w.execute(
|
|
14
|
+
`)break;i+=this.advance()}return this.peek()==="/"&&this.advance(),i=Gt(i),{type:r.REGEX,value:i,line:t,column:n}}readNumber(){let t=this.line,n=this.column,i="";for(;this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="."&&this.isDigit(this.peek(1)))for(i+=this.advance();this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(i+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(i+=this.advance());this.isDigit(this.peek());)i+=this.advance();return{type:r.NUMBER,value:parseFloat(i),line:t,column:n}}readIdentifier(){let t=this.line,n=this.column,i="";for(;this.isAlphaNumeric(this.peek())||this.peek()==="_";)i+=this.advance();let s=_t.get(i);return s!==void 0?{type:s,value:i,line:t,column:n}:{type:r.IDENT,value:i,line:t,column:n}}readOperator(){let t=this.line,n=this.column,i=this.advance(),s=this.peek();switch(i){case"+":return s==="+"?(this.advance(),{type:r.INCREMENT,value:"++",line:t,column:n}):s==="="?(this.advance(),{type:r.PLUS_ASSIGN,value:"+=",line:t,column:n}):{type:r.PLUS,value:"+",line:t,column:n};case"-":return s==="-"?(this.advance(),{type:r.DECREMENT,value:"--",line:t,column:n}):s==="="?(this.advance(),{type:r.MINUS_ASSIGN,value:"-=",line:t,column:n}):{type:r.MINUS,value:"-",line:t,column:n};case"*":return s==="*"?(this.advance(),{type:r.CARET,value:"**",line:t,column:n}):s==="="?(this.advance(),{type:r.STAR_ASSIGN,value:"*=",line:t,column:n}):{type:r.STAR,value:"*",line:t,column:n};case"/":return s==="="?(this.advance(),{type:r.SLASH_ASSIGN,value:"/=",line:t,column:n}):{type:r.SLASH,value:"/",line:t,column:n};case"%":return s==="="?(this.advance(),{type:r.PERCENT_ASSIGN,value:"%=",line:t,column:n}):{type:r.PERCENT,value:"%",line:t,column:n};case"^":return s==="="?(this.advance(),{type:r.CARET_ASSIGN,value:"^=",line:t,column:n}):{type:r.CARET,value:"^",line:t,column:n};case"=":return s==="="?(this.advance(),{type:r.EQ,value:"==",line:t,column:n}):{type:r.ASSIGN,value:"=",line:t,column:n};case"!":return s==="="?(this.advance(),{type:r.NE,value:"!=",line:t,column:n}):s==="~"?(this.advance(),{type:r.NOT_MATCH,value:"!~",line:t,column:n}):{type:r.NOT,value:"!",line:t,column:n};case"<":return s==="="?(this.advance(),{type:r.LE,value:"<=",line:t,column:n}):{type:r.LT,value:"<",line:t,column:n};case">":return s==="="?(this.advance(),{type:r.GE,value:">=",line:t,column:n}):s===">"?(this.advance(),{type:r.APPEND,value:">>",line:t,column:n}):{type:r.GT,value:">",line:t,column:n};case"&":return s==="&"?(this.advance(),{type:r.AND,value:"&&",line:t,column:n}):{type:r.IDENT,value:"&",line:t,column:n};case"|":return s==="|"?(this.advance(),{type:r.OR,value:"||",line:t,column:n}):{type:r.PIPE,value:"|",line:t,column:n};case"~":return{type:r.MATCH,value:"~",line:t,column:n};case"?":return{type:r.QUESTION,value:"?",line:t,column:n};case":":return{type:r.COLON,value:":",line:t,column:n};case",":return{type:r.COMMA,value:",",line:t,column:n};case";":return{type:r.SEMICOLON,value:";",line:t,column:n};case"(":return{type:r.LPAREN,value:"(",line:t,column:n};case")":return{type:r.RPAREN,value:")",line:t,column:n};case"{":return{type:r.LBRACE,value:"{",line:t,column:n};case"}":return{type:r.RBRACE,value:"}",line:t,column:n};case"[":return{type:r.LBRACKET,value:"[",line:t,column:n};case"]":return{type:r.RBRACKET,value:"]",line:t,column:n};case"$":return{type:r.DOLLAR,value:"$",line:t,column:n};default:return{type:r.IDENT,value:i,line:t,column:n}}}isDigit(t){return t>="0"&&t<="9"}isAlpha(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}isAlphaNumeric(t){return this.isDigit(t)||this.isAlpha(t)}};var p={LPAREN:"LPAREN",RPAREN:"RPAREN",QUESTION:"QUESTION",NEWLINE:"NEWLINE",SEMICOLON:"SEMICOLON",RBRACE:"RBRACE",COMMA:"COMMA",PIPE:"PIPE",GT:"GT",APPEND:"APPEND",AND:"AND",OR:"OR",ASSIGN:"ASSIGN",PLUS_ASSIGN:"PLUS_ASSIGN",MINUS_ASSIGN:"MINUS_ASSIGN",STAR_ASSIGN:"STAR_ASSIGN",SLASH_ASSIGN:"SLASH_ASSIGN",PERCENT_ASSIGN:"PERCENT_ASSIGN",CARET_ASSIGN:"CARET_ASSIGN",RBRACKET:"RBRACKET",COLON:"COLON",IN:"IN",PRINT:"PRINT",PRINTF:"PRINTF",IDENT:"IDENT",LT:"LT",LE:"LE",GE:"GE",EQ:"EQ",NE:"NE",MATCH:"MATCH",NOT_MATCH:"NOT_MATCH",NUMBER:"NUMBER",STRING:"STRING",DOLLAR:"DOLLAR",NOT:"NOT",MINUS:"MINUS",PLUS:"PLUS",INCREMENT:"INCREMENT",DECREMENT:"DECREMENT"};function Fe(e){e.expect(p.PRINT);let t=[];if(e.check(p.NEWLINE)||e.check(p.SEMICOLON)||e.check(p.RBRACE)||e.check(p.PIPE)||e.check(p.GT)||e.check(p.APPEND))t.push({type:"field",index:{type:"number",value:0}});else for(t.push(te(e));e.check(p.COMMA);)e.advance(),t.push(te(e));let n;return e.check(p.GT)?(e.advance(),n={redirect:">",file:e.parsePrimary()}):e.check(p.APPEND)&&(e.advance(),n={redirect:">>",file:e.parsePrimary()}),{type:"print",args:t,output:n}}function te(e){return Ut(e)?ce(e,!0):ce(e,!1)}function ce(e,t){let n=t?e.parseTernary():Bt(e);if(e.match(p.ASSIGN,p.PLUS_ASSIGN,p.MINUS_ASSIGN,p.STAR_ASSIGN,p.SLASH_ASSIGN,p.PERCENT_ASSIGN,p.CARET_ASSIGN)){let i=e.advance(),s=ce(e,t);if(n.type!=="variable"&&n.type!=="field"&&n.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:new Map([["=","="],["+=","+="],["-=","-="],["*=","*="],["/=","/="],["%=","%="],["^=","^="]]).get(i.value)??"=",target:n,value:s}}return n}function Ut(e){let t=0,n=e.pos;for(;n<e.tokens.length;){let i=e.tokens[n];if(i.type===p.LPAREN&&t++,i.type===p.RPAREN&&t--,i.type===p.QUESTION&&t===0)return!0;if(i.type===p.NEWLINE||i.type===p.SEMICOLON||i.type===p.RBRACE||i.type===p.COMMA||i.type===p.PIPE)return!1;n++}return!1}function Bt(e){let t=Le(e);for(;e.check(p.OR);){e.advance();let n=Le(e);t={type:"binary",operator:"||",left:t,right:n}}return t}function Le(e){let t=Me(e);for(;e.check(p.AND);){e.advance();let n=Me(e);t={type:"binary",operator:"&&",left:t,right:n}}return t}function Me(e){let t=Ht(e);if(e.check(p.IN)){e.advance();let n=String(e.expect(p.IDENT).value);return{type:"in",key:t,array:n}}return t}function Ht(e){let t=Pe(e);for(;$t(e)&&!Wt(e);){let n=Pe(e);t={type:"binary",operator:" ",left:t,right:n}}return t}function Pe(e){let t=Te(e);for(;e.match(p.MATCH,p.NOT_MATCH);){let n=e.advance().type===p.MATCH?"~":"!~",i=Te(e);t={type:"binary",operator:n,left:t,right:i}}return t}function Te(e){let t=e.parseAddSub();for(;e.match(p.LT,p.LE,p.GE,p.EQ,p.NE);){let n=e.advance(),i=e.parseAddSub();t={type:"binary",operator:new Map([["<","<"],["<=","<="],[">=",">="],["==","=="],["!=","!="]]).get(n.value)??"==",left:t,right:i}}return t}function $t(e){return e.match(p.NUMBER,p.STRING,p.IDENT,p.DOLLAR,p.LPAREN,p.NOT,p.MINUS,p.PLUS,p.INCREMENT,p.DECREMENT)}function Wt(e){return e.match(p.AND,p.OR,p.QUESTION,p.ASSIGN,p.PLUS_ASSIGN,p.MINUS_ASSIGN,p.STAR_ASSIGN,p.SLASH_ASSIGN,p.PERCENT_ASSIGN,p.CARET_ASSIGN,p.COMMA,p.SEMICOLON,p.NEWLINE,p.RBRACE,p.RPAREN,p.RBRACKET,p.COLON,p.PIPE,p.APPEND,p.GT,p.IN)}function De(e){e.expect(p.PRINTF);let t=e.check(p.LPAREN);t&&(e.advance(),e.skipNewlines());let n=t?e.parseExpression():te(e),i=[];for(;e.check(p.COMMA);)e.advance(),t&&e.skipNewlines(),i.push(t?e.parseExpression():te(e));t&&(e.skipNewlines(),e.expect(p.RPAREN));let s;return e.check(p.GT)?(e.advance(),s={redirect:">",file:e.parsePrimary()}):e.check(p.APPEND)&&(e.advance(),s={redirect:">>",file:e.parsePrimary()}),{type:"printf",format:n,args:i,output:s}}var ne=class{tokens=[];pos=0;parse(t){let n=new ee(t);return this.tokens=n.tokenize(),this.pos=0,this.parseProgram()}setPos(t){this.pos=t}current(){return this.tokens[this.pos]||{type:r.EOF,value:"",line:0,column:0}}advance(){let t=this.current();return this.pos<this.tokens.length&&this.pos++,t}match(...t){return t.includes(this.current().type)}check(t){return this.current().type===t}expect(t,n){if(!this.check(t)){let i=this.current();throw new Error(n||`Expected ${t}, got ${i.type} at line ${i.line}:${i.column}`)}return this.advance()}skipNewlines(){for(;this.check(r.NEWLINE);)this.advance()}skipTerminators(){for(;this.check(r.NEWLINE)||this.check(r.SEMICOLON);)this.advance()}parseProgram(){let t=[],n=[];for(this.skipNewlines();!this.check(r.EOF)&&(this.skipNewlines(),!this.check(r.EOF));)this.check(r.FUNCTION)?t.push(this.parseFunction()):n.push(this.parseRule()),this.skipTerminators();return{functions:t,rules:n}}parseFunction(){this.expect(r.FUNCTION);let t=this.expect(r.IDENT).value;this.expect(r.LPAREN);let n=[];if(!this.check(r.RPAREN))for(n.push(this.expect(r.IDENT).value);this.check(r.COMMA);)this.advance(),n.push(this.expect(r.IDENT).value);this.expect(r.RPAREN),this.skipNewlines();let i=this.parseBlock();return{name:t,params:n,body:i}}parseRule(){let t;if(this.check(r.BEGIN))this.advance(),t={type:"begin"};else if(this.check(r.END))this.advance(),t={type:"end"};else if(this.check(r.LBRACE))t=void 0;else if(this.check(r.REGEX)){let i=this.advance();if(this.check(r.AND)||this.check(r.OR)){let s={type:"binary",operator:"~",left:{type:"field",index:{type:"number",value:0}},right:{type:"regex",pattern:i.value}};t={type:"expr_pattern",expression:this.parseLogicalOrRest(s)}}else{let s={type:"regex_pattern",pattern:i.value};if(this.check(r.COMMA)){this.advance();let a;this.check(r.REGEX)?a={type:"regex_pattern",pattern:this.advance().value}:a={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:s,end:a}}else t=s}}else{let s={type:"expr_pattern",expression:this.parseExpression()};if(this.check(r.COMMA)){this.advance();let a;this.check(r.REGEX)?a={type:"regex_pattern",pattern:this.advance().value}:a={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:s,end:a}}else t=s}this.skipNewlines();let n;return this.check(r.LBRACE)?n=this.parseBlock():n={type:"block",statements:[{type:"print",args:[{type:"field",index:{type:"number",value:0}}]}]},{pattern:t,action:n}}parseBlock(){this.expect(r.LBRACE),this.skipNewlines();let t=[];for(;!this.check(r.RBRACE)&&!this.check(r.EOF);)t.push(this.parseStatement()),this.skipTerminators();return this.expect(r.RBRACE),{type:"block",statements:t}}parseStatement(){if(this.check(r.SEMICOLON)||this.check(r.NEWLINE))return this.advance(),{type:"block",statements:[]};if(this.check(r.LBRACE))return this.parseBlock();if(this.check(r.IF))return this.parseIf();if(this.check(r.WHILE))return this.parseWhile();if(this.check(r.DO))return this.parseDoWhile();if(this.check(r.FOR))return this.parseFor();if(this.check(r.BREAK))return this.advance(),{type:"break"};if(this.check(r.CONTINUE))return this.advance(),{type:"continue"};if(this.check(r.NEXT))return this.advance(),{type:"next"};if(this.check(r.NEXTFILE))return this.advance(),{type:"nextfile"};if(this.check(r.EXIT)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"exit",code:n}}if(this.check(r.RETURN)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"return",value:n}}if(this.check(r.DELETE)){this.advance();let n=this.parsePrimary();if(n.type!=="array_access"&&n.type!=="variable")throw new Error("delete requires array element or array");return{type:"delete",target:n}}return this.check(r.PRINT)?Fe(this):this.check(r.PRINTF)?De(this):{type:"expr_stmt",expression:this.parseExpression()}}parseIf(){this.expect(r.IF),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();this.skipTerminators();let i;return this.check(r.ELSE)&&(this.advance(),this.skipNewlines(),i=this.parseStatement()),{type:"if",condition:t,consequent:n,alternate:i}}parseWhile(){this.expect(r.WHILE),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();return{type:"while",condition:t,body:n}}parseDoWhile(){this.expect(r.DO),this.skipNewlines();let t=this.parseStatement();this.skipNewlines(),this.expect(r.WHILE),this.expect(r.LPAREN);let n=this.parseExpression();return this.expect(r.RPAREN),{type:"do_while",body:t,condition:n}}parseFor(){if(this.expect(r.FOR),this.expect(r.LPAREN),this.check(r.IDENT)){let a=this.advance();if(this.check(r.IN)){this.advance();let o=this.expect(r.IDENT).value;this.expect(r.RPAREN),this.skipNewlines();let l=this.parseStatement();return{type:"for_in",variable:a.value,array:o,body:l}}this.pos--}let t;this.check(r.SEMICOLON)||(t=this.parseExpression()),this.expect(r.SEMICOLON);let n;this.check(r.SEMICOLON)||(n=this.parseExpression()),this.expect(r.SEMICOLON);let i;this.check(r.RPAREN)||(i=this.parseExpression()),this.expect(r.RPAREN),this.skipNewlines();let s=this.parseStatement();return{type:"for",init:t,condition:n,update:i,body:s}}parseExpression(){return this.parseAssignment()}parseAssignment(){let t=this.parseTernary();if(this.match(r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN)){let n=this.advance(),i=this.parseAssignment();if(t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid assignment target");let s=new Set(["=","+=","-=","*=","/=","%=","^="]),a=n.value;if(!s.has(a))throw new Error(`Unknown assignment operator: ${a}`);return{type:"assignment",operator:a,target:t,value:i}}return t}parseTernary(){let t=this.parsePipeGetline();if(this.check(r.QUESTION)){this.advance();let n=this.parseExpression();this.expect(r.COLON);let i=this.parseExpression();t={type:"ternary",condition:t,consequent:n,alternate:i}}return t}parsePipeGetline(){let t=this.parseOr();if(this.check(r.PIPE)){if(this.advance(),!this.check(r.GETLINE))throw new Error("Expected 'getline' after '|' in expression context");this.advance();let n;return this.check(r.IDENT)&&(n=this.advance().value),{type:"getline",command:t,variable:n}}return t}parseOr(){let t=this.parseAnd();for(;this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalOrRest(t){for(t=this.parseLogicalAndRest(t);this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalAndRest(t){for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseAnd(){let t=this.parseIn();for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseIn(){let t=this.parseConcatenation();if(this.check(r.IN)){this.advance();let n=this.expect(r.IDENT).value;return{type:"in",key:t,array:n}}return t}parseConcatenation(){let t=this.parseMatch();for(;this.canStartExpression()&&!this.isConcatTerminator();){let n=this.parseMatch();t={type:"binary",operator:" ",left:t,right:n}}return t}parseMatch(){let t=this.parseComparison();for(;this.match(r.MATCH,r.NOT_MATCH);){let n=this.advance().type===r.MATCH?"~":"!~",i=this.parseComparison();t={type:"binary",operator:n,left:t,right:i}}return t}parseComparison(){let t=this.parseAddSub();for(;this.match(r.LT,r.LE,r.GT,r.GE,r.EQ,r.NE);){let n=this.advance(),i=this.parseAddSub();t={type:"binary",operator:new Map([["<","<"],["<=","<="],[">",">"],[">=",">="],["==","=="],["!=","!="]]).get(n.value)??"==",left:t,right:i}}return t}canStartExpression(){return this.match(r.NUMBER,r.STRING,r.IDENT,r.DOLLAR,r.LPAREN,r.NOT,r.MINUS,r.PLUS,r.INCREMENT,r.DECREMENT)}isConcatTerminator(){return this.match(r.AND,r.OR,r.QUESTION,r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN,r.COMMA,r.SEMICOLON,r.NEWLINE,r.RBRACE,r.RPAREN,r.RBRACKET,r.COLON,r.PIPE,r.APPEND,r.IN)}parseAddSub(){let t=this.parseMulDiv();for(;this.match(r.PLUS,r.MINUS);){let n=this.advance().value,i=this.parseMulDiv();t={type:"binary",operator:n,left:t,right:i}}return t}parseMulDiv(){let t=this.parseUnary();for(;this.match(r.STAR,r.SLASH,r.PERCENT);){let n=this.advance(),i=this.parseUnary();t={type:"binary",operator:new Map([["*","*"],["/","/"],["%","%"]]).get(n.value)??"*",left:t,right:i}}return t}parseUnary(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseUnary();return{type:"unary",operator:t,operand:n}}return this.parsePower()}parsePower(){let t=this.parsePostfix();if(this.check(r.CARET)){this.advance();let n=this.parsePower();t={type:"binary",operator:"^",left:t,right:n}}return t}parsePostfix(){let t=this.parsePrimary();if(this.check(r.INCREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid increment operand");return{type:"post_increment",operand:t}}if(this.check(r.DECREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid decrement operand");return{type:"post_decrement",operand:t}}return t}parseFieldIndex(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseFieldIndex();return{type:"unary",operator:t,operand:n}}return this.parseFieldIndexPower()}parseFieldIndexPower(){let t=this.parseFieldIndexPrimary();if(this.check(r.CARET)){this.advance();let n=this.parseFieldIndexPower();t={type:"binary",operator:"^",left:t,right:n}}return t}parseFieldIndexPrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();return this.expect(r.RPAREN),t}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=this.parseExpression();if(this.check(r.COMMA)){let i=[n];for(;this.check(r.COMMA);)this.advance(),i.push(this.parseExpression());this.expect(r.RBRACKET);let s=i.reduce((a,o)=>({type:"binary",operator:" ",left:{type:"binary",operator:" ",left:a,right:{type:"variable",name:"SUBSEP"}},right:o}));return{type:"array_access",array:t,key:s}}return this.expect(r.RBRACKET),{type:"array_access",array:t,key:n}}return{type:"variable",name:t}}throw new Error(`Unexpected token in field index: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}parsePrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.REGEX))return{type:"regex",pattern:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();if(this.check(r.COMMA)){let n=[t];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"tuple",elements:n}}return this.expect(r.RPAREN),t}if(this.check(r.GETLINE)){this.advance();let t,n;return this.check(r.IDENT)&&(t=this.advance().value),this.check(r.LT)&&(this.advance(),n=this.parsePrimary()),{type:"getline",variable:t,file:n}}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(this.skipNewlines(),!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),this.skipNewlines(),n.push(this.parseExpression());return this.skipNewlines(),this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=[this.parseExpression()];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());this.expect(r.RBRACKET);let i;if(n.length===1)i=n[0];else{i=n[0];for(let s=1;s<n.length;s++)i={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:i,right:{type:"variable",name:"SUBSEP"}},right:n[s]}}return{type:"array_access",array:t,key:i}}return{type:"variable",name:t}}throw new Error(`Unexpected token: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}};var Vt={name:"awk",summary:"pattern scanning and text processing language",usage:"awk [OPTIONS] 'PROGRAM' [FILE...]",options:["-F FS use FS as field separator","-v VAR=VAL assign VAL to variable VAR"," --help display this help and exit"]},Vn={name:"awk",async execute(e,t){D(t.requireDefenseContext,"awk","execution entry");let n=(h,c)=>_(t.requireDefenseContext,"awk",h,c);if(fe(e))return pe(Vt);let i=new H(/\s+/),s=" ",a=Object.create(null),o=0;for(let h=0;h<e.length;h++){let c=e[h];if(c==="-F"&&h+1<e.length)s=he(e[++h]),i=_e(s),o=h+1;else if(c.startsWith("-F"))s=he(c.slice(2)),i=_e(s),o=h+1;else if(c==="-v"&&h+1<e.length){let E=e[++h],F=E.indexOf("=");if(F>0){let G=E.slice(0,F),xe=he(E.slice(F+1));a[G]=xe}o=h+1}else{if(c.startsWith("--"))return re("awk",c);if(c.startsWith("-")&&c.length>1){let E=c[1];if(E!=="F"&&E!=="v")return re("awk",`-${E}`);o=h+1}else if(!c.startsWith("-")){o=h;break}}}if(o>=e.length)return{stdout:"",stderr:`awk: missing program
|
|
15
|
+
`,exitCode:1};let l=e[o],u=e.slice(o+1),N=new ne,A;try{A=N.parse(l)}catch(h){return{stdout:"",stderr:`awk: ${h instanceof Error?h.message:String(h)}
|
|
16
|
+
`,exitCode:1}}let C={readFile:t.fs.readFile.bind(t.fs),writeFile:t.fs.writeFile.bind(t.fs),appendFile:async(h,c)=>{try{let E=await n("appendFile read",()=>t.fs.readFile(h));await n("appendFile write",()=>t.fs.writeFile(h,E+c))}catch(E){if(E instanceof x)throw E;await n("appendFile create",()=>t.fs.writeFile(h,c))}},resolvePath:t.fs.resolvePath.bind(t.fs)},O=t.exec,I=ie({fieldSep:i,maxIterations:t.limits?.maxAwkIterations,maxOutputSize:t.limits?.maxStringLength,fs:C,cwd:t.cwd,exec:O?h=>n("command pipe exec",()=>O(h,{cwd:t.cwd,signal:t.signal})):void 0,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext});I.FS=s,I.vars=Object.assign(Object.create(null),a),I.ARGC=u.length+1,I.ARGV=Object.create(null),I.ARGV[0]="awk";for(let h=0;h<u.length;h++)I.ARGV[String(h+1)]=u[h];I.ENVIRON=de(t.env);let w=new q(I);w.execute(A);let d=A.rules.some(h=>h.pattern?.type!=="begin"&&h.pattern?.type!=="end"),R=A.rules.some(h=>h.pattern?.type==="end");try{if(await n("BEGIN execution",()=>w.executeBegin()),I.shouldExit)return await n("END execution after BEGIN exit",()=>w.executeEnd()),{stdout:w.getOutput(),stderr:"",exitCode:w.getExitCode()};if(!d&&!R)return{stdout:w.getOutput(),stderr:"",exitCode:w.getExitCode()};let h=[];if(u.length>0)for(let c of u)try{let E=t.fs.resolvePath(t.cwd,c),G=(await n("input file read",()=>t.fs.readFile(E))).split(`
|
|
17
17
|
`);G.length>0&&G[G.length-1]===""&&G.pop(),h.push({filename:c,lines:G})}catch(E){if(E instanceof x)throw E;return{stdout:"",stderr:`awk: ${c}: No such file or directory
|
|
18
18
|
`,exitCode:1}}else{let c=t.stdin.split(`
|
|
19
19
|
`);c.length>0&&c[c.length-1]===""&&c.pop(),h.push({filename:"",lines:c})}for(let c of h){for(I.FILENAME=c.filename,I.FNR=0,I.lines=c.lines,I.lineIndex=-1,I.shouldNextFile=!1;I.lineIndex<c.lines.length-1;){I.lineIndex++;let E=I.lineIndex;if(await n("line execution",()=>w.executeLine(c.lines[E])),I.shouldExit||I.shouldNextFile)break}if(I.shouldExit)break}return await n("END execution",()=>w.executeEnd()),{stdout:w.getOutput(),stderr:"",exitCode:w.getExitCode()}}catch(h){if(h instanceof x)throw h;let c=h instanceof Error?h.message:String(h),E=h instanceof P?P.EXIT_CODE:2;return{stdout:w.getOutput(),stderr:`awk: ${c}
|
|
20
20
|
`,exitCode:E}}}};function he(e){return e.replace(/\\t/g," ").replace(/\\n/g,`
|
|
21
|
-
`).replace(/\\r/g,"\r").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\a/g,"\x07").replace(/\\v/g,"\v").replace(/\\\\/g,"\\")}function _e(e){if(e===" ")return
|
|
21
|
+
`).replace(/\\r/g,"\r").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\a/g,"\x07").replace(/\\v/g,"\v").replace(/\\\\/g,"\\")}function _e(e){if(e===" ")return v("\\s+");if(/[[\](){}.*+?^$|\\]/.test(e))try{return v(e)}catch{return v(Ge(e))}return v(Ge(e))}function Ge(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Kn={name:"awk",flags:[{flag:"-F",type:"value",valueHint:"delimiter"},{flag:"-v",type:"value",valueHint:"string"}],stdinType:"text",needsArgs:!0};export{Vn as a,Kn as b};
|