// @bun
var{defineProperty:J,getOwnPropertyNames:O,getOwnPropertyDescriptor:Q}=Object,R=Object.prototype.hasOwnProperty;function U(b){return this[b]}var $=(b)=>{var v=(K??=new WeakMap).get(b),j;if(v)return v;if(v=J({},"__esModule",{value:!0}),b&&typeof b==="object"||typeof b==="function"){for(var w of O(b))if(!R.call(v,w))J(v,w,{get:U.bind(b,w),enumerable:!(j=Q(b,w))||j.enumerable})}return K.set(b,v),v},K;var V=(b)=>b;function W(b,v){this[b]=V.bind(null,v)}var G=(b,v)=>{for(var j in v)J(b,j,{get:v[j],enumerable:!0,configurable:!0,set:W.bind(v,j)})};var I=(b,v)=>()=>(b&&(v=b(b=0)),v);var X=import.meta.require;class Z{source;pos=0;line=1;column=0;tokens=[];constructor(b){this.source=b}tokenize(){this.tokens=[],this.pos=0,this.line=1,this.column=0;while(this.pos<this.source.length){let b=this.nextToken();if(b)this.tokens.push(b)}return this.tokens.push({type:"EOF",value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),this.tokens}nextToken(){if(this.pos>=this.source.length)return null;let b=this.pos,v=this.line,j=this.column,w=this.source[this.pos];if(/\s/.test(w))return this.readWhitespace(b,v,j);if(w==="/"&&this.peek(1)==="/")return this.readLineComment(b,v,j);if(w==="/"&&this.peek(1)==="*")return this.readBlockComment(b,v,j);if(w==='"'||w==="'")return this.readString(w,b,v,j);if(w==="`")return this.readTemplateString(b,v,j);if(/\d/.test(w)||w==="."&&/\d/.test(this.peek(1)||""))return this.readNumber(b,v,j);if(/[a-z_$]/i.test(w))return this.readIdentifier(b,v,j);if(w==="{"){if(this.peek(1)==="{"&&this.peek(2)==="{")return this.advance(3),{type:"RAW_START",value:"{{{",start:b,end:this.pos,line:v,column:j};if(this.peek(1)==="{")return this.advance(2),{type:"EXPRESSION_START",value:"{{",start:b,end:this.pos,line:v,column:j};if(this.peek(1)==="!"&&this.peek(2)==="!")return this.advance(3),{type:"RAW_START",value:"{!!",start:b,end:this.pos,line:v,column:j}}if(w==="}"){if(this.peek(1)==="}"&&this.peek(2)==="}")return this.advance(3),{type:"RAW_END",value:"}}}",start:b,end:this.pos,line:v,column:j};if(this.peek(1)==="}")return this.advance(2),{type:"EXPRESSION_END",value:"}}",start:b,end:this.pos,line:v,column:j}}if(w==="!"&&this.peek(1)==="!"&&this.peek(2)==="}")return this.advance(3),{type:"RAW_END",value:"!!}",start:b,end:this.pos,line:v,column:j};if(w==="@"&&/[a-z]/i.test(this.peek(1)||""))return this.readDirective(b,v,j);let z=["===","!==","==","!=","<=",">=","&&","||","??","++","--","+=","-=","*=","/=","%=","**","=>","?.","...","<<",">>",">>>","&=","|=","^="];for(let B of z)if(this.source.slice(this.pos,this.pos+B.length)===B)return this.advance(B.length),{type:"OPERATOR",value:B,start:b,end:this.pos,line:v,column:j};if(/[+\-*/%<>=!&|^~?:]/.test(w))return this.advance(),{type:"OPERATOR",value:w,start:b,end:this.pos,line:v,column:j};if(/[()[\]{},;.]/.test(w))return this.advance(),{type:"PUNCTUATION",value:w,start:b,end:this.pos,line:v,column:j};return this.advance(),{type:"PUNCTUATION",value:w,start:b,end:this.pos,line:v,column:j}}readWhitespace(b,v,j){while(this.pos<this.source.length&&/\s/.test(this.source[this.pos]))this.advance();return{type:"WHITESPACE",value:this.source.slice(b,this.pos),start:b,end:this.pos,line:v,column:j}}readLineComment(b,v,j){this.advance(2);while(this.pos<this.source.length&&this.source[this.pos]!==`
`)this.advance();return{type:"COMMENT",value:this.source.slice(b,this.pos),start:b,end:this.pos,line:v,column:j}}readBlockComment(b,v,j){this.advance(2);while(this.pos<this.source.length-1){if(this.source[this.pos]==="*"&&this.source[this.pos+1]==="/"){this.advance(2);break}this.advance()}return{type:"COMMENT",value:this.source.slice(b,this.pos),start:b,end:this.pos,line:v,column:j}}readString(b,v,j,w){this.advance();while(this.pos<this.source.length){let z=this.source[this.pos];if(z==="\\"){this.advance(2);continue}if(z===b){this.advance();break}this.advance()}return{type:"STRING",value:this.source.slice(v,this.pos),start:v,end:this.pos,line:j,column:w}}readTemplateString(b,v,j){this.advance();let w=0,z=256;while(this.pos<this.source.length){let B=this.source[this.pos];if(B==="\\"){this.advance(2);continue}if(B==="$"&&this.peek(1)==="{"){if(w>=z){this.pos=this.source.length;break}this.advance(2),w++;continue}if(B==="{"&&w>0){w++,this.advance();continue}if(B==="}"&&w>0){w--,this.advance();continue}if(B==="`"&&w===0){this.advance();break}this.advance()}return{type:"TEMPLATE_STRING",value:this.source.slice(b,this.pos),start:b,end:this.pos,line:v,column:j}}readNumber(b,v,j){if(this.source[this.pos]==="0"){let w=this.peek(1)?.toLowerCase();if(w==="x"||w==="o"||w==="b"){this.advance(2);while(this.pos<this.source.length&&/[\da-f_]/i.test(this.source[this.pos]))this.advance();return{type:"NUMBER",value:this.source.slice(b,this.pos),start:b,end:this.pos,line:v,column:j}}}while(this.pos<this.source.length&&/[\d_]/.test(this.source[this.pos]))this.advance();if(this.source[this.pos]==="."&&/\d/.test(this.peek(1)||"")){this.advance();while(this.pos<this.source.length&&/[\d_]/.test(this.source[this.pos]))this.advance()}if(/e/i.test(this.source[this.pos]||"")){if(this.advance(),/[+-]/.test(this.source[this.pos]||""))this.advance();while(this.pos<this.source.length&&/[\d_]/.test(this.source[this.pos]))this.advance()}if(this.source[this.pos]==="n")this.advance();return{type:"NUMBER",value:this.source.slice(b,this.pos),start:b,end:this.pos,line:v,column:j}}readIdentifier(b,v,j){while(this.pos<this.source.length&&/[\w$]/.test(this.source[this.pos]))this.advance();return{type:"IDENTIFIER",value:this.source.slice(b,this.pos),start:b,end:this.pos,line:v,column:j}}readDirective(b,v,j){this.advance();while(this.pos<this.source.length&&/[a-z]/i.test(this.source[this.pos]))this.advance();return{type:"DIRECTIVE",value:this.source.slice(b,this.pos),start:b,end:this.pos,line:v,column:j}}advance(b=1){for(let v=0;v<b&&this.pos<this.source.length;v++){if(this.source[this.pos]===`
`)this.line++,this.column=0;else this.column++;this.pos++}}peek(b){return this.source[this.pos+b]}saveState(){return{pos:this.pos,line:this.line,column:this.column}}restoreState(b){this.pos=b.pos,this.line=b.line,this.column=b.column}}function q(b,v,j,w=0){let z=0,B=w,y=null,D=0,H=!1;while(B<b.length){let F=b[B];if(y&&H){H=!1,B++;continue}if(y&&F==="\\"){H=!0,B++;continue}if(H=!1,(F==='"'||F==="'"||F==="`")&&!y){y=F,B++;continue}if(F===y&&y!=="`"){y=null,B++;continue}if(y==="`"&&F==="$"&&b[B+1]==="{"){D++,B+=2;continue}if(D>0&&F==="}"){D--,B++;continue}if(F==="`"&&y==="`"&&D===0){y=null,B++;continue}if(y){B++;continue}if(F===v)z++;else if(F===j){if(z--,z===0)return B}B++}return-1}function A(b,v){let j=v,w={paren:0,bracket:0,brace:0},z=null,B=0;while(j<b.length){let y=b[j];if((j>0?b[j-1]:"")==="\\"&&z){j++;continue}if((y==='"'||y==="'")&&!z){z=y,j++;continue}if(y===z&&z!=="`"){z=null,j++;continue}if(y==="`"&&!z){z="`",j++;continue}if(y==="`"&&z==="`"&&B===0){z=null,j++;continue}if(z==="`"&&y==="$"&&b[j+1]==="{"){B++,j+=2;continue}if(B>0){if(y==="{")B++;else if(y==="}")B--;j++;continue}if(z){j++;continue}if(w.paren===0&&w.bracket===0&&w.brace===0){if(b.slice(j,j+2)==="}}"||b.slice(j,j+3)==="!!}")break;if(y===","||y===";")break}if(y==="(")w.paren++;else if(y===")"){if(w.paren--,w.paren<0)break}else if(y==="[")w.bracket++;else if(y==="]"){if(w.bracket--,w.bracket<0)break}else if(y==="{")w.brace++;else if(y==="}"){if(w.brace--,w.brace<0)break}j++}return{expression:b.slice(v,j),endPos:j}}function M(b){let v=[],j="",w={paren:0,bracket:0,brace:0},z=null,B=0;for(let y=0;y<b.length;y++){let D=b[y];if((y>0?b[y-1]:"")==="\\"&&z){j+=D;continue}if((D==='"'||D==="'")&&!z){z=D,j+=D;continue}if(D===z&&z!=="`"){z=null,j+=D;continue}if(D==="`"&&!z){z="`",j+=D;continue}if(D==="`"&&z==="`"&&B===0){z=null,j+=D;continue}if(z==="`"&&D==="$"&&b[y+1]==="{"){B++,j+=D+b[y+1],y++;continue}if(B>0&&D==="{"){B++,j+=D;continue}if(B>0&&D==="}"){B--,j+=D;continue}if(z){j+=D;continue}if(D==="(")w.paren++;else if(D===")")w.paren--;else if(D==="[")w.bracket++;else if(D==="]")w.bracket--;else if(D==="{")w.brace++;else if(D==="}")w.brace--;if(D==="|"&&b[y+1]!=="|"&&(y===0||b[y-1]!=="|")&&b[y-1]!=="\\"&&w.paren===0&&w.bracket===0&&w.brace===0){v.push(j.trim()),j="";continue}if(D==="|"&&b[y-1]==="\\"&&!z){j=j.slice(0,-1)+D;continue}j+=D}if(j.trim())v.push(j.trim());return v}export{M as splitByPipe,q as findMatchingDelimiter,A as extractBalancedExpression,Z as Tokenizer};
