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