@sheetxl/sdk
Version:
SDK - A high-performance, embeddable spreadsheet engine.
125 lines • 166 kB
JavaScript
"use strict";/**
* @license @sheetxl/sdk - SDK - A high-performance, embeddable spreadsheet engine. - v0.6.4
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./B41PzxC0w5TPpEci.cjs"),w=require("@sheetxl/primitives"),X=require("@sheetxl/utils");var No=typeof global=="object"&&global&&global.Object===Object&&global,Ms=typeof self=="object"&&self&&self.Object===Object&&self,bt=No||Ms||Function("return this")(),Tt=bt.Symbol,Ro=Object.prototype,Us=Ro.hasOwnProperty,Fs=Ro.toString,Te=Tt?Tt.toStringTag:void 0,Ds=Object.prototype.toString,Kr=Tt?Tt.toStringTag:void 0;function qt(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Kr&&Kr in Object(t)?function(e){var n=Us.call(e,Te),r=e[Te];try{e[Te]=void 0;var i=!0}catch{}var o=Fs.call(e);return i&&(n?e[Te]=r:delete e[Te]),o}(t):function(e){return Ds.call(e)}(t)}function Rt(t){return t!=null&&typeof t=="object"}function En(t){return typeof t=="symbol"||Rt(t)&&qt(t)=="[object Symbol]"}function gn(t,e){for(var n=-1,r=t==null?0:t.length,i=Array(r);++n<r;)i[n]=e(t[n],n,t);return i}var D=Array.isArray,zr=Tt?Tt.prototype:void 0,Vr=zr?zr.toString:void 0;function Oo(t){if(typeof t=="string")return t;if(D(t))return gn(t,Oo)+"";if(En(t))return Vr?Vr.call(t):"";var e=t+"";return e=="0"&&1/t==-1/0?"-0":e}var js=/\s/,Bs=/^\s+/;function $s(t){return t&&t.slice(0,function(e){for(var n=e.length;n--&&js.test(e.charAt(n)););return n}(t)+1).replace(Bs,"")}function At(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var Ws=/^[-+]0x[0-9a-f]+$/i,Gs=/^0b[01]+$/i,Ks=/^0o[0-7]+$/i,zs=parseInt,Vs=1/0;function Hs(t){return t?(t=function(e){if(typeof e=="number")return e;if(En(e))return NaN;if(At(e)){var n=typeof e.valueOf=="function"?e.valueOf():e;e=At(n)?n+"":n}if(typeof e!="string")return e===0?e:+e;e=$s(e);var r=Gs.test(e);return r||Ks.test(e)?zs(e.slice(2),r?2:8):Ws.test(e)?NaN:+e}(t))===Vs||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:t===0?t:0}function Tn(t){var e=Hs(t),n=e%1;return e==e?n?e-n:e:0}function fe(t){return t}function Vt(t){if(!At(t))return!1;var e=qt(t);return e=="[object Function]"||e=="[object GeneratorFunction]"||e=="[object AsyncFunction]"||e=="[object Proxy]"}var Hr,kn=bt["__core-js_shared__"],Yr=(Hr=/[^.]+$/.exec(kn&&kn.keys&&kn.keys.IE_PROTO||""))?"Symbol(src)_1."+Hr:"",Ys=Function.prototype.toString;function re(t){if(t!=null){try{return Ys.call(t)}catch{}try{return t+""}catch{}}return""}var Xs=/^\[object .+?Constructor\]$/,qs=Function.prototype,Zs=Object.prototype,Qs=qs.toString,Js=Zs.hasOwnProperty,ta=RegExp("^"+Qs.call(Js).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ea(t){return!(!At(t)||(e=t,Yr&&Yr in e))&&(Vt(t)?ta:Xs).test(re(t));var e}function ie(t,e){var n=function(r,i){return r?.[i]}(t,e);return ea(n)?n:void 0}var ir=ie(bt,"WeakMap"),Xr=Object.create,na=function(){function t(){}return function(e){if(!At(e))return{};if(Xr)return Xr(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}();function Q(){}var ra=Date.now,qr,bn,Pn,on=function(){try{var t=ie(Object,"defineProperty");return t({},"",{}),t}catch{}}(),ia=on?function(t,e){return on(t,"toString",{configurable:!0,enumerable:!1,value:(n=e,function(){return n}),writable:!0});var n}:fe,oa=(qr=ia,bn=0,Pn=0,function(){var t=ra(),e=16-(t-Pn);if(Pn=t,e>0){if(++bn>=800)return arguments[0]}else bn=0;return qr.apply(void 0,arguments)});function So(t,e){for(var n=-1,r=t==null?0:t.length;++n<r&&e(t[n],n,t)!==!1;);return t}function _o(t,e,n,r){for(var i=t.length,o=n+-1;++o<i;)if(e(t[o],o,t))return o;return-1}function sa(t){return t!=t}function Ir(t,e,n){return e==e?function(r,i,o){for(var s=o-1,a=r.length;++s<a;)if(r[s]===i)return s;return-1}(t,e,n):_o(t,sa,n)}function Lo(t,e){return!!(t!=null&&t.length)&&Ir(t,e,0)>-1}var aa=/^(?:0|[1-9]\d*)$/;function An(t,e){var n=typeof t;return!!(e=e??9007199254740991)&&(n=="number"||n!="symbol"&&aa.test(t))&&t>-1&&t%1==0&&t<e}function yr(t,e,n){e=="__proto__"&&on?on(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}function Fe(t,e){return t===e||t!=t&&e!=e}var ca=Object.prototype.hasOwnProperty;function In(t,e,n){var r=t[e];ca.call(t,e)&&Fe(r,n)&&(n!==void 0||e in t)||yr(t,e,n)}function or(t,e,n,r){var i=!n;n||(n={});for(var o=-1,s=e.length;++o<s;){var a=e[o],c=void 0;c===void 0&&(c=t[a]),i?yr(n,a,c):In(n,a,c)}return n}var Zr=Math.max;function vr(t,e){return oa(function(n,r,i){return r=Zr(r===void 0?n.length-1:r,0),function(){for(var o=arguments,s=-1,a=Zr(o.length-r,0),c=Array(a);++s<a;)c[s]=o[r+s];s=-1;for(var u=Array(r+1);++s<r;)u[s]=o[s];return u[r]=i(c),function(l,h,f){switch(f.length){case 0:return l.call(h);case 1:return l.call(h,f[0]);case 2:return l.call(h,f[0],f[1]);case 3:return l.call(h,f[0],f[1],f[2])}return l.apply(h,f)}(n,this,u)}}(t,e,fe),t+"")}function Nr(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=9007199254740991}function Pt(t){return t!=null&&Nr(t.length)&&!Vt(t)}function xo(t,e,n){if(!At(n))return!1;var r=typeof e;return!!(r=="number"?Pt(n)&&An(e,n.length):r=="string"&&e in n)&&Fe(n[e],t)}var ua=Object.prototype;function De(t){var e=t&&t.constructor;return t===(typeof e=="function"&&e.prototype||ua)}function Qr(t){return Rt(t)&&qt(t)=="[object Arguments]"}var Co=Object.prototype,la=Co.hasOwnProperty,ha=Co.propertyIsEnumerable,yn=Qr(function(){return arguments}())?Qr:function(t){return Rt(t)&&la.call(t,"callee")&&!ha.call(t,"callee")},ko=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Jr=ko&&typeof module=="object"&&module&&!module.nodeType&&module,ti=Jr&&Jr.exports===ko?bt.Buffer:void 0,be=(ti?ti.isBuffer:void 0)||function(){return!1},z={};function vn(t){return function(e){return t(e)}}z["[object Float32Array]"]=z["[object Float64Array]"]=z["[object Int8Array]"]=z["[object Int16Array]"]=z["[object Int32Array]"]=z["[object Uint8Array]"]=z["[object Uint8ClampedArray]"]=z["[object Uint16Array]"]=z["[object Uint32Array]"]=!0,z["[object Arguments]"]=z["[object Array]"]=z["[object ArrayBuffer]"]=z["[object Boolean]"]=z["[object DataView]"]=z["[object Date]"]=z["[object Error]"]=z["[object Function]"]=z["[object Map]"]=z["[object Number]"]=z["[object Object]"]=z["[object RegExp]"]=z["[object Set]"]=z["[object String]"]=z["[object WeakMap]"]=!1;var bo=typeof exports=="object"&&exports&&!exports.nodeType&&exports,_e=bo&&typeof module=="object"&&module&&!module.nodeType&&module,wn=_e&&_e.exports===bo&&No.process,Yt=function(){try{var t=_e&&_e.require&&_e.require("util").types;return t||wn&&wn.binding&&wn.binding("util")}catch{}}(),ei=Yt&&Yt.isTypedArray,Rr=ei?vn(ei):function(t){return Rt(t)&&Nr(t.length)&&!!z[qt(t)]},fa=Object.prototype.hasOwnProperty;function Po(t,e){var n=D(t),r=!n&&yn(t),i=!n&&!r&&be(t),o=!n&&!r&&!i&&Rr(t),s=n||r||i||o,a=s?function(l,h){for(var f=-1,d=Array(l);++f<l;)d[f]=h(f);return d}(t.length,String):[],c=a.length;for(var u in t)!e&&!fa.call(t,u)||s&&(u=="length"||i&&(u=="offset"||u=="parent")||o&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||An(u,c))||a.push(u);return a}function wo(t,e){return function(n){return t(e(n))}}var da=wo(Object.keys,Object),pa=Object.prototype.hasOwnProperty;function Mo(t){if(!De(t))return da(t);var e=[];for(var n in Object(t))pa.call(t,n)&&n!="constructor"&&e.push(n);return e}function It(t){return Pt(t)?Po(t):Mo(t)}var Mn,ma=Object.prototype.hasOwnProperty,ft=(Mn=function(t,e){if(De(e)||Pt(e))or(e,It(e),t);else for(var n in e)ma.call(e,n)&&In(t,n,e[n])},vr(function(t,e){var n=-1,r=e.length,i=r>1?e[r-1]:void 0,o=r>2?e[2]:void 0;for(i=Mn.length>3&&typeof i=="function"?(r--,i):void 0,o&&xo(e[0],e[1],o)&&(i=r<3?void 0:i,r=1),t=Object(t);++n<r;){var s=e[n];s&&Mn(t,s,n,i)}return t})),Ea=Object.prototype.hasOwnProperty;function ga(t){if(!At(t))return function(i){var o=[];if(i!=null)for(var s in Object(i))o.push(s);return o}(t);var e=De(t),n=[];for(var r in t)(r!="constructor"||!e&&Ea.call(t,r))&&n.push(r);return n}function Uo(t){return Pt(t)?Po(t,!0):ga(t)}var Ta=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Aa=/^\w*$/;function Or(t,e){if(D(t))return!1;var n=typeof t;return!(n!="number"&&n!="symbol"&&n!="boolean"&&t!=null&&!En(t))||Aa.test(t)||!Ta.test(t)||e!=null&&t in Object(e)}var Ae=ie(Object,"create"),Ia=Object.prototype.hasOwnProperty,ya=Object.prototype.hasOwnProperty;function Jt(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function We(t,e){for(var n=t.length;n--;)if(Fe(t[n][0],e))return n;return-1}Jt.prototype.clear=function(){this.__data__=Ae?Ae(null):{},this.size=0},Jt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Jt.prototype.get=function(t){var e=this.__data__;if(Ae){var n=e[t];return n==="__lodash_hash_undefined__"?void 0:n}return Ia.call(e,t)?e[t]:void 0},Jt.prototype.has=function(t){var e=this.__data__;return Ae?e[t]!==void 0:ya.call(e,t)},Jt.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=Ae&&e===void 0?"__lodash_hash_undefined__":e,this};var va=Array.prototype.splice;function Wt(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}Wt.prototype.clear=function(){this.__data__=[],this.size=0},Wt.prototype.delete=function(t){var e=this.__data__,n=We(e,t);return!(n<0)&&(n==e.length-1?e.pop():va.call(e,n,1),--this.size,!0)},Wt.prototype.get=function(t){var e=this.__data__,n=We(e,t);return n<0?void 0:e[n][1]},Wt.prototype.has=function(t){return We(this.__data__,t)>-1},Wt.prototype.set=function(t,e){var n=this.__data__,r=We(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};var Pe=ie(bt,"Map");function Ge(t,e){var n,r,i=t.__data__;return((r=typeof(n=e))=="string"||r=="number"||r=="symbol"||r=="boolean"?n!=="__proto__":n===null)?i[typeof e=="string"?"string":"hash"]:i.map}function Gt(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}Gt.prototype.clear=function(){this.size=0,this.__data__={hash:new Jt,map:new(Pe||Wt),string:new Jt}},Gt.prototype.delete=function(t){var e=Ge(this,t).delete(t);return this.size-=e?1:0,e},Gt.prototype.get=function(t){return Ge(this,t).get(t)},Gt.prototype.has=function(t){return Ge(this,t).has(t)},Gt.prototype.set=function(t,e){var n=Ge(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function Sr(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError("Expected a function");var n=function(){var r=arguments,i=e?e.apply(this,r):r[0],o=n.cache;if(o.has(i))return o.get(i);var s=t.apply(this,r);return n.cache=o.set(i,s)||o,s};return n.cache=new(Sr.Cache||Gt),n}Sr.Cache=Gt;var Na=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ra=/\\(\\)?/g,Oa=function(t){var e=Sr(t,function(r){return n.size===500&&n.clear(),r}),n=e.cache;return e}(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(Na,function(n,r,i,o){e.push(i?o.replace(Ra,"$1"):r||n)}),e});function Nn(t,e){return D(t)?t:Or(t,e)?[t]:Oa(function(n){return n==null?"":Oo(n)}(t))}function je(t){if(typeof t=="string"||En(t))return t;var e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function _r(t,e){for(var n=0,r=(e=Nn(e,t)).length;t!=null&&n<r;)t=t[je(e[n++])];return n&&n==r?t:void 0}function Lr(t,e){for(var n=-1,r=e.length,i=t.length;++n<r;)t[i+n]=e[n];return t}var ni=Tt?Tt.isConcatSpreadable:void 0;function Sa(t){return D(t)||yn(t)||!!(ni&&t&&t[ni])}function xr(t,e,n,r,i){var o=-1,s=t.length;for(n||(n=Sa),i||(i=[]);++o<s;){var a=t[o];n(a)?Lr(i,a):r||(i[i.length]=a)}return i}function vt(t){return t!=null&&t.length?xr(t):[]}var Fo=wo(Object.getPrototypeOf,Object);function Do(t,e,n){var r=-1,i=t.length;e<0&&(e=-e>i?0:i+e),(n=n>i?i:n)<0&&(n+=i),i=e>n?0:n-e>>>0,e>>>=0;for(var o=Array(i);++r<i;)o[r]=t[r+e];return o}function _a(t,e,n,r){var i=-1,o=t==null?0:t.length;for(r&&o&&(n=t[++i]);++i<o;)n=e(n,t[i],i,t);return n}function Ct(t){var e=this.__data__=new Wt(t);this.size=e.size}Ct.prototype.clear=function(){this.__data__=new Wt,this.size=0},Ct.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},Ct.prototype.get=function(t){return this.__data__.get(t)},Ct.prototype.has=function(t){return this.__data__.has(t)},Ct.prototype.set=function(t,e){var n=this.__data__;if(n instanceof Wt){var r=n.__data__;if(!Pe||r.length<199)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new Gt(r)}return n.set(t,e),this.size=n.size,this};var jo=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ri=jo&&typeof module=="object"&&module&&!module.nodeType&&module,ii=ri&&ri.exports===jo?bt.Buffer:void 0,oi=ii?ii.allocUnsafe:void 0;function Cr(t,e){for(var n=-1,r=t==null?0:t.length,i=0,o=[];++n<r;){var s=t[n];e(s,n,t)&&(o[i++]=s)}return o}function Bo(){return[]}var La=Object.prototype.propertyIsEnumerable,si=Object.getOwnPropertySymbols,kr=si?function(t){return t==null?[]:(t=Object(t),Cr(si(t),function(e){return La.call(t,e)}))}:Bo,xa=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Lr(e,kr(t)),t=Fo(t);return e}:Bo;function $o(t,e,n){var r=e(t);return D(t)?r:Lr(r,n(t))}function sr(t){return $o(t,It,kr)}var ar=ie(bt,"DataView"),cr=ie(bt,"Promise"),le=ie(bt,"Set"),ai="[object Map]",ci="[object Promise]",ui="[object Set]",li="[object WeakMap]",hi="[object DataView]",Ca=re(ar),ka=re(Pe),ba=re(cr),Pa=re(le),wa=re(ir),Et=qt;(ar&&Et(new ar(new ArrayBuffer(1)))!=hi||Pe&&Et(new Pe)!=ai||cr&&Et(cr.resolve())!=ci||le&&Et(new le)!=ui||ir&&Et(new ir)!=li)&&(Et=function(t){var e=qt(t),n=e=="[object Object]"?t.constructor:void 0,r=n?re(n):"";if(r)switch(r){case Ca:return hi;case ka:return ai;case ba:return ci;case Pa:return ui;case wa:return li}return e});var Ma=Object.prototype.hasOwnProperty,sn=bt.Uint8Array,Ua=/\w*$/,fi=Tt?Tt.prototype:void 0,di=fi?fi.valueOf:void 0;function Fa(t,e,n){var r,i,o,s,a,c=t.constructor;switch(e){case"[object ArrayBuffer]":return a=new(s=t).constructor(s.byteLength),new sn(a).set(new sn(s)),a;case"[object Boolean]":case"[object Date]":return new c(+t);case"[object DataView]":return o=(i=t).buffer,new i.constructor(o,i.byteOffset,i.byteLength);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return function(u){var l=u.buffer;return new u.constructor(l,u.byteOffset,u.length)}(t);case"[object Map]":case"[object Set]":return new c;case"[object Number]":case"[object String]":return new c(t);case"[object RegExp]":return function(u){var l=new u.constructor(u.source,Ua.exec(u));return l.lastIndex=u.lastIndex,l}(t);case"[object Symbol]":return r=t,di?Object(di.call(r)):{}}}var pi=Yt&&Yt.isMap,Da=pi?vn(pi):function(t){return Rt(t)&&Et(t)=="[object Map]"},mi=Yt&&Yt.isSet,ja=mi?vn(mi):function(t){return Rt(t)&&Et(t)=="[object Set]"},Wo="[object Arguments]",Go="[object Function]",Ko="[object Object]",W={};function Ze(t,e,n,r,i,o){var s;if(s!==void 0)return s;if(!At(t))return t;var a=D(t);if(a)return s=function(f){var d=f.length,E=new f.constructor(d);return d&&typeof f[0]=="string"&&Ma.call(f,"index")&&(E.index=f.index,E.input=f.input),E}(t),function(f,d){var E=-1,I=f.length;for(d||(d=Array(I));++E<I;)d[E]=f[E];return d}(t,s);var c=Et(t),u=c==Go||c=="[object GeneratorFunction]";if(be(t))return function(f){var d=f.length,E=oi?oi(d):new f.constructor(d);return f.copy(E),E}(t);if(c==Ko||c==Wo||u&&!i)return s=u?{}:function(f){return typeof f.constructor!="function"||De(f)?{}:na(Fo(f))}(t),function(f,d){return or(f,kr(f),d)}(t,function(f,d){return f&&or(d,It(d),f)}(s,t));if(!W[c])return i?t:{};s=Fa(t,c),o||(o=new Ct);var l=o.get(t);if(l)return l;o.set(t,s),ja(t)?t.forEach(function(f){s.add(Ze(f,e,n,f,t,o))}):Da(t)&&t.forEach(function(f,d){s.set(d,Ze(f,e,n,d,t,o))});var h=a?void 0:sr(t);return So(h||t,function(f,d){h&&(f=t[d=f]),In(s,d,Ze(f,e,n,d,t,o))}),s}W[Wo]=W["[object Array]"]=W["[object ArrayBuffer]"]=W["[object DataView]"]=W["[object Boolean]"]=W["[object Date]"]=W["[object Float32Array]"]=W["[object Float64Array]"]=W["[object Int8Array]"]=W["[object Int16Array]"]=W["[object Int32Array]"]=W["[object Map]"]=W["[object Number]"]=W[Ko]=W["[object RegExp]"]=W["[object Set]"]=W["[object String]"]=W["[object Symbol]"]=W["[object Uint8Array]"]=W["[object Uint8ClampedArray]"]=W["[object Uint16Array]"]=W["[object Uint32Array]"]=!0,W["[object Error]"]=W[Go]=W["[object WeakMap]"]=!1;function nt(t){return Ze(t,4)}function Be(t){for(var e=-1,n=t==null?0:t.length,r=0,i=[];++e<n;){var o=t[e];o&&(i[r++]=o)}return i}function he(t){var e=-1,n=t==null?0:t.length;for(this.__data__=new Gt;++e<n;)this.add(t[e])}function zo(t,e){for(var n=-1,r=t==null?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1}function br(t,e){return t.has(e)}he.prototype.add=he.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},he.prototype.has=function(t){return this.__data__.has(t)};function Ei(t,e,n,r,i,o){var s=1&n,a=t.length,c=e.length;if(a!=c&&!(s&&c>a))return!1;var u=o.get(t),l=o.get(e);if(u&&l)return u==e&&l==t;var h=-1,f=!0,d=2&n?new he:void 0;for(o.set(t,e),o.set(e,t);++h<a;){var E=t[h],I=e[h];if(r)var S=s?r(I,E,h,e,t,o):r(E,I,h,t,e,o);if(S!==void 0){if(S)continue;f=!1;break}if(d){if(!zo(e,function(T,m){if(!br(d,m)&&(E===T||i(E,T,n,r,o)))return d.push(m)})){f=!1;break}}else if(E!==I&&!i(E,I,n,r,o)){f=!1;break}}return o.delete(t),o.delete(e),f}function Ba(t){var e=-1,n=Array(t.size);return t.forEach(function(r,i){n[++e]=[i,r]}),n}function Pr(t){var e=-1,n=Array(t.size);return t.forEach(function(r){n[++e]=r}),n}var gi=Tt?Tt.prototype:void 0,Un=gi?gi.valueOf:void 0,$a=Object.prototype.hasOwnProperty,Ti="[object Arguments]",Ai="[object Array]",Ke="[object Object]",Ii=Object.prototype.hasOwnProperty;function Wa(t,e,n,r,i,o){var s=D(t),a=D(e),c=s?Ai:Et(t),u=a?Ai:Et(e),l=(c=c==Ti?Ke:c)==Ke,h=(u=u==Ti?Ke:u)==Ke,f=c==u;if(f&&be(t)){if(!be(e))return!1;s=!0,l=!1}if(f&&!l)return o||(o=new Ct),s||Rr(t)?Ei(t,e,n,r,i,o):function(T,m,p,A,O,g,R){switch(p){case"[object DataView]":if(T.byteLength!=m.byteLength||T.byteOffset!=m.byteOffset)return!1;T=T.buffer,m=m.buffer;case"[object ArrayBuffer]":return!(T.byteLength!=m.byteLength||!g(new sn(T),new sn(m)));case"[object Boolean]":case"[object Date]":case"[object Number]":return Fe(+T,+m);case"[object Error]":return T.name==m.name&&T.message==m.message;case"[object RegExp]":case"[object String]":return T==m+"";case"[object Map]":var v=Ba;case"[object Set]":var y=1&A;if(v||(v=Pr),T.size!=m.size&&!y)return!1;var N=R.get(T);if(N)return N==m;A|=2,R.set(T,m);var U=Ei(v(T),v(m),A,O,g,R);return R.delete(T),U;case"[object Symbol]":if(Un)return Un.call(T)==Un.call(m)}return!1}(t,e,c,n,r,i,o);if(!(1&n)){var d=l&&Ii.call(t,"__wrapped__"),E=h&&Ii.call(e,"__wrapped__");if(d||E){var I=d?t.value():t,S=E?e.value():e;return o||(o=new Ct),i(I,S,n,r,o)}}return!!f&&(o||(o=new Ct),function(T,m,p,A,O,g){var R=1&p,v=sr(T),y=v.length;if(y!=sr(m).length&&!R)return!1;for(var N=y;N--;){var U=v[N];if(!(R?U in m:$a.call(m,U)))return!1}var M=g.get(T),F=g.get(m);if(M&&F)return M==m&&F==T;var $=!0;g.set(T,m),g.set(m,T);for(var x=R;++N<y;){var C=T[U=v[N]],j=m[U];if(A)var q=R?A(j,C,U,m,T,g):A(C,j,U,T,m,g);if(!(q===void 0?C===j||O(C,j,p,A,g):q)){$=!1;break}x||(x=U=="constructor")}if($&&!x){var B=T.constructor,rt=m.constructor;B==rt||!("constructor"in T)||!("constructor"in m)||typeof B=="function"&&B instanceof B&&typeof rt=="function"&&rt instanceof rt||($=!1)}return g.delete(T),g.delete(m),$}(t,e,n,r,i,o))}function wr(t,e,n,r,i){return t===e||(t==null||e==null||!Rt(t)&&!Rt(e)?t!=t&&e!=e:Wa(t,e,n,r,wr,i))}function Vo(t){return t==t&&!At(t)}function Ho(t,e){return function(n){return n!=null&&n[t]===e&&(e!==void 0||t in Object(n))}}function Ga(t){var e=function(n){for(var r=It(n),i=r.length;i--;){var o=r[i],s=n[o];r[i]=[o,s,Vo(s)]}return r}(t);return e.length==1&&e[0][2]?Ho(e[0][0],e[0][1]):function(n){return n===t||function(r,i,o,s){var a=o.length,c=a;if(r==null)return!c;for(r=Object(r);a--;){var u=o[a];if(u[2]?u[1]!==r[u[0]]:!(u[0]in r))return!1}for(;++a<c;){var l=(u=o[a])[0],h=r[l],f=u[1];if(u[2]){if(h===void 0&&!(l in r))return!1}else if(!wr(f,h,3,s,new Ct))return!1}return!0}(n,0,e)}}function Ka(t,e){return t!=null&&e in Object(t)}function Yo(t,e,n){for(var r=-1,i=(e=Nn(e,t)).length,o=!1;++r<i;){var s=je(e[r]);if(!(o=t!=null&&n(t,s)))break;t=t[s]}return o||++r!=i?o:!!(i=t==null?0:t.length)&&Nr(i)&&An(s,i)&&(D(t)||yn(t))}function za(t,e){return Or(t)&&Vo(e)?Ho(je(t),e):function(n){var r=function(i,o,s){var a=i==null?void 0:_r(i,o);return a===void 0?s:a}(n,t);return r===void 0&&r===e?function(i,o){return i!=null&&Yo(i,o,Ka)}(n,t):wr(e,r,3)}}function Va(t){return Or(t)?(e=je(t),function(n){return n?.[e]}):function(n){return function(r){return _r(r,n)}}(t);var e}function kt(t){return typeof t=="function"?t:t==null?fe:typeof t=="object"?D(t)?za(t[0],t[1]):Ga(t):Va(t)}function Ha(t,e,n,r){for(var i=-1,o=t==null?0:t.length;++i<o;){var s=t[i];e(r,s,n(s),t)}return r}var Ya=function(t,e,n){for(var r=-1,i=Object(t),o=n(t),s=o.length;s--;){var a=o[++r];if(e(i[a],a,i)===!1)break}return t},yi,oe=(yi=function(t,e){return t&&Ya(t,e,It)},function(t,e){if(t==null)return t;if(!Pt(t))return yi(t,e);for(var n=t.length,r=-1,i=Object(t);++r<n&&e(i[r],r,i)!==!1;);return t});function Xa(t,e,n,r){return oe(t,function(i,o,s){e(r,i,n(i),s)}),r}var Xo=Object.prototype,qa=Xo.hasOwnProperty,Mr=vr(function(t,e){t=Object(t);var n=-1,r=e.length,i=r>2?e[2]:void 0;for(i&&xo(e[0],e[1],i)&&(r=1);++n<r;)for(var o=e[n],s=Uo(o),a=-1,c=s.length;++a<c;){var u=s[a],l=t[u];(l===void 0||Fe(l,Xo[u])&&!qa.call(t,u))&&(t[u]=o[u])}return t});function vi(t){return Rt(t)&&Pt(t)}var an=vr(function(t,e){return vi(t)?function(n,r,i,o){var s=-1,a=Lo,c=!0,u=n.length,l=[],h=r.length;if(!u)return l;r.length>=200&&(a=br,c=!1,r=new he(r));t:for(;++s<u;){var f=n[s],d=f;if(f=f!==0?f:0,c&&d==d){for(var E=h;E--;)if(r[E]===d)continue t;l.push(f)}else a(r,d,o)||l.push(f)}return l}(t,xr(e,0,vi,!0)):[]});function de(t){var e=t==null?0:t.length;return e?t[e-1]:void 0}function et(t,e,n){var r=t==null?0:t.length;return r?Do(t,(e=e===void 0?1:Tn(e))<0?0:e,r):[]}function we(t,e,n){var r=t==null?0:t.length;return r?Do(t,0,(e=r-(e=e===void 0?1:Tn(e)))<0?0:e):[]}function k(t,e){var n;return(D(t)?So:oe)(t,typeof(n=e)=="function"?n:fe)}function Za(t,e){for(var n=-1,r=t==null?0:t.length;++n<r;)if(!e(t[n],n,t))return!1;return!0}function Qa(t,e){var n=!0;return oe(t,function(r,i,o){return n=!!e(r,i,o)}),n}function Nt(t,e,n){return(D(t)?Za:Qa)(t,kt(e))}function qo(t,e){var n=[];return oe(t,function(r,i,o){e(r,i,o)&&n.push(r)}),n}function mt(t,e){return(D(t)?Cr:qo)(t,kt(e))}var Ja=Math.max,Ni,pe=(Ni=function(t,e,n){var r=t==null?0:t.length;if(!r)return-1;var i=n==null?0:Tn(n);return i<0&&(i=Ja(r+i,0)),_o(t,kt(e),i)},function(t,e,n){var r=Object(t);if(!Pt(t)){var i=kt(e);t=It(t),e=function(s){return i(r[s],s,r)}}var o=Ni(t,e,n);return o>-1?r[i?t[o]:o]:void 0});function Ot(t){return t&&t.length?t[0]:void 0}function tc(t,e){var n=-1,r=Pt(t)?Array(t.length):[];return oe(t,function(i,o,s){r[++n]=e(i,o,s)}),r}function _(t,e){return(D(t)?gn:tc)(t,kt(e))}function gt(t,e){return xr(_(t,e))}var Ri,Oi,ec=Object.prototype.hasOwnProperty,nc=(Ri=function(t,e,n){ec.call(t,n)?t[n].push(e):yr(t,n,[e])},function(t,e){var n=D(t)?Ha:Xa,r=Oi?Oi():{};return n(t,Ri,kt(e),r)}),rc=Object.prototype.hasOwnProperty;function ic(t,e){return t!=null&&rc.call(t,e)}function L(t,e){return t!=null&&Yo(t,e,ic)}function ut(t){return typeof t=="string"||!D(t)&&Rt(t)&&qt(t)=="[object String]"}function J(t){return t==null?[]:function(e,n){return gn(n,function(r){return e[r]})}(t,It(t))}var oc=Math.max;function st(t,e,n,r){t=Pt(t)?t:J(t),n=n?Tn(n):0;var i=t.length;return n<0&&(n=oc(i+n,0)),ut(t)?n<=i&&t.indexOf(e,n)>-1:!!i&&Ir(t,e,n)>-1}function Si(t,e,n){return t!=null&&t.length?Ir(t,e,0):-1}var sc=Object.prototype.hasOwnProperty;function K(t){if(t==null)return!0;if(Pt(t)&&(D(t)||typeof t=="string"||typeof t.splice=="function"||be(t)||Rr(t)||yn(t)))return!t.length;var e=Et(t);if(e=="[object Map]"||e=="[object Set]")return!t.size;if(De(t))return!Mo(t).length;for(var n in t)if(sc.call(t,n))return!1;return!0}var _i=Yt&&Yt.isRegExp,Kt=_i?vn(_i):function(t){return Rt(t)&&qt(t)=="[object RegExp]"};function zt(t){return t===void 0}function ac(t,e,n,r){if(!At(t))return t;for(var i=-1,o=(e=Nn(e,t)).length,s=o-1,a=t;a!=null&&++i<o;){var c=je(e[i]),u=n;if(c==="__proto__"||c==="constructor"||c==="prototype")return t;if(i!=s){var l=a[c];(u=void 0)==void 0&&(u=At(l)?l:An(e[i+1])?[]:{})}In(a,c,u),a=a[c]}return t}function St(t,e){if(t==null)return{};var n=gn(function(r){return $o(r,Uo,xa)}(t),function(r){return[r]});return e=kt(e),function(r,i,o){for(var s=-1,a=i.length,c={};++s<a;){var u=i[s],l=_r(r,u);o(l,u)&&ac(c,Nn(u,r),l)}return c}(t,n,function(r,i){return e(r,i[0])})}function cc(t,e,n,r,i){return i(t,function(o,s,a){n=r?(r=!1,o):e(n,o,s,a)}),n}function dt(t,e,n){var r=D(t)?_a:cc,i=arguments.length<3;return r(t,kt(e),n,i,oe)}function Rn(t,e){return(D(t)?Cr:qo)(t,function(n){if(typeof n!="function")throw new TypeError("Expected a function");return function(){var r=arguments;switch(r.length){case 0:return!n.call(this);case 1:return!n.call(this,r[0]);case 2:return!n.call(this,r[0],r[1]);case 3:return!n.call(this,r[0],r[1],r[2])}return!n.apply(this,r)}}(kt(e)))}function uc(t,e){var n;return oe(t,function(r,i,o){return!(n=e(r,i,o))}),!!n}function Zo(t,e,n){return(D(t)?zo:uc)(t,kt(e))}var lc=le&&1/Pr(new le([,-0]))[1]==1/0?function(t){return new le(t)}:Q;function ur(t){return t&&t.length?function(e,n,r){var i=-1,o=Lo,s=e.length,a=!0,c=[],u=c;if(s>=200){var l=lc(e);if(l)return Pr(l);a=!1,o=br,u=new he}else u=c;t:for(;++i<s;){var h=e[i],f=h;if(h=h!==0?h:0,a&&f==f){for(var d=u.length;d--;)if(u[d]===f)continue t;c.push(h)}else o(u,f,r)||(u!==c&&u.push(f),c.push(h))}return c}(t):[]}function lr(t){console&&console.error&&console.error(`Error: ${t}`)}function Qo(t){console&&console.warn&&console.warn(`Warning: ${t}`)}function Jo(t){const e=new Date().getTime(),n=t();return{time:new Date().getTime()-e,value:n}}function ts(t){function e(){}e.prototype=t;const n=new e;function r(){return typeof n.bar}return r(),r(),t}function hc(t){return ut((e=t).LABEL)&&e.LABEL!==""?t.LABEL:t.name;var e}class wt{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){this._definition=e}accept(e){e.visit(this),k(this.definition,n=>{n.accept(e)})}}class pt extends wt{constructor(e){super([]),this.idx=1,ft(this,St(e,n=>n!==void 0))}set definition(e){}get definition(){return this.referencedRule!==void 0?this.referencedRule.definition:[]}accept(e){e.visit(this)}}class me extends wt{constructor(e){super(e.definition),this.orgText="",ft(this,St(e,n=>n!==void 0))}}class ht extends wt{constructor(e){super(e.definition),this.ignoreAmbiguities=!1,ft(this,St(e,n=>n!==void 0))}}class lt extends wt{constructor(e){super(e.definition),this.idx=1,ft(this,St(e,n=>n!==void 0))}}class Mt extends wt{constructor(e){super(e.definition),this.idx=1,ft(this,St(e,n=>n!==void 0))}}class Ut extends wt{constructor(e){super(e.definition),this.idx=1,ft(this,St(e,n=>n!==void 0))}}class tt extends wt{constructor(e){super(e.definition),this.idx=1,ft(this,St(e,n=>n!==void 0))}}class _t extends wt{constructor(e){super(e.definition),this.idx=1,ft(this,St(e,n=>n!==void 0))}}class Lt extends wt{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){super(e.definition),this.idx=1,this.ignoreAmbiguities=!1,this.hasPredicates=!1,ft(this,St(e,n=>n!==void 0))}}class V{constructor(e){this.idx=1,ft(this,St(e,n=>n!==void 0))}accept(e){e.visit(this)}}function Qe(t){function e(n){return _(n,Qe)}if(t instanceof pt){const n={type:"NonTerminal",name:t.nonTerminalName,idx:t.idx};return ut(t.label)&&(n.label=t.label),n}if(t instanceof ht)return{type:"Alternative",definition:e(t.definition)};if(t instanceof lt)return{type:"Option",idx:t.idx,definition:e(t.definition)};if(t instanceof Mt)return{type:"RepetitionMandatory",idx:t.idx,definition:e(t.definition)};if(t instanceof Ut)return{type:"RepetitionMandatoryWithSeparator",idx:t.idx,separator:Qe(new V({terminalType:t.separator})),definition:e(t.definition)};if(t instanceof _t)return{type:"RepetitionWithSeparator",idx:t.idx,separator:Qe(new V({terminalType:t.separator})),definition:e(t.definition)};if(t instanceof tt)return{type:"Repetition",idx:t.idx,definition:e(t.definition)};if(t instanceof Lt)return{type:"Alternation",idx:t.idx,definition:e(t.definition)};if(t instanceof V){const n={type:"Terminal",name:t.terminalType.name,label:hc(t.terminalType),idx:t.idx};ut(t.label)&&(n.terminalLabel=t.label);const r=t.terminalType.PATTERN;return t.terminalType.PATTERN&&(n.pattern=Kt(r)?r.source:r),n}if(t instanceof me)return{type:"Rule",name:t.name,orgText:t.orgText,definition:e(t.definition)};throw Error("non exhaustive match")}class Ee{visit(e){const n=e;switch(n.constructor){case pt:return this.visitNonTerminal(n);case ht:return this.visitAlternative(n);case lt:return this.visitOption(n);case Mt:return this.visitRepetitionMandatory(n);case Ut:return this.visitRepetitionMandatoryWithSeparator(n);case _t:return this.visitRepetitionWithSeparator(n);case tt:return this.visitRepetition(n);case Lt:return this.visitAlternation(n);case V:return this.visitTerminal(n);case me:return this.visitRule(n);default:throw Error("non exhaustive match")}}visitNonTerminal(e){}visitAlternative(e){}visitOption(e){}visitRepetition(e){}visitRepetitionMandatory(e){}visitRepetitionMandatoryWithSeparator(e){}visitRepetitionWithSeparator(e){}visitAlternation(e){}visitTerminal(e){}visitRule(e){}}function cn(t,e=[]){return t instanceof lt||t instanceof tt||t instanceof _t||(t instanceof Lt?Zo(t.definition,n=>cn(n,e)):!(t instanceof pt&&st(e,t))&&t instanceof wt&&(t instanceof pt&&e.push(t),Nt(t.definition,n=>cn(n,e))))}function xt(t){if(t instanceof pt)return"SUBRULE";if(t instanceof lt)return"OPTION";if(t instanceof Lt)return"OR";if(t instanceof Mt)return"AT_LEAST_ONE";if(t instanceof Ut)return"AT_LEAST_ONE_SEP";if(t instanceof _t)return"MANY_SEP";if(t instanceof tt)return"MANY";if(t instanceof V)return"CONSUME";throw Error("non exhaustive match")}class On{walk(e,n=[]){k(e.definition,(r,i)=>{const o=et(e.definition,i+1);if(r instanceof pt)this.walkProdRef(r,o,n);else if(r instanceof V)this.walkTerminal(r,o,n);else if(r instanceof ht)this.walkFlat(r,o,n);else if(r instanceof lt)this.walkOption(r,o,n);else if(r instanceof Mt)this.walkAtLeastOne(r,o,n);else if(r instanceof Ut)this.walkAtLeastOneSep(r,o,n);else if(r instanceof _t)this.walkManySep(r,o,n);else if(r instanceof tt)this.walkMany(r,o,n);else{if(!(r instanceof Lt))throw Error("non exhaustive match");this.walkOr(r,o,n)}})}walkTerminal(e,n,r){}walkProdRef(e,n,r){}walkFlat(e,n,r){const i=n.concat(r);this.walk(e,i)}walkOption(e,n,r){const i=n.concat(r);this.walk(e,i)}walkAtLeastOne(e,n,r){const i=[new lt({definition:e.definition})].concat(n,r);this.walk(e,i)}walkAtLeastOneSep(e,n,r){const i=Li(e,n,r);this.walk(e,i)}walkMany(e,n,r){const i=[new lt({definition:e.definition})].concat(n,r);this.walk(e,i)}walkManySep(e,n,r){const i=Li(e,n,r);this.walk(e,i)}walkOr(e,n,r){const i=n.concat(r);k(e.definition,o=>{const s=new ht({definition:[o]});this.walk(s,i)})}}function Li(t,e,n){return[new lt({definition:[new V({terminalType:t.separator})].concat(t.definition)})].concat(e,n)}function Le(t){if(t instanceof pt)return Le(t.referencedRule);if(t instanceof V)return[t.terminalType];if(function(e){return e instanceof ht||e instanceof lt||e instanceof tt||e instanceof Mt||e instanceof Ut||e instanceof _t||e instanceof V||e instanceof me}(t))return function(e){let n=[];const r=e.definition;let i,o=0,s=r.length>o,a=!0;for(;s&&a;)i=r[o],a=cn(i),n=n.concat(Le(i)),o+=1,s=r.length>o;return ur(n)}(t);if(function(e){return e instanceof Lt}(t))return function(e){const n=_(e.definition,r=>Le(r));return ur(vt(n))}(t);throw Error("non exhaustive match")}const es="_~IN~_";class fc extends On{constructor(e){super(),this.topProd=e,this.follows={}}startWalking(){return this.walk(this.topProd),this.follows}walkTerminal(e,n,r){}walkProdRef(e,n,r){const i=(o=e.referencedRule,s=e.idx,o.name+s+es+this.topProd.name);var o,s;const a=n.concat(r),c=Le(new ht({definition:a}));this.follows[i]=c}}function b(t){return t.charCodeAt(0)}function Fn(t,e){Array.isArray(t)?t.forEach(function(n){e.push(n)}):e.push(t)}function Ie(t,e){if(t[e]===!0)throw"duplicate flag "+e;t[e],t[e]=!0}function se(t){if(t===void 0)throw Error("Internal Error - Should never get here!");return!0}function xi(t){return t.type==="Character"}const un=[];for(let t=b("0");t<=b("9");t++)un.push(t);const ln=[b("_")].concat(un);for(let t=b("a");t<=b("z");t++)ln.push(t);for(let t=b("A");t<=b("Z");t++)ln.push(t);const Ci=[b(" "),b("\f"),b(`
`),b("\r"),b(" "),b("\v"),b(" "),b(" "),b(" "),b(" "),b(" "),b(" "),b(" "),b(" "),b(" "),b(" "),b(" "),b(" "),b(" "),b(" "),b("\u2028"),b("\u2029"),b(" "),b(" "),b(" "),b("\uFEFF")],dc=/[0-9a-fA-F]/,ze=/[0-9]/,pc=/[1-9]/;class hr{visitChildren(e){for(const n in e){const r=e[n];e.hasOwnProperty(n)&&(r.type!==void 0?this.visit(r):Array.isArray(r)&&r.forEach(i=>{this.visit(i)},this))}}visit(e){switch(e.type){case"Pattern":this.visitPattern(e);break;case"Flags":this.visitFlags(e);break;case"Disjunction":this.visitDisjunction(e);break;case"Alternative":this.visitAlternative(e);break;case"StartAnchor":this.visitStartAnchor(e);break;case"EndAnchor":this.visitEndAnchor(e);break;case"WordBoundary":this.visitWordBoundary(e);break;case"NonWordBoundary":this.visitNonWordBoundary(e);break;case"Lookahead":this.visitLookahead(e);break;case"NegativeLookahead":this.visitNegativeLookahead(e);break;case"Character":this.visitCharacter(e);break;case"Set":this.visitSet(e);break;case"Group":this.visitGroup(e);break;case"GroupBackReference":this.visitGroupBackReference(e);break;case"Quantifier":this.visitQuantifier(e)}this.visitChildren(e)}visitPattern(e){}visitFlags(e){}visitDisjunction(e){}visitAlternative(e){}visitStartAnchor(e){}visitEndAnchor(e){}visitWordBoundary(e){}visitNonWordBoundary(e){}visitLookahead(e){}visitNegativeLookahead(e){}visitCharacter(e){}visitSet(e){}visitGroup(e){}visitGroupBackReference(e){}visitQuantifier(e){}}let Je={};const mc=new class{constructor(){this.idx=0,this.input="",this.groupIdx=0}saveState(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}}restoreState(t){this.idx=t.idx,this.input=t.input,this.groupIdx=t.groupIdx}pattern(t){this.idx=0,this.input=t,this.groupIdx=0,this.consumeChar("/");const e=this.disjunction();this.consumeChar("/");const n={type:"Flags",loc:{begin:this.idx,end:t.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};for(;this.isRegExpFlag();)switch(this.popChar()){case"g":Ie(n,"global");break;case"i":Ie(n,"ignoreCase");break;case"m":Ie(n,"multiLine");break;case"u":Ie(n,"unicode");break;case"y":Ie(n,"sticky")}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:n,value:e,loc:this.loc(0)}}disjunction(){const t=[],e=this.idx;for(t.push(this.alternative());this.peekChar()==="|";)this.consumeChar("|"),t.push(this.alternative());return{type:"Disjunction",value:t,loc:this.loc(e)}}alternative(){const t=[],e=this.idx;for(;this.isTerm();)t.push(this.term());return{type:"Alternative",value:t,loc:this.loc(e)}}term(){return this.isAssertion()?this.assertion():this.atom()}assertion(){const t=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(t)};case"$":return{type:"EndAnchor",loc:this.loc(t)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(t)};case"B":return{type:"NonWordBoundary",loc:this.loc(t)}}throw Error("Invalid Assertion Escape");case"(":let e;switch(this.consumeChar("?"),this.popChar()){case"=":e="Lookahead";break;case"!":e="NegativeLookahead"}se(e);const n=this.disjunction();return this.consumeChar(")"),{type:e,value:n,loc:this.loc(t)}}return function(){throw Error("Internal Error - Should never get here!")}()}quantifier(t=!1){let e;const n=this.idx;switch(this.popChar()){case"*":e={atLeast:0,atMost:1/0};break;case"+":e={atLeast:1,atMost:1/0};break;case"?":e={atLeast:0,atMost:1};break;case"{":const r=this.integerIncludingZero();switch(this.popChar()){case"}":e={atLeast:r,atMost:r};break;case",":let i;this.isDigit()?(i=this.integerIncludingZero(),e={atLeast:r,atMost:i}):e={atLeast:r,atMost:1/0},this.consumeChar("}")}if(t===!0&&e===void 0)return;se(e)}if(t!==!0||e!==void 0)return se(e)?(this.peekChar(0)==="?"?(this.consumeChar("?"),e.greedy=!1):e.greedy=!0,e.type="Quantifier",e.loc=this.loc(n),e):void 0}atom(){let t;const e=this.idx;switch(this.peekChar()){case".":t=this.dotAll();break;case"\\":t=this.atomEscape();break;case"[":t=this.characterClass();break;case"(":t=this.group()}if(t===void 0&&this.isPatternCharacter()&&(t=this.patternCharacter()),se(t))return t.loc=this.loc(e),this.isQuantifier()&&(t.quantifier=this.quantifier()),t}dotAll(){return this.consumeChar("."),{type:"Set",complement:!0,value:[b(`
`),b("\r"),b("\u2028"),b("\u2029")]}}atomEscape(){switch(this.consumeChar("\\"),this.peekChar()){case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return this.decimalEscapeAtom();case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}decimalEscapeAtom(){return{type:"GroupBackReference",value:this.positiveInteger()}}characterClassEscape(){let t,e=!1;switch(this.popChar()){case"d":t=un;break;case"D":t=un,e=!0;break;case"s":t=Ci;break;case"S":t=Ci,e=!0;break;case"w":t=ln;break;case"W":t=ln,e=!0}if(se(t))return{type:"Set",value:t,complement:e}}controlEscapeAtom(){let t;switch(this.popChar()){case"f":t=b("\f");break;case"n":t=b(`
`);break;case"r":t=b("\r");break;case"t":t=b(" ");break;case"v":t=b("\v")}if(se(t))return{type:"Character",value:t}}controlLetterEscapeAtom(){this.consumeChar("c");const t=this.popChar();if(/[a-zA-Z]/.test(t)===!1)throw Error("Invalid ");return{type:"Character",value:t.toUpperCase().charCodeAt(0)-64}}nulCharacterAtom(){return this.consumeChar("0"),{type:"Character",value:b("\0")}}hexEscapeSequenceAtom(){return this.consumeChar("x"),this.parseHexDigits(2)}regExpUnicodeEscapeSequenceAtom(){return this.consumeChar("u"),this.parseHexDigits(4)}identityEscapeAtom(){return{type:"Character",value:b(this.popChar())}}classPatternCharacterAtom(){switch(this.peekChar()){case`
`:case"\r":case"\u2028":case"\u2029":case"\\":case"]":throw Error("TBD");default:return{type:"Character",value:b(this.popChar())}}}characterClass(){const t=[];let e=!1;for(this.consumeChar("["),this.peekChar(0)==="^"&&(this.consumeChar("^"),e=!0);this.isClassAtom();){const n=this.classAtom();if(n.type,xi(n)&&this.isRangeDash()){this.consumeChar("-");const r=this.classAtom();if(r.type,xi(r)){if(r.value<n.value)throw Error("Range out of order in character class");t.push({from:n.value,to:r.value})}else Fn(n.value,t),t.push(b("-")),Fn(r.value,t)}else Fn(n.value,t)}return this.consumeChar("]"),{type:"Set",complement:e,value:t}}classAtom(){switch(this.peekChar()){case"]":case`
`:case"\r":case"\u2028":case"\u2029":throw Error("TBD");case"\\":return this.classEscape();default:return this.classPatternCharacterAtom()}}classEscape(){switch(this.consumeChar("\\"),this.peekChar()){case"b":return this.consumeChar("b"),{type:"Character",value:b("\b")};case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}group(){let t=!0;this.consumeChar("("),this.peekChar(0)==="?"?(this.consumeChar("?"),this.consumeChar(":"),t=!1):this.groupIdx++;const e=this.disjunction();this.consumeChar(")");const n={type:"Group",capturing:t,value:e};return t&&(n.idx=this.groupIdx),n}positiveInteger(){let t=this.popChar();if(pc.test(t)===!1)throw Error("Expecting a positive integer");for(;ze.test(this.peekChar(0));)t+=this.popChar();return parseInt(t,10)}integerIncludingZero(){let t=this.popChar();if(ze.test(t)===!1)throw Error("Expecting an integer");for(;ze.test(this.peekChar(0));)t+=this.popChar();return parseInt(t,10)}patternCharacter(){const t=this.popChar();switch(t){case`
`:case"\r":case"\u2028":case"\u2029":case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":throw Error("TBD");default:return{type:"Character",value:b(t)}}}isRegExpFlag(){switch(this.peekChar(0)){case"g":case"i":case"m":case"u":case"y":return!0;default:return!1}}isRangeDash(){return this.peekChar()==="-"&&this.isClassAtom(1)}isDigit(){return ze.test(this.peekChar(0))}isClassAtom(t=0){switch(this.peekChar(t)){case"]":case`
`:case"\r":case"\u2028":case"\u2029":return!1;default:return!0}}isTerm(){return this.isAtom()||this.isAssertion()}isAtom(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case".":case"\\":case"[":case"(":return!0;default:return!1}}isAssertion(){switch(this.peekChar(0)){case"^":case"$":return!0;case"\\":switch(this.peekChar(1)){case"b":case"B":return!0;default:return!1}case"(":return this.peekChar(1)==="?"&&(this.peekChar(2)==="="||this.peekChar(2)==="!");default:return!1}}isQuantifier(){const t=this.saveState();try{return this.quantifier(!0)!==void 0}catch{return!1}finally{this.restoreState(t)}}isPatternCharacter(){switch(this.peekChar()){case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":case"/":case`
`:case"\r":case"\u2028":case"\u2029":return!1;default:return!0}}parseHexDigits(t){let e="";for(let n=0;n<t;n++){const r=this.popChar();if(dc.test(r)===!1)throw Error("Expecting a HexDecimal digits");e+=r}return{type:"Character",value:parseInt(e,16)}}peekChar(t=0){return this.input[this.idx+t]}popChar(){const t=this.peekChar(0);return this.consumeChar(void 0),t}consumeChar(t){if(t!==void 0&&this.input[this.idx]!==t)throw Error("Expected: '"+t+"' but found: '"+this.input[this.idx]+"' at offset: "+this.idx);if(this.idx>=this.input.length)throw Error("Unexpected end of input");this.idx++}loc(t){return{begin:t,end:this.idx}}};function hn(t){const e=t.toString();if(Je.hasOwnProperty(e))return Je[e];{const n=mc.pattern(e);return Je[e]=n,n}}const ns="Complement Sets are not supported for first char optimization",fn=`Unable to use "first char" lexer optimizations:
`;function Ec(t,e=!1){try{const n=hn(t);return fr(n.value,{},n.flags.ignoreCase)}catch(n){if(n.message===ns)e&&Qo(`${fn} Unable to optimize: < ${t.toString()} >
Complement Sets cannot be automatically optimized.
This will disable the lexer's first char optimizations.
See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.`);else{let r="";e&&(r=`
This will disable the lexer's first char optimizations.
See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details.`),lr(`${fn}
Failed parsing: < ${t.toString()} >
Using the @chevrotain/regexp-to-ast library
Please open an issue at: https://github.com/chevrotain/chevrotain/issues`+r)}}return[]}function fr(t,e,n){switch(t.type){case"Disjunction":for(let i=0;i<t.value.length;i++)fr(t.value[i],e,n);break;case"Alternative":const r=t.value;for(let i=0;i<r.length;i++){const o=r[i];switch(o.type){case"EndAnchor":case"GroupBackReference":case"Lookahead":case"NegativeLookahead":case"StartAnchor":case"WordBoundary":case"NonWordBoundary":continue}const s=o;switch(s.type){case"Character":Ve(s.value,e,n);break;case"Set":if(s.complement===!0)throw Error(ns);k(s.value,c=>{if(typeof c=="number")Ve(c,e,n);else{const u=c;if(n===!0)for(let l=u.from;l<=u.to;l++)Ve(l,e,n);else{for(let l=u.from;l<=u.to&&l<Re;l++)Ve(l,e,n);if(u.to>=Re){const l=u.from>=Re?u.from:Re,h=u.to,f=Ht(l),d=Ht(h);for(let E=f;E<=d;E++)e[E]=E}}}});break;case"Group":fr(s.value,e,n);break;default:throw Error("Non Exhaustive Match")}const a=s.quantifier!==void 0&&s.quantifier.atLeast===0;if(s.type==="Group"&&dr(s)===!1||s.type!=="Group"&&a===!1)break}break;default:throw Error("non exhaustive match!")}return J(e)}function Ve(t,e,n){const r=Ht(t);e[r]=r,n===!0&&function(i,o){const s=String.fromCharCode(i),a=s.toUpperCase();if(a!==s){const c=Ht(a.charCodeAt(0));o[c]=c}else{const c=s.toLowerCase();if(c!==s){const u=Ht(c.charCodeAt(0));o[u]=u}}}(t,e)}function ki(t,e){return pe(t.value,n=>{if(typeof n=="number")return st(e,n);{const r=n;return pe(e,i=>r.from<=i&&i<=r.to)!==void 0}})}function dr(t){const e=t.quantifier;return!(!e||e.atLeast!==0)||!!t.value&&(D(t.value)?Nt(t.value,dr):dr(t.value))}class gc extends hr{constructor(e){super(),this.targetCharCodes=e,this.found=!1}visitChildren(e){if(this.found!==!0){switch(e.type){case"Lookahead":return void this.visitLookahead(e);case"NegativeLookahead":return void this.visitNegativeLookahead(e)}super.visitChildren(e)}}visitCharacter(e){st(this.targetCharCodes,e.value)&&(this.found=!0)}visitSet(e){e.complement?ki(e,this.targetCharCodes)===void 0&&(this.found=!0):ki(e,this.targetCharCodes)!==void 0&&(this.found=!0)}}function Ur(t,e){if(e instanceof RegExp){const n=hn(e),r=new gc(t);return r.visit(n),r.found}return pe(e,n=>st(t,n.charCodeAt(0)))!==void 0}const te="PATTERN",ye="defaultMode",Dn="modes";let rs=typeof new RegExp("(?:)").sticky=="boolean";function Tc(t,e){const n=(e=Mr(e,{useSticky:rs,debug:!1,safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r",`
`],tracer:(m,p)=>p()})).tracer;let r;n("initCharCodeToOptimizedIndexMap",()=>{(function(){if(K(tn)){tn=new Array(65536);for(let m=0;m<65536;m++)tn[m]=m>255?255+~~(m/255):m}})()}),n("Reject Lexer.NA",()=>{r=Rn(t,m=>m[te]===ct.NA)});let i,o,s,a,c,u,l,h,f,d,E,I=!1;n("Transform Patterns",()=>{I=!1,i=_(r,m=>{const p=m[te];if(Kt(p)){const A=p.source;return A.length!==1||A==="^"||A==="$"||A==="."||p.ignoreCase?A.length!==2||A[0]!=="\\"||st(["d","D","s","S","t","r","n","t","0","c","b","B","f","v","w","W"],A[1])?e.useSticky?Pi(p):bi(p):A[1]:A}if(Vt(p))return I=!0,{exec:p};if(typeof p=="object")return I=!0,p;if(typeof p=="string"){if(p.length===1)return p;{const A=p.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&"),O=new RegExp(A);return e.useSticky?Pi(O):bi(O)}}throw Error("non exhaustive match")})}),n("misc mapping",()=>{o=_(r,m=>m.tokenTypeIdx),s=_(r,m=>{const p=m.GROUP;if(p!==ct.SKIPPED){if(ut(p))return p;if(zt(p))return!1;throw Error("non exhaustive match")}}),a=_(r,m=>{const p=m.LONGER_ALT;if(p)return D(p)?_(p,A=>Si(r,A)):[Si(r,p)]}),c=_(r,m=>m.PUSH_MODE),u=_(r,m=>L(m,"POP_MODE"))}),n("Line Terminator Handling",()=>{const m=ss(e.lineTerminatorCharacters);l=_(r,p=>!1),e.positionTracking!=="onlyOffset"&&(l=_(r,p=>L(p,"LINE_BREAKS")?!!p.LINE_BREAKS:os(p,m)===!1&&Ur(m,p.PATTERN)))}),n("Misc Mapping #2",()=>{h=_(r,is),f=_(i,Nc),d=dt(r,(m,p)=>{const A=p.GROUP;return ut(A)&&A!==ct.SKIPPED&&(m[A]=[]),m},{}),E=_(i,(m,p)=>({pattern:i[p],longerAlt:a[p],canLineTerminator:l[p],isCustom:h[p],short:f[p],group:s[p],push:c[p],pop:u[p],tokenTypeIdx:o[p],tokenType:r[p]}))});let S=!0,T=[];return e.safeMode||n("First Char Optimization",()=>{T=dt(r,(m,p,A)=>{if(typeof p.PATTERN=="string"){const O=Ht(p.PATTERN.charCodeAt(0));jn(m,O,E[A])}else if(D(p.START_CHARS_HINT)){let O;k(p.START_CHARS_HINT,g=>{const R=Ht(typeof g=="string"?g.charCodeAt(0):g);O!==R&&(O=R,jn(m,R,E[A]))})}else if(Kt(p.PATTERN))if(p.PATTERN.unicode)S=!1,e.ensureOptimizations&&lr(`${fn} Unable to analyze < ${p.PATTERN.toString()} > pattern.
The regexp unicode flag is not currently supported by the regexp-to-ast library.
This will disable the lexer's first char optimizations.
For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE`);else{const O=Ec(p.PATTERN,e.ensureOptimizations);K(O)&&(S=!1),k(O,g=>{jn(m,g,E[A])})}else e.ensureOptimizations&&lr(`${fn} TokenType: <${p.name}> is using a custom token pattern without providing <start_chars_hint> parameter.
This will disable the lexer's first char optimizations.
For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE`),S=!1;return m},[])}),{emptyGroups:d,patternIdxToConfig:E,charCodeToPatternIdxToConfig:T,hasCustom:I,canBeOptimized:S}}function Ac(t,e){let n=[];const r=function(s){const a=mt(s,l=>!L(l,te)),c=_(a,l=>({message:"Token Type: ->"+l.name+"<- missing static 'PATTERN' property",type:H.MISSING_PATTERN,tokenTypes:[l]})),u=an(s,a);return{errors:c,valid:u}}(t);n=n.concat(r.errors);const i=function(s){const a=mt(s,l=>{const h=l[te];return!(Kt(h)||Vt(h)||L(h,"exec")||ut(h))}),c=_(a,l=>({message:"Token Type: ->"+l.name+"<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.",type:H.INVALID_PATTERN,tokenTypes:[l]})),u=an(s,a);return{errors:c,valid:u}}(r.valid),o=i.valid;return n=n.concat(i.errors),n=n.concat(function(s){let a=[];const c=mt(s,u=>Kt(u[te]));return a=a.concat(function(u){class l extends hr{constructor(){super(...arguments),this.found=!1}visitEndAnchor(E){this.found=!0}}const h=mt(u,d=>{const E=d.PATTERN;try{const I=hn(E),S=new l;return S.visit(I),S.found}catch{return Ic.test(E.source)}});return _(h,d=>({message:`Unexpected RegExp Anchor Error:
Token Type: ->`+d.name+`<- static 'PATTERN' cannot contain end of input anchor '$'
See chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:H.EOI_ANCHOR_FOUND,tokenTypes:[d]}))}(c)),a=a.concat(function(u){class l extends hr{constructor(){super(...arguments),this.found=!1}visitStartAnchor(E){this.found=!0}}const h=mt(u,d=>{const E=d.PATTERN;try{const I=hn(E),S=new l;return S.visit(I),S.found}catch{return yc.test(E.source)}});return _(h,d=>({message:`Unexpected RegExp Anchor Error:
Token Type: ->`+d.name+`<- static 'PATTERN' cannot contain start of input anchor '^'
See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:H.SOI_ANCHOR_FOUND,tokenTypes:[d]}))}(c)),a=a.concat(function(u){const l=mt(u,f=>{const d=f[te];return d instanceof RegExp&&(d.multiline||d.global)});return _(l,f=>({message:"Token Type: ->"+f.name+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:H.UNSUPPORTED_FLAGS_FOUND,tokenTypes:[f]}))}(c)),a=a.concat(function(u){const l=[];let h=_(u,d=>dt(u,(E,I)=>(d.PATTERN.source!==I.PATTERN.source||st(l,I)||I.PATTERN===ct.NA||(l.push(I),E.push(I)),E),[]));return h=Be(h),_(mt(h,d=>d.length>1),d=>{const E=_(d,I=>I.name);return{message:`The same RegExp pattern ->${Ot(d).PATTERN}<-has been used in all of the following Token Types: ${E.join(", ")} <-`,type:H.DUPLICATE_PATTERNS_FOUND,tokenTypes:d}})}(c)),a=a.concat(function(u){const l=mt(u,f=>f.PATTERN.test(""));return _(l,f=>({message:"Token Type: ->"+f.name+"<- static 'PATTERN' must not match an empty string",type:H.EMPTY_MATCH_PATTERN,tokenTypes:[f]}))}(c)),a}(o)),n=n.concat(function(s){const a=mt(s,u=>{if(!L(u,"GROUP"))return!1;const l=u.GROUP;return l!==ct.SKIPPED&&l!==ct.NA&&!ut(l)});return _(a,u=>({message:"Token Type: ->"+u.name+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:H.INVALID_GROUP_TYPE_FOUND,tokenTypes:[u]}))}(o)),n=n.concat(function(s,a){const c=mt(s,l=>l.PUSH_MODE!==void 0&&!st(a,l.PUSH_MODE));return _(c,l=>({message:`Token Type: ->${l.name}<- static 'PUSH_MODE' value cannot refer to a Lexer Mode ->${l.PUSH_MODE}<-which does not exist`,type:H.PUSH_MODE_DOES_NOT_EXIST,tokenTypes:[l]}))}(o,e)),n=n.concat(function(s){const a=[],c=dt(s,(u,l,h)=>{const f=l.PATTERN;return f===ct.NA||(ut(f)?u.push({str:f,idx:h,tokenType:l}):Kt(f)&&(d=f,pe([".","\\","[","]","|","^","$","(",")","?","*","+","{"],E=>d.source.indexOf(E)!==-1)===void 0)&&u.push({str:f.source,idx:h,tokenType:l})),u;var d},[]);return k(s,(u,l)=>{k(c,({str:h,idx:f,tokenType:d})=>{if(l<f&&function(E,I){if(Kt(I)){const S=I.exec(E);return S!==null&&S.index===0}if(Vt(I))return I(E,0,[],{});if(L(I,"exec"))return I.exec(E,0,[],{});if(typeof I=="string")return I===E;throw Error("non exhaustive match")}(h,u.PATTERN)){const E=`Token: ->${d.name}<- can never be matched.
Because it appears AFTER the Token Type ->${u.name}<-in the lexer's definition.
See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE`;a.push({message:E,type:H.UNREACHABLE_PATTERN,tokenTypes:[u,d]})}})}),a}(o)),n}const Ic=/[^\\][$]/,yc=/[^\\[][\^]|^\^/;function bi(t){const e=t.ignoreCase?"i":"";return new RegExp(`^(?:${t.source})`,e)}function Pi(t){const e=t.ignoreCase?"iy":"y";return new RegExp(`${t.source}`,e)}function vc(t,e,n){const r=[];let i=!1;const o=Rn(Be(vt(J(t.modes))),a=>a[te]===ct.NA),s=ss(n);return e&&k(o,a=>{const c=os(a,s);if(c!==!1){const u=function(h,f){if(f.issue===H.IDENTIFY_TERMINATOR)return`Warning: unable to identify line terminator usage in pattern.
The problem is in the <${h.name}> Token Type
Root cause: ${f.errMsg}.
For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR`;if(f.issue===H.CUSTOM_LINE_BREAK)return`Warning: A Custom Token Pattern should specify the <line_breaks> option.
The problem is in the <${h.name}> Token Type
For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK`;throw Error("non exhaustive match")}(a,c),l={message:u,type:c.issue,tokenType:a};r.push(l)}else L(a,"LINE_BREAKS")?a.LINE_BREAKS===!0&&(i=!0):Ur(s,a.PATTERN)&&(i=!0)}),e&&!i&&r.push({message:`Warning: No LINE_BREAKS Found.
This Lexer has been defined to track line and column information,
But none of the Token Types can be identified as matching a line terminator.
See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS
for details.`,type:H.NO_LINE_BREAKS_FLAGS}),r}function is(t){const e=t.PATTERN;if(Kt(e))return!1;if(Vt(e)||L(e,"exec"))return!0;if(ut(e))return!1;throw Error("non exhaustive match")}function Nc(t){return!(!ut(t)||t.length!==1)&&t.charCodeAt(0)}const Rc={test:function(t){const e=t.length;for(let n=this.lastIndex;n<e;n++){const r=t.charCodeAt(n);if(r===10)return this.lastIndex=n+1,!0;if(r===13)return t.charCodeAt(n+1)===10?this.lastIndex=n+2:this.lastIndex=n+1,!0}return!1},lastIndex:0};function os(t,e){if(L(t,"LINE_BREAKS"))return!1;if(Kt(t.PATTERN)){try{Ur(e,t.PATTERN)}catch(n){return{issue:H.IDENTIFY_TERMINATOR,errMsg:n.message}}return!1}if(ut(t.PATTERN))return!1;if(is(t))return{issue:H.CUSTOM_LINE_BREAK};throw Error("non exhaustive match")}function ss(t){return _(t,e=>ut(e)?e.charCodeAt(0):e)}function jn(t,e,n){t[e]===void 0?t[e]=[n]:t[e].push(n)}const Re=256;let tn=[];function Ht(t){return t<Re?t:tn[t]}function xe(t,e){const n=t.tokenTypeIdx;return n===e.tokenTypeIdx||e.isParent===!0&&e.categoryMatchesMap[n]===!0}function dn(t,e){return t.tokenTypeIdx===e.tokenTypeIdx}let wi=1;const Mi={};function $e(t){const e=function(n){let r=nt(n),i=n,o=!0;for(;o;){i=Be(vt(_(i,a=>a.CATEGORIES)));const s=an(i,r);r=r.concat(s),K(s)?o=!1:i=s}return r}(t);(function(n){k(n,r=>{cs(r)||(Mi[wi]=r,r.tokenTypeIdx=wi++),Ui(r)&&!D(r.CATEGORIES)&&(r.CATEGORIES=[r.CATEGORIES]),Ui(r)||(r.CATEGORIES=[]),L(r,"categoryMatches")||(r.categoryMatches=[]),function(i){return L(i,"categoryMatchesMap")}(r)||(r.categoryMatchesMap={})})})(e),function(n){k(n,r=>{as([],r)})}(e),function(n){k(n,r=>{r.categoryMatches=[],k(r.categoryMatchesMap,(i,o)=>{r.categoryMatches.push(Mi[o].tokenTypeIdx)})})}(e),k(e,n=>{n.isParent=n.categoryMatches.length>0})}function as(t,e){k(t,n=>{e.categoryMatchesMap[n.tokenTypeIdx]=!0}),k(e.CATEGORIES,n=>{const r=t.concat(e);st(r,n)||as(r,n)})}function cs(t){return L(t,"tokenTypeIdx")}function Ui(t){return L(t,"CATEGORIES")}function Oc(t){return L(t,"tokenTypeIdx")}const Sc={buildUnableToPopLexerModeMessage:t=>`Unable to pop Lexer Mode after encountering Token ->${t.image}<- The Mode Stack is empty`,buildUnexpectedCharactersMessage:(t,e,n,r,i)=>`unexpected character: ->${t.charAt(e)}<- at offset: ${e}, skipped ${n} characters.`};var H;(function(t){t[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND",t[t.PUSH_MODE_DOES_NOT_EXIST=6]="PUSH_MODE_DOES_NOT_EXIST",t[t.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]="MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE",t[t.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]="MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY",t[t.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]="MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST",t[t.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]="LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED",t[t.SOI_ANCHOR_FOUND=11]="SOI_ANCHOR_FOUND",t[t.EMPTY_MATCH_PATTERN=12]="EMPTY_MATCH_PATTERN",t[t.NO_LINE_BREAKS_FLAGS=13]="NO_LINE_BREAKS_FLAGS",t[t.UNREACHABLE_PATTERN=14]="UNREACHABLE_PATTERN",t[t.IDENTIFY_TERMINATOR=15]="IDENTIFY_TERMINATOR",t[t.CUSTOM_LINE_BREAK=16]="CUSTOM_LINE_BREAK",t[t.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE=17]="MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE"})(H||(H={}));const Oe={deferDefinitionErrorsHandling:!1,positionTracking:"full",lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:[`
`,"\r"],ensureOptimizations:!1,safeMode:!1,errorMessageProvider:Sc,traceInitPerf:!1,skipValidations:!1,recoveryEnabled:!0};Object.freeze(Oe);class ct{constructor(e,n=Oe){if(this.lexerDefinition=e,this.lexerDefinitionErrors=[],this.lexerDefinitionWarning=[],this.patternIdxToConfig={},this.charCodeToPatternIdxToConfig={},this.modes=[],this.emptyGroups={},this.trackStartLines=!0,this.trackEndLines=!0,this.hasCustom=!1,this.canModeBeOptimized={},this.TRACE_INIT=(i,o)=>{if(this.traceInitPerf===!0){this.traceInitIndent++;const s=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent<this.traceInitMaxIdent&&console.log(`${s}--> <${i}>`);const{time:a,value:c}=Jo(o),u=a>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&u(`${s}<-- <${i}> time: ${a}ms`),this.traceInitIndent--,c}return o()},typeof n=="boolean")throw Error(`The second argument to the Lexer constructor is now an ILexerConfig Object.
a boolean 2nd argument is no longer supported`);this.config=ft({},Oe,n);const r=this.config.traceInitPerf;r===!0?(this.traceInitMaxIdent=1/0,this.traceInitPerf=!0):typeof r=="number"&&(this.traceInitMaxIdent=r,this.traceInitPerf=!0),this.traceInitIndent=-1,this.TRACE_INIT("Lexer Constructor",()=>{let i,o=!0;this.TRACE_INIT("Lexer Config handling",()=>{if(this.config.lineTerminatorsPattern===Oe.lineTerminatorsPattern)this.config.lineTerminatorsPattern=Rc;else if(this.config.lineTerminatorCharacters===Oe.lineTerminatorCharacters)throw Error(`Error: Missing <lineTerminatorCharacters> property on the Lexer config.
For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS`);if(n.safeMode&&n.ensureOptimizations)throw Error('"safeMode" and "ensureOptimizations" flags are mutually exclusive.');this.trackStartLines=/full|onlyStart/i.test(this.config.positionTracking),this.trackEndLines=/full/i.test(this.config.positionTracking),D(e)?i={modes:{defaultMode:nt(e)},defaultMode:ye}:(o=!1,i=nt(e))}),this.config.skipValidations===!1&&(this.TRACE_INIT("performRuntimeChecks",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(function(a){const c=[];return L(a,ye)||c.push({message:"A MultiMode Lexer cannot be initialized without a <"+ye+`> property in its definition
`,type:H.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE}),L(a,Dn)||c.push({message:`A MultiMode Lexer cannot be initialized without a <modes> property in its definition
`,type:H.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY}),L(a,Dn)&&L(a,ye)&&!L(a.modes,a.defaultMode)&&c.push({message:`A MultiMode Lexer cannot be initialized with a ${ye}: <${a.defaultMode}>which does not exist
`,type:H.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST}),L(a,Dn)&&k(a.modes,(u,l)=>{k(u,(h,f)=>{zt(h)?c.push({message:`A Lexer cannot be initialized using an undefined Token Type. Mode:<${l}> at index: <${f}>
`,type:H.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED}):L(h,"LONGER_ALT")&&k(D(h.LONGER_ALT)?h.LONGER_ALT:[h.LONGER_ALT],d=>{zt(d)||st(u,d)||c.push({message:`A MultiMode Lexer cannot be initialized with a longer_alt <${d.name}> on token <${h.name}> outside of mode <${l}>
`,type:H.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE})})})}),c}(i,this.trackStartLines,this.config.lineTerminatorCharacters))}),this.TRACE_INIT("performWarningRuntimeChecks",()=>{this.lexerDefinitionWarning=this.lexerDefinitionWarning.concat(vc(i,this.trackStartLines,this.config.lineTerminatorCharacters))})),i.modes=i.modes?i.modes:{},k(i.modes,(a,c)=>{i.modes[c]=Rn(a,u=>zt(u))});const s=It(i.modes);if(k(i.modes,(a,c)=>{this.TRACE_INIT(`Mode: <${c}> processing`,()=>{if(this.modes.push(c),this.config.skipValidations===!1&&this.TRACE_INIT("validatePatterns",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(Ac(a,s))}),K(this.lexerDefinitionErrors)){let u;$e(a),this.TRACE_INIT("analyzeTokenTypes",()=>{u=Tc(a,{lineTerminatorCharacters:this.config.lineTerminatorCharacters,positionTracking:n.positionTracking,ensureOptimizations:n.ensureOptimizations,safeMode:n.safeMode,tracer:this.TRACE_INIT})}),this.patternIdxToConfig[c]=u.patternIdxToConfig,this.charCodeToPatternIdxToConfig[c]=u.charCodeToPatternIdxToConfig,this.emptyGroups=ft({},this.emptyGroups,u.emptyGroups),this.hasCustom=u.hasCustom||this.hasCustom,this.canModeBeOptimized[c]=u.canBeOptimized}})}),this.defaultMode=i.defaultMode,!K(this.lexerDefinitionErrors)&&!this.config.deferDefinitionErrorsHandling){const a=_(this.lexerDefinitionErrors,c=>c.message).join(`-----------------------
`);throw new Error(`Errors detected in definition of Lexer:
`+a)}k(this.lexerDefinitionWarning,a=>{Qo(a.message)}),this.TRACE_INIT("Choosing sub-methods implementations",()=>{if(rs?(this.chopInput=fe,this.match=this.matchWithTest):(this.updateLastIndex=Q,this.match=this.matchWithExec),o&&(this.handleModes=Q),this.trackStartLines===!1&&(this.computeNewColumn=fe),this.trackEndLines===!1&&(this.updateTokenEndLineColumnLocation=Q),/full/i.test(this.config.positionTracking))this.createTokenInstance=this.createFullToken;else if(/onlyStart/i.test(this.config.positionTracking))this.createTokenInstance=this.createStartOnlyToken;else{if(!/onlyOffset/i.test(this.config.positionTracking))throw Error(`Invalid <positionTracking> config option: "${this.config.positionTracking}"`);this.createTokenInstance=this.createOffsetOnlyToken}this.hasCustom?(this.addToken=this.addTokenUsingPush,this.handlePayload=this.handlePayloadWithCustom):(this.addToken=this.addTokenUsingMemberAccess,this.handlePayload=this.handlePayloadNoCustom)}),this.TRACE_INIT("Failed Optimization Warnings",()=>{const a=dt(this.canModeBeOptimized,(c,u,l)=>(u===!1&&c.push(l),c),[]);if(n.ensureOptimizations&&!K(a))throw Error(`Lexer Modes: < ${a.join(", ")} > cannot be optimized.
Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode.
Or inspect the console log for details on how to resolve these issues.`)}),this.TRACE_INIT("clearRegExpParserCache",()=>{Je={}}),this.TRACE_INIT("toFastProperties",()=>{ts(this)})})}tokenize(e,n=this.defaultMode){if(!K(this.lexerDefinitionErrors)){const r=_(this.lexerDefinitionErrors,i=>i.message).join(`-----------------------
`);throw new Error(`Unable to Tokenize because Errors detected in definition of Lexer:
`+r)}return this.tokenizeInternal(e,n)}tokenizeInternal(e,n){let r,i,o,s,a,c,u,l,h,f,d,E,I,S,T;const m=e,p=m.length;let A=0,O=0;const g=this.hasCustom?0:Math.floor(e.length/10),R=new Array(g),v=[];let y=this.trackStartLines?1:void 0,N=this.trackStartLines?1:void 0;const U=function(Z){const it={};return k(It(Z),Ft=>{const at=Z[Ft];if(!D(at))throw Error("non exhaustive match");it[Ft]=[]}),it}(this.emptyGroups),M=this.trackStartLines,F=this.config.lineTerminatorsPattern;let $=0,x=[],C=[];const j=[],q=[];let B;function rt(){return x}function Zt(Z){const it=Ht(Z),Ft=C[it];return Ft===void 0?q:Ft}Object.freeze(q);const ge=Z=>{if(j.length===1&&Z.tokenType.PUSH_MODE===void 0){const it=this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(Z);v.push({offset:Z.startOffset,line:Z.startLine,column:Z.startColumn,length:Z.image.length,message:it})}else{j.pop();const it=de(j);x=this.patternIdxToConfig[it],C=this.charCodeToPatternIdxToConfig[it],$=x.length;const Ft=this.canModeBeOptimized[it]&&this.config.safeMode===!1;B=C&&Ft?Zt:rt}};function $r(Z){j.push(Z),C=this.charCodeToPatternIdxToConfig[Z],x=this.patternIdxToConfig[Z],$=x.length,$=x.length;const it=this.canModeBeOptimized[Z]&&this.config.safeMode===!1;B=C&&it?Zt:rt}let yt;$r.call(this,n);const Wr=this.config.recoveryEnabled;for(;A<p;){c=null;const Z=m.charCodeAt(A),it=B(Z),Ft=it.length;for(r=0;r<Ft;r++){yt=it[r];const at=yt.pattern;u=null;const Dt=yt.short;if(Dt!==!1?Z===Dt&&(c=at):yt.isCustom===!0?(T=at.exec(m,A,R,U),T!==null?(c=T[0],T.payload!==void 0&&(u=T.payload)):c=null):(this.updateLastIndex(at,A),c=this.match(at,e,A)),c!==null){if(a=yt.longerAlt,a!==void 0){const jt=a.length;for(o=0;o<jt;o++){const Bt=x[a[o]],Qt=Bt.pattern;if(l=null,Bt.isCustom===!0?(T=Qt.exec(m,A,R,U),T!==null?(s=T[0],T.payload!==void 0&&(l=T.payload)):s=null):(this.updateLastIndex(Qt,A),s=this.match(Qt,e,A)),s&&s.length>c.length){c=s,u=l,yt=Bt;break}}}break}}if(c!==null){if(h=c.length,f=yt.group,f!==void 0&&(d=yt.tokenTypeIdx,E=this.createTokenInstance(c,A,d,yt.tokenType,y,N,h),this.handlePayload(E,u),f===!1?O=this.addToken(R,O,E):U[f].push(E)),e=this.chopInput(e,h),A+=h,N=this.computeNewColumn(N,h),M===!0&&yt.canLineTerminator===!0){let at,Dt,jt=0;F.lastIndex=0;do at=F.test(c),at===!0&&(Dt=F.lastIndex-1,jt++);while(at===!0);jt!==0&&(y+=jt,N=h-Dt,this.updateTokenEndLineColumnLocation(E,f,Dt,jt,y,N,h))}this.handleModes(yt,ge,$r,E)}else{const at=A,Dt=y,jt=N;let Bt=Wr===!1;for(;Bt===!1&&A<p;)for(e=this.chopInput(e,1),A++,i=0;i<$;i++){const Qt=x[i],Cn=Qt.pattern,Gr=Qt.short;if(Gr!==!1?m.charCodeAt(A)===Gr&&(Bt=!0):Qt.isCustom===!0?Bt=Cn.exec(m,A,R,U)!==null:(this.updateLastIndex(Cn,A),Bt=Cn.exec(e)!==null),Bt===!0)break}if(I=A-at,N=this.computeNewColumn(N,I),S=this.config.errorMessageProvider.buildUnexpectedCharactersMessage(m,at,I,Dt,jt),v.push({offset:at,line:Dt,column:jt,length:I,message:S}),Wr===!1)break}}return this.hasCustom||(R.length=O),{tokens:R,groups:U,errors:v}}handleModes(e,n,r,i){if(e.pop===!0){const o=e.push;n(i),o!==void 0&&r.call(this,o)}else e.push!==void 0&&r.call(this,e.push)}chopInput(e,n){return e.substring(n)}updateLastIndex(e,n){e.lastIndex=n}updateTokenEndLineColumnLocation(e,n,r,i,o,s,a){let c,u;n!==void 0&&(c=r===a-1,u=c?-1:0,i===1&&c===!0||(e.endLine=o+u,e.endColumn=s-1-u))}computeNewColumn(e,n){return e+n}createOffsetOnlyToken(e,n,r,i){return{image:e,startOffset:n,tokenTypeIdx:r,tokenType:i}}createStartOnlyToken(e,n,r,i,o,s){return{image:e,startOffset:n,startLine:o,startColumn:s,tokenTypeIdx:r,tokenType:i}}createFullToken(e,n,r,i,o,s,a){return{image:e,startOffset:n,endOffset:n+a-1,startLine:o,endLine:o,startColumn:s,endColumn:s+a-1,tokenTypeIdx:r,tokenType:i}}addTokenUsingPush(e,n,r){return e.push(r),n}addTokenUsingMemberAccess(e,n,r){return e[n]=r,++n}handlePayloadNoCustom(e,n){}handlePayloadWithCustom(e,n){n!==null&&(e.payload=n)}matchWithTest(e,n,r){return e.test(n)===!0?n.substring(r,e.lastIndex):null}matchWithExec(e,n){const r=e.exec(n);return r!==null?r[0]:null}}function Ce(t){return us(t)?t.LABEL:t.name}function us(t){return ut(t.LABEL)&&t.LABEL!==""}ct.SKIPPED="This marks a skipped Token pattern, this means each token identified by it willbe consumed and then thrown into oblivion, this can be used to for example to completely ignore whitespace.",ct.NA=/NOT_APPLICABLE/;const _c="parent",Fi="categories",Di="label",ji="group",Bi="push_mode",$i="pop_mode",Wi="longer_alt",Gi="line_breaks",Ki="start_chars_hint";function P(t){return function(e){const n=e.pattern,r={};if(r.name=e.name,zt(n)||(r.PATTERN=n),L(e,_c))throw`The parent property is no longer supported.
See: https://github.com/chevrotain/chevrotain/issues/564#issuecomment-349062346 for details.`;return L(e,Fi)&&(r.CATEGORIES=e[Fi]),$e([r]),L(e,Di)&&(r.LABEL=e[Di]),L(e,ji)&&(r.GROUP=e[ji]),L(e,$i)&&(r.POP_MODE=e[$i]),L(e,Bi)&&(r.PUSH_MODE=e[Bi]),L(e,Wi)&&(r.LONGER_ALT=e[Wi]),L(e,Gi)&&(r.LINE_BREAKS=e[Gi]),L(e,Ki)&&(r.START_CHARS_HINT=e[Ki]),r}(t)}const ee=P({name:"EOF",pattern:ct.NA});function Fr(t,e,n,r,i,o,s,a){return{image:e,startOffset:n,endOffset:r,startLine:i,endLine:o,startColumn:s,endColumn:a,tokenTypeIdx:t.tokenTypeIdx,tokenType:t}}$e([ee]);const ls={buildMismatchTokenMessage:({expected:t,actual:e,previous:n,ruleName:r})=>`Expecting ${us(t)?`--> ${Ce(t)} <--`:`token of type --> ${t.name} <--`} but found --> '${e.image}' <--`,buildNotAllInputParsedMessage:({firstRedundant:t,ruleName:e})=>"Redundant input, expecting EOF but found: "+t.image,buildNoViableAltMessage({expectedPathsPerAlt:t,actual:e,previous:n,customUserDescription:r,ruleName:i}){const o="Expecting: ",s=`
but found: '`+Ot(e).image+"'";if(r)return o+r+s;{const a=_(dt(t,(c,u)=>c.concat(u),[]),c=>`[${_(c,u=>Ce(u)).join(", ")}]`);return o+`one of these possible Token sequences:
${_(a,(c,u)=>` ${u+1}. ${c}`).join(`
`)}`+s}},buildEarlyExitMessage({expectedIterationPaths:t,actual:e,customUserDescription:n,ruleName:r}){const i="Expecting: ",o=`
but found: '`+Ot(e).image+"'";return n?i+n+o:i+`expecting at least one iteration which starts with one of these possible Token sequences::
<${_(t,s=>`[${_(s,a=>Ce(a)).join(",")}]`).join(" ,")}>`+o}};Object.freeze(ls);const Lc={buildRuleNotFoundError:(t,e)=>"Invalid grammar, reference to a rule which is not defined: ->"+e.nonTerminalName+`<-
inside top level rule: ->`+t.name+"<-"},ne={buildDuplicateFoundError(t,e){const n=t.name,r=Ot(e),i=r.idx,o=xt(r),s=(a=r)instanceof V?a.terminalType.name:a instanceof pt?a.nonTerminalName:"";var a;let c=`->${o}${i>0?i:""}<- ${s?`with argument: ->${s}<-`:""}
appears more than once (${e.length} times) in the top level rule: ->${n}<-.
For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES
`;return c=c.replace(/[ \t]+/g," "),c=c.replace(/\s\s+/g,`
`),c},buildNamespaceConflictError:t=>`Namespace conflict found in grammar.
The grammar has both a Terminal(Token) and a Non-Terminal(Rule) named: <${t.name}>.
To resolve this make sure each Terminal and Non-Terminal names are unique
This is easy to accomplish by using the convention that Terminal names start with an uppercase letter
and Non-Terminal names start with a lower case letter.`,buildAlternationPrefixAmbiguityError(t){const e=_(t.prefixPath,r=>Ce(r)).join(", "),n=t.alternation.idx===0?"":t.alternation.idx;return`Ambiguous alternatives: <${t.ambiguityIndices.join(" ,")}> due to common lookahead prefix
in <OR${n}> inside <${t.topLevelRule.name}> Rule,
<${e}> may appears as a prefix path in all these alternatives.
See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#COMMON_PREFIX
For Further details.`},buildAlternationAmbiguityError(t){const e=_(t.prefixPath,i=>Ce(i)).join(", "),n=t.alternation.idx===0?"":t.alternation.idx;let r=`Ambiguous Alternatives Detected: <${t.ambiguityIndices.join(" ,")}> in <OR${n}> inside <${t.topLevelRule.name}> Rule,
<${e}> may appears as a prefix path in all these alternatives.
`;return r+=`See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES
For Further details.`,r},buildEmptyRepetitionError(t){let e=xt(t.repetition);return t.repetition.idx!==0&&(e+=t.repetition.idx),`The repetition <${e}> within Rule <${t.topLevelRule.name}> can never consume any tokens.
This could lead to an infinite loop.`},buildTokenNameError:t=>"deprecated",buildEmptyAlternationError:t=>`Ambiguous empty alternative: <${t.emptyChoiceIdx+1}> in <OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
Only the last alternative may be an empty alternative.`,buildTooManyAlternativesError:t=>`An Alternation cannot have more than 256 alternatives:
<OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
has ${t.alternation.definition.length+1} alternatives.`,buildLeftRecursionError(t){const e=t.topLevelRule.name;return`Left Recursion found in grammar.
rule: <${e}> can be invoked from itself (directly or indirectly)
without consuming any Tokens. The grammar path that causes this is:
${`${e} --> ${_(t.leftRecursionPath,n=>n.name).concat([e]).join(" --> ")}`}
To fix this refactor your grammar to remove the left recursion.
see: https://en.wikipedia.org/wiki/LL_parser#Left_factoring.`},buildInvalidRuleNameError:t=>"deprecated",buildDuplicateRuleNameError(t){let e;return e=t.topLevelRule instanceof me?t.topLevelRule.name:t.topLevelRule,`Duplicate definition, rule: ->${e}<- is already defined in the grammar: ->${t.grammarName}<-`}};class xc extends Ee{constructor(e,n){super(),this.nameToTopRule=e,this.errMsgProvider=n,this.errors=[]}resolveRefs(){k(J(this.nameToTopRule),e=>{this.currTopLevel=e,e.accept(this)})}visitNonTerminal(e){const n=this.nameToTopRule[e.nonTerminalName];if(n)e.referencedRule=n;else{const r=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,e);this.errors.push({message:r,type:ot.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:e.nonTerminalName})}}}class Cc extends On{constructor(e,n){super(),this.topProd=e,this.path=n,this.possibleTokTypes=[],this.nextProductionName="",this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}startWalking(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=nt(this.path.ruleStack).reverse(),this.occurrenceStack=nt(this.path.occurrenceStack).reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes}walk(e,n=[]){this.found||super.walk(e,n)}walkProdRef(e,n,r){if(e.referencedRule.name===this.nextProductionName&&e.idx===this.nextProductionOccurrence){const i=n.concat(r);this.updateExpectedNext(),this.walk(e.referencedRule,i)}}updateExpectedNext(){K(this.ruleStack)?(this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())}}class kc extends Cc{constructor(e,n){super(e,n),this.path=n,this.nextTerminalName="",this.nextTerminalOccurrence=0,this.nextTerminalName=this.path.lastTok.name,this.nextTerminalOccurrence=this.path.lastTokOccurrence}walkTerminal(e,n,r){if(this.isAtEndOfPath&&e.terminalType.name===this.nextTerminalName&&e.idx===this.nextTerminalOccurrence&&!this.found){const i=n.concat(r),o=new ht({definition:i});this.possibleTokTypes=Le(o),this.found=!0}}}class Sn extends On{constructor(e,n){super(),this.topRule=e,this.occurrence=n,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}startWalking(){return this.walk(this.topRule),this.result}}class bc extends Sn{walkMany(e,n,r){if(e.idx===this.occurrence){const i=Ot(n.concat(r));this.result.isEndOfRule=i===void 0,i instanceof V&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkMany(e,n,r)}}class zi extends Sn{walkManySep(e,n,r){if(e.idx===this.occurrence){const i=Ot(n.concat(r));this.result.isEndOfRule=i===void 0,i instanceof V&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkManySep(e,n,r)}}class Pc extends Sn{walkAtLeastOne(e,n,r){if(e.idx===this.occurrence){const i=Ot(n.concat(r));this.result.isEndOfRule=i===void 0,i instanceof V&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkAtLeastOne(e,n,r)}}class Vi extends Sn{walkAtLeastOneSep(e,n,r){if(e.idx===this.occurrence){const i=Ot(n.concat(r));this.result.isEndOfRule=i===void 0,i instanceof V&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkAtLeastOneSep(e,n,r)}}function pr(t,e,n=[]){n=nt(n);let r=[],i=0;function o(s){const a=pr(s.concat(et(t,i+1)),e,n);return r.concat(a)}for(;n.length<e&&i<t.length;){const s=t[i];if(s instanceof ht||s instanceof pt)return o(s.definition);if(s instanceof lt)r=o(s.definition);else{if(s instanceof Mt)return o(s.definition.concat([new tt({definition:s.definition})]));if(s instanceof Ut)return o([new ht({definition:s.definition}),new tt({definition:[new V({terminalType:s.separator})].concat(s.definition)})]);if(s instanceof _t){const a=s.definition.concat([new tt({definition:[new V({terminalType:s.separator})].concat(s.definition)})]);r=o(a)}else if(s instanceof tt){const a=s.definition.concat([new tt({definition:s.definition})]);r=o(a)}else{if(s instanceof Lt)return k(s.definition,a=>{K(a.definition)===!1&&(r=o(a.definition))}),r;if(!(s instanceof V))throw Error("non exhaustive match");n.push(s.terminalType)}}i++}return r.push({partialPath:n,suffixDef:et(t,i)}),r}function hs(t,e,n,r){const i="EXIT_NONE_TERMINAL",o=[i],s="EXIT_ALTERNATIVE";let a=!1;const c=e.length,u=c-r-1,l=[],h=[];for(h.push({idx:-1,def:t,ruleStack:[],occurrenceStack:[]});!K(h);){const f=h.pop();if(f===s){a&&de(h).idx<=u&&h.pop();continue}const d=f.def,E=f.idx,I=f.ruleStack,S=f.occurrenceStack;if(K(d))continue;const T=d[0];if(T===i){const m={idx:E,def:et(d),ruleStack:we(I),occurrenceStack:we(S)};h.push(m)}else if(T instanceof V)if(E<c-1){const m=E+1;if(n(e[m],T.terminalType)){const p={idx:m,def:et(d),ruleStack:I,occurrenceStack:S};h.push(p)}}else{if(E!==c-1)throw Error("non exhaustive match");l.push({nextTokenType:T.terminalType,nextTokenOccurrence:T.idx,ruleStack:I,occurrenceStack:S}),a=!0}else if(T instanceof pt){const m=nt(I);m.push(T.nonTerminalName);const p=nt(S);p.push(T.idx);const A={idx:E,def:T.definition.concat(o,et(d)),ruleStack:m,occurrenceStack:p};h.push(A)}else if(T instanceof lt){const m={idx:E,def:et(d),ruleStack:I,occurrenceStack:S};h.push(m),h.push(s);const p={idx:E,def:T.definition.concat(et(d)),ruleStack:I,occurrenceStack:S};h.push(p)}else if(T instanceof Mt){const m=new tt({definition:T.definition,idx:T.idx}),p={idx:E,def:T.definition.concat([m],et(d)),ruleStack:I,occurrenceStack:S};h.push(p)}else if(T instanceof Ut){const m=new V({terminalType:T.separator}),p=new tt({definition:[m].concat(T.definition),idx:T.idx}),A={idx:E,def:T.definition.concat([p],et(d)),ruleStack:I,occurrenceStack:S};h.push(A)}else if(T instanceof _t){const m={idx:E,def:et(d),ruleStack:I,occurrenceStack:S};h.push(m),h.push(s);const p=new V({terminalType:T.separator}),A=new tt({definition:[p].concat(T.definition),idx:T.idx}),O={idx:E,def:T.definition.concat([A],et(d)),ruleStack:I,occurrenceStack:S};h.push(O)}else if(T instanceof tt){const m={idx:E,def:et(d),ruleStack:I,occurrenceStack:S};h.push(m),h.push(s);const p=new tt({definition:T.definition,idx:T.idx}),A={idx:E,def:T.definition.concat([p],et(d)),ruleStack:I,occurrenceStack:S};h.push(A)}else if(T instanceof Lt)for(let m=T.definition.length-1;m>=0;m--){const p={idx:E,def:T.definition[m].definition.concat(et(d)),ruleStack:I,occurrenceStack:S};h.push(p),h.push(s)}else if(T instanceof ht)h.push({idx:E,def:T.definition.concat(et(d)),ruleStack:I,occurrenceStack:S});else{if(!(T instanceof me))throw Error("non exhaustive match");h.push(wc(T,E,I,S))}}return l}function wc(t,e,n,r){const i=nt(n);i.push(t.name);const o=nt(r);return o.push(1),{idx:e,def:t.definition,ruleStack:i,occurrenceStack:o}}var Y;function Hi(t){if(t instanceof lt||t==="Option")return Y.OPTION;if(t instanceof tt||t==="Repetition")return Y.REPETITION;if(t instanceof Mt||t==="RepetitionMandatory")return Y.REPETITION_MANDATORY;if(t instanceof Ut||t==="RepetitionMandatoryWithSeparator")return Y.REPETITION_MANDATORY_WITH_SEPARATOR;if(t instanceof _t||t==="RepetitionWithSeparator")return Y.REPETITION_WITH_SEPARATOR;if(t instanceof Lt||t==="Alternation")return Y.ALTERNATION;throw Error("non exhaustive match")}function Mc(t,e,n,r){const i=t.length,o=Nt(t,s=>Nt(s,a=>a.length===1));if(e)return function(s){const a=_(s,c=>c.GATE);for(let c=0;c<i;c++){const u=t[c],l=u.length,h=a[c];if(h===void 0||h.call(this)!==!1)t:for(let f=0;f<l;f++){const d=u[f],E=d.length;for(let I=0;I<E;I++){const S=this.LA(I+1);if(n(S,d[I])===!1)continue t}return c}}};if(o&&!r){const s=dt(_(t,a=>vt(a)),(a,c,u)=>(k(c,l=>{L(a,l.tokenTypeIdx)||(a[l.tokenTypeIdx]=u),k(l.categoryMatches,h=>{L(a,h)||(a[h]=u)})}),a),{});return function(){const a=this.LA(1);return s[a.tokenTypeIdx]}}return function(){for(let s=0;s<i;s++){const a=t[s],c=a.length;t:for(let u=0;u<c;u++){const l=a[u],h=l.length;for(let f=0;f<h;f++){const d=this.LA(f+1);if(n(d,l[f])===!1)continue t}return s}}}}function Uc(t,e,n){const r=Nt(t,o=>o.length===1),i=t.length;if(r&&!n){const o=vt(t);if(o.length===1&&K(o[0].categoryMatches)){const s=o[0].tokenTypeIdx;return function(){return this.LA(1).tokenTypeIdx===s}}{const s=dt(o,(a,c,u)=>(a[c.tokenTypeIdx]=!0,k(c.categoryMatches,l=>{a[l]=!0}),a),[]);return function(){const a=this.LA(1);return s[a.tokenTypeIdx]===!0}}}return function(){t:for(let o=0;o<i;o++){const s=t[o],a=s.length;for(let c=0;c<a;c++){const u=this.LA(c+1);if(e(u,s[c])===!1)continue t}return!0}return!1}}(function(t){t[t.OPTION=0]="OPTION",t[t.REPETITION=1]="REPETITION",t[t.REPETITION_MANDATORY=2]="REPETITION_MANDATORY",t[t.REPETITION_MANDATORY_WITH_SEPARATOR=3]="REPETITION_MANDATORY_WITH_SEPARATOR",t[t.REPETITION_WITH_SEPARATOR=4]="REPETITION_WITH_SEPARATOR",t[t.ALTERNATION=5]="ALTERNATION"})(Y||(Y={}));class Fc extends On{constructor(e,n,r){super(),this.topProd=e,this.targetOccurrence=n,this.targetProdType=r}startWalking(){return this.walk(this.topProd),this.restDef}checkIsTarget(e,n,r,i){return e.idx===this.targetOccurrence&&this.targetProdType===n&&(this.restDef=r.concat(i),!0)}walkOption(e,n,r){this.checkIsTarget(e,Y.OPTION,n,r)||super.walkOption(e,n,r)}walkAtLeastOne(e,n,r){this.checkIsTarget(e,Y.REPETITION_MANDATORY,n,r)||super.walkOption(e,n,r)}walkAtLeastOneSep(e,n,r){this.checkIsTarget(e,Y.REPETITION_MANDATORY_WITH_SEPARATOR,n,r)||super.walkOption(e,n,r)}walkMany(e,n,r){this.checkIsTarget(e,Y.REPETITION,n,r)||super.walkOption(e,n,r)}walkManySep(e,n,r){this.checkIsTarget(e,Y.REPETITION_WITH_SEPARATOR,n,r)||super.walkOption(e,n,r)}}class fs extends Ee{constructor(e,n,r){super(),this.targetOccurrence=e,this.targetProdType=n,this.targetRef=r,this.result=[]}checkIsTarget(e,n){e.idx!==this.targetOccurrence||this.targetProdType!==n||this.targetRef!==void 0&&e!==this.targetRef||(this.result=e.definition)}visitOption(e){this.checkIsTarget(e,Y.OPTION)}visitRepetition(e){this.checkIsTarget(e,Y.REPETITION)}visitRepetitionMandatory(e){this.checkIsTarget(e,Y.REPETITION_MANDATORY)}visitRepetitionMandatoryWithSeparator(e){this.checkIsTarget(e,Y.REPETITION_MANDATORY_WITH_SEPARATOR)}visitRepetitionWithSeparator(e){this.checkIsTarget(e,Y.REPETITION_WITH_SEPARATOR)}visitAlternation(e){this.checkIsTarget(e,Y.ALTERNATION)}}function Yi(t){const e=new Array(t);for(let n=0;n<t;n++)e[n]=[];return e}function Bn(t){let e=[""];for(let n=0;n<t.length;n++){const r=t[n],i=[];for(let o=0;o<e.length;o++){const s=e[o];i.push(s+"_"+r.tokenTypeIdx);for(let a=0;a<r.categoryMatches.length;a++){const c="_"+r.categoryMatches[a];i.push(s+c)}}e=i}return e}function Dc(t,e,n){for(let r=0;r<t.length;r++){if(r===n)continue;const i=t[r];for(let o=0;o<e.length;o++)if(i[e[o]]===!0)return!1}return!0}function ds(t,e){const n=_(t,s=>pr([s],1)),r=Yi(n.length),i=_(n,s=>{const a={};return k(s,c=>{k(Bn(c.partialPath),u=>{a[u]=!0})}),a});let o=n;for(let s=1;s<=e;s++){const a=o;o=Yi(a.length);for(let c=0;c<a.length;c++){const u=a[c];for(let l=0;l<u.length;l++){const h=u[l].partialPath,f=u[l].suffixDef,d=Bn(h);if(Dc(i,d,c)||K(f)||h.length===e){const E=r[c];if(Er(E,h)===!1){E.push(h);for(let I=0;I<d.length;I++){const S=d[I];i[c][S]=!0}}}else{const E=pr(f,s+1,h);o[c]=o[c].concat(E),k(E,I=>{k(Bn(I.partialPath),S=>{i[c][S]=!0})})}}}}return r}function Dr(t,e,n,r){const i=new fs(t,Y.ALTERNATION,r);return e.accept(i),ds(i.result,n)}function mr(t,e,n,r){const i=new fs(t,n);e.accept(i);const o=i.result,s=new Fc(e,t,n).startWalking();return ds([new ht({definition:o}),new ht({definition:s})],r)}function Er(t,e){t:for(let n=0;n<t.length;n++){const r=t[n];if(r.length===e.length){for(let i=0;i<r.length;i++){const o=e[i],s=r[i];if(!(o===s||s.categoryMatchesMap[o.tokenTypeIdx]!==void 0))continue t}return!0}}return!1}function Xi(t){return Nt(t,e=>Nt(e,n=>Nt(n,r=>K(r.categoryMatches))))}function jc(t,e,n,r){const i=gt(t,c=>function(u,l){const h=new $c;u.accept(h);const f=h.allProductions,d=nc(f,Bc);return _(J(St(d,I=>I.length>1)),I=>{const S=Ot(I),T=l.buildDuplicateFoundError(u,I),m=xt(S),p={message:T,type:ot.DUPLICATE_PRODUCTIONS,ruleName:u.name,dslName:m,occurrence:S.idx},A=ps(S);return A&&(p.parameter=A),p})}(c,n)),o=function(c,u,l){const h=[],f=_(u,d=>d.name);return k(c,d=>{const E=d.name;if(st(f,E)){const I=l.buildNamespaceConflictError(d);h.push({message:I,type:ot.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:E})}}),h}(t,e,n),s=gt(t,c=>function(u,l){const h=new jr;return u.accept(h),gt(h.alternations,d=>d.definition.length>255?[{message:l.buildTooManyAlternativesError({topLevelRule:u,alternation:d}),type:ot.TOO_MANY_ALTS,ruleName:u.name,occurrence:d.idx}]:[])}(c,n)),a=gt(t,c=>function(u,l,h,f){const d=[];if(dt(l,(I,S)=>S.name===u.name?I+1:I,0)>1){const I=f.buildDuplicateRuleNameError({topLevelRule:u,grammarName:h});d.push({message:I,type:ot.DUPLICATE_RULE_NAME,ruleName:u.name})}return d}(c,t,r,n));return i.concat(o,s,a)}function Bc(t){return`${xt(t)}_#_${t.idx}_#_${ps(t)}`}function ps(t){return t instanceof V?t.terminalType.name:t instanceof pt?t.nonTerminalName:""}class $c extends Ee{constructor(){super(...arguments),this.allProductions=[]}visitNonTerminal(e){this.allProductions.push(e)}visitOption(e){this.allProductions.push(e)}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}visitAlternation(e){this.allProductions.push(e)}visitTerminal(e){this.allProductions.push(e)}}function ms(t,e,n,r=[]){const i=[],o=en(e.definition);if(K(o))return[];{const s=t.name;st(o,t)&&i.push({message:n.buildLeftRecursionError({topLevelRule:t,leftRecursionPath:r}),type:ot.LEFT_RECURSION,ruleName:s});const a=gt(an(o,r.concat([t])),c=>{const u=nt(r);return u.push(c),ms(t,c,n,u)});return i.concat(a)}}function en(t){let e=[];if(K(t))return e;const n=Ot(t);if(n instanceof pt)e.push(n.referencedRule);else if(n instanceof ht||n instanceof lt||n instanceof Mt||n instanceof Ut||n instanceof _t||n instanceof tt)e=e.concat(en(n.definition));else if(n instanceof Lt)e=vt(_(n.definition,o=>en(o.definition)));else if(!(n instanceof V))throw Error("non exhaustive match");const r=cn(n),i=t.length>1;if(r&&i){const o=et(t);return e.concat(en(o))}return e}class jr extends Ee{constructor(){super(...arguments),this.alternations=[]}visitAlternation(e){this.alternations.push(e)}}function Wc(t,e,n){const r=new jr;t.accept(r);let i=r.alternations;return i=Rn(i,s=>s.ignoreAmbiguities===!0),gt(i,s=>{const a=s.idx,c=s.maxLookahead||e,u=Dr(a,t,c,s),l=function(f,d,E,I){const S=[],T=dt(f,(p,A,O)=>(d.definition[O].ignoreAmbiguities===!0||k(A,g=>{const R=[O];k(f,(v,y)=>{O!==y&&Er(v,g)&&d.definition[y].ignoreAmbiguities!==!0&&R.push(y)}),R.length>1&&!Er(S,g)&&(S.push(g),p.push({alts:R,path:g}))}),p),[]);return _(T,p=>{const A=_(p.alts,O=>O+1);return{message:I.buildAlternationAmbiguityError({topLevelRule:E,alternation:d,ambiguityIndices:A,prefixPath:p.path}),type:ot.AMBIGUOUS_ALTS,ruleName:E.name,occurrence:d.idx,alternatives:p.alts}})}(u,s,t,n),h=function(f,d,E,I){const S=dt(f,(m,p,A)=>{const O=_(p,g=>({idx:A,path:g}));return m.concat(O)},[]);return Be(gt(S,m=>{if(d.definition[m.idx].ignoreAmbiguities===!0)return[];const p=m.idx,A=m.path;return _(mt(S,O=>{return d.definition[O.idx].ignoreAmbiguities!==!0&&O.idx<p&&(g=O.path,R=A,g.length<R.length&&Nt(g,(v,y)=>{const N=R[y];return v===N||N.categoryMatchesMap[v.tokenTypeIdx]}));var g,R}),O=>{const g=[O.idx+1,p+1],R=d.idx===0?"":d.idx;return{message:I.buildAlternationPrefixAmbiguityError({topLevelRule:E,alternation:d,ambiguityIndices:g,prefixPath:O.path}),type:ot.AMBIGUOUS_PREFIX_ALTS,ruleName:E.name,occurrence:R,alternatives:g}})}))}(u,s,t,n);return l.concat(h)})}class Gc extends Ee{constructor(){super(...arguments),this.allProductions=[]}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}}function Kc(t){const e=Mr(t,{errMsgProvider:Lc}),n={};return k(t.rules,r=>{n[r.name]=r}),function(r,i){const o=new xc(r,i);return o.resolveRefs(),o.errors}(n,e.errMsgProvider)}const Es="MismatchedTokenException",gs="NoViableAltException",Ts="EarlyExitException",As="NotAllInputParsedException",Is=[Es,gs,Ts,As];function He(t){return st(Is,t.name)}Object.freeze(Is);class _n extends Error{constructor(e,n){super(e),this.token=n,this.resyncedTokens=[],Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class qi extends _n{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=Es}}class zc extends _n{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=gs}}class Vc extends _n{constructor(e,n){super(e,n),this.name=As}}class Hc extends _n{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=Ts}}const $n={},ys="InRuleRecoveryException";class Yc extends Error{constructor(e){super(e),this.name=ys}}function Xc(t,e,n,r,i,o,s){const a=this.getKeyForAutomaticLookahead(r,i);let c=this.firstAfterRepMap[a];if(c===void 0){const f=this.getCurrRuleFullName();c=new o(this.getGAstProductions()[f],i).startWalking(),this.firstAfterRepMap[a]=c}let u=c.token,l=c.occurrence;const h=c.isEndOfRule;this.RULE_STACK.length===1&&h&&u===void 0&&(u=ee,l=1),u!==void 0&&l!==void 0&&this.shouldInRepetitionRecoveryBeTried(u,l,s)&&this.tryInRepetitionRecovery(t,e,n,u)}const Wn=1024,Gn=1280,Ye=1536;function Kn(t,e,n){return n|e|t}class qc{constructor(e){var n;this.maxLookahead=(n=e?.maxLookahead)!==null&&n!==void 0?n:$t.maxLookahead}validate(e){const n=this.validateNoLeftRecursion(e.rules);if(K(n)){const r=this.validateEmptyOrAlternatives(e.rules),i=this.validateAmbiguousAlternationAlternatives(e.rules,this.maxLookahead),o=this.validateSomeNonEmptyLookaheadPath(e.rules,this.maxLookahead);return[...n,...r,...i,...o]}return n}validateNoLeftRecursion(e){return gt(e,n=>ms(n,n,ne))}validateEmptyOrAlternatives(e){return gt(e,n=>function(r,i){const o=new jr;return r.accept(o),gt(o.alternations,s=>gt(we(s.definition),(a,c)=>K(hs([a],[],xe,1))?[{message:i.buildEmptyAlternationError({topLevelRule:r,alternation:s,emptyChoiceIdx:c}),type:ot.NONE_LAST_EMPTY_ALT,ruleName:r.name,occurrence:s.idx,alternative:c+1}]:[]))}(n,ne))}validateAmbiguousAlternationAlternatives(e,n){return gt(e,r=>Wc(r,n,ne))}validateSomeNonEmptyLookaheadPath(e,n){return function(r,i,o){const s=[];return k(r,a=>{const c=new Gc;a.accept(c),k(c.allProductions,u=>{const l=Hi(u),h=u.maxLookahead||i;if(K(vt(mr(u.idx,a,l,h)[0]))){const f=o.buildEmptyRepetitionError({topLevelRule:a,repetition:u});s.push({message:f,type:ot.NO_NON_EMPTY_LOOKAHEAD,ruleName:a.name})}})}),s}(e,n,ne)}buildLookaheadForAlternation(e){return function(n,r,i,o,s,a){const c=Dr(n,r,i);return a(c,o,Xi(c)?dn:xe,s)}(e.prodOccurrence,e.rule,e.maxLookahead,e.hasPredicates,e.dynamicTokensEnabled,Mc)}buildLookaheadForOptional(e){return function(n,r,i,o,s,a){const c=mr(n,r,s,i),u=Xi(c)?dn:xe;return a(c[0],u,o)}(e.prodOccurrence,e.rule,e.maxLookahead,e.dynamicTokensEnabled,Hi(e.prodType),Uc)}}const Xe=new class extends Ee{constructor(){super(...arguments),this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}reset(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}visitOption(t){this.dslMethods.option.push(t)}visitRepetitionWithSeparator(t){this.dslMethods.repetitionWithSeparator.push(t)}visitRepetitionMandatory(t){this.dslMethods.repetitionMandatory.push(t)}visitRepetitionMandatoryWithSeparator(t){this.dslMethods.repetitionMandatoryWithSeparator.push(t)}visitRepetition(t){this.dslMethods.repetition.push(t)}visitAlternation(t){this.dslMethods.alternation.push(t)}};function Zi(t,e){isNaN(t.startOffset)===!0?(t.startOffset=e.startOffset,t.endOffset=e.endOffset):t.endOffset<e.endOffset&&(t.endOffset=e.endOffset)}function Qi(t,e){isNaN(t.startOffset)===!0?(t.startOffset=e.startOffset,t.startColumn=e.startColumn,t.startLine=e.startLine,t.endOffset=e.endOffset,t.endColumn=e.endColumn,t.endLine=e.endLine):t.endOffset<e.endOffset&&(t.endOffset=e.endOffset,t.endColumn=e.endColumn,t.endLine=e.endLine)}function vs(t,e){Object.defineProperty(t,"name",{enumerable:!1,configurable:!0,writable:!1,value:e})}function Zc(t,e){const n=It(t),r=n.length;for(let i=0;i<r;i++){const o=t[n[i]],s=o.length;for(let a=0;a<s;a++){const c=o[a];c.tokenTypeIdx===void 0&&this[c.name](c.children,e)}}}function Qc(t,e){const n=function(){};vs(n,t+"BaseSemantics");const r={visit:function(i,o){if(D(i)&&(i=i[0]),!zt(i))return this[i.name](i.children,o)},validateVisitor:function(){const i=function(o,s){return function(c,u){const l=mt(u,f=>Vt(c[f])===!1),h=_(l,f=>({msg:`Missing visitor method: <${f}> on ${c.constructor.name} CST Visitor.`,type:gr.MISSING_METHOD,methodName:f}));return Be(h)}(o,s)}(this,e);if(!K(i)){const o=_(i,s=>s.msg);throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>:
${o.join(`
`).replace(/\n/g,`
`)}`)}}};return(n.prototype=r).constructor=n,n._RULE_NAMES=e,n}var gr;(function(t){t[t.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",t[t.MISSING_METHOD=1]="MISSING_METHOD"})(gr||(gr={}));const Ln={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(Ln);const Ji=!0,to=Math.pow(2,8)-1,Ns=P({name:"RECORDING_PHASE_TOKEN",pattern:ct.NA});$e([Ns]);const Rs=Fr(Ns,`This IToken indicates the Parser is in Recording Phase
See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,-1,-1,-1,-1,-1,-1);Object.freeze(Rs);const Jc={name:`This CSTNode indicates the Parser is in Recording Phase
See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,children:{}};function ve(t,e,n,r=!1){pn(n);const i=de(this.recordingProdStack),o=Vt(e)?e:e.DEF,s=new t({definition:[],idx:n});return r&&(s.separator=e.SEP),L(e,"MAX_LOOKAHEAD")&&(s.maxLookahead=e.MAX_LOOKAHEAD),this.recordingProdStack.push(s),o.call(this),i.definition.push(s),this.recordingProdStack.pop(),Ln}function tu(t,e){pn(e);const n=de(this.recordingProdStack),r=D(t)===!1,i=r===!1?t:t.DEF,o=new Lt({definition:[],idx:e,ignoreAmbiguities:r&&t.IGNORE_AMBIGUITIES===!0});L(t,"MAX_LOOKAHEAD")&&(o.maxLookahead=t.MAX_LOOKAHEAD);const s=Zo(i,a=>Vt(a.GATE));return o.hasPredicates=s,n.definition.push(o),k(i,a=>{const c=new ht({definition:[]});o.definition.push(c),L(a,"IGNORE_AMBIGUITIES")?c.ignoreAmbiguities=a.IGNORE_AMBIGUITIES:L(a,"GATE")&&(c.ignoreAmbiguities=!0),this.recordingProdStack.push(c),a.ALT.call(this),this.recordingProdStack.pop()}),Ln}function eo(t){return t===0?"":`${t}`}function pn(t){if(t<0||t>to){const e=new Error(`Invalid DSL Method idx value: <${t}>
Idx value must be a none negative value smaller than ${to+1}`);throw e.KNOWN_RECORDER_ERROR=!0,e}}const nn=Fr(ee,"",NaN,NaN,NaN,NaN,NaN,NaN);Object.freeze(nn);const $t=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:ls,nodeLocationTracking:"none",traceInitPerf:!1,skipValidations:!1}),qe=Object.freeze({recoveryValueFunc:()=>{},resyncEnabled:!0});var ot,zn;(function(t){t[t.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",t[t.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",t[t.INVALID_RULE_OVERRIDE=2]="INVALID_RULE_OVERRIDE",t[t.DUPLICATE_PRODUCTIONS=3]="DUPLICATE_PRODUCTIONS",t[t.UNRESOLVED_SUBRULE_REF=4]="UNRESOLVED_SUBRULE_REF",t[t.LEFT_RECURSION=5]="LEFT_RECURSION",t[t.NONE_LAST_EMPTY_ALT=6]="NONE_LAST_EMPTY_ALT",t[t.AMBIGUOUS_ALTS=7]="AMBIGUOUS_ALTS",t[t.CONFLICT_TOKENS_RULES_NAMESPACE=8]="CONFLICT_TOKENS_RULES_NAMESPACE",t[t.INVALID_TOKEN_NAME=9]="INVALID_TOKEN_NAME",t[t.NO_NON_EMPTY_LOOKAHEAD=10]="NO_NON_EMPTY_LOOKAHEAD",t[t.AMBIGUOUS_PREFIX_ALTS=11]="AMBIGUOUS_PREFIX_ALTS",t[t.TOO_MANY_ALTS=12]="TOO_MANY_ALTS",t[t.CUSTOM_LOOKAHEAD_VALIDATION=13]="CUSTOM_LOOKAHEAD_VALIDATION"})(ot||(ot={}));class Me{static performSelfAnalysis(e){throw Error("The **static** `performSelfAnalysis` method has been deprecated. \nUse the **instance** method with the same name instead.")}performSelfAnalysis(){this.TRACE_INIT("performSelfAnalysis",()=>{let e;this.selfAnalysisDone=!0;const n=this.className;this.TRACE_INIT("toFastProps",()=>{ts(this)}),this.TRACE_INIT("Grammar Recording",()=>{try{this.enableRecording(),k(this.definedRulesNames,i=>{const o=this[i].originalGrammarAction;let s;this.TRACE_INIT(`${i} Rule`,()=>{s=this.topLevelRuleRecord(i,o)}),this.gastProductionsCache[i]=s})}finally{this.disableRecording()}});let r=[];if(this.TRACE_INIT("Grammar Resolving",()=>{r=Kc({rules:J(this.gastProductionsCache)}),this.definitionErrors=this.definitionErrors.concat(r)}),this.TRACE_INIT("Grammar Validations",()=>{if(K(r)&&this.skipValidations===!1){const o=(i={rules:J(this.gastProductionsCache),tokenTypes:J(this.tokensMap),errMsgProvider:ne,grammarName:n},jc((i=Mr(i,{errMsgProvider:ne})).rules,i.tokenTypes,i.errMsgProvider,i.grammarName)),s=function(a){return _(a.lookaheadStrategy.validate({rules:a.rules,tokenTypes:a.tokenTypes,grammarName:a.grammarName}),c=>Object.assign({type:ot.CUSTOM_LOOKAHEAD_VALIDATION},c))}({lookaheadStrategy:this.lookaheadStrategy,rules:J(this.gastProductionsCache),tokenTypes:J(this.tokensMap),grammarName:n});this.definitionErrors=this.definitionErrors.concat(o,s)}var i}),K(this.definitionErrors)&&(this.recoveryEnabled&&this.TRACE_INIT("computeAllProdsFollows",()=>{const i=function(o){const s={};return k(o,a=>{const c=new fc(a).startWalking();ft(s,c)}),s}(J(this.gastProductionsCache));this.resyncFollows=i}),this.TRACE_INIT("ComputeLookaheadFunctions",()=>{var i,o;(o=(i=this.lookaheadStrategy).initialize)===null||o===void 0||o.call(i,{rules:J(this.gastProductionsCache)}),this.preComputeLookaheadFunctions(J(this.gastProductionsCache))})),!Me.DEFER_DEFINITION_ERRORS_HANDLING&&!K(this.definitionErrors))throw e=_(this.definitionErrors,i=>i.message),new Error(`Parser Definition Errors detected:
${e.join(`
-------------------------------
`)}`)})}constructor(e,n){this.definitionErrors=[],this.selfAnalysisDone=!1;const r=this;if(r.initErrorHandler(n),r.initLexerAdapter(),r.initLooksAhead(n),r.initRecognizerEngine(e,n),r.initRecoverable(n),r.initTreeBuilder(n),r.initContentAssist(),r.initGastRecorder(n),r.initPerformanceTracer(n),L(n,"ignoredIssues"))throw new Error(`The <ignoredIssues> IParserConfig property has been deprecated.
Please use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.
See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES
For further details.`);this.skipValidations=L(n,"skipValidations")?n.skipValidations:$t.skipValidations}}Me.DEFER_DEFINITION_ERRORS_HANDLING=!1,zn=Me,[class{initRecoverable(t){this.firstAfterRepMap={},this.resyncFollows={},this.recoveryEnabled=L(t,"recoveryEnabled")?t.recoveryEnabled:$t.recoveryEnabled,this.recoveryEnabled&&(this.attemptInRepetitionRecovery=Xc)}getTokenToInsert(t){const e=Fr(t,"",NaN,NaN,NaN,NaN,NaN,NaN);return e.isInsertedInRecovery=!0,e}canTokenTypeBeInsertedInRecovery(t){return!0}canTokenTypeBeDeletedInRecovery(t){return!0}tryInRepetitionRecovery(t,e,n,r){const i=this.findReSyncTokenType(),o=this.exportLexerState(),s=[];let a=!1;const c=this.LA(1);let u=this.LA(1);const l=()=>{const h=this.LA(0),f=this.errorMessageProvider.buildMismatchTokenMessage({expected:r,actual:c,previous:h,ruleName:this.getCurrRuleFullName()}),d=new qi(f,c,this.LA(0));d.resyncedTokens=we(s),this.SAVE_ERROR(d)};for(;!a;){if(this.tokenMatcher(u,r))return void l();if(n.call(this))return l(),void t.apply(this,e);this.tokenMatcher(u,i)?a=!0:(u=this.SKIP_TOKEN(),this.addToResyncTokens(u,s))}this.importLexerState(o)}shouldInRepetitionRecoveryBeTried(t,e,n){return n!==!1&&!this.tokenMatcher(this.LA(1),t)&&!this.isBackTracking()&&!this.canPerformInRuleRecovery(t,this.getFollowsForInRuleRecovery(t,e))}getFollowsForInRuleRecovery(t,e){const n=this.getCurrentGrammarPath(t,e);return this.getNextPossibleTokenTypes(n)}tryInRuleRecovery(t,e){if(this.canRecoverWithSingleTokenInsertion(t,e))return this.getTokenToInsert(t);if(this.canRecoverWithSingleTokenDeletion(t)){const n=this.SKIP_TOKEN();return this.consumeToken(),n}throw new Yc("sad sad panda")}canPerformInRuleRecovery(t,e){return this.canRecoverWithSingleTokenInsertion(t,e)||this.canRecoverWithSingleTokenDeletion(t)}canRecoverWithSingleTokenInsertion(t,e){if(!this.canTokenTypeBeInsertedInRecovery(t)||K(e))return!1;const n=this.LA(1);return pe(e,r=>this.tokenMatcher(n,r))!==void 0}canRecoverWithSingleTokenDeletion(t){return!!this.canTokenTypeBeDeletedInRecovery(t)&&this.tokenMatcher(this.LA(2),t)}isInCurrentRuleReSyncSet(t){const e=this.getCurrFollowKey();return st(this.getFollowSetFromFollowKey(e),t)}findReSyncTokenType(){const t=this.flattenFollowSet();let e=this.LA(1),n=2;for(;;){const r=pe(t,i=>xe(e,i));if(r!==void 0)return r;e=this.LA(n),n++}}getCurrFollowKey(){if(this.RULE_STACK.length===1)return $n;const t=this.getLastExplicitRuleShortName(),e=this.getLastExplicitRuleOccurrenceIndex(),n=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(t),idxInCallingRule:e,inRule:this.shortRuleNameToFullName(n)}}buildFullFollowKeyStack(){const t=this.RULE_STACK,e=this.RULE_OCCURRENCE_STACK;return _(t,(n,r)=>r===0?$n:{ruleName:this.shortRuleNameToFullName(n),idxInCallingRule:e[r],inRule:this.shortRuleNameToFullName(t[r-1])})}flattenFollowSet(){return vt(_(this.buildFullFollowKeyStack(),t=>this.getFollowSetFromFollowKey(t)))}getFollowSetFromFollowKey(t){if(t===$n)return[ee];const e=t.ruleName+t.idxInCallingRule+es+t.inRule;return this.resyncFollows[e]}addToResyncTokens(t,e){return this.tokenMatcher(t,ee)||e.push(t),e}reSyncTo(t){const e=[];let n=this.LA(1);for(;this.tokenMatcher(n,t)===!1;)n=this.SKIP_TOKEN(),this.addToResyncTokens(n,e);return we(e)}attemptInRepetitionRecovery(t,e,n,r,i,o,s){}getCurrentGrammarPath(t,e){return{ruleStack:this.getHumanReadableRuleStack(),occurrenceStack:nt(this.RULE_OCCURRENCE_STACK),lastTok:t,lastTokOccurrence:e}}getHumanReadableRuleStack(){return _(this.RULE_STACK,t=>this.shortRuleNameToFullName(t))}},class{initLooksAhead(t){this.dynamicTokensEnabled=L(t,"dynamicTokensEnabled")?t.dynamicTokensEnabled:$t.dynamicTokensEnabled,this.maxLookahead=L(t,"maxLookahead")?t.maxLookahead:$t.maxLookahead,this.lookaheadStrategy=L(t,"lookaheadStrategy")?t.lookaheadStrategy:new qc({maxLookahead:this.maxLookahead}),this.lookAheadFuncsCache=new Map}preComputeLookaheadFunctions(t){k(t,e=>{this.TRACE_INIT(`${e.name} Rule Lookahead`,()=>{const{alternation:n,repetition:r,option:i,repetitionMandatory:o,repetitionMandatoryWithSeparator:s,repetitionWithSeparator:a}=function(c){Xe.reset(),c.accept(Xe);const u=Xe.dslMethods;return Xe.reset(),u}(e);k(n,c=>{const u=c.idx===0?"":c.idx;this.TRACE_INIT(`${xt(c)}${u}`,()=>{const l=this.lookaheadStrategy.buildLookaheadForAlternation({prodOccurrence:c.idx,rule:e,maxLookahead:c.maxLookahead||this.maxLookahead,hasPredicates:c.hasPredicates,dynamicTokensEnabled:this.dynamicTokensEnabled}),h=Kn(this.fullRuleNameToShort[e.name],256,c.idx);this.setLaFuncCache(h,l)})}),k(r,c=>{this.computeLookaheadFunc(e,c.idx,768,"Repetition",c.maxLookahead,xt(c))}),k(i,c=>{this.computeLookaheadFunc(e,c.idx,512,"Option",c.maxLookahead,xt(c))}),k(o,c=>{this.computeLookaheadFunc(e,c.idx,Wn,"RepetitionMandatory",c.maxLookahead,xt(c))}),k(s,c=>{this.computeLookaheadFunc(e,c.idx,Ye,"RepetitionMandatoryWithSeparator",c.maxLookahead,xt(c))}),k(a,c=>{this.computeLookaheadFunc(e,c.idx,Gn,"RepetitionWithSeparator",c.maxLookahead,xt(c))})})})}computeLookaheadFunc(t,e,n,r,i,o){this.TRACE_INIT(`${o}${e===0?"":e}`,()=>{const s=this.lookaheadStrategy.buildLookaheadForOptional({prodOccurrence:e,rule:t,maxLookahead:i||this.maxLookahead,dynamicTokensEnabled:this.dynamicTokensEnabled,prodType:r}),a=Kn(this.fullRuleNameToShort[t.name],n,e);this.setLaFuncCache(a,s)})}getKeyForAutomaticLookahead(t,e){return Kn(this.getLastExplicitRuleShortName(),t,e)}getLaFuncFromCache(t){return this.lookAheadFuncsCache.get(t)}setLaFuncCache(t,e){this.lookAheadFuncsCache.set(t,e)}},class{initTreeBuilder(t){if(this.CST_STACK=[],this.outputCst=t.outputCst,this.nodeLocationTracking=L(t,"nodeLocationTracking")?t.nodeLocationTracking:$t.nodeLocationTracking,this.outputCst)if(/full/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=Qi,this.setNodeLocationFromNode=Qi,this.cstPostRule=Q,this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery):(this.setNodeLocationFromToken=Q,this.setNodeLocationFromNode=Q,this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular);else if(/onlyOffset/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=Zi,this.setNodeLocationFromNode=Zi,this.cstPostRule=Q,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery):(this.setNodeLocationFromToken=Q,this.setNodeLocationFromNode=Q,this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular);else{if(!/none/i.test(this.nodeLocationTracking))throw Error(`Invalid <nodeLocationTracking> config option: "${t.nodeLocationTracking}"`);this.setNodeLocationFromToken=Q,this.setNodeLocationFromNode=Q,this.cstPostRule=Q,this.setInitialNodeLocation=Q}else this.cstInvocationStateUpdate=Q,this.cstFinallyStateUpdate=Q,this.cstPostTerminal=Q,this.cstPostNonTerminal=Q,this.cstPostRule=Q}setInitialNodeLocationOnlyOffsetRecovery(t){t.location={startOffset:NaN,endOffset:NaN}}setInitialNodeLocationOnlyOffsetRegular(t){t.location={startOffset:this.LA(1).startOffset,endOffset:NaN}}setInitialNodeLocationFullRecovery(t){t.location={startOffset:NaN,startLine:NaN,startColumn:NaN,endOffset:NaN,endLine:NaN,endColumn:NaN}}setInitialNodeLocationFullRegular(t){const e=this.LA(1);t.location={startOffset:e.startOffset,startLine:e.startLine,startColumn:e.startColumn,endOffset:NaN,endLine:NaN,endColumn:NaN}}cstInvocationStateUpdate(t){const e={name:t,children:Object.create(null)};this.setInitialNodeLocation(e),this.CST_STACK.push(e)}cstFinallyStateUpdate(){this.CST_STACK.pop()}cstPostRuleFull(t){const e=this.LA(0),n=t.location;n.startOffset<=e.startOffset==1?(n.endOffset=e.endOffset,n.endLine=e.endLine,n.endColumn=e.endColumn):(n.startOffset=NaN,n.startLine=NaN,n.startColumn=NaN)}cstPostRuleOnlyOffset(t){const e=this.LA(0),n=t.location;n.startOffset<=e.startOffset==1?n.endOffset=e.endOffset:n.startOffset=NaN}cstPostTerminal(t,e){const n=this.CST_STACK[this.CST_STACK.length-1];var r,i,o;i=e,o=t,(r=n).children[o]===void 0?r.children[o]=[i]:r.children[o].push(i),this.setNodeLocationFromToken(n.location,e)}cstPostNonTerminal(t,e){const n=this.CST_STACK[this.CST_STACK.length-1];(function(r,i,o){r.children[i]===void 0?r.children[i]=[o]:r.children[i].push(o)})(n,e,t),this.setNodeLocationFromNode(n.location,t.location)}getBaseCstVisitorConstructor(){if(zt(this.baseCstVisitorConstructor)){const t=Qc(this.className,It(this.gastProductionsCache));return this.baseCstVisitorConstructor=t,t}return this.baseCstVisitorConstructor}getBaseCstVisitorConstructorWithDefaults(){if(zt(this.baseCstVisitorWithDefaultsConstructor)){const t=function(e,n,r){const i=function(){};vs(i,e+"BaseSemanticsWithDefaults");const o=Object.create(r.prototype);return k(n,s=>{o[s]=Zc}),(i.prototype=o).constructor=i,i}(this.className,It(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=t,t}return this.baseCstVisitorWithDefaultsConstructor}getLastExplicitRuleShortName(){const t=this.RULE_STACK;return t[t.length-1]}getPreviousExplicitRuleShortName(){const t=this.RULE_STACK;return t[t.length-2]}getLastExplicitRuleOccurrenceIndex(){const t=this.RULE_OCCURRENCE_STACK;return t[t.length-1]}},class{initLexerAdapter(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1}set input(t){if(this.selfAnalysisDone!==!0)throw Error("Missing <performSelfAnalysis> invocation at the end of the Parser's constructor.");this.reset(),this.tokVector=t,this.tokVectorLength=t.length}get input(){return this.tokVector}SKIP_TOKEN(){return this.currIdx<=this.tokVector.length-2?(this.consumeToken(),this.LA(1)):nn}LA(t){const e=this.currIdx+t;return e<0||this.tokVectorLength<=e?nn:this.tokVector[e]}consumeToken(){this.currIdx++}exportLexerState(){return this.currIdx}importLexerState(t){this.currIdx=t}resetLexerState(){this.currIdx=-1}moveToTerminatedState(){this.currIdx=this.tokVector.length-1}getLexerPosition(){return this.exportLexerState()}},class{initRecognizerEngine(t,e){if(this.className=this.constructor.name,this.shortRuleNameToFull={},this.fullRuleNameToShort={},this.ruleShortNameIdx=256,this.tokenMatcher=dn,this.subruleIdx=0,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_OCCURRENCE_STACK=[],this.gastProductionsCache={},L(e,"serializedGrammar"))throw Error(`The Parser's configuration can no longer contain a <serializedGrammar> property.
See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0
For Further details.`);if(D(t)){if(K(t))throw Error(`A Token Vocabulary cannot be empty.
Note that the first argument for the parser constructor
is no longer a Token vector (since v4.0).`);if(typeof t[0].startOffset=="number")throw Error(`The Parser constructor no longer accepts a token vector as the first argument.
See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0
For Further details.`)}if(D(t))this.tokensMap=dt(t,(r,i)=>(r[i.name]=i,r),{});else if(L(t,"modes")&&Nt(vt(J(t.modes)),Oc)){const r=ur(vt(J(t.modes)));this.tokensMap=dt(r,(i,o)=>(i[o.name]=o,i),{})}else{if(!At(t))throw new Error("<tokensDictionary> argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");this.tokensMap=nt(t)}this.tokensMap.EOF=ee;const n=Nt(L(t,"modes")?vt(J(t.modes)):J(t),r=>K(r.categoryMatches));this.tokenMatcher=n?dn:xe,$e(J(this.tokensMap))}defineRule(t,e,n){if(this.selfAnalysisDone)throw Error(`Grammar rule <${t}> may not be defined after the 'performSelfAnalysis' method has been called'
Make sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.`);const r=L(n,"resyncEnabled")?n.resyncEnabled:qe.resyncEnabled,i=L(n,"recoveryValueFunc")?n.recoveryValueFunc:qe.recoveryValueFunc,o=this.ruleShortNameIdx<<12;let s;return this.ruleShortNameIdx++,this.shortRuleNameToFull[o]=t,this.fullRuleNameToShort[t]=o,s=this.outputCst===!0?function(...a){try{this.ruleInvocationStateUpdate(o,t,this.subruleIdx),e.apply(this,a);const c=this.CST_STACK[this.CST_STACK.length-1];return this.cstPostRule(c),c}catch(c){return this.invokeRuleCatch(c,r,i)}finally{this.ruleFinallyStateUpdate()}}:function(...a){try{return this.ruleInvocationStateUpdate(o,t,this.subruleIdx),e.apply(this,a)}catch(c){return this.invokeRuleCatch(c,r,i)}finally{this.ruleFinallyStateUpdate()}},Object.assign(s,{ruleName:t,originalGrammarAction:e})}invokeRuleCatch(t,e,n){const r=this.RULE_STACK.length===1,i=e&&!this.isBackTracking()&&this.recoveryEnabled;if(He(t)){const o=t;if(i){const s=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(s)){if(o.resyncedTokens=this.reSyncTo(s),this.outputCst){const a=this.CST_STACK[this.CST_STACK.length-1];return a.recoveredNode=!0,a}return n(t)}if(this.outputCst){const a=this.CST_STACK[this.CST_STACK.length-1];a.recoveredNode=!0,o.partialCstResult=a}throw o}if(r)return this.moveToTerminatedState(),n(t);throw o}throw t}optionInternal(t,e){const n=this.getKeyForAutomaticLookahead(512,e);return this.optionInternalLogic(t,e,n)}optionInternalLogic(t,e,n){let r,i=this.getLaFuncFromCache(n);if(typeof t!="function"){r=t.DEF;const o=t.GATE;if(o!==void 0){const s=i;i=()=>o.call(this)&&s.call(this)}}else r=t;if(i.call(this)===!0)return r.call(this)}atLeastOneInternal(t,e){const n=this.getKeyForAutomaticLookahead(Wn,t);return this.atLeastOneInternalLogic(t,e,n)}atLeastOneInternalLogic(t,e,n){let r,i=this.getLaFuncFromCache(n);if(typeof e!="function"){r=e.DEF;const o=e.GATE;if(o!==void 0){const s=i;i=()=>o.call(this)&&s.call(this)}}else r=e;if(i.call(this)!==!0)throw this.raiseEarlyExitException(t,Y.REPETITION_MANDATORY,e.ERR_MSG);{let o=this.doSingleRepetition(r);for(;i.call(this)===!0&&o===!0;)o=this.doSingleRepetition(r)}this.attemptInRepetitionRecovery(this.atLeastOneInternal,[t,e],i,Wn,t,Pc)}atLeastOneSepFirstInternal(t,e){const n=this.getKeyForAutomaticLookahead(Ye,t);this.atLeastOneSepFirstInternalLogic(t,e,n)}atLeastOneSepFirstInternalLogic(t,e,n){const r=e.DEF,i=e.SEP;if(this.getLaFuncFromCache(n).call(this)!==!0)throw this.raiseEarlyExitException(t,Y.REPETITION_MANDATORY_WITH_SEPARATOR,e.ERR_MSG);{r.call(this);const o=()=>this.tokenMatcher(this.LA(1),i);for(;this.tokenMatcher(this.LA(1),i)===!0;)this.CONSUME(i),r.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,i,o,r,Vi],o,Ye,t,Vi)}}manyInternal(t,e){const n=this.getKeyForAutomaticLookahead(768,t);return this.manyInternalLogic(t,e,n)}manyInternalLogic(t,e,n){let r,i=this.getLaFuncFromCache(n);if(typeof e!="function"){r=e.DEF;const s=e.GATE;if(s!==void 0){const a=i;i=()=>s.call(this)&&a.call(this)}}else r=e;let o=!0;for(;i.call(this)===!0&&o===!0;)o=this.doSingleRepetition(r);this.attemptInRepetitionRecovery(this.manyInternal,[t,e],i,768,t,bc,o)}manySepFirstInternal(t,e){const n=this.getKeyForAutomaticLookahead(Gn,t);this.manySepFirstInternalLogic(t,e,n)}manySepFirstInternalLogic(t,e,n){const r=e.DEF,i=e.SEP;if(this.getLaFuncFromCache(n).call(this)===!0){r.call(this);const o=()=>this.tokenMatcher(this.LA(1),i);for(;this.tokenMatcher(this.LA(1),i)===!0;)this.CONSUME(i),r.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,i,o,r,zi],o,Gn,t,zi)}}repetitionSepSecondInternal(t,e,n,r,i){for(;n();)this.CONSUME(e),r.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,e,n,r,i],n,Ye,t,i)}doSingleRepetition(t){const e=this.getLexerPosition();return t.call(this),this.getLexerPosition()>e}orInternal(t,e){const n=this.getKeyForAutomaticLookahead(256,e),r=D(t)?t:t.DEF,i=this.getLaFuncFromCache(n).call(this,r);if(i!==void 0)return r[i].ALT.call(this);this.raiseNoAltException(e,t.ERR_MSG)}ruleFinallyStateUpdate(){if(this.RULE_STACK.pop(),this.RULE_OCCURRENCE_STACK.pop(),this.cstFinallyStateUpdate(),this.RULE_STACK.length===0&&this.isAtEndOfInput()===!1){const t=this.LA(1),e=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:t,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new Vc(e,t))}}subruleInternal(t,e,n){let r;try{const i=n!==void 0?n.ARGS:void 0;return this.subruleIdx=e,r=t.apply(this,i),this.cstPostNonTerminal(r,n!==void 0&&n.LABEL!==void 0?n.LABEL:t.ruleName),r}catch(i){throw this.subruleInternalError(i,n,t.ruleName)}}subruleInternalError(t,e,n){throw He(t)&&t.partialCstResult!==void 0&&(this.cstPostNonTerminal(t.partialCstResult,e!==void 0&&e.LABEL!==void 0?e.LABEL:n),delete t.partialCstResult),t}consumeInternal(t,e,n){let r;try{const i=this.LA(1);this.tokenMatcher(i,t)===!0?(this.consumeToken(),r=i):this.consumeInternalError(t,i,n)}catch(i){r=this.consumeInternalRecovery(t,e,i)}return this.cstPostTerminal(n!==void 0&&n.LABEL!==void 0?n.LABEL:t.name,r),r}consumeInternalError(t,e,n){let r;const i=this.LA(0);throw r=n!==void 0&&n.ERR_MSG?n.ERR_MSG:this.errorMessageProvider.buildMismatchTokenMessage({expected:t,actual:e,previous:i,ruleName:this.getCurrRuleFullName()}),this.SAVE_ERROR(new qi(r,e,i))}consumeInternalRecovery(t,e,n){if(!this.recoveryEnabled||n.name!=="MismatchedTokenException"||this.isBackTracking())throw n;{const r=this.getFollowsForInRuleRecovery(t,e);try{return this.tryInRuleRecovery(t,r)}catch(i){throw i.name===ys?n:i}}}saveRecogState(){const t=this.errors,e=nt(this.RULE_STACK);return{errors:t,lexerState:this.exportLexerState(),RULE_STACK:e,CST_STACK:this.CST_STACK}}reloadRecogState(t){this.errors=t.errors,this.importLexerState(t.lexerState),this.RULE_STACK=t.RULE_STACK}ruleInvocationStateUpdate(t,e,n){this.RULE_OCCURRENCE_STACK.push(n),this.RULE_STACK.push(t),this.cstInvocationStateUpdate(e)}isBackTracking(){return this.isBackTrackingStack.length!==0}getCurrRuleFullName(){const t=this.getLastExplicitRuleShortName();return this.shortRuleNameToFull[t]}shortRuleNameToFullName(t){return this.shortRuleNameToFull[t]}isAtEndOfInput(){return this.tokenMatcher(this.LA(1),ee)}reset(){this.resetLexerState(),this.subruleIdx=0,this.isBackTrackingStack=[],this.errors=[],this.RULE_STACK=[],this.CST_STACK=[],this.RULE_OCCURRENCE_STACK=[]}},class{ACTION(t){return t.call(this)}consume(t,e,n){return this.consumeInternal(e,t,n)}subrule(t,e,n){return this.subruleInternal(e,t,n)}option(t,e){return this.optionInternal(e,t)}or(t,e){return this.orInternal(e,t)}many(t,e){return this.manyInternal(t,e)}atLeastOne(t,e){return this.atLeastOneInternal(t,e)}CONSUME(t,e){return this.consumeInternal(t,0,e)}CONSUME1(t,e){return this.consumeInternal(t,1,e)}CONSUME2(t,e){return this.consumeInternal(t,2,e)}CONSUME3(t,e){return this.consumeInternal(t,3,e)}CONSUME4(t,e){return this.consumeInternal(t,4,e)}CONSUME5(t,e){return this.consumeInternal(t,5,e)}CONSUME6(t,e){return this.consumeInternal(t,6,e)}CONSUME7(t,e){return this.consumeInternal(t,7,e)}CONSUME8(t,e){return this.consumeInternal(t,8,e)}CONSUME9(t,e){return this.consumeInternal(t,9,e)}SUBRULE(t,e){return this.subruleInternal(t,0,e)}SUBRULE1(t,e){return this.subruleInternal(t,1,e)}SUBRULE2(t,e){return this.subruleInternal(t,2,e)}SUBRULE3(t,e){return this.subruleInternal(t,3,e)}SUBRULE4(t,e){return this.subruleInternal(t,4,e)}SUBRULE5(t,e){return this.subruleInternal(t,5,e)}SUBRULE6(t,e){return this.subruleInternal(t,6,e)}SUBRULE7(t,e){return this.subruleInternal(t,7,e)}SUBRULE8(t,e){return this.subruleInternal(t,8,e)}SUBRULE9(t,e){return this.subruleInternal(t,9,e)}OPTION(t){return this.optionInternal(t,0)}OPTION1(t){return this.optionInternal(t,1)}OPTION2(t){return this.optionInternal(t,2)}OPTION3(t){return this.optionInternal(t,3)}OPTION4(t){return this.optionInternal(t,4)}OPTION5(t){return this.optionInternal(t,5)}OPTION6(t){return this.optionInternal(t,6)}OPTION7(t){return this.optionInternal(t,7)}OPTION8(t){return this.optionInternal(t,8)}OPTION9(t){return this.optionInternal(t,9)}OR(t){return this.orInternal(t,0)}OR1(t){return this.orInternal(t,1)}OR2(t){return this.orInternal(t,2)}OR3(t){return this.orInternal(t,3)}OR4(t){return this.orInternal(t,4)}OR5(t){return this.orInternal(t,5)}OR6(t){return this.orInternal(t,6)}OR7(t){return this.orInternal(t,7)}OR8(t){return this.orInternal(t,8)}OR9(t){return this.orInternal(t,9)}MANY(t){this.manyInternal(0,t)}MANY1(t){this.manyInternal(1,t)}MANY2(t){this.manyInternal(2,t)}MANY3(t){this.manyInternal(3,t)}MANY4(t){this.manyInternal(4,t)}MANY5(t){this.manyInternal(5,t)}MANY6(t){this.manyInternal(6,t)}MANY7(t){this.manyInternal(7,t)}MANY8(t){this.manyInternal(8,t)}MANY9(t){this.manyInternal(9,t)}MANY_SEP(t){this.manySepFirstInternal(0,t)}MANY_SEP1(t){this.manySepFirstInternal(1,t)}MANY_SEP2(t){this.manySepFirstInternal(2,t)}MANY_SEP3(t){this.manySepFirstInternal(3,t)}MANY_SEP4(t){this.manySepFirstInternal(4,t)}MANY_SEP5(t){this.manySepFirstInternal(5,t)}MANY_SEP6(t){this.manySepFirstInternal(6,t)}MANY_SEP7(t){this.manySepFirstInternal(7,t)}MANY_SEP8(t){this.manySepFirstInternal(8,t)}MANY_SEP9(t){this.manySepFirstInternal(9,t)}AT_LEAST_ONE(t){this.atLeastOneInternal(0,t)}AT_LEAST_ONE1(t){return this.atLeastOneInternal(1,t)}AT_LEAST_ONE2(t){this.atLeastOneInternal(2,t)}AT_LEAST_ONE3(t){this.atLeastOneInternal(3,t)}AT_LEAST_ONE4(t){this.atLeastOneInternal(4,t)}AT_LEAST_ONE5(t){this.atLeastOneInternal(5,t)}AT_LEAST_ONE6(t){this.atLeastOneInternal(6,t)}AT_LEAST_ONE7(t){this.atLeastOneInternal(7,t)}AT_LEAST_ONE8(t){this.atLeastOneInternal(8,t)}AT_LEAST_ONE9(t){this.atLeastOneInternal(9,t)}AT_LEAST_ONE_SEP(t){this.atLeastOneSepFirstInternal(0,t)}AT_LEAST_ONE_SEP1(t){this.atLeastOneSepFirstInternal(1,t)}AT_LEAST_ONE_SEP2(t){this.atLeastOneSepFirstInternal(2,t)}AT_LEAST_ONE_SEP3(t){this.atLeastOneSepFirstInternal(3,t)}AT_LEAST_ONE_SEP4(t){this.atLeastOneSepFirstInternal(4,t)}AT_LEAST_ONE_SEP5(t){this.atLeastOneSepFirstInternal(5,t)}AT_LEAST_ONE_SEP6(t){this.atLeastOneSepFirstInternal(6,t)}AT_LEAST_ONE_SEP7(t){this.atLeastOneSepFirstInternal(7,t)}AT_LEAST_ONE_SEP8(t){this.atLeastOneSepFirstInternal(8,t)}AT_LEAST_ONE_SEP9(t){this.atLeastOneSepFirstInternal(9,t)}RULE(t,e,n=qe){if(st(this.definedRulesNames,t)){const i={message:ne.buildDuplicateRuleNameError({topLevelRule:t,grammarName:this.className}),type:ot.DUPLICATE_RULE_NAME,ruleName:t};this.definitionErrors.push(i)}this.definedRulesNames.push(t);const r=this.defineRule(t,e,n);return this[t]=r,r}OVERRIDE_RULE(t,e,n=qe){const r=function(o,s,a){const c=[];let u;return st(s,o)||(u=`Invalid rule override, rule: ->${o}<- cannot be overridden in the grammar: ->${a}<-as it is not defined in any of the super grammars `,c.push({message:u,type:ot.INVALID_RULE_OVERRIDE,ruleName:o})),c}(t,this.definedRulesNames,this.className);this.definitionErrors=this.definitionErrors.concat(r);const i=this.defineRule(t,e,n);return this[t]=i,i}BACKTRACK(t,e){return function(){this.isBackTrackingStack.push(1);const n=this.saveRecogState();try{return t.apply(this,e),!0}catch(r){if(He(r))return!1;throw r}finally{this.reloadRecogState(n),this.isBackTrackingStack.pop()}}}getGAstProductions(){return this.gastProductionsCache}getSerializedGastProductions(){return _(J(this.gastProductionsCache),Qe)}},class{initErrorHandler(t){this._errors=[],this.errorMessageProvider=L(t,"errorMessageProvider")?t.errorMessageProvider:$t.errorMessageProvider}SAVE_ERROR(t){if(He(t))return t.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:nt(this.RULE_OCCURRENCE_STACK)},this._errors.push(t),t;throw Error("Trying to save an Error which is not a RecognitionException")}get errors(){return nt(this._errors)}set errors(t){this._errors=t}raiseEarlyExitException(t,e,n){const r=this.getCurrRuleFullName(),i=mr(t,this.getGAstProductions()[r],e,this.maxLookahead)[0],o=[];for(let a=1;a<=this.maxLookahead;a++)o.push(this.LA(a));const s=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:i,actual:o,previous:this.LA(0),customUserDescription:n,ruleName:r});throw this.SAVE_ERROR(new Hc(s,this.LA(1),this.LA(0)))}raiseNoAltException(t,e){const n=this.getCurrRuleFullName(),r=Dr(t,this.getGAstProductions()[n],this.maxLookahead),i=[];for(let a=1;a<=this.maxLookahead;a++)i.push(this.LA(a));const o=this.LA(0),s=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:r,actual:i,previous:o,customUserDescription:e,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new zc(s,this.LA(1),o))}},class{initContentAssist(){}computeContentAssist(t,e){const n=this.gastProductionsCache[t];if(zt(n))throw Error(`Rule ->${t}<- does not exist in this grammar.`);return hs([n],e,this.tokenMatcher,this.maxLookahead)}getNextPossibleTokenTypes(t){const e=Ot(t.ruleStack),n=this.getGAstProductions()[e];return new kc(n,t).startWalking()}},class{initGastRecorder(t){this.recordingProdStack=[],this.RECORDING_PHASE=!1}enableRecording(){this.RECORDING_PHASE=!0,this.TRACE_INIT("Enable Recording",()=>{for(let t=0;t<10;t++){const e=t>0?t:"";this[`CONSUME${e}`]=function(n,r){return this.consumeInternalRecord(n,t,r)},this[`SUBRULE${e}`]=function(n,r){return this.subruleInternalRecord(n,t,r)},this[`OPTION${e}`]=function(n){return this.optionInternalRecord(n,t)},this[`OR${e}`]=function(n){return this.orInternalRecord(n,t)},this[`MANY${e}`]=function(n){this.manyInternalRecord(t,n)},this[`MANY_SEP${e}`]=function(n){this.manySepFirstInternalRecord(t,n)},this[`AT_LEAST_ONE${e}`]=function(n){this.atLeastOneInternalRecord(t,n)},this[`AT_LEAST_ONE_SEP${e}`]=function(n){this.atLeastOneSepFirstInternalRecord(t,n)}}this.consume=function(t,e,n){return this.consumeInternalRecord(e,t,n)},this.subrule=function(t,e,n){return this.subruleInternalRecord(e,t,n)},this.option=function(t,e){return this.optionInternalRecord(e,t)},this.or=function(t,e){return this.orInternalRecord(e,t)},this.many=function(t,e){this.manyInternalRecord(t,e)},this.atLeastOne=function(t,e){this.atLeastOneInternalRecord(t,e)},this.ACTION=this.ACTION_RECORD,this.BACKTRACK=this.BACKTRACK_RECORD,this.LA=this.LA_RECORD})}disableRecording(){this.RECORDING_PHASE=!1,this.TRACE_INIT("Deleting Recording methods",()=>{const t=this;for(let e=0;e<10;e++){const n=e>0?e:"";delete t[`CONSUME${n}`],delete t[`SUBRULE${n}`],delete t[`OPTION${n}`],delete t[`OR${n}`],delete t[`MANY${n}`],delete t[`MANY_SEP${n}`],delete t[`AT_LEAST_ONE${n}`],delete t[`AT_LEAST_ONE_SEP${n}`]}delete t.consume,delete t.subrule,delete t.option,delete t.or,delete t.many,delete t.atLeastOne,delete t.ACTION,delete t.BACKTRACK,delete t.LA})}ACTION_RECORD(t){}BACKTRACK_RECORD(t,e){return()=>!0}LA_RECORD(t){return nn}topLevelRuleRecord(t,e){try{const n=new me({definition:[],name:t});return n.name=t,this.recordingProdStack.push(n),e.call(this),this.recordingProdStack.pop(),n}catch(n){if(n.KNOWN_RECORDER_ERROR!==!0)try{n.message=n.message+`
This error was thrown during the "grammar recording phase" For more info see:
https://chevrotain.io/docs/guide/internals.html#grammar-recording`}catch{throw n}throw n}}optionInternalRecord(t,e){return ve.call(this,lt,t,e)}atLeastOneInternalRecord(t,e){ve.call(this,Mt,e,t)}atLeastOneSepFirstInternalRecord(t,e){ve.call(this,Ut,e,t,Ji)}manyInternalRecord(t,e){ve.call(this,tt,e,t)}manySepFirstInternalRecord(t,e){ve.call(this,_t,e,t,Ji)}orInternalRecord(t,e){return tu.call(this,t,e)}subruleInternalRecord(t,e,n){if(pn(e),!t||L(t,"ruleName")===!1){const s=new Error(`<SUBRULE${eo(e)}> argument is invalid expecting a Parser method reference but got: <${JSON.stringify(t)}>
inside top level rule: <${this.recordingProdStack[0].name}>`);throw s.KNOWN_RECORDER_ERROR=!0,s}const r=de(this.recordingProdStack),i=t.ruleName,o=new pt({idx:e,nonTerminalName:i,label:n?.LABEL,referencedRule:void 0});return r.definition.push(o),this.outputCst?Jc:Ln}consumeInternalRecord(t,e,n){if(pn(e),!cs(t)){const o=new Error(`<CONSUME${eo(e)}> argument is invalid expecting a TokenType reference but got: <${JSON.stringify(t)}>
inside top level rule: <${this.recordingProdStack[0].name}>`);throw o.KNOWN_RECORDER_ERROR=!0,o}const r=de(this.recordingProdStack),i=new V({idx:e,terminalType:t,label:n?.LABEL});return r.definition.push(i),Rs}},class{initPerformanceTracer(t){if(L(t,"traceInitPerf")){const e=t.traceInitPerf,n=typeof e=="number";this.traceInitMaxIdent=n?e:1/0,this.traceInitPerf=n?e>0:e}else this.traceInitMaxIdent=0,this.traceInitPerf=$t.traceInitPerf;this.traceInitIndent=-1}TRACE_INIT(t,e){if(this.traceInitPerf===!0){this.traceInitIndent++;const n=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent<this.traceInitMaxIdent&&console.log(`${n}--> <${t}>`);const{time:r,value:i}=Jo(e),o=r>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&o(`${n}<-- <${t}> time: ${r}ms`),this.traceInitIndent--,i}return e()}}].forEach(t=>{const e=t.prototype;Object.getOwnPropertyNames(e).forEach(n=>{if(n==="constructor")return;const r=Object.getOwnPropertyDescriptor(e,n);r&&(r.get||r.set)?Object.defineProperty(zn.prototype,n,r):zn.prototype[n]=t.prototype[n]})});class eu extends Me{constructor(e,n=$t){const r=nt(n);r.outputCst=!1,super(e,r)}}const nu=P({name:"WhiteSpace",pattern:/\s+/,group:ct.SKIPPED}),Os=P({name:"String",pattern:/"(""|[^"])*"/}),ru=P({name:"SingleQuotedString",pattern:/'(''|[^'])*'/}),iu=P({name:"SheetQuoted",pattern:/'((?![\\/[\]*?:]).)+?'!/}),ou=P({name:"FunctionToken",pattern:/[A-Za-z_]+[A-Za-z_0-9.]*\(/}),Ss=P({name:"NamedTableReference",pattern:/[A-Za-z_]+[A-Za-z_0-9.]*\[/}),su=P({name:"BracketedString",pattern:/\[([^[\]]*)\]/,longer_alt:[Ss,Os]}),_s=P({name:"LiteralError",pattern:/#PARSE!|#NULL!|#DIV\/0!|#VALUE!|#NUM!|#FIELD!|#N\/A|#GETTING_DATA|#SPILL!|#CONNECT!|#BLOCKED!|#UNKNOWN!|#FIELD!|#CALC!|#BUSY!|#PYTHON!|#TIMEOUT!/}),Ls=P({name:"RefError",pattern:/#REF!|#NAME\?/}),au=P({name:"Sheet",pattern:/[A-Za-z_.\d\u007F-\uFFFF]+!/}),cu=/^[a-zA-Z_][a-zA-Z0-9_.?]*:?/,xn=P({name:"Name",pattern:{exec:(t,e)=>{try{const n=cu.exec(t.substring(e));if(n){const r=n[0];if(r.endsWith(":")){const i=r.length;return r[i-2]==="."?[r.substring(0,i-2)]:[r.substring(0,i-1)]}return[r]}}catch(n){console.warn("Error parsing name",n)}return null}},line_breaks:!1,start_chars_hint:(()=>{const t=[];for(let e=65;e<=90;e++)t.push(e);for(let e=97;e<=122;e++)t.push(e);for(let e=48;e<=57;e++)t.push(e);return t})()}),uu=P({name:"Cell",pattern:/[$]?[A-Za-z]{1,3}[$]?[1-9][0-9]*/,longer_alt:xn}),lu=P({name:"Column",pattern:/[$]?[A-Za-z]{1,3}/,longer_alt:xn}),hu=P({name:"AbsRow",pattern:/[$][0-9]+/,longer_alt:xn}),fu=P({name:"NumberToken",pattern:/[0-9]+[.]?[0-9]*([eE][+-][0-9]+)?/}),du=P({name:"Boolean",pattern:/TRUE|FALSE/i}),pu=P({name:"Comma",pattern:/,/}),mu=P({name:"RangeUnion",pattern:/:/}),Eu=P({name:"RangeTrimFull",pattern:/\.:\./}),gu=P({name:"RangeTrimLeading",pattern:/\.:/}),Tu=P({name:"RangeTrimTrailing",pattern:/:\./}),Au=P({name:"Semicolon",pattern:/;/}),Iu=P({name:"OpenParen",pattern:/\(/}),yu=P({name:"CloseParen",pattern:/\)/}),vu=P({name:"OpenSquareParen",pattern:/\[/}),Nu=P({name:"CloseSquareParen",pattern:/]/});P({name:"exclamationMark",pattern:/!/});const Ru=P({name:"OpenCurlyParen",pattern:/{/}),Ou=P({name:"CloseCurlyParen",pattern:/}/}),Su=P({name:"QuoteS",pattern:/'/}),no=P({name:"MulOp",pattern:/\*/}),_u=P({name:"PlusOp",pattern:/\+/}),Lu=P({name:"DivOp",pattern:/\//}),xu=P({name:"MinOp",pattern:/-/}),Cu=P({name:"ImplicitIntersectOp",pattern:/@/}),ku=P({name:"ConcatOp",pattern:/&/}),bu=P({name:"ExOp",pattern:/\^/}),Pu=P({name:"PercentOp",pattern:/%/}),xs=P({name:"TableSpecifier",pattern:/#(All|Data|Headers|Totals|This Row)/i}),wu=P({name:"ArrayAnchorOp",pattern:/#/,longer_alt:[xs,_s,Ls]}),Mu=P({name:"GtOp",pattern:/>/}),Uu=P({name:"EqOp",pattern:/=/}),Fu=P({name:"LtOp",pattern:/</}),Cs=[nu,Os,iu,ru,ou,Ss,su,_s,Ls,au,uu,du,lu,hu,xs,wu,Cu,xn,fu,pu,Eu,gu,Tu,mu,Au,Iu,yu,vu,Nu,Ru,Ou,Su,no,_u,Lu,xu,ku,bu,no,Pu,P({name:"NeqOp",pattern:/<>/}),P({name:"GteOp",pattern:/>=/}),P({name:"LteOp",pattern:/<=/}),Mu,Uu,Fu],Du=new ct(Cs,{ensureOptimizations:!0}),Br={};Cs.forEach(t=>{Br[t.name]=t});const Xt={boolean:3,string:2,number:1},ju=(t,e)=>{let n=t+e;return n=Math.abs(n)<99e-14?0:n,isFinite(n)?n:Number.NaN},Bu=(t,e)=>{let n=t-e;return n=Math.abs(n)<99e-14?0:n,isFinite(n)?n:Number.NaN},ks=(t,e)=>{let n=t*e;return n=Math.abs(n)<99e-14?0:n,isFinite(n)?n:Number.NaN},bs=(t,e)=>{if(e===0)return 1/0;let n=t/e;return n=Math.abs(n)<99e-14?0:n,isFinite(n)?n:Number.NaN},$u=(t,e)=>{const n=t**e;return isFinite(n)?n:Number.NaN},Wu=(t="",e="")=>(t===null&&(t=""),e===null&&(e=""),typeof t=="boolean"&&(t=t?"TRUE":"FALSE"),typeof e=="boolean"&&(e=e?"TRUE":"FALSE"),""+t+e),Gu=(t=null,e=null)=>typeof t==typeof e&&t===e,Ku=(t=null,e=null)=>typeof t!=typeof e||t!==e,zu=(t=null,e=null)=>{const n=typeof t,r=typeof e;return n===r?t>e:Xt[n]>Xt[r]},Vu=(t=null,e=null)=>{const n=typeof t,r=typeof e;return n===r?t>=e:Xt[n]>=Xt[r]},Hu=(t=null,e=null)=>{const n=typeof t,r=typeof e;return n===r?t<e:Xt[n]<Xt[r]},Yu=(t=null,e=null)=>{const n=typeof t,r=typeof e;return n===r?t<=e:Xt[n]<=Xt[r]},Xu={type:w.ScalarType.Number,coerce:!0,includeBoolean:!0,includeMistyped:!0,mismatchFill:w.FormulaError.BuiltIn.NA},qu={type:w.ScalarType.String,coerce:!0,includeMistyped:!0,mismatchFill:w.FormulaError.BuiltIn.NA},Ps={type:null,coerce:!0,includeMistyped:!0,mismatchFill:w.FormulaError.BuiltIn.NA},ue=(t,e,n,r)=>{if(e!==null&&e.colStart!==void 0&&(e=t.getValueAt(e.rowStart,e.colStart)),n!==null&&n.colStart!==void 0&&(n=t.getValueAt(n.rowStart,n.colStart)),typeof e=="number"&&typeof n=="number")return r(e,n);let i,o;return e?.isIRange?i=e:n?.isIRange&&(o=n),!i&&!o?(e=G.coerceScalar(e,G.typeFromJsValue(e,!0),w.ScalarType.Number,!0,!1),n=G.coerceScalar(n,G.typeFromJsValue(n,!0),w.ScalarType.Number,!0,!1),e instanceof w.FormulaError.Value?e:n instanceof w.FormulaError.Value?n:r(e,n)):(i||(i=t.getRange(e)),i.broadcast(n,r,Xu).fillEmpty(0))},ae=(t,e,n,r)=>{let i,o;return e!==null&&e.colStart!==void 0&&(e=t.getValueAt(e.rowStart,e.colStart)),n!==null&&n.colStart!==void 0&&(n=t.getValueAt(n.rowStart,n.colStart)),e?.isIRange?(i=e,o=n):n?.isIRange&&(i=n,o=e),i?i.broadcast(o,r,Ps):r(e,n)},ro=(t,e)=>{e==null&&(e=0);let n,r=1;if(t==="+")return e;if(t!=="-")throw new w.FormulaError.Value(`Unrecognized prefix: ${t}`);return r=-r,e?.isIRange&&(n=e),n?n.broadcast(r,ks,Ps):typeof(e=G.coerceScalar(e,G.typeFromJsValue(e,!0),w.ScalarType.Number))!="number"||isNaN(e)?w.FormulaError.BuiltIn.Value:e*r},Ne=(t,e,n,r)=>{if(!e||(e.isIReferenceRange&&(e=e.getCoords()),e.colStart===void 0)||(n.isIReferenceRange&&(n=n.getCoords()),n.colStart===void 0))return w.FormulaError.BuiltIn.Ref;const i=r(e,n);return i?t.getReference(i):w.FormulaError.BuiltIn.Null},Zu={"+":(t,e,n)=>ue(t,e,n,ju),"-":(t,e,n)=>ue(t,e,n,Bu),"*":(t,e,n)=>ue(t,e,n,ks),"/":(t,e,n)=>ue(t,e,n,bs),"^":(t,e,n)=>ue(t,e,n,$u)," ":(t,e,n,r)=>Ne(t,e,n,X.CoordUtils.intersectRanges),":":(t,e,n,r)=>Ne(t,e,n,X.CoordUtils.unionRanges),".:.":(t,e,n,r)=>{const i=Ne(t,e,n,X.CoordUtils.unionRanges);return t.getFunction("TRIMRANGE").execute(i,3,3)},".:":(t,e,n,r)=>{const i=Ne(t,e,n,X.CoordUtils.unionRanges);return t.getFunction("TRIMRANGE").execute(i,1,1)},":.":(t,e,n,r)=>{const i=Ne(t,e,n,X.CoordUtils.unionRanges);return t.getFunction("TRIMRANGE").execute(i,2,2)},"&":(t,e,n)=>((r,i,o,s)=>{if(i!==null&&i.colStart!==void 0&&(i=r.getValueAt(i.rowStart,i.colStart)),o!==null&&o.colStart!==void 0&&(o=r.getValueAt(o.rowStart,o.colStart)),typeof i=="string"&&typeof o=="string")return s(i,o);let a,c;return i?.isIRange?a=i:o?.isIRange&&(c=o),a||c?(a||(a=r.getRange(i)),a.broadcast(o,s,qu)):s(i=G.coerceScalar(i,G.typeFromJsValue(i,!0),w.ScalarType.String),o=G.coerceScalar(o,G.typeFromJsValue(o,!0),w.ScalarType.String))})(t,e,n,Wu),"=":(t,e,n)=>ae(t,e,n,Gu),"<>":(t,e,n)=>ae(t,e,n,Ku),">":(t,e,n)=>ae(t,e,n,zu),"<":(t,e,n)=>ae(t,e,n,Hu),">=":(t,e,n)=>ae(t,e,n,Vu),"<=":(t,e,n)=>ae(t,e,n,Yu)},Qu={"-":(t,e)=>ro("-",e),"+":(t,e)=>ro("+",e),"@":(t,e)=>{if(!e||!e.isIReferenceRange)return e;const n=e.getCoords(),r=e,i=t.getPosition(),o=r.getHeight(),s=r.getWidth();if(s>1&&o>1)return w.FormulaError.BuiltIn.Value;if(o>1){const a=i.rowIndex-n.rowStart;if(a>=0&&a<o)return r.getValueAt(a,0)}else{if(!(s>1))return r.getValueAt(0,0);{const a=i.colIndex-n.colStart;if(a>=0&&a<s)return r.getValueAt(0,a)}}return w.FormulaError.BuiltIn.Value}},Ju={"%":(t,e)=>ue(t,e,100,bs),"#":(t,e)=>t.getSpillAt(e.rowStart,e.colStart)||w.FormulaError.BuiltIn.Ref};function io(t){const e=(t=t.toUpperCase()).length;let n=0;for(let r=0;r<e;r++){const i=t.charCodeAt(r);isNaN(i)||(n+=(i-64)*26**(e-r-1))}return n}function Vn(t){return{type:"cell",value:Object.freeze({colIndex:t.colIndex,rowIndex:t.rowIndex,$colIndex:t.$colIndex||!1,$rowIndex:t.$rowIndex||!1}),inputs:null,isReference:!0}}function oo(t,e){const n=t.startsWith("$");n&&(t=t.substring(1));let r=parseInt(t)-1;return n||r===Number.MIN_SAFE_INTEGER||(r-=e.colIndex),{type:"cell",value:Object.freeze({colIndex:Number.MIN_SAFE_INTEGER,$colIndex:!1,rowIndex:r,$rowIndex:n}),inputs:null,isReference:!0}}function so(t,e){return{type:"function",value:t=t.toUpperCase(),inputs:e}}function Hn(t,e){return{type:"tableReference",value:t,inputs:e}}function Yn(t){return{type:"tableSpecifier",value:t,inputs:null,isReference:!0}}function Tr(t,e,n,r=!1){const i={type:"infix",value:t,inputs:[e,n]};return r&&(i.isReference=!0),i}function Xn(t,e,n=!1){const r={type:"postfix",value:t,inputs:[e]};return n&&(r.isReference=!0),r}function Se(t,e,n=!1){const r={type:"prefix",value:t,inputs:[e]};return n&&(r.isReference=!0),r}function qn(t){return{type:"named",value:t,inputs:null,isReference:!0}}function ao(t){return{type:"number",value:Number(t),isLiteral:!0}}function Zn(t){let e=t;const n=t&&t.length>1&&t[0]==='"'&&t[t.length-1]==='"';return n&&(e=t.substring(1,t.length-1)),{type:n?"quotedString":"string",value:e,isLiteral:!0}}function co(t){return{type:"boolean",value:t==="TRUE"||t.toUpperCase()==="TRUE",isLiteral:!0}}function uo(t){return{type:"error",value:w.FormulaError.getBuiltInByLabel(t.toUpperCase()),isLiteral:!0}}function mn(t){return{type:"error",value:t?w.FormulaError.getBuiltInByLabel(t.toUpperCase()):w.FormulaError.BuiltIn.Ref,inputs:null,isReference:!0}}function Ue(t,e){return function r(i,o){const s=i.inputs;let a;if(s){const l=s.length;for(let h=0;h<l;h++){const f=s[h],d=r(f,i);d!==f&&(a||(a=[...s]),a[h]=d)}}const c=a?{...i,inputs:a}:i,u=e(c,o);return u===void 0?c:u}(t,void 0)||this}function rn(t,e){let n=0,r=Ue(t,p=>{const A={...p};return A.evalIndex=n++,A});const i=new Array(n),o=new Set,s=new Map;let a;const c=new Map,u=[],l=[];r=Ue(r,(p,A)=>{const O=p.type,g=p.evalIndex;if(i[g]=null,p.isReference){const R=p,v={node:p,index:c.size,op:null,value:null,inputs:null};if(c.set(R,v),O==="cell"){const y=R.value;return y.$colIndex&&(v.hasHorizontalAbs=!0),y.$rowIndex&&(v.hasVerticalAbs=!0),v.value=s.size,s.set(R,s.size),o.add(v),p.refIndex=l.length,void l.push(v.index)}if(O==="infix"||O==="prefix"||O==="postfix"||O==="spill"){const y=R.inputs,N=y.length,U=p.value;v.op=U;const M=new Array(N);v.inputs=M;for(let F=0;F<N;F++){const $=y[F],x=c.get($);x&&(x.hasHorizontalAbs&&(v.hasHorizontalAbs=!0),x.hasVerticalAbs&&(v.hasVerticalAbs=!0)),M[F]=x?x.index:-1,o.delete(x)}if(o.add(v),ws.includes(U)){const F=y[0],$=!!F&&F.type==="cell",x=y[1],C=!!x&&x.type==="cell";$&&C&&(l.splice(x.refIndex,1),x.refIndex=F.refIndex,p.refIndex=F.refIndex,l[F.refIndex]=v.index)}else U==="#"&&(p.refIndex=y[0].refIndex);return void u.push(p)}if(O==="error"||O==="named"){a||(a=new Map);const y=R.value;let N=a.get(y);return v.op=O,N===void 0&&(N=a.size,a.set(y,N)),v.value=N,o.add(v),p.refIndex=l.length,void l.push(v.index)}O==="tableReference"&&(v.op=O),O==="tableSpecifier"&&(v.op=O),O==="structuredArg"&&(v.op=O)}else if(A&&A.isReference){const R=p,v={node:p,index:c.size,op:"function",value:p.value,inputs:null};c.set(R,v)}if(p.isLiteral)if(O!=="array")i[g]=p.value;else{const R=p.value,v=R.length,y=new Array(v);for(let N=0;N<v;N++){const U=R[N].value,M=U.length,F=new Array(M);for(let $=0;$<M;$++){const x=U[$];let C=x.value;if(x.type==="prefix"){const j=x.value;C=x.inputs[0].value,j==="-"&&(C=-C)}F[$]=C}y[N]=F}i[g]=G.gridFromArray(y)}else{if(O!=="empty")return u.push(p),p;i[g]=void 0}});const h=new Array(s.size);s.forEach((p,A)=>{const O=A.value,g=O.colIndex,R=O.rowIndex,v=O.$colIndex,y=O.$rowIndex,N={colStart:g,rowStart:R,colEnd:g,rowEnd:R,$colStart:v,$rowStart:y,$colEnd:v,$rowEnd:y};g===Number.MIN_SAFE_INTEGER&&(N.colEnd=Number.MAX_SAFE_INTEGER),R===Number.MIN_SAFE_INTEGER&&(N.rowEnd=Number.MAX_SAFE_INTEGER),O.sheetName&&(N.sheetName=O.sheetName),h[p]=N});const f=h.length,d=new Array(f);for(let p=0;p<f;p++)d[p]={colStart:0,rowStart:0,colEnd:0,rowEnd:0,sheetName:null};const E=new Array(c.size);let I;c.forEach(p=>{E[p.index]=p}),a&&(I=[],a.forEach((p,A)=>{I.push(A)}));const S=[];o.forEach(p=>{S.push(p.index)});const T=u.length;for(let p=0;p<T;p++){const A=u[p],O=A.type;if(O==="infix"){const g=A.value;A.fn=Zu[g]}else if(O==="prefix"){const g=A.value;A.fn=Qu[g]}else if(O==="postfix"){const g=A.value;A.fn=Ju[g]}}const m=function(p){const A=[],O=(v,y)=>{const N={type:v.type,value:v.value};v.evalIndex!==void 0&&(N.evalIndex=v.evalIndex),v.refIndex!==void 0&&(N.refIndex=v.refIndex),y&&(N.ctx=y),A.push(N)},g=(v,y,N,U)=>{if(y==null||A.length>1&&v==="whitespace"&&A[A.length-1].type==="whitespace")return;const M={type:v,value:y};N&&(M.ctx=N),U!==void 0&&(M.evalIndex=U),A.push(M)};(function v(y,N,U){const M=y.evalIndex??U??0,F=y.type,$=(x,C,j)=>{if(!x)return;const q=x.length;for(let B=0;B<q;B++)v(x[B],C,j),B<q-1&&g("comma",",",C)};if(y.isLiteral){if(g("whitespace",y.wsBefore,N),F==="array"){g("type","{",N);const x=y.value,C=x.length;for(let j=0;j<C;j++){const q=x[j],B=q.value,rt=B.length;for(let Zt=0;Zt<rt;Zt++){const ge=B[Zt];g("whitespace",ge.wsBefore,N),v(ge,N,M),g("whitespace",ge.wsAfter,N),Zt<rt-1&&g("comma",",",N)}j<C-1&&(g("whitespace",q.wsBefore,N),g("comma",";",N),g("whitespace",q.wsAfter,N))}y.error||g("type","}",N)}else F==="quotedString"&&(y={type:F,value:'"'+y.value+'"'}),O(y,N);g("whitespace",y.wsAfter,N)}else if(F==="infix")v(y.inputs[0],N,M),g("whitespace",y.wsBefore,N),O(y,N),g("whitespace",y.wsAfter,N),v(y.inputs[1],N,M);else if(F==="prefix")g("whitespace",y.wsBefore,N),O(y,N),g("whitespace",y.wsAfter,N),v(y.inputs[0],N,M);else if(F==="postfix")v(y.inputs[0],N,M),g("whitespace",y.wsBefore,N),O(y,N),g("whitespace",y.wsAfter,N);else{g("whitespace",y.wsBefore,N);const x=y.inputs;switch(F){case"function":O(y,N);const C={name:String(y.value),argIndex:-1};if(g("paren","(",C,y.evalIndex),x){const q=x.length;for(let B=0;B<q;B++){const rt={...C,argIndex:B};v(x[B],rt,M),B<q-1&&g("comma",",",rt)}}y.error||g("paren",")",C,y.evalIndex);break;case"cell":O(y,N);break;case"paren":g(F,"(",N,M),$(x,N,M),y.error||g(F,")",N,M);break;case"squareParen":g(F,"[",N,M),$(x,N,M),y.error||g(F,"]",N,M);break;case"tableReference":O(y,N);const j={name:String(y.value),argIndex:-1};if(g("paren","[",j),x){const q=x.length;for(let B=0;B<q;B++){const rt={...j,argIndex:B};v(x[B],rt,M),B<q-1&&g("comma",",",rt)}}y.error||g("paren","]",j);break;default:y.value!==void 0&&O(y,N),x&&x.forEach(q=>v(q,N,M))}g("whitespace",y.wsAfter,N)}})(p);const R=A.length;for(let v=0;v<R;v++){const y=A[v];if(y.type==="whitespace"&&y.evalIndex===void 0){const N=A[v+1];N&&N.evalIndex!==void 0&&(y.evalIndex=N.evalIndex)}}return A}(r);return{ast:r,evaluations:i,executions:u,precedentsAbsolute:d,precedentsExecute:E,precedentsNamed:I,precedentsRelative:h,precedentsRoot:S,references:l,tokens:m,error:e}}function lo(t,e){let n,r=-1,i="";Number.isSafeInteger(t.previousToken?.startLine)?(r=t.previousToken.startLine,n=t.previousToken.endColumn+1):Number.isSafeInteger(t.token?.startLine)&&(r=t.token.startLine,n=t.token.startColumn),r!==-1?(i+=`
`+e.split(`
`)[r-1]+`
`,i+=Array(n-1).fill(" ").join("")+`^
`,i+=`Error at position ${r}:${n}
`+t.message,t.errorLocation={line:r,column:n}):i=e+`
`+t.message;const o=new w.FormulaError.Parse(i);return o.details=t,o}const Qn=function(t,e){return e.wsBefore&&(t.wsBefore=e.wsBefore),e.wsAfter&&(t.wsAfter=e.wsAfter),e.image&&(t.image=e.image),t},tl="_XLFN.",ho=Object.freeze([[":",".:.",".:",,":."],["^"],["*","/"],["+","-"],["&"],["<",">","=","<>","<=",">="]]),ws=Object.freeze([":",".:.",".:",,":."]),el=Object.freeze([":"," ",".:.",".:",,":."]),nl=Object.freeze(["@"]),rl=Object.freeze(["#"]),Jn=Object.freeze(el.concat(nl).concat(rl)),{String:fo,SheetQuoted:il,SingleQuotedString:ol,FunctionToken:sl,NamedTableReference:al,LiteralError:po,RefError:mo,Cell:cl,Sheet:ul,Name:Eo,NumberToken:go,Boolean:To,Column:ll,AbsRow:hl,ImplicitIntersectOp:tr,Comma:ce,RangeUnion:fl,RangeTrimFull:dl,RangeTrimLeading:pl,RangeTrimTrailing:ml,Semicolon:El,OpenParen:gl,CloseParen:er,OpenSquareParen:Ao,CloseSquareParen:Io,OpenCurlyParen:Tl,CloseCurlyParen:Al,MulOp:Il,PlusOp:nr,DivOp:yl,MinOp:rr,ConcatOp:vl,ExOp:Nl,PercentOp:Rl,ArrayAnchorOp:yo,TableSpecifier:Ol,BracketedString:vo,NeqOp:Sl,GteOp:_l,LteOp:Ll,GtOp:xl,EqOp:Cl,LtOp:kl}=Br;class bl extends eu{constructor(){super(Br,{nodeLocationTracking:"full",maxLookahead:1,skipValidations:!0,recoveryEnabled:!0}),this.position={colIndex:0,rowIndex:0},this.astErrors=[];const e=this,n=(r,i,o)=>{let s;e.CONSUME(i);const a=e.getLexerPosition();s=e.ACTION(()=>(s={type:r,value:null,inputs:null},this._ensureWhitespace(s,a,!0)));const c=[],u=e.SUBRULE(e.intersectOp);u&&c.push(u);const l=e.SUBRULE(e.group),h=e.OPTION(()=>this.CONSUME(o));return s=e.ACTION(()=>{if(l)for(let f=0;f<l.length;f++)c.push(l[f]);return s&&(h||this._reportError(s,"Missing closing parenthesis",a),s.inputs=c),this._ensureWhitespace(s,e.getLexerPosition(),!1,!0)}),s};e.RULE("infixOp",()=>{const r=[],i=[e.SUBRULE(e.postfixOp)];return e.MANY(()=>{const o=e.OR(e.c1||(e.c1=[{ALT:()=>e.CONSUME(fl).image},{ALT:()=>e.CONSUME(nr).image},{ALT:()=>e.CONSUME(rr).image},{ALT:()=>e.CONSUME(Il).image},{ALT:()=>e.CONSUME(yl).image},{ALT:()=>e.CONSUME(Nl).image},{ALT:()=>e.CONSUME(vl).image},{ALT:()=>e.CONSUME(xl).image},{ALT:()=>e.CONSUME(Cl).image},{ALT:()=>e.CONSUME(kl).image},{ALT:()=>e.CONSUME(Sl).image},{ALT:()=>e.CONSUME(_l).image},{ALT:()=>e.CONSUME(Ll).image},{ALT:()=>e.CONSUME(dl).image},{ALT:()=>e.CONSUME(pl).image},{ALT:()=>e.CONSUME(ml).image}]));r.push([o,e.getLexerPosition(),Jn.includes(o)]),i.push(e.SUBRULE2(e.postfixOp))}),e.ACTION(()=>{let o=r.length;const s=ho.length;for(let a=0;o>0&&a<s;a++){const c=ho[a];let u=r.length;for(let l=0;l<u;l++){const h=r[l],f=h[0];if(!c.includes(f))continue;let d=Tr(f,i[l],i[l+1],h[2]);d=this._ensureWhitespace(d,h[1]),r.splice(l,1),i.splice(l,2,d),l--,u--,o--}}}),i[0]}),e.RULE("plusMinusOp",()=>e.OR([{ALT:()=>e.CONSUME(nr).image},{ALT:()=>e.CONSUME(rr).image}])),e.RULE("postfixOp",()=>{let r=e.SUBRULE(e.prefixOp);const i=[];return e.MANY(()=>{const o=e.OR([{ALT:()=>e.CONSUME(Rl).image},{ALT:()=>e.CONSUME(yo).image}]);e.ACTION(()=>{i.push([o,e.getLexerPosition()])})}),e.ACTION(()=>{const o=i.length;if(o!==0)for(let s=0;s<o;s++){const a=i[s],c=a[0],u=a[1],l=Jn.includes(c);r=Xn(c,r,l),r=this._ensureWhitespace(r,u)}}),r}),e.RULE("prefixOp",()=>{const r=[];e.MANY(()=>{const o=e.OR([{ALT:()=>e.CONSUME(nr).image},{ALT:()=>e.CONSUME(rr).image},{ALT:()=>e.CONSUME(tr).image}]);e.ACTION(()=>{r.push([o,e.getLexerPosition()])})});let i=e.SUBRULE(e.formula);return e.ACTION(()=>{const o=r.length;if(o!==0)for(let s=o-1;s>=0;s--){const a=r[s],c=a[0],u=a[1],l=Jn.includes(c);i=Se(c,i,l),i=this._ensureWhitespace(i,u)}}),i}),e.RULE("intersectOp",()=>{const r=[e.SUBRULE(e.infixOp)];return e.MANY(()=>{e.OPTION({GATE:()=>{const i=e.LA(0);return e.LA(1).startOffset>i.endOffset+1},DEF:()=>{r.push(e.SUBRULE3(e.infixOp))}})}),e.ACTION(()=>{for(;r.length>1;){let i=r.length-1;for(let o=0;o<i;o++){const s=r[o],a=r[o+1],c=Tr(" ",s,a,!0);if(delete s.wsAfter,a.wsBefore){const u=a.wsBefore.slice(0,-1),l=u.length;delete a.wsBefore,l>0&&(c.wsBefore=u)}o+1<i&&delete a.wsAfter,r.splice(o,2,c),o--,i--}}}),r[0]}),e.RULE("formula",()=>e.OR9([{ALT:()=>e.SUBRULE(e.referenceWithoutInfix)},{ALT:()=>e.SUBRULE(e.function)},{ALT:()=>e.SUBRULE(e.paren)},{ALT:()=>e.SUBRULE(e.namedTableReference)},{ALT:()=>e.SUBRULE(e.bracketedString)},{ALT:()=>e.SUBRULE(e.squareParen)},{ALT:()=>e.SUBRULE(e.literal)},{ALT:()=>e.SUBRULE(e.literalArray)}])),e.RULE("group",()=>{const r=[];return e.MANY(()=>{e.CONSUME(ce);const i=e.SUBRULE2(e.intersectOp);e.ACTION(()=>{r.push(i)})}),r}),e.RULE("paren",()=>n("paren",gl,er)),e.RULE("literalArray",()=>{let r={type:"row",value:[],isLiteral:!0};e.CONSUME(Tl);const i=e.getLexerPosition();let o=e.ACTION(()=>this._ensureWhitespace({type:"array",value:[r],isLiteral:!0},i,!0));const s=e.SUBRULE(e.literalForArray);e.ACTION(()=>{r.value.push(s)}),e.MANY(()=>{const c=e.OR([{ALT:()=>e.CONSUME(ce).image},{ALT:()=>e.CONSUME(El).image}]),u=e.SUBRULE2(e.literalForArray);e.ACTION(()=>{c===","||(r={type:"row",value:[],isLiteral:!0},o.value.push(r)),r.value.push(u)})});const a=e.OPTION(()=>this.CONSUME(Al));return o=e.ACTION(()=>(a||this._reportError(o,"Missing closing parenthesis '}'",i),this._ensureWhitespace(o,e.getLexerPosition(),!1,!0))),o}),e.RULE("literalForArray",()=>e.OR([{ALT:()=>{const r=e.OPTION(()=>e.SUBRULE(e.plusMinusOp)),i=e.CONSUME(go),o=e.ACTION(()=>this._ensureWhitespace(ao(i.image),e.getLexerPosition()));return r?e.ACTION(()=>function(s,a){return{type:"prefix",value:s,inputs:[a]}}(r,o)):o}},{ALT:()=>{const r=e.CONSUME(fo);return e.ACTION(()=>this._ensureWhitespace(Zn(r.image),e.getLexerPosition()))}},{ALT:()=>{const r=e.CONSUME(To);return e.ACTION(()=>this._ensureWhitespace(co(r.image),e.getLexerPosition()))}},{ALT:()=>{const r=e.CONSUME(po);return e.ACTION(()=>this._ensureWhitespace(uo(r.image),e.getLexerPosition()))}},{ALT:()=>{const r=e.CONSUME(mo);return e.ACTION(()=>this._ensureWhitespace(mn(r.image),e.getLexerPosition()))}}])),e.RULE("literal",()=>e.OR([{ALT:()=>{const r=e.CONSUME(go);return e.ACTION(()=>this._ensureWhitespace(ao(r.image),e.getLexerPosition()))}},{ALT:()=>{const r=e.CONSUME(fo);return e.ACTION(()=>this._ensureWhitespace(Zn(r.image),e.getLexerPosition()))}},{ALT:()=>{const r=e.CONSUME(To);return e.ACTION(()=>this._ensureWhitespace(co(r.image),e.getLexerPosition()))}},{ALT:()=>{const r=e.CONSUME(po);return e.ACTION(()=>this._ensureWhitespace(uo(r.image),e.getLexerPosition()))}}])),e.RULE("function",()=>{const r=e.CONSUME(sl).image.slice(0,-1),i=e.getLexerPosition(),o=e.SUBRULE(e.functionArguments);let s=e.ACTION(()=>this._ensureWhitespace(so(r,o),i,!0));const a=e.OPTION(()=>this.CONSUME(er));return s=e.ACTION(()=>(a||this._reportError(s,"Missing closing parenthesis ')'",i),this._ensureWhitespace(s,e.getLexerPosition(),!1,!0))),s}),e.RULE("functionArguments",()=>{const r=[];return e.MANY2(()=>{let i;e.CONSUME2(ce),i=e.ACTION(()=>this._ensureWhitespace({type:"empty",value:""},e.getLexerPosition(),!1,!0)),r.push(i)}),e.OPTION(()=>{r.push(e.SUBRULE(e.intersectOp)),e.MANY(()=>{let i;e.CONSUME1(ce),i=e.ACTION(()=>this._ensureWhitespace({type:"empty",value:""},e.getLexerPosition(),!1,!0)),r.push(i),e.OPTION3(()=>{r.pop(),r.push(e.SUBRULE2(e.intersectOp))})})}),r}),e.RULE("bracketedString",()=>{const r=e.CONSUME(vo),i=e.getLexerPosition();return e.ACTION(()=>{const o=r.image;let s=Hn("",[Yn(o.substring(1,o.length-1))]);return s=this._ensureWhitespace(s,i,!0,!1),s=this._ensureWhitespace(s,e.getLexerPosition(),!1,!0),s})}),e.RULE("squareParen",()=>{e.CONSUME(Ao);const r=e.getLexerPosition();let i=Hn("",[e.SUBRULE(e.structuredArgument)]);const o=e.OPTION(()=>this.CONSUME(Io));return e.ACTION(()=>{o||this._reportError(i,"Missing closing parenthesis ']'",r),i=this._ensureWhitespace(i,r,!0,!1),i=this._ensureWhitespace(i,e.getLexerPosition(),!1,!0)}),i}),e.RULE("namedTableReference",()=>{const r=e.CONSUME(al).image.slice(0,-1),i=e.getLexerPosition(),o=e.SUBRULE(e.structuredArguments);let s=e.ACTION(()=>this._ensureWhitespace(Hn(r,o),i,!0));const a=e.OPTION(()=>this.CONSUME(Io));return s=e.ACTION(()=>(a||this._reportError(s,"Missing closing parenthesis ']'",i),this._ensureWhitespace(s,e.getLexerPosition(),!1,!0))),s}),e.RULE("structuredArguments",()=>{const r=[];return e.MANY2(()=>{e.CONSUME2(ce),e.ACTION(()=>{r.push(this._ensureWhitespace({type:"empty",value:""},e.getLexerPosition(),!1,!0))})}),e.OPTION(()=>{const i=e.SUBRULE(e.structuredArgument);e.ACTION(()=>{i&&r.push(i)}),e.MANY(()=>{e.CONSUME1(ce),e.OPTION3(()=>{let o=e.SUBRULE2(e.structuredArgument);e.ACTION(()=>{o||(o=this._ensureWhitespace({type:"empty",value:""},e.getLexerPosition(),!1,!0)),r.push(o)})})})}),r}),e.RULE("structuredArgument",()=>{const r=e.OPTION(()=>e.CONSUME(tr)),i=e.getLexerPosition(),o=e.OPTION2(()=>this.CONSUME(Ao));let s=e.OR([{ALT:()=>{const a=e.CONSUME(Ol);return e.ACTION(()=>this._ensureWhitespace(Yn(a.image),e.getLexerPosition()))}},{ALT:()=>{const a=e.CONSUME(vo);return e.ACTION(()=>this._ensureWhitespace(Yn(a.image),e.getLexerPosition()))}},{ALT:()=>{const a=e.CONSUME(Eo);return e.ACTION(()=>this._ensureWhitespace(qn(a.image),e.getLexerPosition()))}},{ALT:()=>{const a=e.CONSUME(ol);return e.ACTION(()=>this._ensureWhitespace(Zn(a.image),e.getLexerPosition()))}}]);if(o){const a=e.OPTION3(()=>this.CONSUME(er));e.ACTION(()=>(a||this._reportError(s,"Missing closing parenthesis ']'",i),this._ensureWhitespace(s,e.getLexerPosition(),!1,!0))),s={type:"structuredArg",value:null,inputs:[s]}}return e.ACTION(()=>{r&&(s=Se(r.image,s,!0),s=this._ensureWhitespace(s,e.getLexerPosition()))}),s}),e.RULE("referenceWithoutInfix",()=>e.OR([{ALT:()=>e.SUBRULE(e.reference)},{ALT:()=>{const r=e.SUBRULE(e.prefixSheetName),i=e.SUBRULE2(e.formula);return e.ACTION(()=>{if((o=i)&&o.isFormulaError)return i;var o;i.ref&&(i.ref.sheet=r)}),i}}])),e.RULE("reference",()=>{const r=e.OPTION4(()=>e.CONSUME(tr));let i=e.OR([{ALT:()=>{const o=e.CONSUME(cl),s=e.getLexerPosition(),a=e.OPTION(()=>e.CONSUME(yo));return e.ACTION(()=>{const c=this._ensureWhitespace(function(u,l){const h=u.match(/([$]?)([A-Za-z]{1,3})([$]?)([1-9][0-9]*)/);let f=io(h[2])-1;const d=h[1].length===1;let E=+h[4]-1;const I=h[3].length===1;return d||f===Number.MIN_SAFE_INTEGER||(f-=l.colIndex),I||E===Number.MIN_SAFE_INTEGER||(E-=l.rowIndex),{type:"cell",value:Object.freeze({colIndex:f,rowIndex:E,$colIndex:d,$rowIndex:I}),inputs:null,isReference:!0}}(o.image,e.position),s);return a?this._ensureWhitespace(Xn("#",c,!0),s):c})}},{ALT:()=>{const o=e.CONSUME(Eo);return e.ACTION(()=>this._ensureWhitespace(qn(o.image),e.getLexerPosition()))}},{ALT:()=>{const o=e.CONSUME(ll);return e.ACTION(()=>this._ensureWhitespace(function(s,a){const c=s.startsWith("$");c&&(s=s.substring(1));let u=io(s)-1;return c||u===Number.MIN_SAFE_INTEGER||(u-=a.colIndex),{type:"cell",value:Object.freeze({colIndex:u,rowIndex:Number.MIN_SAFE_INTEGER,$colIndex:c,$rowIndex:!1}),inputs:null,isReference:!0}}(o.image,e.position),e.getLexerPosition()))}},{ALT:()=>{const o=e.CONSUME(hl);return e.ACTION(()=>this._ensureWhitespace(oo(o.image,e.position),e.getLexerPosition()))}},{ALT:()=>{const o=e.CONSUME(mo);return e.ACTION(()=>this._ensureWhitespace(mn(o.image),e.getLexerPosition()))}}]);return e.ACTION(()=>{r&&(i=Se(r,i,!0),i=this._ensureWhitespace(i,e.getLexerPosition()))}),i}),e.RULE("prefixSheetName",()=>e.OR([{ALT:()=>e.CONSUME(ul).image.slice(0,-1)},{ALT:()=>e.CONSUME(il).image.slice(1,-2).replace(/''/g,"'")}])),e.performSelfAnalysis()}_reportError(e,n,r=void 0,i="SyntaxError"){r===void 0&&(r=this.getLexerPosition()),e.error=!0,this.astErrors.push({name:i,message:n,previousToken:this.input[r],ast:e})}_ensureWhitespace(e,n,r=!1,i=!1){if(!e)return console.warn("node is null"),e;const o=this.input,s=o[n];if(e.image||(e.image=s.image),!i){const a=s.startOffset,c=o[n-1],u=c?.endOffset??-1;u+1<a&&(e.wsBefore=" ".repeat(a-u-1))}if(!r){const a=s.endOffset,c=o[n+1],u=c?.startOffset??this.inputTextLength;a+1<u&&(e.wsAfter=" ".repeat(u-a-1))}return e}_createAST(e,n){const r=function(a){const c=Du.tokenize(a);if(c.errors.length>0){const u=c.errors[0],l=u.line,h=u.column;let f=`
`+a.split(`
`)[l-1]+`
`;throw f+=Array(h-1).fill(" ").join("")+`^
`,u.message=f+`Error at position ${l}:${h}
`+u.message,u.errorLocation={line:l,column:h},new w.FormulaError.Parse(u.message,{line:l,column:h,offset:u.offset,length:u.length})}return c}(n);let i;if(!r)return i={type:"text",value:n},i;const o=r.tokens;this.input=o,this.inputTextLength=n.length;const s=e.getPosition();return this.position=s,this.astErrors=[],this.reset(),i=this.intersectOp(),i=Ue(i,(a,c)=>{let u=a.type;if(u==="function"&&a.value&&a.value.toUpperCase().startsWith(tl)){const h=a.value.substring(6);let f=a.image.substring(6),d=a;h==="ANCHORARRAY"?(d=Xn("#",a.inputs[0],!0),f="#"):h==="SINGLE"?(d=Se("@",a.inputs[0],!0),f="@"):d=so(h,a.inputs),Qn(d,a),d.image=f,u=(a=d).type}if(c?.isReference){const h=c.value;if((h===":"||h===".:."||h===".:"||h===":.")&&Number.isInteger(a.value)){const f=c.inputs[0]===a?c.inputs[1]:c.inputs[0];if(f&&Number.isInteger(f.value)){const d=oo(a.image,s);return Qn(d,a),d}}}else if(u==="cell"){const h=a.value;if(h.rowIndex===Number.MIN_SAFE_INTEGER||h.colIndex>=16384){const f=qn(a.image);return Qn(f,a),f}}return a}),i}build(e,n){if(n.length===0)throw Error("Input must not be empty.");let r,i,o;try{r=this._createAST(e,n)}catch(c){o=c instanceof w.FormulaError.Parse?c:new w.FormulaError.Parse(c.message,c)}const s=this.errors;s.length>0&&(o=lo(s[0],n));const a=this.astErrors;return a.length>0&&(o=lo(a[0],n)),i=r?rn(r,o):{ast:null,evaluations:X.CommonUtils.EmptyArray,executions:X.CommonUtils.EmptyArray,precedentsAbsolute:X.CommonUtils.EmptyArray,precedentsExecute:X.CommonUtils.EmptyArray,precedentsNamed:null,precedentsRelative:X.CommonUtils.EmptyArray,precedentsRoot:X.CommonUtils.EmptyArray,references:X.CommonUtils.EmptyArray,tokens:X.CommonUtils.EmptyArray,error:o},i}}class ke{constructor(e,n){this._options=e,this._compiled=n}getTextAt(e,n,r=!1){return r?G.tokensToR1C1(this._compiled.tokens):G.tokensToA1(this._compiled.tokens,e,n)}getTokens(){return this._compiled.tokens}getError(){return this._compiled.error??null}isEquals(e){if(!(e&&e instanceof ke))return!1;if(this===e)return!0;const n=this._compiled.tokens,r=e._compiled.tokens;return n.length!==r.length?!1:G.tokensToR1C1(n)===G.tokensToR1C1(r)}getReferences(){const e=this._compiled,n=e.references,r=n.length;if(r===0)return X.CommonUtils.EmptyArray;const i=e.precedentsExecute,o=e.precedentsRelative,s=new Array(r);for(let a=0;a<r;a++){const c=i[n[a]],u=c.inputs;if(u&&u.length===2){const l=o[i[u[0]].value],h=o[i[u[1]].value];s[a]={colStart:l.colStart,rowStart:l.rowStart,colEnd:h.colEnd,rowEnd:h.rowEnd,$colStart:l.$colStart,$rowStart:l.$rowStart,$colEnd:h.$colEnd,$rowEnd:h.$rowEnd,sheetName:l.sheetName}}else if(c.node.type==="cell"){const l=o[c.value];s[a]={...l}}else if(c.op==="named"){const l=e.precedentsNamed;s[a]=l[c.value]}else c.op==="error"&&(s[a]=c.node.value)}return s}setReferenceAt(e,n){const r=this._compiled,i=r.references;if(i.length===0)return X.CommonUtils.EmptyArray;const o=r.precedentsExecute,s=i[e];if(s===void 0)throw new Error(`Invalid reference index: ${e}`);const a=o[s],c=a.node,u=c.inputs??X.CommonUtils.EmptyArray;let l,h,f=!1;n&&(l={colIndex:n.colStart,rowIndex:n.rowStart,$colIndex:n.$colStart??!1,$rowIndex:n.$rowStart??!1},n.sheetName&&(l.sheetName=n.sheetName),f=!X.CoordUtils.isSingleCell(n),f&&(h={colIndex:n.colEnd,rowIndex:n.rowEnd,$colIndex:n.$colEnd??!1,$rowIndex:n.$rowEnd??!1},n.colEnd===Number.MAX_SAFE_INTEGER&&(h.colIndex=Number.MIN_SAFE_INTEGER),n.rowEnd===Number.MAX_SAFE_INTEGER&&(h.rowIndex=Number.MIN_SAFE_INTEGER)));const d=u.length===2;let E=-1,I=-1;if(d)E=u[0].evalIndex,I=u[1].evalIndex;else{if(c.type!=="cell")throw a.op==="named"?new Error("Cannot setReference for a named reference"):new Error(`Invalidate reference index: ${e}`);E=c.evalIndex}const S=this._compiled.ast,T=Ue(S,A=>{if(!A||!A.isReference)return;const O=A.type;if(!n&&ws.includes(A.value)){const y=u[0],N=u[1];let U=y.evalIndex===E,M=N.evalIndex===I;if(U||M){const F=mn();return F.image="#REF!",F}}if(!(O==="cell"||O==="error"))return;const g=A.evalIndex;let R,v=g===E;if(v||g===I){if(n)if(d===f){let y=v?l:h;R={...A},R.value=y,R.image=null}else R=f?Tr(":",Vn(l),Vn(h),!0):Vn(l);else R=mn(),R.image="#REF!";return R}});if(T===S)return this;const m=rn(T,this._compiled.error),p=this._options;return new ke(p,m)}_resolveNamed(e,n,r,i){const o=this._options?.getNamed;if(!o)return w.FormulaError.BuiltIn.Name;let s=o?.(e,this._options.getSheetName?.())?.[0];return s?(s.isFormulaError||(s=G.toAbsoluteRange(s,n,r,i)),s):w.FormulaError.BuiltIn.Name}getDirectPrecedentsAt(e,n,r=!1,i,o){const s=this._compiled,a=s.precedentsRoot,c=a.length;if(c===0)return X.CommonUtils.EmptyArray;const u=s.precedentsRelative,l=s.precedentsAbsolute,h=u.length;for(let T=0;T<h;T++){const m=u[T];let p=l[T],A=G.toAbsoluteRange(m,e,n,p);l[T]=A}let f=!1;const d=s.precedentsExecute,E=d.length,I=Ar;for(let T=0;T<E;T++){const m=d[T],p=m.op;if(!p){const v=l[m.value];I[m.index]=v;continue}if(p==="named"){f=!0,I[m.index]=this._resolveNamed(m.node.value,e,n);continue}if(p==="error"){I[m.index]=m.node.value;continue}if(p==="@"||p==="#"){I[m.index]=I[m.inputs[0]];continue}const A=m.inputs;if(!A)continue;let O=I[A[0]];if(O===void 0){I[m.index]=w.FormulaError.BuiltIn.Value;continue}if(O.isFormulaError){I[m.index]=O;continue}let g,R=I[A[1]];R!==void 0?R.isFormulaError?I[m.index]=R:(p===" "?g=X.CoordUtils.intersectRanges(O,R):p!==":"&&p!==".:."&&p!==":."&&p!==".:"||(g=I[m.index]=X.CoordUtils.unionRanges(O,R)),I[m.index]=g??w.FormulaError.BuiltIn.Null):I[m.index]=w.FormulaError.BuiltIn.Value}const S=new Array(c);for(let T=0;T<c;T++){const m=a[T],p=I[m];if(S[T]=p?.rowStart!==void 0?{...p}:p,i||o){const A=d[m];f&&A.op==="named"?(i&&(i[T]=p.$colStart||p.$colEnd),o&&(o[T]=p.$rowStart||p.$rowEnd)):(i&&(i[T]=A.hasVerticalAbs),o&&(o[T]=A.hasHorizontalAbs))}}return S}evaluate(e,n,r){const i=e.getPosition(),o=i?.rowIndex??0,s=i?.colIndex??0;let a=this._compiled;if(n!==void 0){let g;if(Ue(a.ast,R=>{R.evalIndex===n&&(g=R)}),!g)throw new Error(`Invalid evalIndex: ${n}`);a=rn(g,a.error)}if(a.error)return a.error;const c=a.evaluations,u=a.executions;let l,h;r||(r=this._resolvePrecedents(e));const f=a.precedentsExecute,d=a.precedentsRelative,E=a.precedentsAbsolute,I=f.length;for(let g=0;g<I;g++){const R=f[g],v=R.op;if(v){if(v==="named"){const y=R.node;let N=this._resolveNamed(R.node.value,o,s);N?.colStart!==void 0&&(N=e.getReference(N)),c[y.evalIndex]=N}else if(v==="error"){const y=R.node;c[y.evalIndex]=R.node.value}}else{const y=d[R.value];let N=E[g];const U=G.toAbsoluteRange(y,o,s,N),M=R.node;c[M.evalIndex]=U}}const S=a.precedentsRoot,T=S.length;if(T!==r.length)return w.FormulaError.BuiltIn.Parse;for(let g=0;g<T;g++){const R=f[S[g]].node;let v=r[g];v.isIRange&&R.type==="cell"&&v.size>1&&(v=v.getValueAt(0,0)??null),c[R.evalIndex]=v}let m;const p=g=>{const R=g.inputs,v=R?R.length:0;let y;switch(g.type){case"infix":const N=g.value;let U=c[R[0].evalIndex],M=c[R[1].evalIndex];if(N==="+"&&typeof U=="number"&&typeof M=="number"){const C=U+M;return Math.abs(C)<99e-14?0:C}if(N==="-"&&typeof U=="number"&&typeof M=="number"){const C=U-M;return Math.abs(C)<99e-14?0:C}if(U&&U.isFormulaError)return U;if(M&&M.isFormulaError)return M;const F=g.fn;return y=F?F(e,U,M):w.FormulaError.BuiltIn.Value,y=G.minCoerce(y,null),y;case"function":m||(m=new Array(v)),m.length!==v&&(m.length=v);for(let C=0;C<v;C++)m[C]=c[R[C].evalIndex];return y=this._callFunction(e,g,m),y&&typeof y.then=="function"?y.then(C=>{C=G.minCoerce(C,e),y instanceof w.FormulaError.Known&&(h=y),c[g.evalIndex]=C}).catch(C=>{const j=C instanceof w.FormulaError.Known?C:new w.FormulaError.Value("Uncaught error",{cause:C});c[g.evalIndex]=j}):y instanceof w.FormulaError.Known&&(h=y),y;case"prefix":case"postfix":let $=c[R[0].evalIndex];if($&&$.isFormulaError)return $;const x=g.fn;return y=x?x(e,$):w.FormulaError.BuiltIn.Value,y;case"paren":if(v===1)return c[R[0].evalIndex];{const C=new Array(v);for(let j=0;j<v;j++)C[j]=c[R[j].evalIndex];return C}case"named":return null;case"empty":return}};let A=u.length;for(let g=0;g<A;g++){const R=u[g];if(h)return h;if(l)l=l.then(()=>{const v=p(R);return c[R.evalIndex]=v,v});else{const v=p(R);c[R.evalIndex]=v,v&&typeof v.then=="function"&&(l=v)}}if(l)return l.then(()=>{const g=c[c.length-1];return this._finalizeReturnValue(e,g)});const O=c[c.length-1];return this._finalizeReturnValue(e,O)}_resolvePrecedents(e){const n=e.getPosition(),r=n?.rowIndex??0,i=n?.colIndex??0,o=this.getDirectPrecedentsAt(r,i),s=o.length;let a;if(s>0){a=new Array(s);for(let c=0;c<s;c++){const u=o[c];if(u instanceof w.FormulaError.Known)a[c]=u;else if(Array.isArray(u)){const l=new Array(u.length);for(let h=0;h<u.length;h++)l[h]=e.getReference(u[h]);a[c]=l}else a[c]=e.getReference(u)}}else a=X.CommonUtils.EmptyArray;return a}wrapImplicit(e,n,r){const i=this._compiled.ast;if(!i||!i.isReference)return this;if(i.type==="cell")return this;if(i.value==="@")return this;if(!r)return this;const o=G.colToString(n)+G.rowToString(e);if(r.has(o))return this;const s=rn(Se("@",i,!0),this._compiled.error);return new ke(this._options,s)}_callFunction(e,n,r){const i=n?.cacheFn??e.getFunction(n.value);if(!i)return new w.FormulaError.Parse;const o=i.isBuiltIn();let s;o?n.cacheFn=i:this._context=e;try{s=i.execute(...r)}catch(a){s=a instanceof w.FormulaError.Known?a:new w.FormulaError.Value(a.message,{cause:a})}return o||(this._context=null),s===void 0?new w.FormulaError.Parse:s}_finalizeReturnValue(e,n){if(n&&n.colStart!==void 0&&(n=e.getValueAt(n.rowStart,n.colStart)),Array.isArray(n))if(n.length===1&&Array.isArray(n[0])&&n[0].length===1)n=n[0][0],Array.isArray(n)&&(n=w.FormulaError.BuiltIn.Value);else try{n=e.getRange(n)}catch{n=w.FormulaError.BuiltIn.Value}return n?.isIRange?n.size===1?(n=n.getValueAt(0,0,Pl),(n=G.minCoerce(n,e))===null&&(n=0)):n=n.fillEmpty(0):(n=G.minCoerce(n,e))===null&&(n=0),n}get[Symbol.toStringTag](){return"[FormulaBlock]"}toString(){const e=this._compiled;if(e.error)return e.error.toString();const n=this._context;if(n){const r=n.getPosition();return this.getTextAt(r.rowIndex,r.colIndex)}return G.tokensToR1C1(e.tokens)}}const Ar=new Array(20);for(let t=0;t<Ar.length;t++)Ar[t]={colStart:0,rowStart:0,colEnd:0,rowEnd:0,sheetName:null};const Pl={type:null};exports.FormulaParser=class{constructor(t){this._options={getEntireCoords:G.defaultGetEntireCoords,...t},this._astBuilder=new bl}parse(t,e){t.getPosition().sheetName;const r=this._astBuilder.build(t,e);return new ke(this._options,r)}eval(t,e){return this.parse(t,e).evaluate(t)}};