import{__require as e}from"./stringify.mjs";import{__require as t}from"./constants.mjs";var n,o;function s(){if(o)return n;o=1;const s=e(),{MAX_LENGTH:p,CHAR_BACKSLASH:i,CHAR_BACKTICK:a,CHAR_COMMA:l,CHAR_DOT:r,CHAR_LEFT_PARENTHESES:u,CHAR_RIGHT_PARENTHESES:c,CHAR_LEFT_CURLY_BRACE:f,CHAR_RIGHT_CURLY_BRACE:y,CHAR_LEFT_SQUARE_BRACKET:_,CHAR_RIGHT_SQUARE_BRACKET:A,CHAR_DOUBLE_QUOTE:E,CHAR_SINGLE_QUOTE:R,CHAR_NO_BREAK_SPACE:g,CHAR_ZERO_WIDTH_NOBREAK_SPACE:d}=t();return n=(e,t={})=>{if("string"!=typeof e)throw new TypeError("Expected a string");const n=t||{},o="number"==typeof n.maxLength?Math.min(p,n.maxLength):p;if(e.length>o)throw new SyntaxError(`Input length (${e.length}), exceeds max characters (${o})`);const C={type:"root",input:e,nodes:[]},h=[C];let v=C,x=C,H=0;const m=e.length;let T,S=0,L=0;const O=()=>e[S++],B=e=>{if("text"===e.type&&"dot"===x.type&&(x.type="text"),!x||"text"!==x.type||"text"!==e.type)return v.nodes.push(e),e.parent=v,e.prev=x,x=e,e;x.value+=e.value};for(B({type:"bos"});S<m;)if(v=h[h.length-1],T=O(),T!==d&&T!==g)if(T!==i)if(T!==A){if(T===_){let e;for(H++;S<m&&(e=O());)if(T+=e,e!==_)if(e!==i){if(e===A&&(H--,0===H))break}else T+=O();else H++;B({type:"text",value:T});continue}if(T!==u)if(T!==c){if(T===E||T===R||T===a){const e=T;let n;for(!0!==t.keepQuotes&&(T="");S<m&&(n=O());)if(n!==i){if(n===e){!0===t.keepQuotes&&(T+=n);break}T+=n}else T+=n+O();B({type:"text",value:T});continue}if(T===f){L++;const e=x.value&&"$"===x.value.slice(-1)||!0===v.dollar;v=B({type:"brace",open:!0,close:!1,dollar:e,depth:L,commas:0,ranges:0,nodes:[]}),h.push(v),B({type:"open",value:T});continue}if(T===y){if("brace"!==v.type){B({type:"text",value:T});continue}const e="close";v=h.pop(),v.close=!0,B({type:e,value:T}),L--,v=h[h.length-1];continue}if(T===l&&L>0){if(v.ranges>0){v.ranges=0;const e=v.nodes.shift();v.nodes=[e,{type:"text",value:s(v)}]}B({type:"comma",value:T}),v.commas++}else{if(T===r&&L>0&&0===v.commas){const e=v.nodes;if(0===L||0===e.length){B({type:"text",value:T});continue}if("dot"===x.type){if(v.range=[],x.value+=T,x.type="range",3!==v.nodes.length&&5!==v.nodes.length){v.invalid=!0,v.ranges=0,x.type="text";continue}v.ranges++,v.args=[];continue}if("range"===x.type){e.pop();const t=e[e.length-1];t.value+=x.value+T,x=t,v.ranges--;continue}B({type:"dot",value:T});continue}B({type:"text",value:T})}}else{if("paren"!==v.type){B({type:"text",value:T});continue}v=h.pop(),B({type:"text",value:T}),v=h[h.length-1]}else v=B({type:"paren",nodes:[]}),h.push(v),B({type:"text",value:T})}else B({type:"text",value:"\\"+T});else B({type:"text",value:(t.keepEscaping?T:"")+O()});do{if(v=h.pop(),"root"!==v.type){v.nodes.forEach(e=>{e.nodes||("open"===e.type&&(e.isOpen=!0),"close"===e.type&&(e.isClose=!0),e.nodes||(e.type="text"),e.invalid=!0)});const e=h[h.length-1],t=e.nodes.indexOf(v);e.nodes.splice(t,1,...v.nodes)}}while(h.length>0);return B({type:"eos"}),C}}export{s as __require};