import{t as e}from"./chunk-YNYSPYQ5-gU4-j5DO.mjs";import{i as t}from"./chunk-GFQRA5P5-DbAN9IDm.mjs";import{n}from"./chunk-5QMZ5MUS-BwpNU33k.mjs";import{r,t as i}from"./chunk-24IMIIXA-DaS5XS55.mjs";import{n as a}from"./chunk-3THT3N7L-B1WzJUh4.mjs";import{n as o,r as s,t as c}from"./chunk-74CEPOFO-V0JXh91S.mjs";var l=new Map([[`alnum`,`a-zA-Z0-9`],[`alpha`,`a-zA-Z`],[`ascii`,`\\x00-\\x7F`],[`blank`,` \\t`],[`cntrl`,`\\x00-\\x1F\\x7F`],[`digit`,`0-9`],[`graph`,`!-~`],[`lower`,`a-z`],[`print`,` -~`],[`punct`,"!-/:-@\\[-`{-~"],[`space`,` \\t\\n\\r\\f\\v`],[`upper`,`A-Z`],[`word`,`a-zA-Z0-9_`],[`xdigit`,`0-9A-Fa-f`]]);function u(e){let t=``,n=0,r=!1;for(;n<e.length;){if(e[n]===`[`&&!r){if(e[n+1]===`[`&&e[n+2]===`:`){let r=e.indexOf(`:]]`,n+3);if(r!==-1){let i=e.slice(n+3,r),a=l.get(i);if(a){t+=`[${a}]`,n=r+3;continue}}}if(e[n+1]===`^`&&e[n+2]===`[`&&e[n+3]===`:`){let r=e.indexOf(`:]]`,n+4);if(r!==-1){let i=e.slice(n+4,r),a=l.get(i);if(a){t+=`[^${a}]`,n=r+3;continue}}}t+=`[`,n++,r=!0,n<e.length&&e[n]===`^`&&(t+=`^`,n++),n<e.length&&e[n]===`]`&&(t+=`\\]`,n++);continue}if(r){if(e[n]===`]`){t+=`]`,n++,r=!1;continue}if(e[n]===`[`&&e[n+1]===`:`){let r=e.indexOf(`:]`,n+2);if(r!==-1){let i=e.slice(n+2,r),a=l.get(i);if(a){t+=a,n=r+2;continue}}}if(e[n]===`\\`&&n+1<e.length){t+=e[n]+e[n+1],n+=2;continue}t+=e[n],n++;continue}if(e[n]===`\\`&&n+1<e.length){let r=e[n+1];if(r===`+`||r===`?`||r===`|`){t+=r,n+=2;continue}if(r===`(`||r===`)`){t+=r,n+=2;continue}if(r===`{`||r===`}`){t+=r,n+=2;continue}if(r===`t`){t+=`	`,n+=2;continue}if(r===`n`){t+=`
`,n+=2;continue}if(r===`r`){t+=`\r`,n+=2;continue}t+=e[n]+r,n+=2;continue}if(e[n]===`+`||e[n]===`?`||e[n]===`|`||e[n]===`(`||e[n]===`)`){t+=`\\${e[n]}`,n++;continue}if(e[n]===`^`&&!(t===``||t.endsWith(`(`))){t+=`\\^`,n++;continue}if(e[n]===`$`){let r=n===e.length-1,i=n+2<e.length&&e[n+1]===`\\`&&e[n+2]===`)`;if(!r&&!i){t+=`\\$`,n++;continue}}t+=e[n],n++}return t}function d(e){let t=``,n=!1;for(let r=0;r<e.length;r++)e[r]===`[`&&!n?(n=!0,t+=`[`,r++,r<e.length&&e[r]===`^`&&(t+=`^`,r++),r<e.length&&e[r]===`]`&&(t+=`]`,r++),r--):e[r]===`]`&&n?(n=!1,t+=`]`):!n&&e[r]===`{`&&e[r+1]===`,`?(t+=`{0,`,r++):t+=e[r];return t}function f(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n],i=r.charCodeAt(0);r===`\\`?t+=`\\\\`:r===`	`?t+=`\\t`:r===`
`?t+=`$
`:r===`\r`?t+=`\\r`:r===`\x07`?t+=`\\a`:r===`\b`?t+=`\\b`:r===`\f`?t+=`\\f`:r===`\v`?t+=`\\v`:i<32||i>=127?t+=`\\${i.toString(8).padStart(3,`0`)}`:t+=r}return`${t}$`}var p=1e4;function m(e,t,n){return{patternSpace:``,holdSpace:``,lineNumber:0,totalLines:e,deleted:!1,printed:!1,quit:!1,quitSilent:!1,exitCode:void 0,errorMessage:void 0,appendBuffer:[],substitutionMade:!1,lineNumberOutput:[],nCommandOutput:[],restartCycle:!1,inDRestartedCycle:!1,currentFilename:t,pendingFileReads:[],pendingFileWrites:[],rangeStates:n||new Map,linesConsumedInCycle:0}}function h(e){return typeof e==`object`&&`first`in e&&`step`in e}function g(e){return typeof e==`object`&&`offset`in e}function _(t,n,r,i,a){if(t===`$`)return n===r;if(typeof t==`number`)return n===t;if(h(t)){let{first:e,step:r}=t;return r===0?n===e:(n-e)%r===0&&n>=e}if(typeof t==`object`&&`pattern`in t)try{let n=t.pattern;return n===``&&a?.lastPattern?n=a.lastPattern:n!==``&&a&&(a.lastPattern=n),e(d(u(n))).test(i)}catch{return!1}return!1}function v(e){let t=e=>e===void 0?`undefined`:e===`$`?`$`:typeof e==`number`?String(e):`pattern`in e?`/${e.pattern}/`:`first`in e?`${e.first}~${e.step}`:`unknown`;return`${t(e.start)},${t(e.end)}`}function y(e,t,n,r,i,a){if(!e||!e.start&&!e.end)return!0;let o=e.start,s=e.end;if(o!==void 0&&s===void 0)return _(o,t,n,r,a);if(o!==void 0&&s!==void 0){let c=typeof o==`object`&&`pattern`in o,l=typeof s==`object`&&`pattern`in s,u=g(s);if(u&&i){let c=v(e),l=i.get(c);return l||(l={active:!1},i.set(c,l)),l.active?(t>=(l.startLine||t)+s.offset&&(l.active=!1,i.set(c,l)),!0):_(o,t,n,r,a)?(l.active=!0,l.startLine=t,i.set(c,l),s.offset===0&&(l.active=!1,i.set(c,l)),!0):!1}if(!c&&!l&&!u){let r=typeof o==`number`?o:o===`$`?n:1,a=typeof s==`number`?s:n;if(r<=a)return t>=r&&t<=a;if(i){let n=v(e),a=i.get(n);return a||(a={active:!1},i.set(n,a)),!a.completed&&t>=r?(a.completed=!0,i.set(n,a),!0):!1}return!1}if(i){let c=v(e),l=i.get(c);if(l||(l={active:!1},i.set(c,l)),l.active)return _(s,t,n,r,a)&&(l.active=!1,typeof o==`number`&&(l.completed=!0),i.set(c,l)),!0;{if(l.completed)return!1;let e=!1;return e=typeof o==`number`?t>=o:_(o,t,n,r,a),e?(l.active=!0,l.startLine=t,i.set(c,l),_(s,t,n,r,a)&&(l.active=!1,typeof o==`number`&&(l.completed=!0),i.set(c,l)),!0):!1}}return _(o,t,n,r,a)}return!0}function b(e,t,n,r,i,a){let o=y(e,t,n,r,i,a);return e?.negated?!o:o}function x(e,t,n,r){let i=``,a=0,o=!1;for(;a<=e.length;){t.lastIndex=a;let n=t.exec(e);if(!n){i+=e.slice(a);break}if(n.index!==a){i+=e.slice(a,n.index),a=n.index,o=!1;continue}let s=n[0],c=n.slice(1);if(o&&s.length===0){if(a<e.length)i+=e[a],a++;else break;o=!1;continue}if(i+=r(s,c),o=!1,s.length===0)if(a<e.length)i+=e[a],a++;else break;else a+=s.length,o=!0}return i}function S(e,t,n){let r=``,i=0;for(;i<e.length;){if(e[i]===`\\`&&i+1<e.length){let a=e[i+1];if(a===`&`){r+=`&`,i+=2;continue}if(a===`n`){r+=`
`,i+=2;continue}if(a===`t`){r+=`	`,i+=2;continue}if(a===`r`){r+=`\r`,i+=2;continue}let o=parseInt(a,10);if(o===0){r+=t,i+=2;continue}if(o>=1&&o<=9){r+=n[o-1]||``,i+=2;continue}r+=a,i+=2;continue}if(e[i]===`&`){r+=t,i++;continue}r+=e[i],i++}return r}function C(e,n,r){if(n>0&&e.length>n)throw new t(`sed: ${r} size limit exceeded (${n} bytes)`,`string_length`)}function w(t,n,r){let{lineNumber:i,totalLines:a,patternSpace:o}=n;if(t.type===`label`){n.coverage?.hit(`sed:cmd:${t.type}`);return}if(b(t.address,i,a,o,n.rangeStates,n))switch(n.coverage?.hit(`sed:cmd:${t.type}`),t.type){case`substitute`:{let r=t,i=``;r.global&&(i+=`g`),r.ignoreCase&&(i+=`i`);let a=r.pattern;a===``&&n.lastPattern?a=n.lastPattern:a!==``&&(n.lastPattern=a);let o=d(r.extendedRegex?a:u(a));try{let t=e(o,i),a=t.test(n.patternSpace);if(t.lastIndex=0,a){if(n.substitutionMade=!0,r.nthOccurrence&&r.nthOccurrence>0&&!r.global){let t=0,i=r.nthOccurrence;n.patternSpace=e(o,`g${r.ignoreCase?`i`:``}`).replace(n.patternSpace,(e,...n)=>{if(t++,t===i){let t=n.slice(0,-2);return S(r.replacement,e,t)}return e})}else if(r.global){let t=e(o,`g${r.ignoreCase?`i`:``}`);n.patternSpace=x(n.patternSpace,t,r.replacement,(e,t)=>S(r.replacement,e,t))}else n.patternSpace=t.replace(n.patternSpace,(e,...t)=>{let n=t.slice(0,-2);return S(r.replacement,e,n)});r.printOnMatch&&n.lineNumberOutput.push(n.patternSpace)}}catch{}break}case`print`:n.lineNumberOutput.push(n.patternSpace);break;case`printFirstLine`:{let e=n.patternSpace.indexOf(`
`);e===-1?n.lineNumberOutput.push(n.patternSpace):n.lineNumberOutput.push(n.patternSpace.slice(0,e));break}case`delete`:n.deleted=!0;break;case`deleteFirstLine`:{let e=n.patternSpace.indexOf(`
`);e===-1?n.deleted=!0:(n.patternSpace=n.patternSpace.slice(e+1),n.restartCycle=!0,n.inDRestartedCycle=!0);break}case`zap`:n.patternSpace=``;break;case`append`:n.appendBuffer.push(t.text);break;case`insert`:n.appendBuffer.unshift(`__INSERT__${t.text}`);break;case`change`:n.deleted=!0,n.changedText=t.text;break;case`hold`:n.holdSpace=n.patternSpace;break;case`holdAppend`:n.holdSpace?n.holdSpace+=`
${n.patternSpace}`:n.holdSpace=n.patternSpace,C(n.holdSpace,r?.maxStringLength??0,`hold space`);break;case`get`:n.patternSpace=n.holdSpace;break;case`getAppend`:n.patternSpace+=`
${n.holdSpace}`,C(n.patternSpace,r?.maxStringLength??0,`pattern space`);break;case`exchange`:{let e=n.patternSpace;n.patternSpace=n.holdSpace,n.holdSpace=e;break}case`next`:n.printed=!0;break;case`quit`:n.quit=!0,t.exitCode!==void 0&&(n.exitCode=t.exitCode);break;case`quitSilent`:n.quit=!0,n.quitSilent=!0,t.exitCode!==void 0&&(n.exitCode=t.exitCode);break;case`list`:{let e=f(n.patternSpace);n.lineNumberOutput.push(e);break}case`printFilename`:n.currentFilename&&n.lineNumberOutput.push(n.currentFilename);break;case`version`:{let e=[4,8,0];if(t.minVersion){let r=t.minVersion.split(`.`),i=[],a=!1;for(let e of r){let r=parseInt(e,10);if(Number.isNaN(r)||r<0){n.quit=!0,n.exitCode=1,n.errorMessage=`sed: invalid version string: ${t.minVersion}`,a=!0;break}i.push(r)}if(!a){for(;i.length<3;)i.push(0);for(let r=0;r<3;r++){if(i[r]>e[r]){n.quit=!0,n.exitCode=1,n.errorMessage=`sed: this is not GNU sed version ${t.minVersion}`;break}if(i[r]<e[r])break}}}break}case`readFile`:n.pendingFileReads.push({filename:t.filename,wholeFile:!0});break;case`readFileLine`:n.pendingFileReads.push({filename:t.filename,wholeFile:!1});break;case`writeFile`:n.pendingFileWrites.push({filename:t.filename,content:`${n.patternSpace}
`});break;case`writeFirstLine`:{let e=n.patternSpace.indexOf(`
`),r=e===-1?n.patternSpace:n.patternSpace.slice(0,e);n.pendingFileWrites.push({filename:t.filename,content:`${r}
`});break}case`execute`:n.errorMessage=`sed: e command (shell execution) is not supported in sandboxed environment`,n.quit=!0;break;case`transliterate`:n.patternSpace=T(n.patternSpace,t);break;case`lineNumber`:n.lineNumberOutput.push(String(n.lineNumber));break;case`branch`:break;case`branchOnSubst`:break;case`branchOnNoSubst`:break;case`group`:break}}function T(e,t){let n=``;for(let r of e){let e=t.source.indexOf(r);e===-1?n+=r:n+=t.dest[e]}return n}function E(e,n,r,i){let a=new Map;for(let t=0;t<e.length;t++){let n=e[t];n.type===`label`&&a.set(n.name,t)}let o=i?.maxIterations??p,s=0,c=0;for(;c<e.length;){if(s++,s>o)throw new t(`sed: command execution exceeded maximum iterations (${o})`,`iterations`);if(n.deleted||n.quit||n.quitSilent||n.restartCycle)break;let l=e[c];if(l.type===`next`){if(b(l.address,n.lineNumber,n.totalLines,n.patternSpace,n.rangeStates,n))if(n.coverage?.hit(`sed:cmd:next`),n.nCommandOutput.push(n.patternSpace),r&&r.currentLineIndex+n.linesConsumedInCycle+1<r.lines.length)n.linesConsumedInCycle++,n.patternSpace=r.lines[r.currentLineIndex+n.linesConsumedInCycle],n.lineNumber=r.currentLineIndex+n.linesConsumedInCycle+1,n.substitutionMade=!1;else{n.quit=!0,n.deleted=!0;break}c++;continue}if(l.type===`nextAppend`){if(b(l.address,n.lineNumber,n.totalLines,n.patternSpace,n.rangeStates,n))if(n.coverage?.hit(`sed:cmd:nextAppend`),r&&r.currentLineIndex+n.linesConsumedInCycle+1<r.lines.length){n.linesConsumedInCycle++;let e=r.lines[r.currentLineIndex+n.linesConsumedInCycle];n.patternSpace+=`
${e}`,n.lineNumber=r.currentLineIndex+n.linesConsumedInCycle+1}else{n.quit=!0;break}c++;continue}if(l.type===`branch`){let e=l;if(b(e.address,n.lineNumber,n.totalLines,n.patternSpace,n.rangeStates,n)){if(n.coverage?.hit(`sed:cmd:branch`),e.label){let t=a.get(e.label);if(t!==void 0){c=t;continue}n.branchRequest=e.label;break}break}c++;continue}if(l.type===`branchOnSubst`){let e=l;if(b(e.address,n.lineNumber,n.totalLines,n.patternSpace,n.rangeStates,n)&&(n.coverage?.hit(`sed:cmd:branchOnSubst`),n.substitutionMade)){if(n.substitutionMade=!1,e.label){let t=a.get(e.label);if(t!==void 0){c=t;continue}n.branchRequest=e.label;break}break}c++;continue}if(l.type===`branchOnNoSubst`){let e=l;if(b(e.address,n.lineNumber,n.totalLines,n.patternSpace,n.rangeStates,n)&&(n.coverage?.hit(`sed:cmd:branchOnNoSubst`),!n.substitutionMade)){if(e.label){let t=a.get(e.label);if(t!==void 0){c=t;continue}n.branchRequest=e.label;break}break}c++;continue}if(l.type===`group`){let e=l;if(b(e.address,n.lineNumber,n.totalLines,n.patternSpace,n.rangeStates,n)&&(n.coverage?.hit(`sed:cmd:group`),E(e.commands,n,r,i),n.branchRequest)){let e=a.get(n.branchRequest);if(e!==void 0){n.branchRequest=void 0,c=e;continue}break}c++;continue}w(l,n,i),c++}return n.linesConsumedInCycle}var D;(function(e){e.NUMBER=`NUMBER`,e.DOLLAR=`DOLLAR`,e.PATTERN=`PATTERN`,e.STEP=`STEP`,e.RELATIVE_OFFSET=`RELATIVE_OFFSET`,e.LBRACE=`LBRACE`,e.RBRACE=`RBRACE`,e.SEMICOLON=`SEMICOLON`,e.NEWLINE=`NEWLINE`,e.COMMA=`COMMA`,e.NEGATION=`NEGATION`,e.COMMAND=`COMMAND`,e.SUBSTITUTE=`SUBSTITUTE`,e.TRANSLITERATE=`TRANSLITERATE`,e.LABEL_DEF=`LABEL_DEF`,e.BRANCH=`BRANCH`,e.BRANCH_ON_SUBST=`BRANCH_ON_SUBST`,e.BRANCH_ON_NO_SUBST=`BRANCH_ON_NO_SUBST`,e.TEXT_CMD=`TEXT_CMD`,e.FILE_READ=`FILE_READ`,e.FILE_READ_LINE=`FILE_READ_LINE`,e.FILE_WRITE=`FILE_WRITE`,e.FILE_WRITE_LINE=`FILE_WRITE_LINE`,e.EXECUTE=`EXECUTE`,e.VERSION=`VERSION`,e.EOF=`EOF`,e.ERROR=`ERROR`})(D||={});var O=class{input;pos=0;line=1;column=1;constructor(e){this.input=e}tokenize(){let e=[];for(;this.pos<this.input.length;){let t=this.nextToken();t&&e.push(t)}return e.push(this.makeToken(D.EOF,``)),e}makeToken(e,t,n){return{type:e,value:t,line:this.line,column:this.column,...n}}peek(e=0){return this.input[this.pos+e]||``}advance(){let e=this.input[this.pos++]||``;return e===`
`?(this.line++,this.column=1):this.column++,e}readEscapedString(e){let t=``;for(;this.pos<this.input.length&&this.peek()!==e;)if(this.peek()===`\\`){this.advance();let e=this.advance();e===`n`?t+=`
`:e===`t`?t+=`	`:t+=e}else{if(this.peek()===`
`)return null;t+=this.advance()}return t}skipWhitespace(){for(;this.pos<this.input.length;){let e=this.peek();if(e===` `||e===`	`||e===`\r`)this.advance();else if(e===`#`)for(;this.pos<this.input.length&&this.peek()!==`
`;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let e=this.line,t=this.column,n=this.peek();return n===`
`?(this.advance(),{type:D.NEWLINE,value:`
`,line:e,column:t}):n===`;`?(this.advance(),{type:D.SEMICOLON,value:`;`,line:e,column:t}):n===`{`?(this.advance(),{type:D.LBRACE,value:`{`,line:e,column:t}):n===`}`?(this.advance(),{type:D.RBRACE,value:`}`,line:e,column:t}):n===`,`?(this.advance(),{type:D.COMMA,value:`,`,line:e,column:t}):n===`!`?(this.advance(),{type:D.NEGATION,value:`!`,line:e,column:t}):n===`$`?(this.advance(),{type:D.DOLLAR,value:`$`,line:e,column:t}):this.isDigit(n)?this.readNumber():n===`+`&&this.isDigit(this.input[this.pos+1]||``)?this.readRelativeOffset():n===`/`?this.readPattern():n===`:`?this.readLabelDef():this.readCommand()}readNumber(){let e=this.line,t=this.column,n=``;for(;this.isDigit(this.peek());)n+=this.advance();if(this.peek()===`~`){this.advance();let r=``;for(;this.isDigit(this.peek());)r+=this.advance();let i=parseInt(n,10),a=parseInt(r,10)||0;return{type:D.STEP,value:`${i}~${a}`,first:i,step:a,line:e,column:t}}return{type:D.NUMBER,value:parseInt(n,10),line:e,column:t}}readRelativeOffset(){let e=this.line,t=this.column;this.advance();let n=``;for(;this.isDigit(this.peek());)n+=this.advance();let r=parseInt(n,10)||0;return{type:D.RELATIVE_OFFSET,value:`+${r}`,offset:r,line:e,column:t}}readPattern(){let e=this.line,t=this.column;this.advance();let n=``,r=!1;for(;this.pos<this.input.length;){let e=this.peek();if(e===`/`&&!r)break;if(e===`\\`)n+=this.advance(),this.pos<this.input.length&&this.peek()!==`
`&&(n+=this.advance());else{if(e===`
`)break;e===`[`&&!r?(r=!0,n+=this.advance(),this.peek()===`^`&&(n+=this.advance()),this.peek()===`]`&&(n+=this.advance())):(e===`]`&&r&&(r=!1),n+=this.advance())}}return this.peek()===`/`&&this.advance(),{type:D.PATTERN,value:n,pattern:n,line:e,column:t}}readLabelDef(){let e=this.line,t=this.column;for(this.advance();this.peek()===` `||this.peek()===`	`;)this.advance();let n=``;for(;this.pos<this.input.length;){let e=this.peek();if(e===` `||e===`	`||e===`
`||e===`;`||e===`}`||e===`{`)break;n+=this.advance()}return{type:D.LABEL_DEF,value:n,label:n,line:e,column:t}}readCommand(){let e=this.line,t=this.column,n=this.advance();switch(n){case`s`:return this.readSubstitute(e,t);case`y`:return this.readTransliterate(e,t);case`a`:case`i`:case`c`:return this.readTextCommand(n,e,t);case`b`:return this.readBranch(D.BRANCH,`b`,e,t);case`t`:return this.readBranch(D.BRANCH_ON_SUBST,`t`,e,t);case`T`:return this.readBranch(D.BRANCH_ON_NO_SUBST,`T`,e,t);case`r`:return this.readFileCommand(D.FILE_READ,`r`,e,t);case`R`:return this.readFileCommand(D.FILE_READ_LINE,`R`,e,t);case`w`:return this.readFileCommand(D.FILE_WRITE,`w`,e,t);case`W`:return this.readFileCommand(D.FILE_WRITE_LINE,`W`,e,t);case`e`:return this.readExecute(e,t);case`p`:case`P`:case`d`:case`D`:case`h`:case`H`:case`g`:case`G`:case`x`:case`n`:case`N`:case`q`:case`Q`:case`z`:case`=`:case`l`:case`F`:return{type:D.COMMAND,value:n,line:e,column:t};case`v`:return this.readVersion(e,t);default:return{type:D.ERROR,value:n,line:e,column:t}}}readSubstitute(e,t){let n=this.advance();if(!n||n===`
`)return{type:D.ERROR,value:`s`,line:e,column:t};let r=``,i=!1;for(;this.pos<this.input.length;){let e=this.peek();if(e===n&&!i)break;if(e===`\\`)this.advance(),this.pos<this.input.length&&this.peek()!==`
`?(this.peek()===n&&!i||(r+=`\\`),r+=this.advance()):r+=`\\`;else{if(e===`
`)break;e===`[`&&!i?(i=!0,r+=this.advance(),this.peek()===`^`&&(r+=this.advance()),this.peek()===`]`&&(r+=this.advance())):(e===`]`&&i&&(i=!1),r+=this.advance())}}if(this.peek()!==n)return{type:D.ERROR,value:`unterminated substitution pattern`,line:e,column:t};this.advance();let a=``;for(;this.pos<this.input.length&&this.peek()!==n;)if(this.peek()===`\\`)if(this.advance(),this.pos<this.input.length){let e=this.peek();e===`\\`?(this.advance(),this.pos<this.input.length&&this.peek()===`
`?(a+=`
`,this.advance()):a+=`\\`):e===`
`?(a+=`
`,this.advance()):a+=`\\${this.advance()}`}else a+=`\\`;else{if(this.peek()===`
`)break;a+=this.advance()}this.peek()===n&&this.advance();let o=``;for(;this.pos<this.input.length;){let e=this.peek();if(e===`g`||e===`i`||e===`p`||e===`I`||this.isDigit(e))o+=this.advance();else break}return{type:D.SUBSTITUTE,value:`s${n}${r}${n}${a}${n}${o}`,pattern:r,replacement:a,flags:o,line:e,column:t}}readTransliterate(e,t){let n=this.advance();if(!n||n===`
`)return{type:D.ERROR,value:`y`,line:e,column:t};let r=this.readEscapedString(n);if(r===null||this.peek()!==n)return{type:D.ERROR,value:`unterminated transliteration source`,line:e,column:t};this.advance();let i=this.readEscapedString(n);if(i===null||this.peek()!==n)return{type:D.ERROR,value:`unterminated transliteration dest`,line:e,column:t};this.advance();let a=this.peek();for(;a===` `||a===`	`;)this.advance(),a=this.peek();return a!==``&&a!==`;`&&a!==`
`&&a!==`}`?{type:D.ERROR,value:`extra text at the end of a transform command`,line:e,column:t}:{type:D.TRANSLITERATE,value:`y${n}${r}${n}${i}${n}`,source:r,dest:i,line:e,column:t}}readTextCommand(e,t,n){let r=!1;this.peek()===`\\`&&this.pos+1<this.input.length&&(this.input[this.pos+1]===`
`||this.input[this.pos+1]===` `||this.input[this.pos+1]===`	`)&&(r=!0,this.advance()),(this.peek()===` `||this.peek()===`	`)&&this.advance(),this.peek()===`\\`&&this.pos+1<this.input.length&&(this.input[this.pos+1]===` `||this.input[this.pos+1]===`	`)&&this.advance(),r&&this.peek()===`
`&&this.advance();let i=``;for(;this.pos<this.input.length;){let e=this.peek();if(e===`
`){if(i.endsWith(`\\`)){i=`${i.slice(0,-1)}
`,this.advance();continue}break}if(e===`\\`&&this.pos+1<this.input.length){let e=this.input[this.pos+1];if(e===`n`){i+=`
`,this.advance(),this.advance();continue}if(e===`t`){i+=`	`,this.advance(),this.advance();continue}if(e===`r`){i+=`\r`,this.advance(),this.advance();continue}}i+=this.advance()}return{type:D.TEXT_CMD,value:e,text:i,line:t,column:n}}readBranch(e,t,n,r){for(;this.peek()===` `||this.peek()===`	`;)this.advance();let i=``;for(;this.pos<this.input.length;){let e=this.peek();if(e===` `||e===`	`||e===`
`||e===`;`||e===`}`||e===`{`)break;i+=this.advance()}return{type:e,value:t,label:i||void 0,line:n,column:r}}readVersion(e,t){for(;this.peek()===` `||this.peek()===`	`;)this.advance();let n=``;for(;this.pos<this.input.length;){let e=this.peek();if(e===` `||e===`	`||e===`
`||e===`;`||e===`}`||e===`{`)break;n+=this.advance()}return{type:D.VERSION,value:`v`,label:n||void 0,line:e,column:t}}readFileCommand(e,t,n,r){for(;this.peek()===` `||this.peek()===`	`;)this.advance();let i=``;for(;this.pos<this.input.length;){let e=this.peek();if(e===`
`||e===`;`)break;i+=this.advance()}return{type:e,value:t,filename:i.trim(),line:n,column:r}}readExecute(e,t){for(;this.peek()===` `||this.peek()===`	`;)this.advance();let n=``;for(;this.pos<this.input.length;){let e=this.peek();if(e===`
`||e===`;`)break;n+=this.advance()}return{type:D.EXECUTE,value:`e`,command:n.trim()||void 0,line:e,column:t}}isDigit(e){return e>=`0`&&e<=`9`}},k=class{scripts;tokens=[];pos=0;extendedRegex=!1;constructor(e,t=!1){this.scripts=e,this.extendedRegex=t}parse(){let e=[];for(let t of this.scripts)for(this.tokens=new O(t).tokenize(),this.pos=0;!this.isAtEnd();){if(this.check(D.NEWLINE)||this.check(D.SEMICOLON)){this.advance();continue}let t=this.pos,n=this.parseCommand();if(n.error)return{commands:[],error:n.error};if(n.command&&e.push(n.command),this.pos===t&&!this.isAtEnd())return{commands:[],error:`unknown command: '${this.peek()?.value??this.peek()?.type}'`}}return{commands:e}}parseCommand(){let e=this.parseAddressRange();if(e?.error)return{command:null,error:e.error};let t=e?.address;for(this.check(D.NEGATION)&&(this.advance(),t&&(t.negated=!0));this.check(D.NEWLINE)||this.check(D.SEMICOLON);)this.advance();if(this.isAtEnd())return t&&(t.start!==void 0||t.end!==void 0)?{command:null,error:`command expected`}:{command:null};let n=this.peek();switch(n.type){case D.COMMAND:return this.parseSimpleCommand(n,t);case D.SUBSTITUTE:return this.parseSubstituteFromToken(n,t);case D.TRANSLITERATE:return this.parseTransliterateFromToken(n,t);case D.LABEL_DEF:return this.advance(),{command:{type:`label`,name:n.label||``}};case D.BRANCH:return this.advance(),{command:{type:`branch`,address:t,label:n.label}};case D.BRANCH_ON_SUBST:return this.advance(),{command:{type:`branchOnSubst`,address:t,label:n.label}};case D.BRANCH_ON_NO_SUBST:return this.advance(),{command:{type:`branchOnNoSubst`,address:t,label:n.label}};case D.TEXT_CMD:return this.advance(),this.parseTextCommand(n,t);case D.FILE_READ:return this.advance(),{command:{type:`readFile`,address:t,filename:n.filename||``}};case D.FILE_READ_LINE:return this.advance(),{command:{type:`readFileLine`,address:t,filename:n.filename||``}};case D.FILE_WRITE:return this.advance(),{command:{type:`writeFile`,address:t,filename:n.filename||``}};case D.FILE_WRITE_LINE:return this.advance(),{command:{type:`writeFirstLine`,address:t,filename:n.filename||``}};case D.EXECUTE:return this.advance(),{command:{type:`execute`,address:t,command:n.command}};case D.VERSION:return this.advance(),{command:{type:`version`,address:t,minVersion:n.label}};case D.LBRACE:return this.parseGroup(t);case D.RBRACE:return{command:null};case D.ERROR:return{command:null,error:`invalid command: ${n.value}`};default:return t&&(t.start!==void 0||t.end!==void 0)?{command:null,error:`command expected`}:{command:null}}}parseSimpleCommand(e,t){this.advance();let n=e.value;switch(n){case`p`:return{command:{type:`print`,address:t}};case`P`:return{command:{type:`printFirstLine`,address:t}};case`d`:return{command:{type:`delete`,address:t}};case`D`:return{command:{type:`deleteFirstLine`,address:t}};case`h`:return{command:{type:`hold`,address:t}};case`H`:return{command:{type:`holdAppend`,address:t}};case`g`:return{command:{type:`get`,address:t}};case`G`:return{command:{type:`getAppend`,address:t}};case`x`:return{command:{type:`exchange`,address:t}};case`n`:return{command:{type:`next`,address:t}};case`N`:return{command:{type:`nextAppend`,address:t}};case`q`:return{command:{type:`quit`,address:t}};case`Q`:return{command:{type:`quitSilent`,address:t}};case`z`:return{command:{type:`zap`,address:t}};case`=`:return{command:{type:`lineNumber`,address:t}};case`l`:return{command:{type:`list`,address:t}};case`F`:return{command:{type:`printFilename`,address:t}};default:return{command:null,error:`unknown command: ${n}`}}}parseSubstituteFromToken(e,t){this.advance();let n=e.flags||``,r,i=n.match(/(\d+)/);return i&&(r=parseInt(i[1],10)),{command:{type:`substitute`,address:t,pattern:e.pattern||``,replacement:e.replacement||``,global:n.includes(`g`),ignoreCase:n.includes(`i`)||n.includes(`I`),printOnMatch:n.includes(`p`),nthOccurrence:r,extendedRegex:this.extendedRegex}}}parseTransliterateFromToken(e,t){this.advance();let n=e.source||``,r=e.dest||``;return n.length===r.length?{command:{type:`transliterate`,address:t,source:n,dest:r}}:{command:null,error:`transliteration sets must have same length`}}parseTextCommand(e,t){let n=e.value,r=e.text||``;switch(n){case`a`:return{command:{type:`append`,address:t,text:r}};case`i`:return{command:{type:`insert`,address:t,text:r}};case`c`:return{command:{type:`change`,address:t,text:r}};default:return{command:null,error:`unknown text command: ${n}`}}}parseGroup(e){this.advance();let t=[];for(;!this.isAtEnd()&&!this.check(D.RBRACE);){if(this.check(D.NEWLINE)||this.check(D.SEMICOLON)){this.advance();continue}let e=this.pos,n=this.parseCommand();if(n.error)return{command:null,error:n.error};if(n.command&&t.push(n.command),this.pos===e&&!this.isAtEnd())return{command:null,error:`unknown command: '${this.peek()?.value??this.peek()?.type}'`}}return this.check(D.RBRACE)?(this.advance(),{command:{type:`group`,address:e,commands:t}}):{command:null,error:`unmatched brace in grouped commands`}}parseAddressRange(){if(this.check(D.COMMA))return{error:`expected context address`};let e=this.parseAddress();if(e===void 0)return;let t;if(this.check(D.RELATIVE_OFFSET))t={offset:this.advance().offset||0};else if(this.check(D.COMMA)&&(this.advance(),t=this.parseAddress(),t===void 0))return{error:`expected context address`};return{address:{start:e,end:t}}}parseAddress(){let e=this.peek();switch(e.type){case D.NUMBER:return this.advance(),e.value;case D.DOLLAR:return this.advance(),`$`;case D.PATTERN:return this.advance(),{pattern:e.pattern||e.value};case D.STEP:return this.advance(),{first:e.first||0,step:e.step||0};case D.RELATIVE_OFFSET:return this.advance(),{offset:e.offset||0};default:return}}peek(){return this.tokens[this.pos]||{type:D.EOF,value:``,line:0,column:0}}advance(){return this.isAtEnd()||this.pos++,this.tokens[this.pos-1]}check(e){return this.peek().type===e}isAtEnd(){return this.peek().type===D.EOF}};function A(e,t=!1){let n=!1,r=!1,i=[];for(let t=0;t<e.length;t++){let a=e[t];if(i.length===0&&t===0){let e=a.match(/^#([nr]+)\s*(?:\n|$)/i);if(e){let t=e[1].toLowerCase();t.includes(`n`)&&(n=!0),t.includes(`r`)&&(r=!0),a=a.slice(e[0].length)}}if(i.length>0&&i[i.length-1].endsWith(`\\`)){let e=i[i.length-1];i[i.length-1]=`${e}
${a}`}else i.push(a)}let a=new k([i.join(`
`)],t||r).parse();if(!a.error&&a.commands.length>0){let e=j(a.commands);if(e)return{commands:[],error:e,silentMode:n,extendedRegexMode:r}}return{...a,silentMode:n,extendedRegexMode:r}}function j(e){let t=new Set;M(e,t);let n=N(e,t);if(n)return`undefined label '${n}'`}function M(e,t){for(let n of e)n.type===`label`?t.add(n.name):n.type===`group`&&M(n.commands,t)}function N(e,t){for(let n of e){if((n.type===`branch`||n.type===`branchOnSubst`||n.type===`branchOnNoSubst`)&&n.label&&!t.has(n.label))return n.label;if(n.type===`group`){let e=N(n.commands,t);if(e)return e}}}var P={name:`sed`,summary:`stream editor for filtering and transforming text`,usage:`sed [OPTION]... {script} [input-file]...`,options:[`-n, --quiet, --silent  suppress automatic printing of pattern space`,`-e script              add the script to commands to be executed`,`-f script-file         read script from file`,`-i, --in-place         edit files in place`,`-E, -r, --regexp-extended  use extended regular expressions`,`    --help             display this help and exit`],description:`Commands:
  s/regexp/replacement/[flags]  substitute
  d                             delete pattern space
  p                             print pattern space
  a\\ text                       append text after line
  i\\ text                       insert text before line
  c\\ text                       change (replace) line with text
  h                             copy pattern space to hold space
  H                             append pattern space to hold space
  g                             copy hold space to pattern space
  G                             append hold space to pattern space
  x                             exchange pattern and hold spaces
  n                             read next line into pattern space
  N                             append next line to pattern space
  y/source/dest/                transliterate characters
  =                             print line number
  l                             list pattern space (escape special chars)
  b [label]                     branch to label
  t [label]                     branch on substitution
  T [label]                     branch if no substitution
  :label                        define label
  q                             quit
  Q                             quit without printing

Addresses:
  N                             line number
  $                             last line
  /regexp/                      lines matching regexp
  N,M                           range from line N to M
  first~step                    every step-th line starting at first`};async function F(e,a,o,s={}){let{limits:c,filename:l,fs:u,cwd:d,coverage:f,requireDefenseContext:p}=s;i(p,`sed`,`processing entry`);let h=(e,t)=>r(p,`sed`,e,t),g=e.endsWith(`
`),_=e.split(`
`);_.length>0&&_[_.length-1]===``&&_.pop();let v=_.length,y=``,b,x=!1,S=c?.maxStringLength??0,C=e=>{if(y+=e,S>0&&y.length>S)throw new t(`sed: output size limit exceeded (${S} bytes)`,`string_length`)},w=``,T,D=new Map,O=new Map,k=new Map,A=new Map,j=c?{maxIterations:c.maxSedIterations,maxStringLength:S}:void 0;for(let e=0;e<_.length;e++){let t={...m(v,l,D),patternSpace:_[e],holdSpace:w,lastPattern:T,lineNumber:e+1,totalLines:v,substitutionMade:!1,coverage:f},r={lines:_,currentLineIndex:e},i=0;t.linesConsumedInCycle=0;do{if(i++,i>1e4)break;if(t.restartCycle=!1,t.pendingFileReads=[],t.pendingFileWrites=[],E(a,t,r,j),u&&d){for(let e of t.pendingFileReads){let r=u.resolvePath(d,e.filename);try{if(e.wholeFile){let e=await h(`read command file`,()=>u.readFile(r));t.appendBuffer.push(e.replace(/\n$/,``))}else{if(!O.has(r)){let e=await h(`read command file line cache`,()=>u.readFile(r));O.set(r,e.split(`
`)),k.set(r,0)}let e=O.get(r),n=k.get(r);e&&n!==void 0&&n<e.length&&(t.appendBuffer.push(e[n]),k.set(r,n+1))}}catch(e){if(e instanceof n)throw e}}for(let e of t.pendingFileWrites){let t=u.resolvePath(d,e.filename),n=A.get(t)||``;A.set(t,n+e.content)}}}while(t.restartCycle&&!t.deleted&&!t.quit&&!t.quitSilent);if(e+=t.linesConsumedInCycle,w=t.holdSpace,T=t.lastPattern,!o)for(let e of t.nCommandOutput)C(`${e}
`);let s=t.lineNumberOutput.length>0;for(let e of t.lineNumberOutput)C(`${e}
`);let c=[],p=[];for(let e of t.appendBuffer)e.startsWith(`__INSERT__`)?c.push(e.slice(10)):p.push(e);for(let e of c)C(`${e}
`);let g=!1;!t.deleted&&!t.quitSilent?o?t.printed&&(C(`${t.patternSpace}
`),g=!0):(C(`${t.patternSpace}
`),g=!0):t.changedText!==void 0&&(C(`${t.changedText}
`),g=!0);for(let e of p)C(`${e}
`);if(x=(s||g)&&p.length===0,t.quit||t.quitSilent){if(t.exitCode!==void 0&&(b=t.exitCode),t.errorMessage)return{output:``,exitCode:b||1,errorMessage:t.errorMessage};break}}if(u&&d)for(let[e,t]of A)try{await h(`flush pending file writes`,()=>u.writeFile(e,t))}catch(e){if(e instanceof n)throw e}return!g&&x&&y.endsWith(`
`)&&(y=y.slice(0,-1)),{output:y,exitCode:b}}var I={name:`sed`,async execute(e,l){i(l.requireDefenseContext,`sed`,`execution entry`);let u=(e,t)=>r(l.requireDefenseContext,`sed`,e,t);if(c(e))return s(P);let d=[],f=[],p=!1,m=!1,h=!1,g=[];for(let t=0;t<e.length;t++){let n=e[t];if(n===`-n`||n===`--quiet`||n===`--silent`)p=!0;else if(n===`-i`||n===`--in-place`)m=!0;else if(n.startsWith(`-i`))m=!0;else if(n===`-E`||n===`-r`||n===`--regexp-extended`)h=!0;else if(n===`-e`)t+1<e.length&&d.push(e[++t]);else if(n===`-f`)t+1<e.length&&f.push(e[++t]);else{if(n.startsWith(`--`))return o(`sed`,n);if(n===`-`)g.push(n);else if(n.startsWith(`-`)&&n.length>1){for(let e of n.slice(1))if(e!==`n`&&e!==`e`&&e!==`f`&&e!==`i`&&e!==`E`&&e!==`r`)return o(`sed`,`-${e}`);n.includes(`n`)&&(p=!0),n.includes(`i`)&&(m=!0),(n.includes(`E`)||n.includes(`r`))&&(h=!0),n.includes(`e`)&&!n.includes(`n`)&&!n.includes(`i`)&&t+1<e.length&&d.push(e[++t]),n.includes(`f`)&&!n.includes(`e`)&&t+1<e.length&&f.push(e[++t])}else !n.startsWith(`-`)&&d.length===0&&f.length===0?d.push(n):n.startsWith(`-`)||g.push(n)}}for(let e of f){let t=l.fs.resolvePath(l.cwd,e);try{let e=await u(`script file read`,()=>l.fs.readFile(t));for(let t of e.split(`
`)){let e=t.trim();e&&!e.startsWith(`#`)&&d.push(e)}}catch(t){if(t instanceof n)throw t;return{stdout:``,stderr:`sed: couldn't open file ${e}: No such file or directory
`,exitCode:1}}}if(d.length===0)return{stdout:``,stderr:`sed: no script specified
`,exitCode:1};let{commands:_,error:v,silentMode:y}=A(d,h);if(v)return{stdout:``,stderr:`sed: ${v}
`,exitCode:1};let b=!!(p||y);if(m){if(g.length===0)return{stdout:``,stderr:`sed: -i requires at least one file argument
`,exitCode:1};for(let e of g){if(e===`-`)continue;let r=l.fs.resolvePath(l.cwd,e);try{let t=await u(`in-place input read`,()=>l.fs.readFile(r)),n=await u(`in-place processing`,()=>F(t,_,b,{limits:l.limits,filename:e,fs:l.fs,cwd:l.cwd,coverage:l.coverage,requireDefenseContext:l.requireDefenseContext}));if(n.errorMessage)return{stdout:``,stderr:`${n.errorMessage}
`,exitCode:n.exitCode??1};await u(`in-place output write`,()=>l.fs.writeFile(r,n.output))}catch(r){if(r instanceof n)throw r;return r instanceof t?{stdout:``,stderr:`sed: ${a(r.message)}
`,exitCode:t.EXIT_CODE}:{stdout:``,stderr:`sed: ${e}: No such file or directory
`,exitCode:1}}}return{stdout:``,stderr:``,exitCode:0}}let x=``;if(g.length===0){x=l.stdin;try{let e=await u(`stdin processing`,()=>F(x,_,b,{limits:l.limits,fs:l.fs,cwd:l.cwd,coverage:l.coverage,requireDefenseContext:l.requireDefenseContext}));return{stdout:e.output,stderr:e.errorMessage?`${e.errorMessage}
`:``,exitCode:e.exitCode??0}}catch(e){if(e instanceof n)throw e;if(e instanceof t)return{stdout:``,stderr:`sed: ${a(e.message)}
`,exitCode:t.EXIT_CODE};throw e}}let S=!1;for(let e of g){let r;if(e===`-`)S?r=``:(r=l.stdin,S=!0);else{let i=l.fs.resolvePath(l.cwd,e);try{r=await u(`input file read`,()=>l.fs.readFile(i))}catch(r){if(r instanceof n)throw r;return r instanceof t?{stdout:``,stderr:`sed: ${a(r.message)}
`,exitCode:t.EXIT_CODE}:{stdout:``,stderr:`sed: ${e}: No such file or directory
`,exitCode:1}}}x.length>0&&r.length>0&&!x.endsWith(`
`)&&(x+=`
`),x+=r}try{let e=await u(`final processing`,()=>F(x,_,b,{limits:l.limits,filename:g.length===1?g[0]:void 0,fs:l.fs,cwd:l.cwd,coverage:l.coverage,requireDefenseContext:l.requireDefenseContext}));return{stdout:e.output,stderr:e.errorMessage?`${e.errorMessage}
`:``,exitCode:e.exitCode??0}}catch(e){if(e instanceof n)throw e;if(e instanceof t)return{stdout:``,stderr:`sed: ${a(e.message)}
`,exitCode:t.EXIT_CODE};throw e}}},L={name:`sed`,flags:[{flag:`-n`,type:`boolean`},{flag:`-i`,type:`boolean`},{flag:`-E`,type:`boolean`},{flag:`-r`,type:`boolean`},{flag:`-e`,type:`value`,valueHint:`string`}],stdinType:`text`,needsArgs:!0};export{L as n,I as t};
//# sourceMappingURL=chunk-OL3S66CO-CWEDi2F_.mjs.map