function lexer(e){var r=[];var i=0;while(i<e.length){var n=e[i];if(n==="*"||n==="+"||n==="?"){r.push({type:"MODIFIER",index:i,value:e[i++]});continue}if(n==="\\"){r.push({type:"ESCAPED_CHAR",index:i++,value:e[i++]});continue}if(n==="{"){r.push({type:"OPEN",index:i,value:e[i++]});continue}if(n==="}"){r.push({type:"CLOSE",index:i,value:e[i++]});continue}if(n===":"){var t="";var a=i+1;while(a<e.length){var f=e.charCodeAt(a);if(f>=48&&f<=57||f>=65&&f<=90||f>=97&&f<=122||f===95){t+=e[a++];continue}break}if(!t)throw new TypeError("Missing parameter name at "+i);r.push({type:"NAME",index:i,value:t});i=a;continue}if(n==="("){var p=1;var o="";var a=i+1;if(e[a]==="?"){throw new TypeError('Pattern cannot start with "?" at '+a)}while(a<e.length){if(e[a]==="\\"){o+=e[a++]+e[a++];continue}if(e[a]===")"){p--;if(p===0){a++;break}}else if(e[a]==="("){p++;if(e[a+1]!=="?"){throw new TypeError("Capturing groups are not allowed at "+a)}}o+=e[a++]}if(p)throw new TypeError("Unbalanced pattern at "+i);if(!o)throw new TypeError("Missing pattern at "+i);r.push({type:"PATTERN",index:i,value:o});i=a;continue}r.push({type:"CHAR",index:i,value:e[i++]})}r.push({type:"END",index:i,value:""});return r}function parse(e,r){if(r===void 0){r={}}var i=lexer(e);var n=r.prefixes,t=n===void 0?"./":n;var a="[^"+escapeString(r.delimiter||"/#?")+"]+?";var f=[];var p=0;var o=0;var u="";var v=function(e){if(o<i.length&&i[o].type===e)return i[o++].value};var s=function(e){var r=v(e);if(r!==undefined)return r;var n=i[o],t=n.type,a=n.index;throw new TypeError("Unexpected "+t+" at "+a+", expected "+e)};var c=function(){var e="";var r;while(r=v("CHAR")||v("ESCAPED_CHAR")){e+=r}return e};while(o<i.length){var g=v("CHAR");var x=v("NAME");var d=v("PATTERN");if(x||d){var h=g||"";if(t.indexOf(h)===-1){u+=h;h=""}if(u){f.push(u);u=""}f.push({name:x||p++,prefix:h,suffix:"",pattern:d||a,modifier:v("MODIFIER")||""});continue}var l=g||v("ESCAPED_CHAR");if(l){u+=l;continue}if(u){f.push(u);u=""}var E=v("OPEN");if(E){var h=c();var R=v("NAME")||"";var T=v("PATTERN")||"";var w=c();s("CLOSE");f.push({name:R||(T?p++:""),pattern:R&&!T?a:T,prefix:h,suffix:w,modifier:v("MODIFIER")||""});continue}s("END")}return f}function escapeString(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function flags(e){return e&&e.sensitive?"":"i"}function regexpToRegexp(e,r){if(!r)return e;var i=/\((?:\?<(.*?)>)?(?!\?)/g;var n=0;var t=i.exec(e.source);while(t){r.push({name:t[1]||n++,prefix:"",suffix:"",modifier:"",pattern:""});t=i.exec(e.source)}return e}function arrayToRegexp(e,r,i){var n=e.map((function(e){return pathToRegexp(e,r,i).source}));return new RegExp("(?:"+n.join("|")+")",flags(i))}function stringToRegexp(e,r,i){return tokensToRegexp(parse(e,i),r,i)}function tokensToRegexp(e,r,i){if(i===void 0){i={}}var n=i.strict,t=n===void 0?false:n,a=i.start,f=a===void 0?true:a,p=i.end,o=p===void 0?true:p,u=i.encode,v=u===void 0?function(e){return e}:u;var s="["+escapeString(i.endsWith||"")+"]|$";var c="["+escapeString(i.delimiter||"/#?")+"]";var g=f?"^":"";for(var x=0,d=e;x<d.length;x++){var h=d[x];if(typeof h==="string"){g+=escapeString(v(h))}else{var l=escapeString(v(h.prefix));var E=escapeString(v(h.suffix));if(h.pattern){if(r)r.push(h);if(l||E){if(h.modifier==="+"||h.modifier==="*"){var R=h.modifier==="*"?"?":"";g+="(?:"+l+"((?:"+h.pattern+")(?:"+E+l+"(?:"+h.pattern+"))*)"+E+")"+R}else{g+="(?:"+l+"("+h.pattern+")"+E+")"+h.modifier}}else{g+="("+h.pattern+")"+h.modifier}}else{g+="(?:"+l+E+")"+h.modifier}}}if(o){if(!t)g+=c+"?";g+=!i.endsWith?"$":"(?="+s+")"}else{var T=e[e.length-1];var w=typeof T==="string"?c.indexOf(T[T.length-1])>-1:T===undefined;if(!t){g+="(?:"+c+"(?="+s+"))?"}if(!w){g+="(?="+c+"|"+s+")"}}return new RegExp(g,flags(i))}function pathToRegexp(e,r,i){if(e instanceof RegExp)return regexpToRegexp(e,r);if(Array.isArray(e))return arrayToRegexp(e,r,i);return stringToRegexp(e,r,i)}export{pathToRegexp as p};