just-bash 2.9.5 → 2.9.7
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/dist/Bash.d.ts +5 -0
- package/dist/bin/chunks/{awk2-JBWRWZZH.js → awk2-PWEGD656.js} +1 -1
- package/dist/bin/{shell/chunks/base64-OHU2WTUF.js → chunks/base64-YXBFJFHG.js} +1 -1
- package/dist/bin/{shell/chunks/bash-RJTQJAKW.js → chunks/bash-WB6O736J.js} +1 -1
- package/dist/bin/chunks/chunk-A4442AOC.js +6 -0
- package/dist/bin/chunks/chunk-BARKRZDC.js +6 -0
- package/dist/bin/chunks/{chunk-CHQBMS62.js → chunk-CHB75QIN.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-7FTB27TY.js → chunks/chunk-FEBB4TFH.js} +15 -15
- package/dist/bin/{shell/chunks/chunk-ZJSZ2BE5.js → chunks/chunk-K7XSYP4L.js} +11 -11
- package/dist/bin/chunks/{chunk-Q4AUWUII.js → chunk-LS25HZNJ.js} +1 -1
- package/dist/bin/chunks/{chunk-F26OLHG5.js → chunk-MNNOATCV.js} +1 -1
- package/dist/bin/chunks/{chunk-DSNA7727.js → chunk-QEBPVWVB.js} +1 -1
- package/dist/bin/chunks/{chunk-OIKCUTTB.js → chunk-RDZMRK5M.js} +1 -1
- package/dist/bin/chunks/{expansion-HIAVHGBZ.js → expansion-TL4Q62VX.js} +1 -1
- package/dist/bin/chunks/{flag-coverage-FNEHS7AY.js → flag-coverage-SFRIE2LL.js} +1 -1
- package/dist/bin/{shell/chunks/jq-3VHS7DR6.js → chunks/jq-CXQ33VMW.js} +1 -1
- package/dist/bin/{shell/chunks/sed-XP3QCHIB.js → chunks/sed-WNL6TIIN.js} +1 -1
- package/dist/bin/chunks/{xan-EBI2W7YX.js → xan-FMSZPFX4.js} +1 -1
- package/dist/bin/chunks/{yq-O56CEX4T.js → yq-WUJ5JNDT.js} +1 -1
- package/dist/bin/just-bash.js +52 -52
- package/dist/bin/shell/chunks/{awk2-JBWRWZZH.js → awk2-PWEGD656.js} +1 -1
- package/dist/bin/{chunks/base64-OHU2WTUF.js → shell/chunks/base64-YXBFJFHG.js} +1 -1
- package/dist/bin/{chunks/bash-RJTQJAKW.js → shell/chunks/bash-WB6O736J.js} +1 -1
- package/dist/bin/shell/chunks/chunk-A4442AOC.js +6 -0
- package/dist/bin/shell/chunks/chunk-BARKRZDC.js +6 -0
- package/dist/bin/shell/chunks/{chunk-CHQBMS62.js → chunk-CHB75QIN.js} +1 -1
- package/dist/bin/{chunks/chunk-7FTB27TY.js → shell/chunks/chunk-FEBB4TFH.js} +15 -15
- package/dist/bin/{chunks/chunk-ZJSZ2BE5.js → shell/chunks/chunk-K7XSYP4L.js} +11 -11
- package/dist/bin/shell/chunks/{chunk-Q4AUWUII.js → chunk-LS25HZNJ.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-F26OLHG5.js → chunk-MNNOATCV.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-DSNA7727.js → chunk-QEBPVWVB.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-OIKCUTTB.js → chunk-RDZMRK5M.js} +1 -1
- package/dist/bin/shell/chunks/{expansion-HIAVHGBZ.js → expansion-TL4Q62VX.js} +1 -1
- package/dist/bin/shell/chunks/{flag-coverage-FNEHS7AY.js → flag-coverage-SFRIE2LL.js} +1 -1
- package/dist/bin/{chunks/jq-3VHS7DR6.js → shell/chunks/jq-CXQ33VMW.js} +1 -1
- package/dist/bin/{chunks/sed-XP3QCHIB.js → shell/chunks/sed-WNL6TIIN.js} +1 -1
- package/dist/bin/shell/chunks/{xan-EBI2W7YX.js → xan-FMSZPFX4.js} +1 -1
- package/dist/bin/shell/chunks/{yq-O56CEX4T.js → yq-WUJ5JNDT.js} +1 -1
- package/dist/bin/shell/shell.js +4 -4
- package/dist/bundle/browser.js +657 -657
- package/dist/bundle/chunks/{awk2-M5NFQRYA.js → awk2-BDPR2JPZ.js} +1 -1
- package/dist/bundle/chunks/{base64-HYOQ5I2F.js → base64-A3SGWC34.js} +1 -1
- package/dist/bundle/chunks/{bash-OVBCDR7G.js → bash-DYXMG247.js} +1 -1
- package/dist/bundle/chunks/{chunk-GQ7SJRUH.js → chunk-2OCD45J4.js} +1 -1
- package/dist/bundle/chunks/{chunk-WEIVGBP5.js → chunk-3KWUDRIP.js} +11 -11
- package/dist/bundle/chunks/chunk-FRDGR5VK.js +5 -0
- package/dist/bundle/chunks/chunk-IBFD7QQD.js +5 -0
- package/dist/bundle/chunks/{chunk-UAHZJD43.js → chunk-JI3KJ32H.js} +1 -1
- package/dist/bundle/chunks/{chunk-HXILPMCG.js → chunk-JP44OYZS.js} +1 -1
- package/dist/bundle/chunks/{chunk-CCL4U6Q4.js → chunk-UJXASUXJ.js} +1 -1
- package/dist/bundle/chunks/{chunk-VTHR2H5Q.js → chunk-WACZHM4L.js} +15 -15
- package/dist/bundle/chunks/{chunk-GOBUJIHS.js → chunk-XMDVFEVC.js} +1 -1
- package/dist/bundle/chunks/{expansion-R2VVQUSY.js → expansion-L4NRX44B.js} +1 -1
- package/dist/bundle/chunks/{flag-coverage-KDDXWVDJ.js → flag-coverage-MX32DFGQ.js} +1 -1
- package/dist/bundle/chunks/{jq-HA6MN2H5.js → jq-OJYNICKX.js} +1 -1
- package/dist/bundle/chunks/{sed-MUVA7R2C.js → sed-RXIECPPB.js} +1 -1
- package/dist/bundle/chunks/{xan-6DLWA2BW.js → xan-Z6KVJKEE.js} +1 -1
- package/dist/bundle/chunks/{yq-LO2NVDTD.js → yq-FD5F3WOJ.js} +1 -1
- package/dist/bundle/index.js +4 -4
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
- package/dist/bin/chunks/chunk-FZNYF2PQ.js +0 -6
- package/dist/bin/chunks/chunk-STU6KQN4.js +0 -6
- package/dist/bin/shell/chunks/chunk-FZNYF2PQ.js +0 -6
- package/dist/bin/shell/chunks/chunk-STU6KQN4.js +0 -6
- package/dist/bundle/chunks/chunk-JSZMK2JZ.js +0 -5
- package/dist/bundle/chunks/chunk-RSXSWZBQ.js +0 -5
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as oe}from"./chunk-4PRVMER6.js";import{a as A,b as P}from"./chunk-SE4C7FJY.js";import{k as O}from"./chunk-K5IXNHO5.js";import{a as se,b as ae,c as z}from"./chunk-GTNBSMZR.js";var Le=1e4,Me=100,Pe=new P(/\s+/);function Q(e={}){let{fieldSep:t=Pe,maxIterations:n=Le,maxRecursionDepth:i=Me,maxOutputSize:a=0,fs:s,cwd:o,exec:
|
|
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:a,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,inEndBlock:!1,output:"",openedFiles:new Set,fs:s,cwd:o,exec:
|
|
4
|
-
`,a+=2):s==="t"?(i+=" ",a+=2):(i+=s,a+=2)}else e[a]==="&"?(i+=t,a++):(i+=e[a],a++);return i}async function He(e,t,n){return e.length===0?"":
|
|
5
|
-
`;break;case"t":i+=" ";break;case"r":i+="\r";break;case"\\":i+="\\";break;default:i+=s}a+=2}else i+=e[a++];return i}var de=new Map([["length",Te],["substr",Fe],["index",_e],["split",Ge],["sub",De],["gsub",
|
|
6
|
-
`),o.length>0&&o[o.length-1]===""&&o.pop(),e.vars[a]=JSON.stringify(o),e.vars[s]=-1,
|
|
7
|
-
`),
|
|
2
|
+
import{a as oe}from"./chunk-4PRVMER6.js";import{a as A,b as P}from"./chunk-SE4C7FJY.js";import{k as O}from"./chunk-K5IXNHO5.js";import{a as se,b as ae,c as z}from"./chunk-GTNBSMZR.js";var Le=1e4,Me=100,Pe=new P(/\s+/);function Q(e={}){let{fieldSep:t=Pe,maxIterations:n=Le,maxRecursionDepth:i=Me,maxOutputSize:a=0,fs:s,cwd:o,exec:c,coverage:u}=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:a,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,inEndBlock:!1,output:"",openedFiles:new Set,fs:s,cwd:o,exec:c,coverage:u}}function le(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 C(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function I(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}async function U(e,t){if(e.type==="regex")return e.pattern;let n=I(await t.evalExpr(e));return n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)),n}async function ue(e,t){return e?e.type==="variable"?e.name:e.type==="field"?`$${Math.floor(C(await t.evalExpr(e.index)))}`:"$0":"$0"}function he(e,t){if(e==="$0")return t.line;if(e.startsWith("$")){let n=parseInt(e.slice(1),10)-1;return t.fields[n]||""}return I(t.vars[e]??"")}function pe(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 Te(e,t,n){return e.length===0?t.line.length:I(await n.evalExpr(e[0])).length}async function Fe(e,t,n){if(e.length<2)return"";let i=I(await n.evalExpr(e[0])),a=Math.floor(C(await n.evalExpr(e[1])))-1;if(e.length>=3){let s=Math.floor(C(await n.evalExpr(e[2])));return i.substr(Math.max(0,a),s)}return i.substr(Math.max(0,a))}async function _e(e,t,n){if(e.length<2)return 0;let i=I(await n.evalExpr(e[0])),a=I(await n.evalExpr(e[1])),s=i.indexOf(a);return s===-1?0:s+1}async function Ge(e,t,n){if(e.length<2)return 0;let i=I(await n.evalExpr(e[0])),a=e[1];if(a.type!=="variable")return 0;let s=a.name,o=t.FS;if(e.length>=3){let u=e[2];if(u.type==="regex")o=A(u.pattern);else{let N=I(await n.evalExpr(u));o=N===" "?A("\\s+"):N}}else t.FS===" "&&(o=A("\\s+"));let c=typeof o=="string"?i.split(o):o.split(i);t.arrays[s]=Object.create(null);for(let u=0;u<c.length;u++)t.arrays[s][String(u+1)]=c[u];return c.length}async function De(e,t,n){if(e.length<2)return 0;let i=await U(e[0],n),a=I(await n.evalExpr(e[1])),s=await ue(e[2],n),o=he(s,t);try{let u=A(i).replace(o,fe(a)),N=u!==o?1:0;return pe(s,u,t),N}catch{return 0}}async function xe(e,t,n){if(e.length<2)return 0;let i=await U(e[0],n),a=I(await n.evalExpr(e[1])),s=await ue(e[2],n),o=he(s,t);try{let c=A(i,"g"),u=c.match(o),N=u?u.length:0,k=c.replace(o,fe(a));return pe(s,k,t),N}catch{return 0}}function fe(e){return t=>{let n="",i=0;for(;i<e.length;)if(e[i]==="\\"&&i+1<e.length){let a=e[i+1];a==="&"?(n+="&",i+=2):a==="\\"?(n+="\\",i+=2):(n+=e[i+1],i+=2)}else e[i]==="&"?(n+=t,i++):(n+=e[i],i++);return n}}async function Ue(e,t,n){if(e.length<2)return t.RSTART=0,t.RLENGTH=-1,0;let i=I(await n.evalExpr(e[0])),a=await U(e[1],n);try{let o=A(a).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 Be(e,t,n){if(e.length<3)return"";let i=await U(e[0],n),a=I(await n.evalExpr(e[1])),s=I(await n.evalExpr(e[2])),o=e.length>=4?I(await n.evalExpr(e[3])):t.line;try{let c=s.toLowerCase()==="g",u=c?0:parseInt(s,10)||1;if(c)return A(i,"g").replace(o,(k,...y)=>ce(a,k,y.slice(0,-2)));{let N=0;return A(i,"g").replace(o,(y,...w)=>(N++,N===u?ce(a,y,w.slice(0,-2)):y))}}catch{return o}}function ce(e,t,n){let i="",a=0;for(;a<e.length;)if(e[a]==="\\"&&a+1<e.length){let s=e[a+1];if(s==="&")i+="&",a+=2;else if(s==="0")i+=t,a+=2;else if(s>="1"&&s<="9"){let o=parseInt(s,10)-1;i+=n[o]||"",a+=2}else s==="n"?(i+=`
|
|
4
|
+
`,a+=2):s==="t"?(i+=" ",a+=2):(i+=s,a+=2)}else e[a]==="&"?(i+=t,a++):(i+=e[a],a++);return i}async function He(e,t,n){return e.length===0?"":I(await n.evalExpr(e[0])).toLowerCase()}async function $e(e,t,n){return e.length===0?"":I(await n.evalExpr(e[0])).toUpperCase()}async function We(e,t,n){if(e.length===0)return"";let i=I(await n.evalExpr(e[0])),a=[];for(let s=1;s<e.length;s++)a.push(await n.evalExpr(e[s]));return B(i,a)}async function Ve(e,t,n){return e.length===0?0:Math.floor(C(await n.evalExpr(e[0])))}async function Ke(e,t,n){return e.length===0?0:Math.sqrt(C(await n.evalExpr(e[0])))}async function Xe(e,t,n){return e.length===0?0:Math.sin(C(await n.evalExpr(e[0])))}async function je(e,t,n){return e.length===0?0:Math.cos(C(await n.evalExpr(e[0])))}async function ze(e,t,n){let i=e.length>0?C(await n.evalExpr(e[0])):0,a=e.length>1?C(await n.evalExpr(e[1])):0;return Math.atan2(i,a)}async function Qe(e,t,n){return e.length===0?0:Math.log(C(await n.evalExpr(e[0])))}async function qe(e,t,n){return e.length===0?1:Math.exp(C(await n.evalExpr(e[0])))}function Je(e,t,n){return t.random?t.random():Math.random()}async function Ze(e,t,n){let i=e.length>0?C(await n.evalExpr(e[0])):Date.now();return t.vars._srand_seed=i,i}function Ye(e,t){return()=>{throw new Error(`${e}() is not supported - ${t}`)}}function q(e){return()=>{throw new Error(`function '${e}()' is not implemented`)}}var L=1e4;function B(e,t){let n=0,i="",a=0;for(;a<e.length;)if(e[a]==="%"&&a+1<e.length){let s=a+1,o="",c="",u="",N,k=s;for(;s<e.length&&/\d/.test(e[s]);)s++;s>k&&e[s]==="$"?(N=parseInt(e.substring(k,s),10)-1,s++):s=k;let y=()=>{if(s<e.length){if(s+1<e.length&&(e[s]==="h"&&e[s+1]==="h"||e[s]==="l"&&e[s+1]==="l")){s+=2;return}/[lzjh]/.test(e[s])&&s++}};for(;s<e.length&&/[-+ #0]/.test(e[s]);)o+=e[s++];if(e[s]==="*"){let l=t[n++],p=l!==void 0?Math.floor(Number(l)):0;p<0?(o+="-",c=String(Math.min(-p,L))):c=String(Math.min(p,L)),s++}else for(;s<e.length&&/\d/.test(e[s]);)c+=e[s++];if(c&&parseInt(c,10)>L&&(c=String(L)),e[s]==="."){if(s++,e[s]==="*"){let l=t[n++];u=String(Math.min(l!==void 0?Math.floor(Number(l)):0,L)),s++}else for(;s<e.length&&/\d/.test(e[s]);)u+=e[s++];u&&parseInt(u,10)>L&&(u=String(L))}y();let w=e[s],g=t[N!==void 0?N:n];switch(w){case"s":{let l=g!==void 0?String(g):"";if(u&&(l=l.substring(0,parseInt(u,10))),c){let p=parseInt(c,10);o.includes("-")?l=l.padEnd(p):l=l.padStart(p)}i+=l,N===void 0&&n++;break}case"d":case"i":{let l=g!==void 0?Math.floor(Number(g)):0;Number.isNaN(l)&&(l=0);let p=l<0,E=Math.abs(l).toString();if(u){let b=parseInt(u,10);E=E.padStart(b,"0")}let d="";p?d="-":o.includes("+")?d="+":o.includes(" ")&&(d=" ");let R=d+E;if(c){let b=parseInt(c,10);o.includes("-")?R=R.padEnd(b):o.includes("0")&&!u?R=d+E.padStart(b-d.length,"0"):R=R.padStart(b)}i+=R,N===void 0&&n++;break}case"f":{let l=g!==void 0?Number(g):0;Number.isNaN(l)&&(l=0);let p=u?parseInt(u,10):6,E=l.toFixed(p);if(c){let d=parseInt(c,10);o.includes("-")?E=E.padEnd(d):E=E.padStart(d)}i+=E,N===void 0&&n++;break}case"e":case"E":{let l=g!==void 0?Number(g):0;Number.isNaN(l)&&(l=0);let p=u?parseInt(u,10):6,E=l.toExponential(p);if(w==="E"&&(E=E.toUpperCase()),c){let d=parseInt(c,10);o.includes("-")?E=E.padEnd(d):E=E.padStart(d)}i+=E,N===void 0&&n++;break}case"g":case"G":{let l=g!==void 0?Number(g):0;Number.isNaN(l)&&(l=0);let p=u?parseInt(u,10):6,E=l!==0?Math.floor(Math.log10(Math.abs(l))):0,d;if(l===0?d="0":E<-4||E>=p?(d=l.toExponential(p-1),w==="G"&&(d=d.toUpperCase())):d=l.toPrecision(p),d.includes(".")&&(d=d.replace(/\.?0+$/,"").replace(/\.?0+e/,"e")),d.includes("e")&&(d=d.replace(/\.?0+e/,"e")),c){let R=parseInt(c,10);o.includes("-")?d=d.padEnd(R):d=d.padStart(R)}i+=d,N===void 0&&n++;break}case"x":case"X":{let l=g!==void 0?Math.floor(Number(g)):0;Number.isNaN(l)&&(l=0);let p=Math.abs(l).toString(16);if(w==="X"&&(p=p.toUpperCase()),u){let R=parseInt(u,10);p=p.padStart(R,"0")}let E=l<0?"-":"",d=E+p;if(c){let R=parseInt(c,10);o.includes("-")?d=d.padEnd(R):o.includes("0")&&!u?d=E+p.padStart(R-E.length,"0"):d=d.padStart(R)}i+=d,N===void 0&&n++;break}case"o":{let l=g!==void 0?Math.floor(Number(g)):0;Number.isNaN(l)&&(l=0);let p=Math.abs(l).toString(8);if(u){let R=parseInt(u,10);p=p.padStart(R,"0")}let E=l<0?"-":"",d=E+p;if(c){let R=parseInt(c,10);o.includes("-")?d=d.padEnd(R):o.includes("0")&&!u?d=E+p.padStart(R-E.length,"0"):d=d.padStart(R)}i+=d,N===void 0&&n++;break}case"c":{typeof g=="number"?i+=String.fromCharCode(g):i+=String(g??"").charAt(0)||"",N===void 0&&n++;break}case"%":i+="%";break;default:i+=e.substring(a,s+1)}a=s+1}else if(e[a]==="\\"&&a+1<e.length){let s=e[a+1];switch(s){case"n":i+=`
|
|
5
|
+
`;break;case"t":i+=" ";break;case"r":i+="\r";break;case"\\":i+="\\";break;default:i+=s}a+=2}else i+=e[a++];return i}var de=new Map([["length",Te],["substr",Fe],["index",_e],["split",Ge],["sub",De],["gsub",xe],["match",Ue],["gensub",Be],["tolower",He],["toupper",$e],["sprintf",We],["int",Ve],["sqrt",Ke],["sin",Xe],["cos",je],["atan2",ze],["log",Qe],["exp",qe],["rand",Je],["srand",Ze],["system",Ye("system","shell execution not allowed in sandboxed environment")],["close",()=>0],["fflush",()=>0],["systime",q("systime")],["mktime",q("mktime")],["strftime",q("strftime")]]);function v(e){return typeof e=="number"?e!==0:!(e===""||e==="0")}function m(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function S(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}function J(e){if(typeof e=="number")return!0;let t=String(e).trim();return t===""?!1:!Number.isNaN(Number(t))}function G(e,t){try{return A(e).test(t)}catch{return!1}}function Ee(e,t){return t===""?[]:e.FS===" "?t.trim().split(/\s+/).filter(Boolean):e.fieldSep.split(t)}function H(e,t){return t===0?e.line:t<0||t>e.fields.length?"":e.fields[t-1]??""}function Z(e,t,n){if(t===0)e.line=S(n),e.fields=Ee(e,e.line),e.NF=e.fields.length;else if(t>0){for(;e.fields.length<t;)e.fields.push("");e.fields[t-1]=S(n),e.NF=e.fields.length,e.line=e.fields.join(e.OFS)}}function T(e,t){e.line=t,e.fields=Ee(e,t),e.NF=e.fields.length}function Ne(e,t){if(e.FS=t,t===" ")e.fieldSep=new P(/\s+/);else try{e.fieldSep=A(t)}catch{e.fieldSep=A(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"))}}function $(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 F(e,t,n){switch(t){case"FS":Ne(e,S(n));return;case"OFS":e.OFS=S(n);return;case"ORS":e.ORS=S(n);return;case"OFMT":e.OFMT=S(n);return;case"NR":e.NR=Math.floor(m(n));return;case"NF":{let i=Math.floor(m(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(m(n));return;case"FILENAME":e.FILENAME=S(n);return;case"RSTART":e.RSTART=Math.floor(m(n));return;case"RLENGTH":e.RLENGTH=Math.floor(m(n));return;case"SUBSEP":e.SUBSEP=S(n);return}e.vars[t]=n}function D(e,t){let n=t,i=new Set,a=e.arrayAliases.get(n);for(;a!==void 0&&!i.has(n);)i.add(n),n=a,a=e.arrayAliases.get(n);return n}function W(e,t,n){if(t==="ARGV")return e.ARGV[n]??"";if(t==="ENVIRON")return e.ENVIRON[n]??"";let i=D(e,t);return e.arrays[i]?.[n]??""}function Y(e,t,n,i){let a=D(e,t);e.arrays[a]||(e.arrays[a]=Object.create(null)),e.arrays[a][n]=i}function Se(e,t,n){if(t==="ARGV")return e.ARGV[n]!==void 0;if(t==="ENVIRON")return e.ENVIRON[n]!==void 0;let i=D(e,t);return e.arrays[i]?.[n]!==void 0}function ye(e,t,n){let i=D(e,t);e.arrays[i]&&delete e.arrays[i][n]}function Re(e,t){let n=D(e,t);delete e.arrays[n]}var ee=null;function me(e){ee=e}async function f(e,t){switch(e.coverage?.hit(`awk:expr:${t.type}`),t.type){case"number":return t.value;case"string":return t.value;case"regex":return G(t.pattern,e.line)?1:0;case"field":return et(e,t);case"variable":return $(e,t.name);case"array_access":return tt(e,t);case"binary":return nt(e,t);case"unary":return st(e,t);case"ternary":return v(await f(e,t.condition))?await f(e,t.consequent):await f(e,t.alternate);case"call":return at(e,t.name,t.args);case"assignment":return lt(e,t);case"pre_increment":return ct(e,t.operand);case"pre_decrement":return ut(e,t.operand);case"post_increment":return ht(e,t.operand);case"post_decrement":return pt(e,t.operand);case"in":return ft(e,t.key,t.array);case"getline":return dt(e,t.variable,t.file,t.command);case"tuple":return St(e,t.elements);default:return""}}async function et(e,t){let n=Math.floor(m(await f(e,t.index)));return H(e,n)}async function tt(e,t){let n=S(await f(e,t.key));return W(e,t.array,n)}async function nt(e,t){let n=t.operator;if(n==="||")return v(await f(e,t.left))||v(await f(e,t.right))?1:0;if(n==="&&")return v(await f(e,t.left))&&v(await f(e,t.right))?1:0;if(n==="~"){let c=await f(e,t.left);t.right.type==="regex"&&e.coverage?.hit("awk:expr:regex");let u=t.right.type==="regex"?t.right.pattern:S(await f(e,t.right));try{return A(u).test(S(c))?1:0}catch{return 0}}if(n==="!~"){let c=await f(e,t.left);t.right.type==="regex"&&e.coverage?.hit("awk:expr:regex");let u=t.right.type==="regex"?t.right.pattern:S(await f(e,t.right));try{return A(u).test(S(c))?0:1}catch{return 1}}let i=await f(e,t.left),a=await f(e,t.right);if(n===" "){let c=S(i)+S(a);if(e.maxOutputSize>0&&c.length>e.maxOutputSize)throw new O(`awk: string concatenation size limit exceeded (${e.maxOutputSize} bytes)`,"string_length",e.output);return c}if(rt(n))return it(i,a,n);let s=m(i),o=m(a);return le(s,o,n)}function rt(e){return["<","<=",">",">=","==","!="].includes(e)}function it(e,t,n){let i=J(e),a=J(t);if(i&&a){let c=m(e),u=m(t);switch(n){case"<":return c<u?1:0;case"<=":return c<=u?1:0;case">":return c>u?1:0;case">=":return c>=u?1:0;case"==":return c===u?1:0;case"!=":return c!==u?1:0}}let s=S(e),o=S(t);switch(n){case"<":return s<o?1:0;case"<=":return s<=o?1:0;case">":return s>o?1:0;case">=":return s>=o?1:0;case"==":return s===o?1:0;case"!=":return s!==o?1:0}return 0}async function st(e,t){let n=await f(e,t.operand);switch(t.operator){case"!":return v(n)?0:1;case"-":return-m(n);case"+":return+m(n);default:return n}}async function at(e,t,n){let i=de.get(t);if(i)return i(n,e,{evalExpr:s=>f(e,s)});let a=e.functions.get(t);return a?ot(e,a,n):""}async function ot(e,t,n){if(e.currentRecursionDepth++,e.currentRecursionDepth>e.maxRecursionDepth)throw e.currentRecursionDepth--,new O(`awk: recursion depth exceeded maximum (${e.maxRecursionDepth})`,"recursion",e.output);let i=Object.create(null);for(let o of t.params)i[o]=e.vars[o];let a=[];for(let o=0;o<t.params.length;o++){let c=t.params[o];if(o<n.length){let u=n[o];u.type==="variable"&&(e.arrayAliases.set(c,u.name),a.push(c));let N=await f(e,u);e.vars[c]=N}else e.vars[c]=""}e.hasReturn=!1,e.returnValue=void 0,ee&&await ee(e,t.body.statements);let s=e.returnValue??"";for(let o of t.params)i[o]!==void 0?e.vars[o]=i[o]:delete e.vars[o];for(let o of a)e.arrayAliases.delete(o);return e.hasReturn=!1,e.returnValue=void 0,e.currentRecursionDepth--,s}async function lt(e,t){let n=await f(e,t.value),i=t.target,a=t.operator,s;if(a==="=")s=n;else{let o;if(i.type==="field"){let N=Math.floor(m(await f(e,i.index)));o=H(e,N)}else if(i.type==="variable")o=$(e,i.name);else{let N=S(await f(e,i.key));o=W(e,i.array,N)}let c=m(o),u=m(n);switch(a){case"+=":s=c+u;break;case"-=":s=c-u;break;case"*=":s=c*u;break;case"/=":s=u!==0?c/u:0;break;case"%=":s=u!==0?c%u:0;break;case"^=":s=c**u;break;default:s=n}}if(i.type==="field"){let o=Math.floor(m(await f(e,i.index)));Z(e,o,s)}else if(i.type==="variable")F(e,i.name,s);else{let o=S(await f(e,i.key));Y(e,i.array,o,s)}return s}async function V(e,t,n,i){let a;if(t.type==="field"){let s=Math.floor(m(await f(e,t.index)));a=m(H(e,s)),Z(e,s,a+n)}else if(t.type==="variable")a=m($(e,t.name)),F(e,t.name,a+n);else{let s=S(await f(e,t.key));a=m(W(e,t.array,s)),Y(e,t.array,s,a+n)}return i?a+n:a}async function ct(e,t){return V(e,t,1,!0)}async function ut(e,t){return V(e,t,-1,!0)}async function ht(e,t){return V(e,t,1,!1)}async function pt(e,t){return V(e,t,-1,!1)}async function ft(e,t,n){let i;if(t.type==="tuple"){e.coverage?.hit("awk:expr:tuple");let a=[];for(let s of t.elements)a.push(S(await f(e,s)));i=a.join(e.SUBSEP)}else i=S(await f(e,t));return Se(e,n,i)?1:0}async function dt(e,t,n,i){if(i)return Et(e,t,i);if(n)return Nt(e,t,n);if(!e.lines||e.lineIndex===void 0)return-1;let a=e.lineIndex+1;if(a>=e.lines.length)return 0;let s=e.lines[a];return t?F(e,t,s):T(e,s),e.NR++,e.lineIndex=a,1}async function Et(e,t,n){if(!e.exec)return-1;let i=S(await f(e,n)),a=`__cmd_${i}`,s=`__cmdi_${i}`,o,c;if(e.vars[a]===void 0)try{o=(await e.exec(i)).stdout.split(`
|
|
6
|
+
`),o.length>0&&o[o.length-1]===""&&o.pop(),e.vars[a]=JSON.stringify(o),e.vars[s]=-1,c=-1}catch{return-1}else o=JSON.parse(e.vars[a]),c=e.vars[s];let u=c+1;if(u>=o.length)return 0;let N=o[u];return e.vars[s]=u,t?F(e,t,N):T(e,N),1}async function Nt(e,t,n){if(!e.fs||!e.cwd)return-1;let i=S(await f(e,n));if(i==="/dev/null")return 0;let a=e.fs.resolvePath(e.cwd,i),s=`__fc_${a}`,o=`__fi_${a}`,c,u;if(e.vars[s]===void 0)try{c=(await e.fs.readFile(a)).split(`
|
|
7
|
+
`),c.length>0&&c[c.length-1]===""&&c.pop(),e.vars[s]=JSON.stringify(c),e.vars[o]=-1,u=-1}catch{return-1}else c=JSON.parse(e.vars[s]),u=e.vars[o];let N=u+1;if(N>=c.length)return 0;let k=c[N];return e.vars[o]=N,t?F(e,t,k):T(e,k),1}async function St(e,t){if(t.length===0)return"";for(let n=0;n<t.length-1;n++)await f(e,t[n]);return f(e,t[t.length-1])}me(_);function te(e){if(e.maxOutputSize>0&&e.output.length>e.maxOutputSize)throw new O(`awk: output size limit exceeded (${e.maxOutputSize} bytes)`,"string_length",e.output)}async function _(e,t){for(let n of t)if(await M(e,n),yt(e))break}function yt(e){return e.shouldExit||e.shouldNext||e.shouldNextFile||e.loopBreak||e.loopContinue||e.hasReturn}async function M(e,t){switch(e.coverage?.hit(`awk:stmt:${t.type}`),t.type){case"block":await _(e,t.statements);break;case"expr_stmt":await f(e,t.expression);break;case"print":await Rt(e,t.args,t.output);break;case"printf":await mt(e,t.format,t.args,t.output);break;case"if":await At(e,t);break;case"while":await wt(e,t);break;case"do_while":await gt(e,t);break;case"for":await It(e,t);break;case"for_in":await vt(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,e.exitCode=t.code?Math.floor(m(await f(e,t.code))):0;break;case"return":e.hasReturn=!0,e.returnValue=t.value?await f(e,t.value):"";break;case"delete":await kt(e,t.target);break}}async function Rt(e,t,n){let i=[];for(let s of t){let o=await f(e,s);typeof o=="number"?Number.isInteger(o)&&Math.abs(o)<Number.MAX_SAFE_INTEGER?i.push(String(o)):i.push(B(e.OFMT,[o])):i.push(S(o))}let a=i.join(e.OFS)+e.ORS;n?await Ae(e,n.redirect,n.file,a):(e.output+=a,te(e))}async function mt(e,t,n,i){let a=S(await f(e,t)),s=[];for(let c of n)s.push(await f(e,c));let o=B(a,s);i?await Ae(e,i.redirect,i.file,o):(e.output+=o,te(e))}async function Ae(e,t,n,i){if(!e.fs||!e.cwd){e.output+=i,te(e);return}let a=S(await f(e,n)),s=e.fs.resolvePath(e.cwd,a);t===">"?e.openedFiles.has(s)?await e.fs.appendFile(s,i):(await e.fs.writeFile(s,i),e.openedFiles.add(s)):(e.openedFiles.has(s)||e.openedFiles.add(s),await e.fs.appendFile(s,i))}async function At(e,t){v(await f(e,t.condition))?await M(e,t.consequent):t.alternate&&await M(e,t.alternate)}async function wt(e,t){let n=0;for(;v(await f(e,t.condition));){if(n++,n>e.maxIterations)throw new O(`awk: while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await M(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function gt(e,t){let n=0;do{if(n++,n>e.maxIterations)throw new O(`awk: do-while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await M(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}while(v(await f(e,t.condition)))}async function It(e,t){t.init&&await f(e,t.init);let n=0;for(;!t.condition||v(await f(e,t.condition));){if(n++,n>e.maxIterations)throw new O(`awk: for loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await M(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break;t.update&&await f(e,t.update)}}async function vt(e,t){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 M(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function kt(e,t){if(t.type==="array_access"){let n=S(await f(e,t.key));ye(e,t.array,n)}else t.type==="variable"&&Re(e,t.name)}var x=class{ctx;program=null;rangeStates=[];constructor(t){this.ctx=t}execute(t){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.program){for(let t of this.program.rules)if(t.pattern?.type==="begin"&&(await _(this.ctx,t.action.statements),this.ctx.shouldExit))break}}async executeLine(t){if(!(!this.program||this.ctx.shouldExit)){T(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.matchesRule(i,n)&&await _(this.ctx,i.action.statements)}}}async executeEnd(){if(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.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){let i=t.pattern;if(!i)return!0;switch(i.type){case"begin":case"end":return!1;case"regex_pattern":return G(i.pattern,this.ctx.line);case"expr_pattern":return v(await f(this.ctx,i.expression));case"range":{let a=await this.matchPattern(i.start),s=await this.matchPattern(i.end);return this.rangeStates[n]?(s&&(this.rangeStates[n]=!1),!0):a?(this.rangeStates[n]=!0,s&&(this.rangeStates[n]=!1),!0):!1}default:return!1}}async matchPattern(t){switch(t.type){case"regex_pattern":return G(t.pattern,this.ctx.line);case"expr_pattern":return v(await 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 Ct=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 Ot(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 K=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
11
|
`?(this.advance(),{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 a=this.advance();switch(a){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 s="";for(;s.length<2&&/[0-9a-fA-F]/.test(this.peek());)s+=this.advance();s.length>0?i+=String.fromCharCode(parseInt(s,16)):i+="x";break}default:if(/[0-7]/.test(a)){let s=a;for(;s.length<3&&/[0-7]/.test(this.peek());)s+=this.advance();i+=String.fromCharCode(parseInt(s,8))}else i+=a}}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=Ot(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 a=Ct.get(i);return a!==void 0?{type:a,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(),a=this.peek();switch(i){case"+":return a==="+"?(this.advance(),{type:r.INCREMENT,value:"++",line:t,column:n}):a==="="?(this.advance(),{type:r.PLUS_ASSIGN,value:"+=",line:t,column:n}):{type:r.PLUS,value:"+",line:t,column:n};case"-":return a==="-"?(this.advance(),{type:r.DECREMENT,value:"--",line:t,column:n}):a==="="?(this.advance(),{type:r.MINUS_ASSIGN,value:"-=",line:t,column:n}):{type:r.MINUS,value:"-",line:t,column:n};case"*":return a==="*"?(this.advance(),{type:r.CARET,value:"**",line:t,column:n}):a==="="?(this.advance(),{type:r.STAR_ASSIGN,value:"*=",line:t,column:n}):{type:r.STAR,value:"*",line:t,column:n};case"/":return a==="="?(this.advance(),{type:r.SLASH_ASSIGN,value:"/=",line:t,column:n}):{type:r.SLASH,value:"/",line:t,column:n};case"%":return a==="="?(this.advance(),{type:r.PERCENT_ASSIGN,value:"%=",line:t,column:n}):{type:r.PERCENT,value:"%",line:t,column:n};case"^":return a==="="?(this.advance(),{type:r.CARET_ASSIGN,value:"^=",line:t,column:n}):{type:r.CARET,value:"^",line:t,column:n};case"=":return a==="="?(this.advance(),{type:r.EQ,value:"==",line:t,column:n}):{type:r.ASSIGN,value:"=",line:t,column:n};case"!":return a==="="?(this.advance(),{type:r.NE,value:"!=",line:t,column:n}):a==="~"?(this.advance(),{type:r.NOT_MATCH,value:"!~",line:t,column:n}):{type:r.NOT,value:"!",line:t,column:n};case"<":return a==="="?(this.advance(),{type:r.LE,value:"<=",line:t,column:n}):{type:r.LT,value:"<",line:t,column:n};case">":return a==="="?(this.advance(),{type:r.GE,value:">=",line:t,column:n}):a===">"?(this.advance(),{type:r.APPEND,value:">>",line:t,column:n}):{type:r.GT,value:">",line:t,column:n};case"&":return a==="&"?(this.advance(),{type:r.AND,value:"&&",line:t,column:n}):{type:r.IDENT,value:"&",line:t,column:n};case"|":return a==="|"?(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 h={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 ke(e){e.expect(h.PRINT);let t=[];if(e.check(h.NEWLINE)||e.check(h.SEMICOLON)||e.check(h.RBRACE)||e.check(h.PIPE)||e.check(h.GT)||e.check(h.APPEND))t.push({type:"field",index:{type:"number",value:0}});else for(t.push(X(e));e.check(h.COMMA);)e.advance(),t.push(X(e));let n;return e.check(h.GT)?(e.advance(),n={redirect:">",file:e.parsePrimary()}):e.check(h.APPEND)&&(e.advance(),n={redirect:">>",file:e.parsePrimary()}),{type:"print",args:t,output:n}}function X(e){return bt(e)?ne(e,!0):ne(e,!1)}function ne(e,t){let n=t?e.parseTernary():Lt(e);if(e.match(h.ASSIGN,h.PLUS_ASSIGN,h.MINUS_ASSIGN,h.STAR_ASSIGN,h.SLASH_ASSIGN,h.PERCENT_ASSIGN,h.CARET_ASSIGN)){let i=e.advance(),a=ne(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:a}}return n}function bt(e){let t=0,n=e.pos;for(;n<e.tokens.length;){let i=e.tokens[n];if(i.type===h.LPAREN&&t++,i.type===h.RPAREN&&t--,i.type===h.QUESTION&&t===0)return!0;if(i.type===h.NEWLINE||i.type===h.SEMICOLON||i.type===h.RBRACE||i.type===h.COMMA||i.type===h.PIPE)return!1;n++}return!1}function Lt(e){let t=we(e);for(;e.check(h.OR);){e.advance();let n=we(e);t={type:"binary",operator:"||",left:t,right:n}}return t}function we(e){let t=Ie(e);for(;e.check(h.AND);){e.advance();let n=Ie(e);t={type:"binary",operator:"&&",left:t,right:n}}return t}function Ie(e){let t=Mt(e);if(e.check(h.IN)){e.advance();let n=String(e.expect(h.IDENT).value);return{type:"in",key:t,array:n}}return t}function Mt(e){let t=ge(e);for(;Pt(e)&&!Tt(e);){let n=ge(e);t={type:"binary",operator:" ",left:t,right:n}}return t}function ge(e){let t=ve(e);for(;e.match(h.MATCH,h.NOT_MATCH);){let n=e.advance().type===h.MATCH?"~":"!~",i=ve(e);t={type:"binary",operator:n,left:t,right:i}}return t}function ve(e){let t=e.parseAddSub();for(;e.match(h.LT,h.LE,h.GE,h.EQ,h.NE);){let n=e.advance(),i=e.parseAddSub();t={type:"binary",operator:new Map([["<","<"],["<=","<="],[">=",">="],["==","=="],["!=","!="]]).get(n.value)??"==",left:t,right:i}}return t}function Pt(e){return e.match(h.NUMBER,h.STRING,h.IDENT,h.DOLLAR,h.LPAREN,h.NOT,h.MINUS,h.PLUS,h.INCREMENT,h.DECREMENT)}function Tt(e){return e.match(h.AND,h.OR,h.QUESTION,h.ASSIGN,h.PLUS_ASSIGN,h.MINUS_ASSIGN,h.STAR_ASSIGN,h.SLASH_ASSIGN,h.PERCENT_ASSIGN,h.CARET_ASSIGN,h.COMMA,h.SEMICOLON,h.NEWLINE,h.RBRACE,h.RPAREN,h.RBRACKET,h.COLON,h.PIPE,h.APPEND,h.GT,h.IN)}function Ce(e){e.expect(h.PRINTF);let t=e.check(h.LPAREN);t&&(e.advance(),e.skipNewlines());let n=t?e.parseExpression():X(e),i=[];for(;e.check(h.COMMA);)e.advance(),t&&e.skipNewlines(),i.push(t?e.parseExpression():X(e));t&&(e.skipNewlines(),e.expect(h.RPAREN));let a;return e.check(h.GT)?(e.advance(),a={redirect:">",file:e.parsePrimary()}):e.check(h.APPEND)&&(e.advance(),a={redirect:">>",file:e.parsePrimary()}),{type:"printf",format:n,args:i,output:a}}var j=class{tokens=[];pos=0;parse(t){let n=new K(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 a={type:"binary",operator:"~",left:{type:"field",index:{type:"number",value:0}},right:{type:"regex",pattern:i.value}};t={type:"expr_pattern",expression:this.parseLogicalOrRest(a)}}else{let a={type:"regex_pattern",pattern:i.value};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}}else{let a={type:"expr_pattern",expression:this.parseExpression()};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}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)?ke(this):this.check(r.PRINTF)?Ce(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 s=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:s.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 a=this.parseStatement();return{type:"for",init:t,condition:n,update:i,body:a}}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");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[n.value],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 a=i.reduce((s,o)=>({type:"binary",operator:" ",left:{type:"binary",operator:" ",left:s,right:{type:"variable",name:"SUBSEP"}},right:o}));return{type:"array_access",array:t,key:a}}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 a=1;a<n.length;a++)i={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:i,right:{type:"variable",name:"SUBSEP"}},right:n[a]}}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 Ft={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"]},On={name:"awk",async execute(e,t){if(ae(e))return se(Ft);let n=new P(/\s+/),i=" ",a=Object.create(null),s=0;for(let c=0;c<e.length;c++){let p=e[c];if(p==="-F"&&c+1<e.length)i=re(e[++c]),n=Oe(i),s=c+1;else if(p.startsWith("-F"))i=re(p.slice(2)),n=Oe(i),s=c+1;else if(p==="-v"&&c+1<e.length){let E=e[++c],d=E.indexOf("=");if(d>0){let R=E.slice(0,d),b=re(E.slice(d+1));a[R]=b}s=c+1}else{if(p.startsWith("--"))return z("awk",p);if(p.startsWith("-")&&p.length>1){let E=p[1];if(E!=="F"&&E!=="v")return z("awk",`-${E}`);s=c+1}else if(!p.startsWith("-")){s=c;break}}}if(s>=e.length)return{stdout:"",stderr:`awk: missing program
|
|
15
|
-
`,exitCode:1};let o=e[s],
|
|
16
|
-
`,exitCode:1}}let k={readFile:t.fs.readFile.bind(t.fs),writeFile:t.fs.writeFile.bind(t.fs),appendFile:async(
|
|
17
|
-
`);R.length>0&&R[R.length-1]===""&&R.pop(),
|
|
14
|
+
`)break;i+=this.advance()}return this.peek()==="/"&&this.advance(),i=Ot(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 a=Ct.get(i);return a!==void 0?{type:a,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(),a=this.peek();switch(i){case"+":return a==="+"?(this.advance(),{type:r.INCREMENT,value:"++",line:t,column:n}):a==="="?(this.advance(),{type:r.PLUS_ASSIGN,value:"+=",line:t,column:n}):{type:r.PLUS,value:"+",line:t,column:n};case"-":return a==="-"?(this.advance(),{type:r.DECREMENT,value:"--",line:t,column:n}):a==="="?(this.advance(),{type:r.MINUS_ASSIGN,value:"-=",line:t,column:n}):{type:r.MINUS,value:"-",line:t,column:n};case"*":return a==="*"?(this.advance(),{type:r.CARET,value:"**",line:t,column:n}):a==="="?(this.advance(),{type:r.STAR_ASSIGN,value:"*=",line:t,column:n}):{type:r.STAR,value:"*",line:t,column:n};case"/":return a==="="?(this.advance(),{type:r.SLASH_ASSIGN,value:"/=",line:t,column:n}):{type:r.SLASH,value:"/",line:t,column:n};case"%":return a==="="?(this.advance(),{type:r.PERCENT_ASSIGN,value:"%=",line:t,column:n}):{type:r.PERCENT,value:"%",line:t,column:n};case"^":return a==="="?(this.advance(),{type:r.CARET_ASSIGN,value:"^=",line:t,column:n}):{type:r.CARET,value:"^",line:t,column:n};case"=":return a==="="?(this.advance(),{type:r.EQ,value:"==",line:t,column:n}):{type:r.ASSIGN,value:"=",line:t,column:n};case"!":return a==="="?(this.advance(),{type:r.NE,value:"!=",line:t,column:n}):a==="~"?(this.advance(),{type:r.NOT_MATCH,value:"!~",line:t,column:n}):{type:r.NOT,value:"!",line:t,column:n};case"<":return a==="="?(this.advance(),{type:r.LE,value:"<=",line:t,column:n}):{type:r.LT,value:"<",line:t,column:n};case">":return a==="="?(this.advance(),{type:r.GE,value:">=",line:t,column:n}):a===">"?(this.advance(),{type:r.APPEND,value:">>",line:t,column:n}):{type:r.GT,value:">",line:t,column:n};case"&":return a==="&"?(this.advance(),{type:r.AND,value:"&&",line:t,column:n}):{type:r.IDENT,value:"&",line:t,column:n};case"|":return a==="|"?(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 h={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 ke(e){e.expect(h.PRINT);let t=[];if(e.check(h.NEWLINE)||e.check(h.SEMICOLON)||e.check(h.RBRACE)||e.check(h.PIPE)||e.check(h.GT)||e.check(h.APPEND))t.push({type:"field",index:{type:"number",value:0}});else for(t.push(X(e));e.check(h.COMMA);)e.advance(),t.push(X(e));let n;return e.check(h.GT)?(e.advance(),n={redirect:">",file:e.parsePrimary()}):e.check(h.APPEND)&&(e.advance(),n={redirect:">>",file:e.parsePrimary()}),{type:"print",args:t,output:n}}function X(e){return bt(e)?ne(e,!0):ne(e,!1)}function ne(e,t){let n=t?e.parseTernary():Lt(e);if(e.match(h.ASSIGN,h.PLUS_ASSIGN,h.MINUS_ASSIGN,h.STAR_ASSIGN,h.SLASH_ASSIGN,h.PERCENT_ASSIGN,h.CARET_ASSIGN)){let i=e.advance(),a=ne(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:a}}return n}function bt(e){let t=0,n=e.pos;for(;n<e.tokens.length;){let i=e.tokens[n];if(i.type===h.LPAREN&&t++,i.type===h.RPAREN&&t--,i.type===h.QUESTION&&t===0)return!0;if(i.type===h.NEWLINE||i.type===h.SEMICOLON||i.type===h.RBRACE||i.type===h.COMMA||i.type===h.PIPE)return!1;n++}return!1}function Lt(e){let t=we(e);for(;e.check(h.OR);){e.advance();let n=we(e);t={type:"binary",operator:"||",left:t,right:n}}return t}function we(e){let t=ge(e);for(;e.check(h.AND);){e.advance();let n=ge(e);t={type:"binary",operator:"&&",left:t,right:n}}return t}function ge(e){let t=Mt(e);if(e.check(h.IN)){e.advance();let n=String(e.expect(h.IDENT).value);return{type:"in",key:t,array:n}}return t}function Mt(e){let t=Ie(e);for(;Pt(e)&&!Tt(e);){let n=Ie(e);t={type:"binary",operator:" ",left:t,right:n}}return t}function Ie(e){let t=ve(e);for(;e.match(h.MATCH,h.NOT_MATCH);){let n=e.advance().type===h.MATCH?"~":"!~",i=ve(e);t={type:"binary",operator:n,left:t,right:i}}return t}function ve(e){let t=e.parseAddSub();for(;e.match(h.LT,h.LE,h.GE,h.EQ,h.NE);){let n=e.advance(),i=e.parseAddSub();t={type:"binary",operator:new Map([["<","<"],["<=","<="],[">=",">="],["==","=="],["!=","!="]]).get(n.value)??"==",left:t,right:i}}return t}function Pt(e){return e.match(h.NUMBER,h.STRING,h.IDENT,h.DOLLAR,h.LPAREN,h.NOT,h.MINUS,h.PLUS,h.INCREMENT,h.DECREMENT)}function Tt(e){return e.match(h.AND,h.OR,h.QUESTION,h.ASSIGN,h.PLUS_ASSIGN,h.MINUS_ASSIGN,h.STAR_ASSIGN,h.SLASH_ASSIGN,h.PERCENT_ASSIGN,h.CARET_ASSIGN,h.COMMA,h.SEMICOLON,h.NEWLINE,h.RBRACE,h.RPAREN,h.RBRACKET,h.COLON,h.PIPE,h.APPEND,h.GT,h.IN)}function Ce(e){e.expect(h.PRINTF);let t=e.check(h.LPAREN);t&&(e.advance(),e.skipNewlines());let n=t?e.parseExpression():X(e),i=[];for(;e.check(h.COMMA);)e.advance(),t&&e.skipNewlines(),i.push(t?e.parseExpression():X(e));t&&(e.skipNewlines(),e.expect(h.RPAREN));let a;return e.check(h.GT)?(e.advance(),a={redirect:">",file:e.parsePrimary()}):e.check(h.APPEND)&&(e.advance(),a={redirect:">>",file:e.parsePrimary()}),{type:"printf",format:n,args:i,output:a}}var j=class{tokens=[];pos=0;parse(t){let n=new K(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 a={type:"binary",operator:"~",left:{type:"field",index:{type:"number",value:0}},right:{type:"regex",pattern:i.value}};t={type:"expr_pattern",expression:this.parseLogicalOrRest(a)}}else{let a={type:"regex_pattern",pattern:i.value};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}}else{let a={type:"expr_pattern",expression:this.parseExpression()};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}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)?ke(this):this.check(r.PRINTF)?Ce(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 s=this.advance();if(this.check(r.IN)){this.advance();let o=this.expect(r.IDENT).value;this.expect(r.RPAREN),this.skipNewlines();let c=this.parseStatement();return{type:"for_in",variable:s.value,array:o,body:c}}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 a=this.parseStatement();return{type:"for",init:t,condition:n,update:i,body:a}}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");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[n.value],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 a=i.reduce((s,o)=>({type:"binary",operator:" ",left:{type:"binary",operator:" ",left:s,right:{type:"variable",name:"SUBSEP"}},right:o}));return{type:"array_access",array:t,key:a}}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 a=1;a<n.length;a++)i={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:i,right:{type:"variable",name:"SUBSEP"}},right:n[a]}}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 Ft={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"]},On={name:"awk",async execute(e,t){if(ae(e))return se(Ft);let n=new P(/\s+/),i=" ",a=Object.create(null),s=0;for(let l=0;l<e.length;l++){let p=e[l];if(p==="-F"&&l+1<e.length)i=re(e[++l]),n=Oe(i),s=l+1;else if(p.startsWith("-F"))i=re(p.slice(2)),n=Oe(i),s=l+1;else if(p==="-v"&&l+1<e.length){let E=e[++l],d=E.indexOf("=");if(d>0){let R=E.slice(0,d),b=re(E.slice(d+1));a[R]=b}s=l+1}else{if(p.startsWith("--"))return z("awk",p);if(p.startsWith("-")&&p.length>1){let E=p[1];if(E!=="F"&&E!=="v")return z("awk",`-${E}`);s=l+1}else if(!p.startsWith("-")){s=l;break}}}if(s>=e.length)return{stdout:"",stderr:`awk: missing program
|
|
15
|
+
`,exitCode:1};let o=e[s],c=e.slice(s+1),u=new j,N;try{N=u.parse(o)}catch(l){return{stdout:"",stderr:`awk: ${l instanceof Error?l.message:String(l)}
|
|
16
|
+
`,exitCode:1}}let k={readFile:t.fs.readFile.bind(t.fs),writeFile:t.fs.writeFile.bind(t.fs),appendFile:async(l,p)=>{try{let E=await t.fs.readFile(l);await t.fs.writeFile(l,E+p)}catch{await t.fs.writeFile(l,p)}},resolvePath:t.fs.resolvePath.bind(t.fs)},y=Q({fieldSep:n,maxIterations:t.limits?.maxAwkIterations,maxOutputSize:t.limits?.maxStringLength,fs:k,cwd:t.cwd,exec:t.exec?l=>t.exec(l,{cwd:t.cwd}):void 0,coverage:t.coverage});y.FS=i,y.vars=Object.assign(Object.create(null),a),y.ARGC=c.length+1,y.ARGV=Object.create(null),y.ARGV[0]="awk";for(let l=0;l<c.length;l++)y.ARGV[String(l+1)]=c[l];y.ENVIRON=oe(t.env);let w=new x(y);w.execute(N);let ie=N.rules.some(l=>l.pattern?.type!=="begin"&&l.pattern?.type!=="end"),g=N.rules.some(l=>l.pattern?.type==="end");try{if(await w.executeBegin(),y.shouldExit)return await w.executeEnd(),{stdout:w.getOutput(),stderr:"",exitCode:w.getExitCode()};if(!ie&&!g)return{stdout:w.getOutput(),stderr:"",exitCode:w.getExitCode()};let l=[];if(c.length>0)for(let p of c)try{let E=t.fs.resolvePath(t.cwd,p),R=(await t.fs.readFile(E)).split(`
|
|
17
|
+
`);R.length>0&&R[R.length-1]===""&&R.pop(),l.push({filename:p,lines:R})}catch{return{stdout:"",stderr:`awk: ${p}: No such file or directory
|
|
18
18
|
`,exitCode:1}}else{let p=t.stdin.split(`
|
|
19
|
-
`);p.length>0&&p[p.length-1]===""&&p.pop(),
|
|
19
|
+
`);p.length>0&&p[p.length-1]===""&&p.pop(),l.push({filename:"",lines:p})}for(let p of l){for(y.FILENAME=p.filename,y.FNR=0,y.lines=p.lines,y.lineIndex=-1,y.shouldNextFile=!1;y.lineIndex<p.lines.length-1&&(y.lineIndex++,await w.executeLine(p.lines[y.lineIndex]),!(y.shouldExit||y.shouldNextFile)););if(y.shouldExit)break}return await w.executeEnd(),{stdout:w.getOutput(),stderr:"",exitCode:w.getExitCode()}}catch(l){let p=l instanceof Error?l.message:String(l),E=l instanceof O?O.EXIT_CODE:2;return{stdout:w.getOutput(),stderr:`awk: ${p}
|
|
20
20
|
`,exitCode:E}}}};function re(e){return e.replace(/\\t/g," ").replace(/\\n/g,`
|
|
21
21
|
`).replace(/\\r/g,"\r").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\a/g,"\x07").replace(/\\v/g,"\v").replace(/\\\\/g,"\\")}function Oe(e){if(e===" ")return A("\\s+");if(/[[\](){}.*+?^$|\\]/.test(e))try{return A(e)}catch{return A(be(e))}return A(be(e))}function be(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var bn={name:"awk",flags:[{flag:"-F",type:"value",valueHint:"delimiter"},{flag:"-v",type:"value",valueHint:"string"}],stdinType:"text",needsArgs:!0};export{On as a,bn as b};
|
|
@@ -66,7 +66,7 @@ Gid: ${s} ${s} ${s} ${s}
|
|
|
66
66
|
`)}return s.effectiveValue}async function Pn(e,t,r,s){return e.coverage?.hit("bash:expansion:use_alternative"),!(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):""}async function Rn(e,t,r,s,n){e.coverage?.hit("bash:expansion:pattern_removal");let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let o of r.pattern.parts)if(o.type==="Glob")a+=k(o.pattern,r.greedy,i);else if(o.type==="Literal")a+=k(o.value,r.greedy,i);else if(o.type==="SingleQuoted"||o.type==="Escaped")a+=I(o.value);else if(o.type==="DoubleQuoted"){let u=await s(e,o.parts);a+=I(u)}else if(o.type==="ParameterExpansion"){let u=await n(e,o);a+=k(u,r.greedy,i)}else{let u=await n(e,o);a+=I(u)}if(r.side==="prefix")return O(`^${a}`,"s").replace(t,"");let l=O(`${a}$`,"s");if(r.greedy)return l.replace(t,"");for(let o=t.length;o>=0;o--){let u=t.slice(o);if(l.test(u))return t.slice(0,o)}return t}async function In(e,t,r,s,n){e.coverage?.hit("bash:expansion:pattern_replacement");let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let u of r.pattern.parts)if(u.type==="Glob")a+=k(u.pattern,!0,i);else if(u.type==="Literal")a+=k(u.value,!0,i);else if(u.type==="SingleQuoted"||u.type==="Escaped")a+=I(u.value);else if(u.type==="DoubleQuoted"){let c=await s(e,u.parts);a+=I(c)}else if(u.type==="ParameterExpansion"){let c=await n(e,u);a+=k(c,!0,i)}else{let c=await n(e,u);a+=I(c)}let l=r.replacement?await s(e,r.replacement.parts):"";if(r.anchor==="start"?a=`^${a}`:r.anchor==="end"&&(a=`${a}$`),a==="")return t;let o=r.all?"gs":"s";try{let u=O(a,o);if(r.all){let c="",f=0,h=u.exec(t);for(;h!==null&&!(h[0].length===0&&h.index===t.length);)c+=t.slice(f,h.index)+l,f=h.index+h[0].length,h[0].length===0&&f++,h=u.exec(t);return c+=t.slice(f),c}return u.replace(t,l)}catch{return t}}function vn(e,t,r){e.coverage?.hit("bash:expansion:length");let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(s){let n=s[1],a=P(e,n);return a.length>0?String(a.length):e.state.env.get(n)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&Se(e,t)){if(t==="FUNCNAME"){let a=e.state.funcNameStack?.[0]||"";return String([...a].length)}if(t==="BASH_LINENO"){let a=e.state.callLineStack?.[0];return String(a!==void 0?[...String(a)].length:0)}let n=e.state.env.get(`${t}_0`)||"";return String([...n].length)}return String([...r].length)}async function Dn(e,t,r,s){e.coverage?.hit("bash:expansion:substring");let n=await R(e,s.offset.expression),a=s.length?await R(e,s.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let g=1;g<=u;g++)c.push(e.state.env.get(String(g))||"");let f=e.state.env.get("0")||"bash",h,d;if(n<=0)if(h=[f,...c],n<0){if(d=h.length+n,d<0)return""}else d=0;else h=c,d=n-1;if(d<0||d>=h.length)return"";if(a!==void 0){let g=a<0?h.length+a:d+a;return h.slice(d,Math.max(d,g)).join(" ")}return h.slice(d).join(" ")}let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i){let u=i[1];if(e.state.associativeArrays?.has(u))throw new j(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution
|
|
67
67
|
`);let c=P(e,u),f=0;if(n<0){if(c.length>0){let h=c[c.length-1][0],g=(typeof h=="number"?h:0)+1+n;if(g<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=g),f<0))return""}}else if(f=c.findIndex(([h])=>typeof h=="number"&&h>=n),f<0)return"";if(a!==void 0){if(a<0)throw new C(`${i[1]}[@]: substring expression < 0`);return c.slice(f,f+a).map(([,h])=>h).join(" ")}return c.slice(f).map(([,h])=>h).join(" ")}let l=[...r],o=n;if(o<0&&(o=Math.max(0,l.length+o)),a!==void 0){if(a<0){let u=l.length+a;return l.slice(o,Math.max(o,u)).join("")}return l.slice(o,o+a).join("")}return l.slice(o).join("")}async function xn(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:case_modification"),r.pattern){let a=e.state.shoptOptions.extglob,i="";for(let f of r.pattern.parts)if(f.type==="Glob")i+=k(f.pattern,!0,a);else if(f.type==="Literal")i+=k(f.value,!0,a);else if(f.type==="SingleQuoted"||f.type==="Escaped")i+=I(f.value);else if(f.type==="DoubleQuoted"){let h=await s(e,f.parts);i+=I(h)}else if(f.type==="ParameterExpansion"){let h=await n(e,f);i+=k(h,!0,a)}let l=O(`^(?:${i})$`),o=r.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!r.all&&c?u+=f:l.test(f)?(u+=o(f),c=!0):u+=f;return u}return r.direction==="upper"?r.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):r.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function $n(e,t,r,s,n){e.coverage?.hit("bash:expansion:transform");let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a&&n.operator==="Q")return P(e,a[1]).map(([,u])=>le(u)).join(" ");if(a&&n.operator==="a")return ce(e,a[1]);let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(i&&n.operator==="a")return ce(e,i[1]);switch(n.operator){case"Q":return s?"":le(r);case"P":return be(e,r);case"a":return ce(e,t);case"A":return s?"":`${t}=${le(r)}`;case"E":return r.replace(/\\([\\abefnrtv'"?])/g,(l,o)=>{switch(o){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
|
|
68
68
|
`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return s?"":le(r);case"u":return r.charAt(0).toUpperCase()+r.slice(1);case"U":return r.toUpperCase();case"L":return r.toLowerCase();default:return r}}async function _n(e,t,r,s,n,a,i=!1){if(e.coverage?.hit("bash:expansion:indirection"),L(e,t))return Ae(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(s){if(n.innerOp?.type==="UseAlternative")return"";throw new re(`\${!${t}}`)}let o=r;if(l&&(o===""||o.includes(" ")))throw new re(`\${!${t}}`);let u=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new re(`\${!${t}}`);if(n.innerOp){let c={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return a(e,c,i)}return await v(e,o)}function Cn(e,t){e.coverage?.hit("bash:expansion:array_keys");let s=P(e,t.array).map(([n])=>String(n));return t.star?s.join(N(e.state.env)):s.join(" ")}function On(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let r=de(e,t.prefix);return t.star?r.join(N(e.state.env)):r.join(" ")}function Ln(e,t,r,s){let n=Number.parseInt(e.state.env.get("#")||"0",10),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:r};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:r};if(a){let[,i,l]=a,o=P(e,i);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let u=N(e.state.env),c=o.map(([,f])=>f).join(u);return{isEmpty:s?c==="":!1,effectiveValue:c}}return{isEmpty:o.length===1&&o.every(([,u])=>u===""),effectiveValue:o.map(([,u])=>u).join(" ")}}return{isEmpty:r==="",effectiveValue:r}}function Wn(e){let t=0;for(;t<e.length;){let r=e[t];if(r==="\\"&&t+1<e.length){t+=2;continue}if(r==="'"){let s=e.indexOf("'",t+1);if(s!==-1){t=s+1;continue}}if(r==="$"&&t+1<e.length&&e[t+1]==="("||r==="`")return!0;t++}return!1}function Tn(e,t){let r=1,s=t,n=!1,a=!1;for(;s<e.length&&r>0;){let i=e[s];if(i==="\\"&&!n&&s+1<e.length){s+=2;continue}if(i==="'"&&!a){n=!n,s++;continue}if(i==='"'&&!n){a=!a,s++;continue}if(!n&&!a){if(i==="(")r++;else if(i===")"&&(r--,r===0))return s}s++}return-1}async function We(e,t){let r=new M,s;try{s=r.parse(t)}catch{return""}let n=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let a=new Map(e.state.env),i=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let o=await e.executeScript(s),u=o.exitCode;return e.state.env=a,e.state.cwd=i,e.state.suppressVerbose=l,e.state.lastExitCode=u,e.state.env.set("?",String(u)),o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),e.state.bashPid=n,o.stdout.replace(/\n+$/,"")}catch(o){if(e.state.env=a,e.state.cwd=i,e.state.bashPid=n,e.state.suppressVerbose=l,o instanceof B)throw o;return o instanceof j?(e.state.lastExitCode=o.exitCode,e.state.env.set("?",String(o.exitCode)),o.stdout?.replace(/\n+$/,"")??""):""}}function Nt(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=K(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=As(e,l);r+=K(o),s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}function As(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}async function Mn(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=K(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=await Ss(e,l);r+=K(o),s=a+1;continue}}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Tn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}async function Ss(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Tn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}function Vn(e,t){if(!t.startsWith("~"))return t;e.coverage?.hit("bash:expansion:tilde");let r=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return r+t.slice(1);let s=1;for(;s<t.length&&/[a-zA-Z0-9_-]/.test(t[s]);)s++;let n=t.slice(1,s),a=t.slice(s);return a!==""&&!a.startsWith("/")?t:n==="root"?`/root${a}`:t}async function bs(e,t,r,s){let n="";for(let a of t.parts)if(a.type==="Glob")n+=k(a.pattern,!0,e.state.shoptOptions.extglob);else if(a.type==="Literal")n+=k(a.value,!0,e.state.shoptOptions.extglob);else if(a.type==="SingleQuoted"||a.type==="Escaped")n+=I(a.value);else if(a.type==="DoubleQuoted"){let i=await r(e,a.parts);n+=I(i)}else if(a.type==="ParameterExpansion"){let i=await s(e,a);n+=k(i,!0,e.state.shoptOptions.extglob)}else{let i=await s(e,a);n+=I(i)}return n}async function qn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternReplacement")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",u=a.operation,c=P(e,l),f=c.map(([,E])=>E);if(c.length===0){let E=e.state.env.get(l);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let h="";u.pattern&&(h=await bs(e,u.pattern,r,s));let d=u.replacement?await r(e,u.replacement.parts):"",g=h;u.anchor==="start"?g=`^${h}`:u.anchor==="end"&&(g=`${h}$`);let m=[];try{let E=O(g,u.all?"g":"");for(let A of f)m.push(E.replace(A,d))}catch{m.push(...f)}if(o){let E=N(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function Bn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",u=a.operation,c=P(e,l),f=c.map(([,m])=>m);if(c.length===0){let m=e.state.env.get(l);m!==void 0&&f.push(m)}if(f.length===0)return{values:[],quoted:!0};let h="",d=e.state.shoptOptions.extglob;if(u.pattern)for(let m of u.pattern.parts)if(m.type==="Glob")h+=k(m.pattern,u.greedy,d);else if(m.type==="Literal")h+=k(m.value,u.greedy,d);else if(m.type==="SingleQuoted"||m.type==="Escaped")h+=I(m.value);else if(m.type==="DoubleQuoted"){let E=await r(e,m.parts);h+=I(E)}else if(m.type==="ParameterExpansion"){let E=await s(e,m);h+=k(E,u.greedy,d)}else{let E=await s(e,m);h+=I(E)}let g=[];for(let m of f)g.push(se(m,h,u.side,u.greedy));if(o){let m=N(e.state.env);return{values:[g.join(m)],quoted:!0}}return{values:g,quoted:!0}}async function Fn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="DefaultValue"&&r.parts[0].operation?.type!=="UseAlternative"&&r.parts[0].operation?.type!=="AssignDefault")return null;let s=r.parts[0],n=s.operation,a=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),i,l=!1;if(a){let o=a[1];l=a[2]==="*";let u=P(e,o),c=u.length>0||e.state.env.has(o),f=u.length===0||u.length===1&&u.every(([,d])=>d===""),h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=c&&!(h&&f):i=!c||h&&f,!i){if(u.length>0){let g=u.map(([,m])=>m);if(l){let m=N(e.state.env);return{values:[g.join(m)],quoted:!0}}return{values:g,quoted:!0}}let d=e.state.env.get(o);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}else{let o=s.parameter,u=await te(e,o),c=await v(e,o),f=c==="",h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=u&&!(h&&f):i=!u||h&&f,!i)return{values:[c],quoted:!0}}if(i&&n.word){let o=n.word.parts,u=null,c=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let h=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(h){u=h[1],c=h[2]==="*";break}}if(u){let f=P(e,u);if(f.length>0){let d=f.map(([,g])=>g);if(c||l){let g=N(e.state.env);return{values:[d.join(g)],quoted:!0}}return{values:d,quoted:!0}}let h=e.state.env.get(u);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}return null}async function Qn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0],i=-1,l="",o=!1,u=null;for(let m=0;m<a.parts.length;m++){let E=a.parts[m];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let A=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){i=m,l=A[1],o=A[2]==="*",u=E.operation;break}}}if(i===-1||i===0&&i===a.parts.length-1)return null;let c="";for(let m=0;m<i;m++)c+=await s(e,a.parts[m]);let f="";for(let m=i+1;m<a.parts.length;m++)f+=await s(e,a.parts[m]);let h=P(e,l),d=h.map(([,m])=>m);if(h.length===0){let m=e.state.env.get(l);if(m!==void 0)d=[m];else{if(o)return{values:[c+f],quoted:!0};let E=c+f;return{values:E?[E]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,E="",A=e.state.shoptOptions.extglob;if(m.pattern)for(let S of m.pattern.parts)if(S.type==="Glob")E+=k(S.pattern,m.greedy,A);else if(S.type==="Literal")E+=k(S.value,m.greedy,A);else if(S.type==="SingleQuoted"||S.type==="Escaped")E+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await n(e,S.parts);E+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);E+=k(y,m.greedy,A)}else{let y=await s(e,S);E+=I(y)}d=d.map(S=>se(S,E,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,E="";if(m.pattern)for(let y of m.pattern.parts)if(y.type==="Glob")E+=k(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")E+=k(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")E+=I(y.value);else if(y.type==="DoubleQuoted"){let b=await n(e,y.parts);E+=I(b)}else if(y.type==="ParameterExpansion"){let b=await s(e,y);E+=k(b,!0,e.state.shoptOptions.extglob)}else{let b=await s(e,y);E+=I(b)}let A=m.replacement?await n(e,m.replacement.parts):"",S=E;m.anchor==="start"?S=`^${E}`:m.anchor==="end"&&(S=`${E}$`);try{let y=O(S,m.all?"g":"");d=d.map(b=>y.replace(b,A))}catch{}}if(o){let m=N(e.state.env);return{values:[c+d.join(m)+f],quoted:!0}}return d.length===1?{values:[c+d[0]+f],quoted:!0}:{values:[c+d[0],...d.slice(1,-1),d[d.length-1]+f],quoted:!0}}async function zn(e,t,r,s){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i="",l=!1;for(let d=0;d<n.parts.length;d++){let g=n.parts[d];if(g.type==="ParameterExpansion"&&!g.operation){let m=g.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){a=d,i=m[1],l=m[2]==="*";break}}}if(a===-1)return null;let o="";for(let d=0;d<a;d++)o+=await s(e,n.parts[d]);let u="";for(let d=a+1;d<n.parts.length;d++)u+=await s(e,n.parts[d]);let c=P(e,i),f=c.map(([,d])=>d);if(c.length===0){let d=e.state.env.get(i);if(d!==void 0)return{values:[o+d+u],quoted:!0};if(l)return{values:[o+u],quoted:!0};let g=o+u;return{values:g?[g]:[],quoted:!0}}if(l){let d=N(e.state.env);return{values:[o+f.join(d)+u],quoted:!0}}return f.length===1?{values:[o+f[0]+u],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function Zn(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Substring")return null;let n=s.parts[0],a=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let i=a[1],l=a[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(i))throw new j(1,"",`bash: \${${i}[@]: 0: 3}: bad substitution
|
|
69
|
-
`);let u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=P(e,i),h=0;if(u<0){if(f.length>0){let g=f[f.length-1][0],E=(typeof g=="number"?g:0)+1+u;if(E<0)return{values:[],quoted:!0};h=f.findIndex(([A])=>typeof A=="number"&&A>=E),h<0&&(h=f.length)}}else h=f.findIndex(([g])=>typeof g=="number"&&g>=u),h<0&&(h=f.length);let d;if(c!==void 0){if(c<0)throw new C(`${i}[@]: substring expression < 0`);d=f.slice(h,h+c).map(([,g])=>g)}else d=f.slice(h).map(([,g])=>g);if(d.length===0)return{values:[],quoted:!0};if(l){let g=N(e.state.env);return{values:[d.join(g)],quoted:!0}}return{values:d,quoted:!0}}function Gn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Transform")return null;let s=r.parts[0],n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let a=n[1],i=n[2]==="*",l=s.operation,o=P(e,a);if(o.length===0){let f=e.state.env.get(a);if(f!==void 0){let h;switch(l.operator){case"a":h="";break;case"P":h=be(e,f);break;case"Q":h=le(f);break;default:h=f}return{values:[h],quoted:!0}}return i?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=ce(e,a),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>be(e,f));break;case"Q":c=o.map(([,f])=>le(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(i){let f=N(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function Un(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion")return null;let s=r.parts[0];if(s.operation)return null;let n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let a=n[1];if(L(e,a)){let o=Ae(e,a);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let i=P(e,a);if(i.length>0)return{values:i.map(([,o])=>o),quoted:!0};let l=e.state.env.get(a);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function Hn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation)return null;let n=r.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!L(e,n))return null;let a=Ae(e,n);if(!a)return null;let i=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!i)return null;let l=i[1],o=P(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function jn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],l=i.operation,o=await v(e,i.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let g=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=g;E++)m.push(e.state.env.get(String(E))||"");return o==="*"?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",h=P(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return ws(e,h,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return Ns(e,h,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let m=ce(e,c),E=h.map(()=>m);return f?{values:[E.join(N(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let g=[];for(let[,m]of h){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},A=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let S=await s(e,E,!0);g.push(S)}finally{A!==void 0?e.state.env.set("_indirect_elem_",A):e.state.env.delete("_indirect_elem_")}}return f?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}if(h.length>0){let g=h.map(([,m])=>m);return f?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}async function ws(e,t,r,s,n){let a=n.offset?await R(e,n.offset.expression):0,i=n.length?await R(e,n.length.expression):void 0,l=0;if(a<0){if(t.length>0){let c=t[t.length-1][0],h=(typeof c=="number"?c:0)+1+a;if(h<0)return{values:[],quoted:!0};if(l=t.findIndex(([d])=>typeof d=="number"&&d>=h),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=a),l<0)return{values:[],quoted:!0};let o;if(i!==void 0){if(i<0)throw new C(`${r}[@]: substring expression < 0`);o=t.slice(l,l+i)}else o=t.slice(l);let u=o.map(([,c])=>c);return s?{values:[u.join(N(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function Ns(e,t,r,s,n,a){let i=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||i&&o)&&n.word){let f=await a(e,n.word.parts,!0);return e.state.env.set(`${r}_0`,f),e.state.env.set(`${r}__length`,"1"),{values:[f],quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function Kn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let r=t[0],s=r.operation,n=s?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let a=n.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],o=(await v(e,i.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await te(e,r.parameter),c=await v(e,r.parameter)==="",f=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=u&&!(f&&c):h=!u||f&&c,h){let d=o[1],g=o[2]==="*",m=P(e,d);if(m.length>0){let A=m.map(([,S])=>S);return g?{values:[A.join(N(e.state.env))],quoted:!0}:{values:A,quoted:!0}}let E=e.state.env.get(d);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Xn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let r=t[0],n=r.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let a=n.word;if(!a||a.parts.length!==1||a.parts[0].type!=="DoubleQuoted")return null;let i=a.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let l=i.parts[0],u=(await v(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await v(e,r.parameter),f=await te(e,r.parameter),h=c==="",d=n.checkEmpty??!1,g;if(n.type==="UseAlternative"?g=f&&!(d&&h):g=!f||d&&h,g){let m=u[1],E=u[2]==="*",A=P(e,m);if(A.length>0){let y=A.map(([,b])=>b);return E?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let S=e.state.env.get(m);return S!==void 0?{values:[S],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Jn(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),r=[];for(let s=1;s<=t;s++)r.push(e.state.env.get(String(s))||"");return r}async function Yn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let S=0;S<n.parts.length;S++){let y=n.parts[S];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="Substring"){a=S,i=y.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),h=[];for(let S=1;S<=f;S++)h.push(e.state.env.get(String(S))||"");let d=e.state.env.get("0")||"bash",g;if(u<=0){let S=[d,...h],y=S.length+u;if(y<0)g=[];else{let b=u<0?y:0;if(c!==void 0){let D=c<0?S.length+c:b+c;g=S.slice(b,Math.max(b,D))}else g=S.slice(b)}}else{let S=u-1;if(S>=h.length)g=[];else if(c!==void 0){let y=c<0?h.length+c:S+c;g=h.slice(S,Math.max(S,y))}else g=h.slice(S)}let m="";for(let S=0;S<a;S++)m+=await s(e,n.parts[S]);let E="";for(let S=a+1;S<n.parts.length;S++)E+=await s(e,n.parts[S]);if(g.length===0){let S=m+E;return{values:S?[S]:[],quoted:!0}}if(i){let S=N(e.state.env);return{values:[m+g.join(S)+E],quoted:!0}}return g.length===1?{values:[m+g[0]+E],quoted:!0}:{values:[m+g[0],...g.slice(1,-1),g[g.length-1]+E],quoted:!0}}async function er(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let A=0;A<n.parts.length;A++){let S=n.parts[A];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="PatternReplacement"){a=A,i=S.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=Jn(e),c="";for(let A=0;A<a;A++)c+=await r(e,n.parts[A]);let f="";for(let A=a+1;A<n.parts.length;A++)f+=await r(e,n.parts[A]);if(u.length===0){let A=c+f;return{values:A?[A]:[],quoted:!0}}let h="";if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")h+=k(A.pattern,!0,e.state.shoptOptions.extglob);else if(A.type==="Literal")h+=k(A.value,!0,e.state.shoptOptions.extglob);else if(A.type==="SingleQuoted"||A.type==="Escaped")h+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await s(e,A.parts);h+=I(S)}else if(A.type==="ParameterExpansion"){let S=await r(e,A);h+=k(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,A);h+=I(S)}let d=o.replacement?await s(e,o.replacement.parts):"",g=h;o.anchor==="start"?g=`^${h}`:o.anchor==="end"&&(g=`${h}$`);let m=[];try{let A=O(g,o.all?"g":"");for(let S of u)m.push(A.replace(S,d))}catch{m.push(...u)}if(i){let A=N(e.state.env);return{values:[c+m.join(A)+f],quoted:!0}}return m.length===1?{values:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function tr(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let E=0;E<n.parts.length;E++){let A=n.parts[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){a=E,i=A.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=Jn(e),c="";for(let E=0;E<a;E++)c+=await r(e,n.parts[E]);let f="";for(let E=a+1;E<n.parts.length;E++)f+=await r(e,n.parts[E]);if(u.length===0){let E=c+f;return{values:E?[E]:[],quoted:!0}}let h="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let E of o.pattern.parts)if(E.type==="Glob")h+=k(E.pattern,o.greedy,d);else if(E.type==="Literal")h+=k(E.value,o.greedy,d);else if(E.type==="SingleQuoted"||E.type==="Escaped")h+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await s(e,E.parts);h+=I(A)}else if(E.type==="ParameterExpansion"){let A=await r(e,E);h+=k(A,o.greedy,d)}else{let A=await r(e,E);h+=I(A)}let g=[];for(let E of u)g.push(se(E,h,o.side,o.greedy));if(i){let E=N(e.state.env);return{values:[c+g.join(E)+f],quoted:!0}}return g.length===1?{values:[c+g[0]+f],quoted:!0}:{values:[c+g[0],...g.slice(1,-1),g[g.length-1]+f],quoted:!0}}async function nr(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],n=-1,a=!1;for(let h=0;h<s.parts.length;h++){let d=s.parts[h];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")){n=h,a=d.parameter==="*";break}}if(n===-1)return null;let i=s.parts[n];if(i.type==="ParameterExpansion"&&i.operation)return null;let l=Number.parseInt(e.state.env.get("#")||"0",10),o="";for(let h=0;h<n;h++)o+=await r(e,s.parts[h]);let u="";for(let h=n+1;h<s.parts.length;h++)u+=await r(e,s.parts[h]);if(l===0){if(a)return{values:[o+u],quoted:!0};let h=o+u;return{values:h?[h]:[],quoted:!0}}let c=[];for(let h=1;h<=l;h++)c.push(e.state.env.get(String(h))||"");if(a){let h=N(e.state.env);return{values:[o+c.join(h)+u],quoted:!0}}return c.length===1?{values:[o+c[0]+u],quoted:!0}:{values:[o+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function ks(e){return new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations})}async function Te(e,t){if(e.state.options.noglob)return t;let r=ks(e),s=[];for(let n of t)if(ne(n,e.state.shoptOptions.extglob)){let a=await r.expand(n);if(a.length>0)s.push(...a);else{if(r.hasFailglob())throw new Pe(n);r.hasNullglob()||s.push(n)}}else s.push(n);return s}async function rr(e,t,r,s){let n=-1,a="",i=!1;for(let S=0;S<t.length;S++){let y=t[S];if(y.type==="ParameterExpansion"&&y.operation?.type==="PatternReplacement"){let b=y.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){n=S,a=b[1],i=b[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=P(e,a),c=u.map(([,S])=>S);if(u.length===0){let S=e.state.env.get(a);S!==void 0&&(c=[S])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")f+=k(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=k(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);f+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);f+=k(y,!0,e.state.shoptOptions.extglob)}else{let y=await s(e,S);f+=I(y)}let h=o.replacement?await r(e,o.replacement.parts):"",d=f;o.anchor==="start"?d=`^${f}`:o.anchor==="end"&&(d=`${f}$`);let g=[];try{let S=O(d,o.all?"g":"");for(let y of c)g.push(S.replace(y,h))}catch{g.push(...c)}let m=W(e.state.env),E=V(e.state.env);if(i){let S=N(e.state.env),y=g.join(S);return E?{values:y?[y]:[],quoted:!1}:{values:x(y,m),quoted:!1}}if(E)return{values:g,quoted:!1};let A=[];for(let S of g)S===""?A.push(""):A.push(...x(S,m));return{values:A,quoted:!1}}async function sr(e,t,r,s){let n=-1,a="",i=!1;for(let A=0;A<t.length;A++){let S=t[A];if(S.type==="ParameterExpansion"&&S.operation?.type==="PatternRemoval"){let y=S.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(y){n=A,a=y[1],i=y[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=P(e,a),c=u.map(([,A])=>A);if(u.length===0){let A=e.state.env.get(a);A!==void 0&&(c=[A])}if(c.length===0)return{values:[],quoted:!1};let f="",h=e.state.shoptOptions.extglob;if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")f+=k(A.pattern,o.greedy,h);else if(A.type==="Literal")f+=k(A.value,o.greedy,h);else if(A.type==="SingleQuoted"||A.type==="Escaped")f+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await r(e,A.parts);f+=I(S)}else if(A.type==="ParameterExpansion"){let S=await s(e,A);f+=k(S,o.greedy,h)}else{let S=await s(e,A);f+=I(S)}let d=[];for(let A of c)d.push(se(A,f,o.side,o.greedy));let g=W(e.state.env),m=V(e.state.env);if(i){let A=N(e.state.env),S=d.join(A);return m?{values:S?[S]:[],quoted:!1}:{values:x(S,g),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[];for(let A of d)A===""?E.push(""):E.push(...x(A,g));return{values:E,quoted:!1}}async function ir(e,t,r,s){let n=-1,a=!1;for(let E=0;E<t.length;E++){let A=t[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){n=E,a=A.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let E=1;E<=o;E++)u.push(e.state.env.get(String(E))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(l.pattern)for(let E of l.pattern.parts)if(E.type==="Glob")c+=k(E.pattern,l.greedy,f);else if(E.type==="Literal")c+=k(E.value,l.greedy,f);else if(E.type==="SingleQuoted"||E.type==="Escaped")c+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await r(e,E.parts);c+=I(A)}else if(E.type==="ParameterExpansion"){let A=await s(e,E);c+=k(A,l.greedy,f)}else{let A=await s(e,E);c+=I(A)}let h=[];for(let E of u)h.push(se(E,c,l.side,l.greedy));let d=W(e.state.env),g=V(e.state.env);if(a){let E=N(e.state.env),A=h.join(E);return g?{values:A?[A]:[],quoted:!1}:{values:x(A,d),quoted:!1}}if(g)return{values:h,quoted:!1};let m=[];for(let E of h)E===""?m.push(""):m.push(...x(E,d));return{values:m,quoted:!1}}async function ar(e,t,r,s){let n=-1,a=!1;for(let y=0;y<t.length;y++){let b=t[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){n=y,a=b.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=l.offset?await r(e,l.offset.expression):0,u=l.length?await r(e,l.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let y=1;y<=c;y++)f.push(e.state.env.get(String(y))||"");let h=e.state.env.get("0")||"bash",d;if(o<=0){let y=[h,...f],b=y.length+o;if(b<0)d=[];else{let D=o<0?b:0;if(u!==void 0){let Z=u<0?y.length+u:D+u;d=y.slice(D,Math.max(D,Z))}else d=y.slice(D)}}else{let y=o-1;if(y>=f.length)d=[];else if(u!==void 0){let b=u<0?f.length+u:y+u;d=f.slice(y,Math.max(y,b))}else d=f.slice(y)}let g="";for(let y=0;y<n;y++)g+=await s(e,t[y]);let m="";for(let y=n+1;y<t.length;y++)m+=await s(e,t[y]);let E=W(e.state.env),A=V(e.state.env);if(d.length===0){let y=g+m;return y?A?{values:[y],quoted:!1}:{values:x(y,E),quoted:!1}:{values:[],quoted:!1}}let S;if(a){let y=N(e.state.env),b=g+d.join(y)+m;A?S=b?[b]:[]:S=x(b,E)}else if(A)d.length===1?S=[g+d[0]+m]:S=[g+d[0],...d.slice(1,-1),d[d.length-1]+m];else{S=[];for(let y=0;y<d.length;y++){let b=d[y];if(y===0&&(b=g+b),y===d.length-1&&(b=b+m),b==="")S.push("");else{let D=x(b,E);S.push(...D)}}}return{values:await Te(e,S),quoted:!1}}async function or(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let r=t[0].parameter==="*",s=Number.parseInt(e.state.env.get("#")||"0",10);if(s===0)return{values:[],quoted:!1};let n=[];for(let u=1;u<=s;u++)n.push(e.state.env.get(String(u))||"");let a=W(e.state.env),i=V(e.state.env),l=Ce(e.state.env),o;if(r)if(i)o=n.filter(u=>u!=="");else{let u=N(e.state.env),c=n.join(u);o=x(c,a)}else if(i)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=x(u,a);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=x(u,a);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Te(e,o),quoted:!1}}async function lr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let r=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!r)return null;let s=r[1],n=r[2]==="*",a=P(e,s),i;if(a.length===0){let f=e.state.env.get(s);if(f!==void 0)i=[f];else return{values:[],quoted:!1}}else i=a.map(([,f])=>f);let l=W(e.state.env),o=V(e.state.env),u=Ce(e.state.env),c;if(n)if(o)c=i.filter(f=>f!=="");else{let f=N(e.state.env),h=i.join(f);c=x(h,l)}else if(o)c=i.filter(f=>f!=="");else if(u){c=[];for(let f of i){if(f==="")continue;let h=x(f,l);c.push(...h)}}else{c=[];for(let f of i)if(f==="")c.push("");else{let h=x(f,l);c.push(...h)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Te(e,c),quoted:!1}}function cr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let r=t[0].operation,s=de(e,r.prefix);if(s.length===0)return{values:[],quoted:!1};let n=W(e.state.env),a=V(e.state.env),i;if(r.star)if(a)i=s;else{let l=N(e.state.env),o=s.join(l);i=x(o,n)}else if(a)i=s;else{i=[];for(let l of s){let o=x(l,n);i.push(...o)}}return{values:i,quoted:!1}}function ur(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let r=t[0].operation,n=P(e,r.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let a=W(e.state.env),i=V(e.state.env),l;if(r.star)if(i)l=n;else{let o=N(e.state.env),u=n.join(o);l=x(u,a)}else if(i)l=n;else{l=[];for(let o of n){let u=x(o,a);l.push(...u)}}return{values:l,quoted:!1}}async function fr(e,t,r){let s=-1;for(let h=0;h<t.length;h++){let d=t[h];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")&&!d.operation){s=h;break}}if(s===-1||t.length<=1)return null;let n=Number.parseInt(e.state.env.get("#")||"0",10),a=[];for(let h=1;h<=n;h++)a.push(e.state.env.get(String(h))||"");let i="";for(let h=0;h<s;h++)i+=await r(e,t[h]);let l="";for(let h=s+1;h<t.length;h++)l+=await r(e,t[h]);let o=W(e.state.env),u=V(e.state.env),c=Ce(e.state.env);if(n===0){let h=i+l;return{values:h?[h]:[],quoted:!1}}let f;{let h=[];for(let d=0;d<a.length;d++){let g=a[d];d===0&&(g=i+g),d===a.length-1&&(g=g+l),h.push(g)}if(u)f=h.filter(d=>d!=="");else if(c){f=[];for(let d of h){if(d==="")continue;let g=x(d,o);f.push(...g)}}else{f=[];for(let d of h)if(d==="")f.push("");else{let g=x(d,o);f.push(...g)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Te(e,f),quoted:!1}}async function dr(e,t,r){e.coverage?.hit("bash:expansion:word_glob");let s=t.parts,{hasQuoted:n,hasCommandSub:a,hasArrayVar:i,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=ye(s),h=r.hasBraceExpansion(s)?await r.expandWordWithBracesAsync(e,t):null;if(h&&h.length>1)return Ps(e,h,n);let d=await Rs(e,s,l,u,c,r);if(d!==null)return d;let g=await vs(e,s,r);if(g!==null)return g;let m=await Ds(e,s,r);if(m!==null)return m;let E=await $s(e,s,r.expandPart);if(E!==null)return pr(e,E);if((a||i||o)&&!V(e.state.env)){let S=W(e.state.env),y=r.buildIfsCharClassPattern(S),b=await r.smartWordSplit(e,s,S,y,r.expandPart);return pr(e,b)}let A=await r.expandWordAsync(e,t);return _s(e,t,s,A,n,r.expandWordForGlobbing)}async function Ps(e,t,r){let s=[];for(let n of t)if(!(!r&&n===""))if(!r&&!e.state.options.noglob&&ne(n,e.state.shoptOptions.extglob)){let a=await Me(e,n);s.push(...a)}else s.push(n);return{values:s,quoted:!1}}async function Rs(e,t,r,s,n,a){if(r){let i=Un(e,t);if(i!==null)return i}{let i=Hn(e,t);if(i!==null)return i}{let i=await Fn(e,t);if(i!==null)return i}{let i=await Qn(e,t,r,a.expandPart,a.expandWordPartsAsync);if(i!==null)return i}{let i=await zn(e,t,r,a.expandPart);if(i!==null)return i}{let i=await Zn(e,t,a.evaluateArithmetic);if(i!==null)return i}{let i=Gn(e,t);if(i!==null)return i}{let i=await qn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}{let i=await Bn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}if(s&&t.length===1&&t[0].type==="DoubleQuoted"){let i=Is(e,t);if(i!==null)return i}{let i=await jn(e,t,n,a.expandParameterAsync,a.expandWordPartsAsync);if(i!==null)return i}{let i=await Kn(e,t);if(i!==null)return i}{let i=await Xn(e,t);if(i!==null)return i}return null}function Is(e,t){let r=t[0];if(r.type!=="DoubleQuoted")return null;if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="VarNamePrefix"){let s=r.parts[0].operation,n=de(e,s.prefix);return s.star?{values:[n.join(N(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="ArrayKeys"){let s=r.parts[0].operation,a=P(e,s.array).map(([i])=>String(i));return s.star?{values:[a.join(N(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return null}async function vs(e,t,r){{let s=await Yn(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await er(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await tr(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await nr(e,t,r.expandPart);if(s!==null)return s}return null}async function Ds(e,t,r){{let s=await rr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await sr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ir(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ar(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await or(e,t);if(s!==null)return s}{let s=await lr(e,t);if(s!==null)return s}{let s=cr(e,t);if(s!==null)return s}{let s=ur(e,t);if(s!==null)return s}{let s=await fr(e,t,r.expandPart);if(s!==null)return s}return null}function hr(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let r=e.parts[t];if(r.type!=="ParameterExpansion"||r.operation)continue;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s)return{type:"array",name:s[1],atIndex:t,isStar:s[2]==="*"};if(r.parameter==="@"||r.parameter==="*")return{type:"positional",atIndex:t,isStar:r.parameter==="*"}}return null}async function xs(e,t,r,s){let n="";for(let l=0;l<r.atIndex;l++)n+=await s(e,t.parts[l]);let a="";for(let l=r.atIndex+1;l<t.parts.length;l++)a+=await s(e,t.parts[l]);let i;if(r.type==="array"){if(i=P(e,r.name).map(([,o])=>o),i.length===0){let o=e.state.env.get(r.name);o!==void 0&&(i=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);i=[];for(let o=1;o<=l;o++)i.push(e.state.env.get(String(o))||"")}if(r.isStar){let l=N(e.state.env),o=i.join(l);return[n+o+a]}if(i.length===0){let l=n+a;return l?[l]:[]}return i.length===1?[n+i[0]+a]:[n+i[0],...i.slice(1,-1),i[i.length-1]+a]}async function $s(e,t,r){if(t.length<2)return null;let s=!1;for(let o of t)if(hr(o)){s=!0;break}if(!s)return null;let n=W(e.state.env),a=V(e.state.env),i=[];for(let o of t){let u=hr(o);if(u&&o.type==="DoubleQuoted"){let c=await xs(e,o,u,r);i.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await r(e,o);i.push([c])}else if(o.type==="Literal")i.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=x(c,n);i.push(f)}}else{let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=x(c,n);i.push(f)}}}let l=[];for(let o of i)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c<o.length;c++)l.push(o[c])}return l}async function pr(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let r=[];for(let s of t)if(ne(s,e.state.shoptOptions.extglob)){let n=await Me(e,s);r.push(...n)}else r.push(s);return{values:r,quoted:!1}}async function Me(e,t){let r=new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),s=await r.expand(t);if(s.length>0)return s;if(r.hasFailglob())throw new Pe(t);return r.hasNullglob()?[]:[t]}async function _s(e,t,r,s,n,a){let i=r.some(l=>l.type==="Glob");if(!e.state.options.noglob&&i){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let u=await Me(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=St(s);if(!V(e.state.env)){let u=W(e.state.env);return{values:x(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&ne(s,e.state.shoptOptions.extglob)){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let o=await Me(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(s===""&&!n)return{values:[],quoted:!1};if(i&&!n){let l=St(s);if(!V(e.state.env)){let o=W(e.state.env);return{values:x(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[s],quoted:n}}async function gr(e,t){let r=t.operation;if(!r||r.type!=="DefaultValue"&&r.type!=="AssignDefault"&&r.type!=="UseAlternative")return null;let s=r.word;if(!s||s.parts.length===0)return null;let n=await te(e,t.parameter),i=await v(e,t.parameter,!1)==="",l=r.checkEmpty??!1,o;return r.type==="UseAlternative"?o=n&&!(l&&i):o=!n||l&&i,o?s.parts:null}function Cs(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(r=>r.type==="Literal"):!1}async function Os(e,t){if(t.type!=="ParameterExpansion")return null;let r=await gr(e,t);if(!r||r.length<=1)return null;let s=r.some(a=>Cs(a)),n=r.some(a=>a.type==="Literal"||a.type==="ParameterExpansion"||a.type==="CommandSubstitution"||a.type==="ArithmeticExpansion");return s&&n?r:null}function Ls(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?dt(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&mn(e))}async function yr(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let h=t[0],d=await gr(e,h);if(d&&d.length>0&&d.length>1&&d.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&d.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return mr(e,d,r,s,n)}let a=[],i=!1;for(let h of t){let d=Ls(h),g=h.type==="DoubleQuoted"||h.type==="SingleQuoted",m=d?await Os(e,h):null,E=await n(e,h);a.push({value:E,isSplittable:d,isQuoted:g,mixedDefaultParts:m??void 0}),d&&(i=!0)}if(!i){let h=a.map(d=>d.value).join("");return h?[h]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let h of a)if(!h.isSplittable)c?h.isQuoted&&h.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):h.value!==""?(o!==""&&l.push(o),o=h.value,c=!1,f=!1):(o+=h.value,f=!1):(o+=h.value,f=h.isQuoted&&h.value==="");else if(h.mixedDefaultParts){let d=await mr(e,h.mixedDefaultParts,r,s,n);if(d.length!==0)if(d.length===1)o+=d[0],u=!0;else{o+=d[0],l.push(o),u=!0;for(let g=1;g<d.length-1;g++)l.push(d[g]);o=d[d.length-1]}c=!1,f=!1}else{let{words:d,hadLeadingDelimiter:g,hadTrailingDelimiter:m}=Oe(h.value,r);if(f&&g&&o===""&&(l.push(""),u=!0),d.length===0)m&&(c=!0);else if(d.length===1)o+=d[0],u=!0,c=m;else{o+=d[0],l.push(o),u=!0;for(let E=1;E<d.length-1;E++)l.push(d[E]);o=d[d.length-1],c=m}f=!1}return o!==""?l.push(o):l.length===0&&u&&l.push(""),l}function Ws(e,t){return e.length>0&&t.includes(e[0])}async function mr(e,t,r,s,n){let a=[];for(let c of t){let h=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),d=await n(e,c);a.push({value:d,isSplittable:h})}let i=[],l="",o=!1,u=!1;for(let c of a)if(!c.isSplittable)u&&c.value!==""?(l!==""&&i.push(l),l=c.value,u=!1):l+=c.value;else{Ws(c.value,r)&&l!==""&&(i.push(l),l="",o=!0);let{words:h,hadTrailingDelimiter:d}=Oe(c.value,r);if(h.length===0)d&&(u=!0);else if(h.length===1)l+=h[0],o=!0,u=d;else{l+=h[0],i.push(l),o=!0;for(let g=1;g<h.length-1;g++)i.push(h[g]);l=h[h.length-1],u=d}}return l!==""?i.push(l):i.length===0&&o&&i.push(""),i}function Er(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Ar(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function we(e,t,r){if(e.length>t)throw new B(`${r}: string length limit exceeded (${t} bytes)`,"string_length")}async function X(e,t,r=!1){let s=[];for(let n of t)s.push(await U(e,n,r));return s.join("")}function Ts(e){return Ar(e)}function Al(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Ts(t))return!1;return!0}function Ms(e,t,r=!1){let s=Er(t);if(s!==null)return s;switch(t.type){case"TildeExpansion":return r?t.user===null?"~":`~${t.user}`:t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`;case"Glob":return Nt(e,t.pattern);default:return null}}async function Pt(e,t){return Rt(e,t)}async function Sl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped")r.push(`\\${s.value}`);else if(s.type==="SingleQuoted")r.push(s.value);else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(n)}else if(s.type==="TildeExpansion"){let n=await U(e,s);r.push(bt(n))}else r.push(await U(e,s));return r.join("")}async function bl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped"){let n=s.value;"()|*?[]".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="SingleQuoted")r.push(K(s.value));else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(K(n))}else r.push(await U(e,s));return r.join("")}async function Sr(e,t){let r=[];for(let s of t.parts)if(s.type==="SingleQuoted")r.push(K(s.value));else if(s.type==="Escaped"){let n=s.value;"*?[]\\()|".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(K(n))}else s.type==="Glob"?Wn(s.pattern)?r.push(await Mn(e,s.pattern)):r.push(Nt(e,s.pattern)):s.type==="Literal"?r.push(s.value):r.push(await U(e,s));return r.join("")}function qe(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&qe(t.parts))return!0;return!1}var Vs=1e4,kt=1e5;async function br(e,t,r={count:0}){if(r.count>kt)return[[]];let s=[[]];for(let n of t)if(n.type==="BraceExpansion"){let a=[],i=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=At(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let h of f.expanded)r.count++,a.push(h);else{i=!0,l=f.literal;break}}else{let f=await br(e,c.word.parts,r);for(let h of f){r.count++;let d=[];for(let g of h)typeof g=="string"?d.push(g):d.push(await U(e,g));a.push(d.join(""))}}if(i){for(let c of s)r.count++,c.push(l);continue}if(s.length*a.length>Vs||r.count>kt)return s;let u=[];for(let c of s)for(let f of a){if(r.count++,r.count>kt)return u.length>0?u:s;u.push([...c,f])}s=u}else for(let a of s)r.count++,a.push(n);return s}async function wr(e,t){let r=t.parts;if(!qe(r))return[await Pt(e,t)];let s=await br(e,r),n=[];for(let a of s){let i=[];for(let l of a)typeof l=="string"?i.push(l):i.push(await U(e,l));n.push(Vn(e,i.join("")))}return n}function qs(){return{expandWordAsync:Rt,expandWordForGlobbing:Sr,expandWordWithBracesAsync:wr,expandWordPartsAsync:X,expandPart:U,expandParameterAsync:Ve,hasBraceExpansion:qe,evaluateArithmetic:R,buildIfsCharClassPattern:En,smartWordSplit:yr}}async function wl(e,t){return dr(e,t,qs())}function Bs(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Fs(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function s(n){for(let a of n)if(a.type==="DoubleQuoted"){for(let i of a.parts)if(i.type==="ParameterExpansion"&&i.parameter==="@"&&!i.operation)return!0}return!1}return s(t.parts)}async function Nl(e,t){if(Fs(e,t))return{error:`bash: $@: ambiguous redirect
|
|
69
|
+
`);let u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=P(e,i),h=0;if(u<0){if(f.length>0){let g=f[f.length-1][0],E=(typeof g=="number"?g:0)+1+u;if(E<0)return{values:[],quoted:!0};h=f.findIndex(([A])=>typeof A=="number"&&A>=E),h<0&&(h=f.length)}}else h=f.findIndex(([g])=>typeof g=="number"&&g>=u),h<0&&(h=f.length);let d;if(c!==void 0){if(c<0)throw new C(`${i}[@]: substring expression < 0`);d=f.slice(h,h+c).map(([,g])=>g)}else d=f.slice(h).map(([,g])=>g);if(d.length===0)return{values:[],quoted:!0};if(l){let g=N(e.state.env);return{values:[d.join(g)],quoted:!0}}return{values:d,quoted:!0}}function Gn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Transform")return null;let s=r.parts[0],n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let a=n[1],i=n[2]==="*",l=s.operation,o=P(e,a);if(o.length===0){let f=e.state.env.get(a);if(f!==void 0){let h;switch(l.operator){case"a":h="";break;case"P":h=be(e,f);break;case"Q":h=le(f);break;default:h=f}return{values:[h],quoted:!0}}return i?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=ce(e,a),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>be(e,f));break;case"Q":c=o.map(([,f])=>le(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(i){let f=N(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function Un(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion")return null;let s=r.parts[0];if(s.operation)return null;let n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let a=n[1];if(L(e,a)){let o=Ae(e,a);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let i=P(e,a);if(i.length>0)return{values:i.map(([,o])=>o),quoted:!0};let l=e.state.env.get(a);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function Hn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation)return null;let n=r.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!L(e,n))return null;let a=Ae(e,n);if(!a)return null;let i=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!i)return null;let l=i[1],o=P(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function jn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],l=i.operation,o=await v(e,i.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let g=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=g;E++)m.push(e.state.env.get(String(E))||"");return o==="*"?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",h=P(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return ws(e,h,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return Ns(e,h,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let m=ce(e,c),E=h.map(()=>m);return f?{values:[E.join(N(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let g=[];for(let[,m]of h){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},A=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let S=await s(e,E,!0);g.push(S)}finally{A!==void 0?e.state.env.set("_indirect_elem_",A):e.state.env.delete("_indirect_elem_")}}return f?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}if(h.length>0){let g=h.map(([,m])=>m);return f?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}async function ws(e,t,r,s,n){let a=n.offset?await R(e,n.offset.expression):0,i=n.length?await R(e,n.length.expression):void 0,l=0;if(a<0){if(t.length>0){let c=t[t.length-1][0],h=(typeof c=="number"?c:0)+1+a;if(h<0)return{values:[],quoted:!0};if(l=t.findIndex(([d])=>typeof d=="number"&&d>=h),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=a),l<0)return{values:[],quoted:!0};let o;if(i!==void 0){if(i<0)throw new C(`${r}[@]: substring expression < 0`);o=t.slice(l,l+i)}else o=t.slice(l);let u=o.map(([,c])=>c);return s?{values:[u.join(N(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function Ns(e,t,r,s,n,a){let i=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||i&&o)&&n.word){let f=await a(e,n.word.parts,!0);return e.state.env.set(`${r}_0`,f),e.state.env.set(`${r}__length`,"1"),{values:[f],quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function Kn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let r=t[0],s=r.operation,n=s?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let a=n.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],o=(await v(e,i.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await te(e,r.parameter),c=await v(e,r.parameter)==="",f=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=u&&!(f&&c):h=!u||f&&c,h){let d=o[1],g=o[2]==="*",m=P(e,d);if(m.length>0){let A=m.map(([,S])=>S);return g?{values:[A.join(N(e.state.env))],quoted:!0}:{values:A,quoted:!0}}let E=e.state.env.get(d);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Xn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let r=t[0],n=r.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let a=n.word;if(!a||a.parts.length!==1||a.parts[0].type!=="DoubleQuoted")return null;let i=a.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let l=i.parts[0],u=(await v(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await v(e,r.parameter),f=await te(e,r.parameter),h=c==="",d=n.checkEmpty??!1,g;if(n.type==="UseAlternative"?g=f&&!(d&&h):g=!f||d&&h,g){let m=u[1],E=u[2]==="*",A=P(e,m);if(A.length>0){let y=A.map(([,b])=>b);return E?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let S=e.state.env.get(m);return S!==void 0?{values:[S],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Jn(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),r=[];for(let s=1;s<=t;s++)r.push(e.state.env.get(String(s))||"");return r}async function Yn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let S=0;S<n.parts.length;S++){let y=n.parts[S];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="Substring"){a=S,i=y.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),h=[];for(let S=1;S<=f;S++)h.push(e.state.env.get(String(S))||"");let d=e.state.env.get("0")||"bash",g;if(u<=0){let S=[d,...h],y=S.length+u;if(y<0)g=[];else{let b=u<0?y:0;if(c!==void 0){let D=c<0?S.length+c:b+c;g=S.slice(b,Math.max(b,D))}else g=S.slice(b)}}else{let S=u-1;if(S>=h.length)g=[];else if(c!==void 0){let y=c<0?h.length+c:S+c;g=h.slice(S,Math.max(S,y))}else g=h.slice(S)}let m="";for(let S=0;S<a;S++)m+=await s(e,n.parts[S]);let E="";for(let S=a+1;S<n.parts.length;S++)E+=await s(e,n.parts[S]);if(g.length===0){let S=m+E;return{values:S?[S]:[],quoted:!0}}if(i){let S=N(e.state.env);return{values:[m+g.join(S)+E],quoted:!0}}return g.length===1?{values:[m+g[0]+E],quoted:!0}:{values:[m+g[0],...g.slice(1,-1),g[g.length-1]+E],quoted:!0}}async function er(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let A=0;A<n.parts.length;A++){let S=n.parts[A];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="PatternReplacement"){a=A,i=S.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=Jn(e),c="";for(let A=0;A<a;A++)c+=await r(e,n.parts[A]);let f="";for(let A=a+1;A<n.parts.length;A++)f+=await r(e,n.parts[A]);if(u.length===0){let A=c+f;return{values:A?[A]:[],quoted:!0}}let h="";if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")h+=k(A.pattern,!0,e.state.shoptOptions.extglob);else if(A.type==="Literal")h+=k(A.value,!0,e.state.shoptOptions.extglob);else if(A.type==="SingleQuoted"||A.type==="Escaped")h+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await s(e,A.parts);h+=I(S)}else if(A.type==="ParameterExpansion"){let S=await r(e,A);h+=k(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,A);h+=I(S)}let d=o.replacement?await s(e,o.replacement.parts):"",g=h;o.anchor==="start"?g=`^${h}`:o.anchor==="end"&&(g=`${h}$`);let m=[];try{let A=O(g,o.all?"g":"");for(let S of u)m.push(A.replace(S,d))}catch{m.push(...u)}if(i){let A=N(e.state.env);return{values:[c+m.join(A)+f],quoted:!0}}return m.length===1?{values:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function tr(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let E=0;E<n.parts.length;E++){let A=n.parts[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){a=E,i=A.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=Jn(e),c="";for(let E=0;E<a;E++)c+=await r(e,n.parts[E]);let f="";for(let E=a+1;E<n.parts.length;E++)f+=await r(e,n.parts[E]);if(u.length===0){let E=c+f;return{values:E?[E]:[],quoted:!0}}let h="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let E of o.pattern.parts)if(E.type==="Glob")h+=k(E.pattern,o.greedy,d);else if(E.type==="Literal")h+=k(E.value,o.greedy,d);else if(E.type==="SingleQuoted"||E.type==="Escaped")h+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await s(e,E.parts);h+=I(A)}else if(E.type==="ParameterExpansion"){let A=await r(e,E);h+=k(A,o.greedy,d)}else{let A=await r(e,E);h+=I(A)}let g=[];for(let E of u)g.push(se(E,h,o.side,o.greedy));if(i){let E=N(e.state.env);return{values:[c+g.join(E)+f],quoted:!0}}return g.length===1?{values:[c+g[0]+f],quoted:!0}:{values:[c+g[0],...g.slice(1,-1),g[g.length-1]+f],quoted:!0}}async function nr(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],n=-1,a=!1;for(let h=0;h<s.parts.length;h++){let d=s.parts[h];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")){n=h,a=d.parameter==="*";break}}if(n===-1)return null;let i=s.parts[n];if(i.type==="ParameterExpansion"&&i.operation)return null;let l=Number.parseInt(e.state.env.get("#")||"0",10),o="";for(let h=0;h<n;h++)o+=await r(e,s.parts[h]);let u="";for(let h=n+1;h<s.parts.length;h++)u+=await r(e,s.parts[h]);if(l===0){if(a)return{values:[o+u],quoted:!0};let h=o+u;return{values:h?[h]:[],quoted:!0}}let c=[];for(let h=1;h<=l;h++)c.push(e.state.env.get(String(h))||"");if(a){let h=N(e.state.env);return{values:[o+c.join(h)+u],quoted:!0}}return c.length===1?{values:[o+c[0]+u],quoted:!0}:{values:[o+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function ks(e){return new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations})}async function Te(e,t){if(e.state.options.noglob)return t;let r=ks(e),s=[];for(let n of t)if(ne(n,e.state.shoptOptions.extglob)){let a=await r.expand(n);if(a.length>0)s.push(...a);else{if(r.hasFailglob())throw new Pe(n);r.hasNullglob()||s.push(n)}}else s.push(n);return s}async function rr(e,t,r,s){let n=-1,a="",i=!1;for(let S=0;S<t.length;S++){let y=t[S];if(y.type==="ParameterExpansion"&&y.operation?.type==="PatternReplacement"){let b=y.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){n=S,a=b[1],i=b[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=P(e,a),c=u.map(([,S])=>S);if(u.length===0){let S=e.state.env.get(a);S!==void 0&&(c=[S])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")f+=k(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=k(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);f+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);f+=k(y,!0,e.state.shoptOptions.extglob)}else{let y=await s(e,S);f+=I(y)}let h=o.replacement?await r(e,o.replacement.parts):"",d=f;o.anchor==="start"?d=`^${f}`:o.anchor==="end"&&(d=`${f}$`);let g=[];try{let S=O(d,o.all?"g":"");for(let y of c)g.push(S.replace(y,h))}catch{g.push(...c)}let m=W(e.state.env),E=V(e.state.env);if(i){let S=N(e.state.env),y=g.join(S);return E?{values:y?[y]:[],quoted:!1}:{values:x(y,m),quoted:!1}}if(E)return{values:g,quoted:!1};let A=[];for(let S of g)S===""?A.push(""):A.push(...x(S,m));return{values:A,quoted:!1}}async function sr(e,t,r,s){let n=-1,a="",i=!1;for(let A=0;A<t.length;A++){let S=t[A];if(S.type==="ParameterExpansion"&&S.operation?.type==="PatternRemoval"){let y=S.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(y){n=A,a=y[1],i=y[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=P(e,a),c=u.map(([,A])=>A);if(u.length===0){let A=e.state.env.get(a);A!==void 0&&(c=[A])}if(c.length===0)return{values:[],quoted:!1};let f="",h=e.state.shoptOptions.extglob;if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")f+=k(A.pattern,o.greedy,h);else if(A.type==="Literal")f+=k(A.value,o.greedy,h);else if(A.type==="SingleQuoted"||A.type==="Escaped")f+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await r(e,A.parts);f+=I(S)}else if(A.type==="ParameterExpansion"){let S=await s(e,A);f+=k(S,o.greedy,h)}else{let S=await s(e,A);f+=I(S)}let d=[];for(let A of c)d.push(se(A,f,o.side,o.greedy));let g=W(e.state.env),m=V(e.state.env);if(i){let A=N(e.state.env),S=d.join(A);return m?{values:S?[S]:[],quoted:!1}:{values:x(S,g),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[];for(let A of d)A===""?E.push(""):E.push(...x(A,g));return{values:E,quoted:!1}}async function ir(e,t,r,s){let n=-1,a=!1;for(let E=0;E<t.length;E++){let A=t[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){n=E,a=A.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let E=1;E<=o;E++)u.push(e.state.env.get(String(E))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(l.pattern)for(let E of l.pattern.parts)if(E.type==="Glob")c+=k(E.pattern,l.greedy,f);else if(E.type==="Literal")c+=k(E.value,l.greedy,f);else if(E.type==="SingleQuoted"||E.type==="Escaped")c+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await r(e,E.parts);c+=I(A)}else if(E.type==="ParameterExpansion"){let A=await s(e,E);c+=k(A,l.greedy,f)}else{let A=await s(e,E);c+=I(A)}let h=[];for(let E of u)h.push(se(E,c,l.side,l.greedy));let d=W(e.state.env),g=V(e.state.env);if(a){let E=N(e.state.env),A=h.join(E);return g?{values:A?[A]:[],quoted:!1}:{values:x(A,d),quoted:!1}}if(g)return{values:h,quoted:!1};let m=[];for(let E of h)E===""?m.push(""):m.push(...x(E,d));return{values:m,quoted:!1}}async function ar(e,t,r,s){let n=-1,a=!1;for(let y=0;y<t.length;y++){let b=t[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){n=y,a=b.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=l.offset?await r(e,l.offset.expression):0,u=l.length?await r(e,l.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let y=1;y<=c;y++)f.push(e.state.env.get(String(y))||"");let h=e.state.env.get("0")||"bash",d;if(o<=0){let y=[h,...f],b=y.length+o;if(b<0)d=[];else{let D=o<0?b:0;if(u!==void 0){let Z=u<0?y.length+u:D+u;d=y.slice(D,Math.max(D,Z))}else d=y.slice(D)}}else{let y=o-1;if(y>=f.length)d=[];else if(u!==void 0){let b=u<0?f.length+u:y+u;d=f.slice(y,Math.max(y,b))}else d=f.slice(y)}let g="";for(let y=0;y<n;y++)g+=await s(e,t[y]);let m="";for(let y=n+1;y<t.length;y++)m+=await s(e,t[y]);let E=W(e.state.env),A=V(e.state.env);if(d.length===0){let y=g+m;return y?A?{values:[y],quoted:!1}:{values:x(y,E),quoted:!1}:{values:[],quoted:!1}}let S;if(a){let y=N(e.state.env),b=g+d.join(y)+m;A?S=b?[b]:[]:S=x(b,E)}else if(A)d.length===1?S=[g+d[0]+m]:S=[g+d[0],...d.slice(1,-1),d[d.length-1]+m];else{S=[];for(let y=0;y<d.length;y++){let b=d[y];if(y===0&&(b=g+b),y===d.length-1&&(b=b+m),b==="")S.push("");else{let D=x(b,E);S.push(...D)}}}return{values:await Te(e,S),quoted:!1}}async function or(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let r=t[0].parameter==="*",s=Number.parseInt(e.state.env.get("#")||"0",10);if(s===0)return{values:[],quoted:!1};let n=[];for(let u=1;u<=s;u++)n.push(e.state.env.get(String(u))||"");let a=W(e.state.env),i=V(e.state.env),l=Ce(e.state.env),o;if(r)if(i)o=n.filter(u=>u!=="");else{let u=N(e.state.env),c=n.join(u);o=x(c,a)}else if(i)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=x(u,a);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=x(u,a);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Te(e,o),quoted:!1}}async function lr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let r=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!r)return null;let s=r[1],n=r[2]==="*",a=P(e,s),i;if(a.length===0){let f=e.state.env.get(s);if(f!==void 0)i=[f];else return{values:[],quoted:!1}}else i=a.map(([,f])=>f);let l=W(e.state.env),o=V(e.state.env),u=Ce(e.state.env),c;if(n)if(o)c=i.filter(f=>f!=="");else{let f=N(e.state.env),h=i.join(f);c=x(h,l)}else if(o)c=i.filter(f=>f!=="");else if(u){c=[];for(let f of i){if(f==="")continue;let h=x(f,l);c.push(...h)}}else{c=[];for(let f of i)if(f==="")c.push("");else{let h=x(f,l);c.push(...h)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Te(e,c),quoted:!1}}function cr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let r=t[0].operation,s=de(e,r.prefix);if(s.length===0)return{values:[],quoted:!1};let n=W(e.state.env),a=V(e.state.env),i;if(r.star)if(a)i=s;else{let l=N(e.state.env),o=s.join(l);i=x(o,n)}else if(a)i=s;else{i=[];for(let l of s){let o=x(l,n);i.push(...o)}}return{values:i,quoted:!1}}function ur(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let r=t[0].operation,n=P(e,r.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let a=W(e.state.env),i=V(e.state.env),l;if(r.star)if(i)l=n;else{let o=N(e.state.env),u=n.join(o);l=x(u,a)}else if(i)l=n;else{l=[];for(let o of n){let u=x(o,a);l.push(...u)}}return{values:l,quoted:!1}}async function fr(e,t,r){let s=-1;for(let h=0;h<t.length;h++){let d=t[h];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")&&!d.operation){s=h;break}}if(s===-1||t.length<=1)return null;let n=Number.parseInt(e.state.env.get("#")||"0",10),a=[];for(let h=1;h<=n;h++)a.push(e.state.env.get(String(h))||"");let i="";for(let h=0;h<s;h++)i+=await r(e,t[h]);let l="";for(let h=s+1;h<t.length;h++)l+=await r(e,t[h]);let o=W(e.state.env),u=V(e.state.env),c=Ce(e.state.env);if(n===0){let h=i+l;return{values:h?[h]:[],quoted:!1}}let f;{let h=[];for(let d=0;d<a.length;d++){let g=a[d];d===0&&(g=i+g),d===a.length-1&&(g=g+l),h.push(g)}if(u)f=h.filter(d=>d!=="");else if(c){f=[];for(let d of h){if(d==="")continue;let g=x(d,o);f.push(...g)}}else{f=[];for(let d of h)if(d==="")f.push("");else{let g=x(d,o);f.push(...g)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Te(e,f),quoted:!1}}async function dr(e,t,r){e.coverage?.hit("bash:expansion:word_glob");let s=t.parts,{hasQuoted:n,hasCommandSub:a,hasArrayVar:i,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=ye(s),h=r.hasBraceExpansion(s)?await r.expandWordWithBracesAsync(e,t):null;if(h&&h.length>1)return Ps(e,h,n);let d=await Rs(e,s,l,u,c,r);if(d!==null)return d;let g=await vs(e,s,r);if(g!==null)return g;let m=await Ds(e,s,r);if(m!==null)return m;let E=await $s(e,s,r.expandPart);if(E!==null)return pr(e,E);if((a||i||o)&&!V(e.state.env)){let S=W(e.state.env),y=r.buildIfsCharClassPattern(S),b=await r.smartWordSplit(e,s,S,y,r.expandPart);return pr(e,b)}let A=await r.expandWordAsync(e,t);return _s(e,t,s,A,n,r.expandWordForGlobbing)}async function Ps(e,t,r){let s=[];for(let n of t)if(!(!r&&n===""))if(!r&&!e.state.options.noglob&&ne(n,e.state.shoptOptions.extglob)){let a=await Me(e,n);s.push(...a)}else s.push(n);return{values:s,quoted:!1}}async function Rs(e,t,r,s,n,a){if(r){let i=Un(e,t);if(i!==null)return i}{let i=Hn(e,t);if(i!==null)return i}{let i=await Fn(e,t);if(i!==null)return i}{let i=await Qn(e,t,r,a.expandPart,a.expandWordPartsAsync);if(i!==null)return i}{let i=await zn(e,t,r,a.expandPart);if(i!==null)return i}{let i=await Zn(e,t,a.evaluateArithmetic);if(i!==null)return i}{let i=Gn(e,t);if(i!==null)return i}{let i=await qn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}{let i=await Bn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}if(s&&t.length===1&&t[0].type==="DoubleQuoted"){let i=Is(e,t);if(i!==null)return i}{let i=await jn(e,t,n,a.expandParameterAsync,a.expandWordPartsAsync);if(i!==null)return i}{let i=await Kn(e,t);if(i!==null)return i}{let i=await Xn(e,t);if(i!==null)return i}return null}function Is(e,t){let r=t[0];if(r.type!=="DoubleQuoted")return null;if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="VarNamePrefix"){let s=r.parts[0].operation,n=de(e,s.prefix);return s.star?{values:[n.join(N(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="ArrayKeys"){let s=r.parts[0].operation,a=P(e,s.array).map(([i])=>String(i));return s.star?{values:[a.join(N(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return null}async function vs(e,t,r){{let s=await Yn(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await er(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await tr(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await nr(e,t,r.expandPart);if(s!==null)return s}return null}async function Ds(e,t,r){{let s=await rr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await sr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ir(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ar(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await or(e,t);if(s!==null)return s}{let s=await lr(e,t);if(s!==null)return s}{let s=cr(e,t);if(s!==null)return s}{let s=ur(e,t);if(s!==null)return s}{let s=await fr(e,t,r.expandPart);if(s!==null)return s}return null}function hr(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let r=e.parts[t];if(r.type!=="ParameterExpansion"||r.operation)continue;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s)return{type:"array",name:s[1],atIndex:t,isStar:s[2]==="*"};if(r.parameter==="@"||r.parameter==="*")return{type:"positional",atIndex:t,isStar:r.parameter==="*"}}return null}async function xs(e,t,r,s){let n="";for(let l=0;l<r.atIndex;l++)n+=await s(e,t.parts[l]);let a="";for(let l=r.atIndex+1;l<t.parts.length;l++)a+=await s(e,t.parts[l]);let i;if(r.type==="array"){if(i=P(e,r.name).map(([,o])=>o),i.length===0){let o=e.state.env.get(r.name);o!==void 0&&(i=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);i=[];for(let o=1;o<=l;o++)i.push(e.state.env.get(String(o))||"")}if(r.isStar){let l=N(e.state.env),o=i.join(l);return[n+o+a]}if(i.length===0){let l=n+a;return l?[l]:[]}return i.length===1?[n+i[0]+a]:[n+i[0],...i.slice(1,-1),i[i.length-1]+a]}async function $s(e,t,r){if(t.length<2)return null;let s=!1;for(let o of t)if(hr(o)){s=!0;break}if(!s)return null;let n=W(e.state.env),a=V(e.state.env),i=[];for(let o of t){let u=hr(o);if(u&&o.type==="DoubleQuoted"){let c=await xs(e,o,u,r);i.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await r(e,o);i.push([c])}else if(o.type==="Literal")i.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=x(c,n);i.push(f)}}else{let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=x(c,n);i.push(f)}}}let l=[];for(let o of i)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c<o.length;c++)l.push(o[c])}return l}async function pr(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let r=[];for(let s of t)if(ne(s,e.state.shoptOptions.extglob)){let n=await Me(e,s);r.push(...n)}else r.push(s);return{values:r,quoted:!1}}async function Me(e,t){let r=new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),s=await r.expand(t);if(s.length>0)return s;if(r.hasFailglob())throw new Pe(t);return r.hasNullglob()?[]:[t]}async function _s(e,t,r,s,n,a){let i=r.some(l=>l.type==="Glob");if(!e.state.options.noglob&&i){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let u=await Me(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=St(s);if(!V(e.state.env)){let u=W(e.state.env);return{values:x(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&ne(s,e.state.shoptOptions.extglob)){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let o=await Me(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(s===""&&!n)return{values:[],quoted:!1};if(i&&!n){let l=St(s);if(!V(e.state.env)){let o=W(e.state.env);return{values:x(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[s],quoted:n}}async function gr(e,t){let r=t.operation;if(!r||r.type!=="DefaultValue"&&r.type!=="AssignDefault"&&r.type!=="UseAlternative")return null;let s=r.word;if(!s||s.parts.length===0)return null;let n=await te(e,t.parameter),i=await v(e,t.parameter,!1)==="",l=r.checkEmpty??!1,o;return r.type==="UseAlternative"?o=n&&!(l&&i):o=!n||l&&i,o?s.parts:null}function Cs(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(r=>r.type==="Literal"):!1}async function Os(e,t){if(t.type!=="ParameterExpansion")return null;let r=await gr(e,t);if(!r||r.length<=1)return null;let s=r.some(a=>Cs(a)),n=r.some(a=>a.type==="Literal"||a.type==="ParameterExpansion"||a.type==="CommandSubstitution"||a.type==="ArithmeticExpansion");return s&&n?r:null}function Ls(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?dt(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&mn(e))}async function yr(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let h=t[0],d=await gr(e,h);if(d&&d.length>0&&d.length>1&&d.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&d.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return mr(e,d,r,s,n)}let a=[],i=!1;for(let h of t){let d=Ls(h),g=h.type==="DoubleQuoted"||h.type==="SingleQuoted",m=d?await Os(e,h):null,E=await n(e,h);a.push({value:E,isSplittable:d,isQuoted:g,mixedDefaultParts:m??void 0}),d&&(i=!0)}if(!i){let h=a.map(d=>d.value).join("");return h?[h]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let h of a)if(!h.isSplittable)c?h.isQuoted&&h.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):h.value!==""?(o!==""&&l.push(o),o=h.value,c=!1,f=!1):(o+=h.value,f=!1):(o+=h.value,f=h.isQuoted&&h.value==="");else if(h.mixedDefaultParts){let d=await mr(e,h.mixedDefaultParts,r,s,n);if(d.length!==0)if(d.length===1)o+=d[0],u=!0;else{o+=d[0],l.push(o),u=!0;for(let g=1;g<d.length-1;g++)l.push(d[g]);o=d[d.length-1]}c=!1,f=!1}else{let{words:d,hadLeadingDelimiter:g,hadTrailingDelimiter:m}=Oe(h.value,r);if(f&&g&&o===""&&(l.push(""),u=!0),d.length===0)m&&(c=!0);else if(d.length===1)o+=d[0],u=!0,c=m;else{o+=d[0],l.push(o),u=!0;for(let E=1;E<d.length-1;E++)l.push(d[E]);o=d[d.length-1],c=m}f=!1}return o!==""?l.push(o):l.length===0&&u&&l.push(""),l}function Ws(e,t){return e.length>0&&t.includes(e[0])}async function mr(e,t,r,s,n){let a=[];for(let c of t){let h=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),d=await n(e,c);a.push({value:d,isSplittable:h})}let i=[],l="",o=!1,u=!1;for(let c of a)if(!c.isSplittable)u&&c.value!==""?(l!==""&&i.push(l),l=c.value,u=!1):l+=c.value;else{Ws(c.value,r)&&l!==""&&(i.push(l),l="",o=!0);let{words:h,hadTrailingDelimiter:d}=Oe(c.value,r);if(h.length===0)d&&(u=!0);else if(h.length===1)l+=h[0],o=!0,u=d;else{l+=h[0],i.push(l),o=!0;for(let g=1;g<h.length-1;g++)i.push(h[g]);l=h[h.length-1],u=d}}return l!==""?i.push(l):i.length===0&&o&&i.push(""),i}function Er(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Ar(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function we(e,t,r){if(e.length>t)throw new B(`${r}: string length limit exceeded (${t} bytes)`,"string_length")}async function X(e,t,r=!1){let s=[];for(let n of t)s.push(await U(e,n,r));return s.join("")}function Ts(e){return Ar(e)}function Al(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Ts(t))return!1;return!0}function Ms(e,t,r=!1){let s=Er(t);if(s!==null)return s;switch(t.type){case"TildeExpansion":return r?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return Nt(e,t.pattern);default:return null}}async function Pt(e,t){return Rt(e,t)}async function Sl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped")r.push(`\\${s.value}`);else if(s.type==="SingleQuoted")r.push(s.value);else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(n)}else if(s.type==="TildeExpansion"){let n=await U(e,s);r.push(bt(n))}else r.push(await U(e,s));return r.join("")}async function bl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped"){let n=s.value;"()|*?[]".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="SingleQuoted")r.push(K(s.value));else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(K(n))}else r.push(await U(e,s));return r.join("")}async function Sr(e,t){let r=[];for(let s of t.parts)if(s.type==="SingleQuoted")r.push(K(s.value));else if(s.type==="Escaped"){let n=s.value;"*?[]\\()|".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(K(n))}else s.type==="Glob"?Wn(s.pattern)?r.push(await Mn(e,s.pattern)):r.push(Nt(e,s.pattern)):s.type==="Literal"?r.push(s.value):r.push(await U(e,s));return r.join("")}function qe(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&qe(t.parts))return!0;return!1}var Vs=1e4,kt=1e5;async function br(e,t,r={count:0}){if(r.count>kt)return[[]];let s=[[]];for(let n of t)if(n.type==="BraceExpansion"){let a=[],i=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=At(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let h of f.expanded)r.count++,a.push(h);else{i=!0,l=f.literal;break}}else{let f=await br(e,c.word.parts,r);for(let h of f){r.count++;let d=[];for(let g of h)typeof g=="string"?d.push(g):d.push(await U(e,g));a.push(d.join(""))}}if(i){for(let c of s)r.count++,c.push(l);continue}if(s.length*a.length>Vs||r.count>kt)return s;let u=[];for(let c of s)for(let f of a){if(r.count++,r.count>kt)return u.length>0?u:s;u.push([...c,f])}s=u}else for(let a of s)r.count++,a.push(n);return s}async function wr(e,t){let r=t.parts;if(!qe(r))return[await Pt(e,t)];let s=await br(e,r),n=[];for(let a of s){let i=[];for(let l of a)typeof l=="string"?i.push(l):i.push(await U(e,l));n.push(Vn(e,i.join("")))}return n}function qs(){return{expandWordAsync:Rt,expandWordForGlobbing:Sr,expandWordWithBracesAsync:wr,expandWordPartsAsync:X,expandPart:U,expandParameterAsync:Ve,hasBraceExpansion:qe,evaluateArithmetic:R,buildIfsCharClassPattern:En,smartWordSplit:yr}}async function wl(e,t){return dr(e,t,qs())}function Bs(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Fs(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function s(n){for(let a of n)if(a.type==="DoubleQuoted"){for(let i of a.parts)if(i.type==="ParameterExpansion"&&i.parameter==="@"&&!i.operation)return!0}return!1}return s(t.parts)}async function Nl(e,t){if(Fs(e,t))return{error:`bash: $@: ambiguous redirect
|
|
70
70
|
`};let r=t.parts,{hasQuoted:s}=ye(r);if(qe(r)&&(await wr(e,t)).length>1)return{error:`bash: ${r.map(d=>d.type==="Literal"?d.value:d.type==="BraceExpansion"?`{${d.items.map(m=>{if(m.type==="Range"){let E=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${E}`}return m.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
|
|
71
71
|
`};let n=await Rt(e,t),{hasParamExpansion:a,hasCommandSub:i}=ye(r);if((a||i)&&!s&&!V(e.state.env)){let f=W(e.state.env);if(x(n,f).length>1)return{error:`bash: $${Bs(r)}: ambiguous redirect
|
|
72
72
|
`}}if(s||e.state.options.noglob)return{target:n};let o=await Sr(e,t);if(!ne(o,e.state.shoptOptions.extglob))return{target:n};let u=new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),c=await u.expand(o);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${n}
|