UNPKG

@sheetxl/sdk

Version:

SDK - A high-performance, embeddable spreadsheet engine.

5,654 lines 217 kB
import { c as Pe, t as we, g as $s, a as Ws, b as Ke, d as Un, e as Gs, r as zs, m as Ve, f as Ks } from "./DFlrI09lk7wnQtws.mjs";
import { FormulaError as U, ScalarType as re } from "@sheetxl/primitives";
import { CoordUtils as Vt, CommonUtils as lt } from "@sheetxl/utils";
/**
 * @license @sheetxl/sdk - SDK - A high-performance, embeddable spreadsheet engine. - v0.6.4
 *
 * (C) 2025-present SheetXL Inc. & Michael T. Ford
 * License: The license can be found at https://www.sheetxl.com/license.
 */
var xo = typeof global == "object" && global && global.Object === Object && global, Vs = typeof self == "object" && self && self.Object === Object && self, kt = xo || Vs || Function("return this")(), gt = kt.Symbol, Co = Object.prototype, Hs = Co.hasOwnProperty, Ys = Co.toString, Ae = gt ? gt.toStringTag : void 0, Xs = Object.prototype.toString, qr = gt ? gt.toStringTag : void 0;
function qt(t) {
  return t == null ? t === void 0 ? "[object Undefined]" : "[object Null]" : qr && qr in Object(t) ? function(e) {
    var n = Hs.call(e, Ae), r = e[Ae];
    try {
      e[Ae] = void 0;
      var i = !0;
    } catch {
    }
    var o = Ys.call(e);
    return i && (n ? e[Ae] = r : delete e[Ae]), o;
  }(t) : function(e) {
    return Xs.call(e);
  }(t);
}
function yt(t) {
  return t != null && typeof t == "object";
}
function vn(t) {
  return typeof t == "symbol" || yt(t) && qt(t) == "[object Symbol]";
}
function Nn(t, e) {
  for (var n = -1, r = t == null ? 0 : t.length, i = Array(r); ++n < r; ) i[n] = e(t[n], n, t);
  return i;
}
var D = Array.isArray, Zr = gt ? gt.prototype : void 0, Qr = Zr ? Zr.toString : void 0;
function ko(t) {
  if (typeof t == "string") return t;
  if (D(t)) return Nn(t, ko) + "";
  if (vn(t)) return Qr ? Qr.call(t) : "";
  var e = t + "";
  return e == "0" && 1 / t == -1 / 0 ? "-0" : e;
}
var qs = /\s/, Zs = /^\s+/;
function Qs(t) {
  return t && t.slice(0, function(e) {
    for (var n = e.length; n-- && qs.test(e.charAt(n)); ) ;
    return n;
  }(t) + 1).replace(Zs, "");
}
function Tt(t) {
  var e = typeof t;
  return t != null && (e == "object" || e == "function");
}
var Js = /^[-+]0x[0-9a-f]+$/i, ta = /^0b[01]+$/i, ea = /^0o[0-7]+$/i, na = parseInt, ra = 1 / 0;
function ia(t) {
  return t ? (t = function(e) {
    if (typeof e == "number") return e;
    if (vn(e)) return NaN;
    if (Tt(e)) {
      var n = typeof e.valueOf == "function" ? e.valueOf() : e;
      e = Tt(n) ? n + "" : n;
    }
    if (typeof e != "string") return e === 0 ? e : +e;
    e = Qs(e);
    var r = ta.test(e);
    return r || ea.test(e) ? na(e.slice(2), r ? 2 : 8) : Js.test(e) ? NaN : +e;
  }(t)) === ra || t === -1 / 0 ? 17976931348623157e292 * (t < 0 ? -1 : 1) : t == t ? t : 0 : t === 0 ? t : 0;
}
function yn(t) {
  var e = ia(t), n = e % 1;
  return e == e ? n ? e - n : e : 0;
}
function de(t) {
  return t;
}
function Kt(t) {
  if (!Tt(t)) return !1;
  var e = qt(t);
  return e == "[object Function]" || e == "[object GeneratorFunction]" || e == "[object AsyncFunction]" || e == "[object Proxy]";
}
var Jr, Fn = kt["__core-js_shared__"], ti = (Jr = /[^.]+$/.exec(Fn && Fn.keys && Fn.keys.IE_PROTO || "")) ? "Symbol(src)_1." + Jr : "", oa = Function.prototype.toString;
function ie(t) {
  if (t != null) {
    try {
      return oa.call(t);
    } catch {
    }
    try {
      return t + "";
    } catch {
    }
  }
  return "";
}
var sa = /^\[object .+?Constructor\]$/, aa = Function.prototype, ca = Object.prototype, ua = aa.toString, la = ca.hasOwnProperty, ha = RegExp("^" + ua.call(la).replace(/[\\^$.*+?()[\]{}|]/g, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$");
function fa(t) {
  return !(!Tt(t) || (e = t, ti && ti in e)) && (Kt(t) ? ha : sa).test(ie(t));
  var e;
}
function oe(t, e) {
  var n = function(r, i) {
    return r?.[i];
  }(t, e);
  return fa(n) ? n : void 0;
}
var lr = oe(kt, "WeakMap"), ei = Object.create, da = /* @__PURE__ */ function() {
  function t() {
  }
  return function(e) {
    if (!Tt(e)) return {};
    if (ei) return ei(e);
    t.prototype = e;
    var n = new t();
    return t.prototype = void 0, n;
  };
}();
function q() {
}
var pa = Date.now, ni, Dn, jn, ln = function() {
  try {
    var t = oe(Object, "defineProperty");
    return t({}, "", {}), t;
  } catch {
  }
}(), ma = ln ? function(t, e) {
  return ln(t, "toString", { configurable: !0, enumerable: !1, value: (n = e, function() {
    return n;
  }), writable: !0 });
  var n;
} : de, Ea = (ni = ma, Dn = 0, jn = 0, function() {
  var t = pa(), e = 16 - (t - jn);
  if (jn = t, e > 0) {
    if (++Dn >= 800) return arguments[0];
  } else Dn = 0;
  return ni.apply(void 0, arguments);
});
function bo(t, e) {
  for (var n = -1, r = t == null ? 0 : t.length; ++n < r && e(t[n], n, t) !== !1; ) ;
  return t;
}
function Po(t, e, n, r) {
  for (var i = t.length, o = n + -1; ++o < i; ) if (e(t[o], o, t)) return o;
  return -1;
}
function ga(t) {
  return t != t;
}
function Sr(t, e, n) {
  return e == e ? function(r, i, o) {
    for (var s = o - 1, a = r.length; ++s < a; ) if (r[s] === i) return s;
    return -1;
  }(t, e, n) : Po(t, ga, n);
}
function wo(t, e) {
  return !!(t != null && t.length) && Sr(t, e, 0) > -1;
}
var Ta = /^(?:0|[1-9]\d*)$/;
function Rn(t, e) {
  var n = typeof t;
  return !!(e = e ?? 9007199254740991) && (n == "number" || n != "symbol" && Ta.test(t)) && t > -1 && t % 1 == 0 && t < e;
}
function _r(t, e, n) {
  e == "__proto__" && ln ? ln(t, e, { configurable: !0, enumerable: !0, value: n, writable: !0 }) : t[e] = n;
}
function Be(t, e) {
  return t === e || t != t && e != e;
}
var Aa = Object.prototype.hasOwnProperty;
function On(t, e, n) {
  var r = t[e];
  Aa.call(t, e) && Be(r, n) && (n !== void 0 || e in t) || _r(t, e, n);
}
function hr(t, e, n, r) {
  var i = !n;
  n || (n = {});
  for (var o = -1, s = e.length; ++o < s; ) {
    var a = e[o], c = void 0;
    c === void 0 && (c = t[a]), i ? _r(n, a, c) : On(n, a, c);
  }
  return n;
}
var ri = Math.max;
function Lr(t, e) {
  return Ea(function(n, r, i) {
    return r = ri(r === void 0 ? n.length - 1 : r, 0), function() {
      for (var o = arguments, s = -1, a = ri(o.length - r, 0), c = Array(a); ++s < a; ) c[s] = o[r + s];
      s = -1;
      for (var u = Array(r + 1); ++s < r; ) u[s] = o[s];
      return u[r] = i(c), function(l, h, f) {
        switch (f.length) {
          case 0:
            return l.call(h);
          case 1:
            return l.call(h, f[0]);
          case 2:
            return l.call(h, f[0], f[1]);
          case 3:
            return l.call(h, f[0], f[1], f[2]);
        }
        return l.apply(h, f);
      }(n, this, u);
    };
  }(t, e, de), t + "");
}
function xr(t) {
  return typeof t == "number" && t > -1 && t % 1 == 0 && t <= 9007199254740991;
}
function bt(t) {
  return t != null && xr(t.length) && !Kt(t);
}
function Mo(t, e, n) {
  if (!Tt(n)) return !1;
  var r = typeof e;
  return !!(r == "number" ? bt(n) && Rn(e, n.length) : r == "string" && e in n) && Be(n[e], t);
}
var Ia = Object.prototype;
function $e(t) {
  var e = t && t.constructor;
  return t === (typeof e == "function" && e.prototype || Ia);
}
function ii(t) {
  return yt(t) && qt(t) == "[object Arguments]";
}
var Uo = Object.prototype, va = Uo.hasOwnProperty, Na = Uo.propertyIsEnumerable, Sn = ii(/* @__PURE__ */ function() {
  return arguments;
}()) ? ii : function(t) {
  return yt(t) && va.call(t, "callee") && !Na.call(t, "callee");
}, Fo = typeof exports == "object" && exports && !exports.nodeType && exports, oi = Fo && typeof module == "object" && module && !module.nodeType && module, si = oi && oi.exports === Fo ? kt.Buffer : void 0, Me = (si ? si.isBuffer : void 0) || function() {
  return !1;
}, z = {};
function _n(t) {
  return function(e) {
    return t(e);
  };
}
z["[object Float32Array]"] = z["[object Float64Array]"] = z["[object Int8Array]"] = z["[object Int16Array]"] = z["[object Int32Array]"] = z["[object Uint8Array]"] = z["[object Uint8ClampedArray]"] = z["[object Uint16Array]"] = z["[object Uint32Array]"] = !0, z["[object Arguments]"] = z["[object Array]"] = z["[object ArrayBuffer]"] = z["[object Boolean]"] = z["[object DataView]"] = z["[object Date]"] = z["[object Error]"] = z["[object Function]"] = z["[object Map]"] = z["[object Number]"] = z["[object Object]"] = z["[object RegExp]"] = z["[object Set]"] = z["[object String]"] = z["[object WeakMap]"] = !1;
var Do = typeof exports == "object" && exports && !exports.nodeType && exports, Le = Do && typeof module == "object" && module && !module.nodeType && module, Bn = Le && Le.exports === Do && xo.process, Yt = function() {
  try {
    var t = Le && Le.require && Le.require("util").types;
    return t || Bn && Bn.binding && Bn.binding("util");
  } catch {
  }
}(), ai = Yt && Yt.isTypedArray, Cr = ai ? _n(ai) : function(t) {
  return yt(t) && xr(t.length) && !!z[qt(t)];
}, ya = Object.prototype.hasOwnProperty;
function jo(t, e) {
  var n = D(t), r = !n && Sn(t), i = !n && !r && Me(t), o = !n && !r && !i && Cr(t), s = n || r || i || o, a = s ? function(l, h) {
    for (var f = -1, d = Array(l); ++f < l; ) d[f] = h(f);
    return d;
  }(t.length, String) : [], c = a.length;
  for (var u in t) !e && !ya.call(t, u) || s && (u == "length" || i && (u == "offset" || u == "parent") || o && (u == "buffer" || u == "byteLength" || u == "byteOffset") || Rn(u, c)) || a.push(u);
  return a;
}
function Bo(t, e) {
  return function(n) {
    return t(e(n));
  };
}
var Ra = Bo(Object.keys, Object), Oa = Object.prototype.hasOwnProperty;
function $o(t) {
  if (!$e(t)) return Ra(t);
  var e = [];
  for (var n in Object(t)) Oa.call(t, n) && n != "constructor" && e.push(n);
  return e;
}
function At(t) {
  return bt(t) ? jo(t) : $o(t);
}
var $n, Sa = Object.prototype.hasOwnProperty, ht = ($n = function(t, e) {
  if ($e(e) || bt(e)) hr(e, At(e), t);
  else for (var n in e) Sa.call(e, n) && On(t, n, e[n]);
}, Lr(function(t, e) {
  var n = -1, r = e.length, i = r > 1 ? e[r - 1] : void 0, o = r > 2 ? e[2] : void 0;
  for (i = $n.length > 3 && typeof i == "function" ? (r--, i) : void 0, o && Mo(e[0], e[1], o) && (i = r < 3 ? void 0 : i, r = 1), t = Object(t); ++n < r; ) {
    var s = e[n];
    s && $n(t, s, n, i);
  }
  return t;
})), _a = Object.prototype.hasOwnProperty;
function La(t) {
  if (!Tt(t)) return function(i) {
    var o = [];
    if (i != null) for (var s in Object(i)) o.push(s);
    return o;
  }(t);
  var e = $e(t), n = [];
  for (var r in t) (r != "constructor" || !e && _a.call(t, r)) && n.push(r);
  return n;
}
function Wo(t) {
  return bt(t) ? jo(t, !0) : La(t);
}
var xa = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, Ca = /^\w*$/;
function kr(t, e) {
  if (D(t)) return !1;
  var n = typeof t;
  return !(n != "number" && n != "symbol" && n != "boolean" && t != null && !vn(t)) || Ca.test(t) || !xa.test(t) || e != null && t in Object(e);
}
var Ie = oe(Object, "create"), ka = Object.prototype.hasOwnProperty, ba = Object.prototype.hasOwnProperty;
function Jt(t) {
  var e = -1, n = t == null ? 0 : t.length;
  for (this.clear(); ++e < n; ) {
    var r = t[e];
    this.set(r[0], r[1]);
  }
}
function He(t, e) {
  for (var n = t.length; n--; ) if (Be(t[n][0], e)) return n;
  return -1;
}
Jt.prototype.clear = function() {
  this.__data__ = Ie ? Ie(null) : {}, this.size = 0;
}, Jt.prototype.delete = function(t) {
  var e = this.has(t) && delete this.__data__[t];
  return this.size -= e ? 1 : 0, e;
}, Jt.prototype.get = function(t) {
  var e = this.__data__;
  if (Ie) {
    var n = e[t];
    return n === "__lodash_hash_undefined__" ? void 0 : n;
  }
  return ka.call(e, t) ? e[t] : void 0;
}, Jt.prototype.has = function(t) {
  var e = this.__data__;
  return Ie ? e[t] !== void 0 : ba.call(e, t);
}, Jt.prototype.set = function(t, e) {
  var n = this.__data__;
  return this.size += this.has(t) ? 0 : 1, n[t] = Ie && e === void 0 ? "__lodash_hash_undefined__" : e, this;
};
var Pa = Array.prototype.splice;
function $t(t) {
  var e = -1, n = t == null ? 0 : t.length;
  for (this.clear(); ++e < n; ) {
    var r = t[e];
    this.set(r[0], r[1]);
  }
}
$t.prototype.clear = function() {
  this.__data__ = [], this.size = 0;
}, $t.prototype.delete = function(t) {
  var e = this.__data__, n = He(e, t);
  return !(n < 0) && (n == e.length - 1 ? e.pop() : Pa.call(e, n, 1), --this.size, !0);
}, $t.prototype.get = function(t) {
  var e = this.__data__, n = He(e, t);
  return n < 0 ? void 0 : e[n][1];
}, $t.prototype.has = function(t) {
  return He(this.__data__, t) > -1;
}, $t.prototype.set = function(t, e) {
  var n = this.__data__, r = He(n, t);
  return r < 0 ? (++this.size, n.push([t, e])) : n[r][1] = e, this;
};
var Ue = oe(kt, "Map");
function Ye(t, e) {
  var n, r, i = t.__data__;
  return ((r = typeof (n = e)) == "string" || r == "number" || r == "symbol" || r == "boolean" ? n !== "__proto__" : n === null) ? i[typeof e == "string" ? "string" : "hash"] : i.map;
}
function Wt(t) {
  var e = -1, n = t == null ? 0 : t.length;
  for (this.clear(); ++e < n; ) {
    var r = t[e];
    this.set(r[0], r[1]);
  }
}
Wt.prototype.clear = function() {
  this.size = 0, this.__data__ = { hash: new Jt(), map: new (Ue || $t)(), string: new Jt() };
}, Wt.prototype.delete = function(t) {
  var e = Ye(this, t).delete(t);
  return this.size -= e ? 1 : 0, e;
}, Wt.prototype.get = function(t) {
  return Ye(this, t).get(t);
}, Wt.prototype.has = function(t) {
  return Ye(this, t).has(t);
}, Wt.prototype.set = function(t, e) {
  var n = Ye(this, t), r = n.size;
  return n.set(t, e), this.size += n.size == r ? 0 : 1, this;
};
function br(t, e) {
  if (typeof t != "function" || e != null && typeof e != "function") throw new TypeError("Expected a function");
  var n = function() {
    var r = arguments, i = e ? e.apply(this, r) : r[0], o = n.cache;
    if (o.has(i)) return o.get(i);
    var s = t.apply(this, r);
    return n.cache = o.set(i, s) || o, s;
  };
  return n.cache = new (br.Cache || Wt)(), n;
}
br.Cache = Wt;
var wa = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g, Ma = /\\(\\)?/g, Ua = function(t) {
  var e = br(t, function(r) {
    return n.size === 500 && n.clear(), r;
  }), n = e.cache;
  return e;
}(function(t) {
  var e = [];
  return t.charCodeAt(0) === 46 && e.push(""), t.replace(wa, function(n, r, i, o) {
    e.push(i ? o.replace(Ma, "$1") : r || n);
  }), e;
});
function Ln(t, e) {
  return D(t) ? t : kr(t, e) ? [t] : Ua(function(n) {
    return n == null ? "" : ko(n);
  }(t));
}
function We(t) {
  if (typeof t == "string" || vn(t)) return t;
  var e = t + "";
  return e == "0" && 1 / t == -1 / 0 ? "-0" : e;
}
function Pr(t, e) {
  for (var n = 0, r = (e = Ln(e, t)).length; t != null && n < r; ) t = t[We(e[n++])];
  return n && n == r ? t : void 0;
}
function wr(t, e) {
  for (var n = -1, r = e.length, i = t.length; ++n < r; ) t[i + n] = e[n];
  return t;
}
var ci = gt ? gt.isConcatSpreadable : void 0;
function Fa(t) {
  return D(t) || Sn(t) || !!(ci && t && t[ci]);
}
function Mr(t, e, n, r, i) {
  var o = -1, s = t.length;
  for (n || (n = Fa), i || (i = []); ++o < s; ) {
    var a = t[o];
    n(a) ? wr(i, a) : r || (i[i.length] = a);
  }
  return i;
}
function vt(t) {
  return t != null && t.length ? Mr(t) : [];
}
var Go = Bo(Object.getPrototypeOf, Object);
function zo(t, e, n) {
  var r = -1, i = t.length;
  e < 0 && (e = -e > i ? 0 : i + e), (n = n > i ? i : n) < 0 && (n += i), i = e > n ? 0 : n - e >>> 0, e >>>= 0;
  for (var o = Array(i); ++r < i; ) o[r] = t[r + e];
  return o;
}
function Da(t, e, n, r) {
  var i = -1, o = t == null ? 0 : t.length;
  for (r && o && (n = t[++i]); ++i < o; ) n = e(n, t[i], i, t);
  return n;
}
function xt(t) {
  var e = this.__data__ = new $t(t);
  this.size = e.size;
}
xt.prototype.clear = function() {
  this.__data__ = new $t(), this.size = 0;
}, xt.prototype.delete = function(t) {
  var e = this.__data__, n = e.delete(t);
  return this.size = e.size, n;
}, xt.prototype.get = function(t) {
  return this.__data__.get(t);
}, xt.prototype.has = function(t) {
  return this.__data__.has(t);
}, xt.prototype.set = function(t, e) {
  var n = this.__data__;
  if (n instanceof $t) {
    var r = n.__data__;
    if (!Ue || r.length < 199) return r.push([t, e]), this.size = ++n.size, this;
    n = this.__data__ = new Wt(r);
  }
  return n.set(t, e), this.size = n.size, this;
};
var Ko = typeof exports == "object" && exports && !exports.nodeType && exports, ui = Ko && typeof module == "object" && module && !module.nodeType && module, li = ui && ui.exports === Ko ? kt.Buffer : void 0, hi = li ? li.allocUnsafe : void 0;
function Ur(t, e) {
  for (var n = -1, r = t == null ? 0 : t.length, i = 0, o = []; ++n < r; ) {
    var s = t[n];
    e(s, n, t) && (o[i++] = s);
  }
  return o;
}
function Vo() {
  return [];
}
var ja = Object.prototype.propertyIsEnumerable, fi = Object.getOwnPropertySymbols, Fr = fi ? function(t) {
  return t == null ? [] : (t = Object(t), Ur(fi(t), function(e) {
    return ja.call(t, e);
  }));
} : Vo, Ba = Object.getOwnPropertySymbols ? function(t) {
  for (var e = []; t; ) wr(e, Fr(t)), t = Go(t);
  return e;
} : Vo;
function Ho(t, e, n) {
  var r = e(t);
  return D(t) ? r : wr(r, n(t));
}
function fr(t) {
  return Ho(t, At, Fr);
}
var dr = oe(kt, "DataView"), pr = oe(kt, "Promise"), he = oe(kt, "Set"), di = "[object Map]", pi = "[object Promise]", mi = "[object Set]", Ei = "[object WeakMap]", gi = "[object DataView]", $a = ie(dr), Wa = ie(Ue), Ga = ie(pr), za = ie(he), Ka = ie(lr), mt = qt;
(dr && mt(new dr(new ArrayBuffer(1))) != gi || Ue && mt(new Ue()) != di || pr && mt(pr.resolve()) != pi || he && mt(new he()) != mi || lr && mt(new lr()) != Ei) && (mt = function(t) {
  var e = qt(t), n = e == "[object Object]" ? t.constructor : void 0, r = n ? ie(n) : "";
  if (r) switch (r) {
    case $a:
      return gi;
    case Wa:
      return di;
    case Ga:
      return pi;
    case za:
      return mi;
    case Ka:
      return Ei;
  }
  return e;
});
var Va = Object.prototype.hasOwnProperty, hn = kt.Uint8Array, Ha = /\w*$/, Ti = gt ? gt.prototype : void 0, Ai = Ti ? Ti.valueOf : void 0;
function Ya(t, e, n) {
  var r, i, o, s, a, c = t.constructor;
  switch (e) {
    case "[object ArrayBuffer]":
      return a = new (s = t).constructor(s.byteLength), new hn(a).set(new hn(s)), a;
    case "[object Boolean]":
    case "[object Date]":
      return new c(+t);
    case "[object DataView]":
      return o = (i = t).buffer, new i.constructor(o, i.byteOffset, i.byteLength);
    case "[object Float32Array]":
    case "[object Float64Array]":
    case "[object Int8Array]":
    case "[object Int16Array]":
    case "[object Int32Array]":
    case "[object Uint8Array]":
    case "[object Uint8ClampedArray]":
    case "[object Uint16Array]":
    case "[object Uint32Array]":
      return function(u) {
        var l = u.buffer;
        return new u.constructor(l, u.byteOffset, u.length);
      }(t);
    case "[object Map]":
    case "[object Set]":
      return new c();
    case "[object Number]":
    case "[object String]":
      return new c(t);
    case "[object RegExp]":
      return function(u) {
        var l = new u.constructor(u.source, Ha.exec(u));
        return l.lastIndex = u.lastIndex, l;
      }(t);
    case "[object Symbol]":
      return r = t, Ai ? Object(Ai.call(r)) : {};
  }
}
var Ii = Yt && Yt.isMap, Xa = Ii ? _n(Ii) : function(t) {
  return yt(t) && mt(t) == "[object Map]";
}, vi = Yt && Yt.isSet, qa = vi ? _n(vi) : function(t) {
  return yt(t) && mt(t) == "[object Set]";
}, Yo = "[object Arguments]", Xo = "[object Function]", qo = "[object Object]", W = {};
function nn(t, e, n, r, i, o) {
  var s;
  if (s !== void 0) return s;
  if (!Tt(t)) return t;
  var a = D(t);
  if (a) return s = function(f) {
    var d = f.length, E = new f.constructor(d);
    return d && typeof f[0] == "string" && Va.call(f, "index") && (E.index = f.index, E.input = f.input), E;
  }(t), function(f, d) {
    var E = -1, I = f.length;
    for (d || (d = Array(I)); ++E < I; ) d[E] = f[E];
    return d;
  }(t, s);
  var c = mt(t), u = c == Xo || c == "[object GeneratorFunction]";
  if (Me(t)) return function(f) {
    var d = f.length, E = hi ? hi(d) : new f.constructor(d);
    return f.copy(E), E;
  }(t);
  if (c == qo || c == Yo || u && !i) return s = u ? {} : function(f) {
    return typeof f.constructor != "function" || $e(f) ? {} : da(Go(f));
  }(t), function(f, d) {
    return hr(f, Fr(f), d);
  }(t, function(f, d) {
    return f && hr(d, At(d), f);
  }(s, t));
  if (!W[c]) return i ? t : {};
  s = Ya(t, c), o || (o = new xt());
  var l = o.get(t);
  if (l) return l;
  o.set(t, s), qa(t) ? t.forEach(function(f) {
    s.add(nn(f, e, n, f, t, o));
  }) : Xa(t) && t.forEach(function(f, d) {
    s.set(d, nn(f, e, n, d, t, o));
  });
  var h = a ? void 0 : fr(t);
  return bo(h || t, function(f, d) {
    h && (f = t[d = f]), On(s, d, nn(f, e, n, d, t, o));
  }), s;
}
W[Yo] = W["[object Array]"] = W["[object ArrayBuffer]"] = W["[object DataView]"] = W["[object Boolean]"] = W["[object Date]"] = W["[object Float32Array]"] = W["[object Float64Array]"] = W["[object Int8Array]"] = W["[object Int16Array]"] = W["[object Int32Array]"] = W["[object Map]"] = W["[object Number]"] = W[qo] = W["[object RegExp]"] = W["[object Set]"] = W["[object String]"] = W["[object Symbol]"] = W["[object Uint8Array]"] = W["[object Uint8ClampedArray]"] = W["[object Uint16Array]"] = W["[object Uint32Array]"] = !0, W["[object Error]"] = W[Xo] = W["[object WeakMap]"] = !1;
function tt(t) {
  return nn(t, 4);
}
function Ge(t) {
  for (var e = -1, n = t == null ? 0 : t.length, r = 0, i = []; ++e < n; ) {
    var o = t[e];
    o && (i[r++] = o);
  }
  return i;
}
function fe(t) {
  var e = -1, n = t == null ? 0 : t.length;
  for (this.__data__ = new Wt(); ++e < n; ) this.add(t[e]);
}
function Zo(t, e) {
  for (var n = -1, r = t == null ? 0 : t.length; ++n < r; ) if (e(t[n], n, t)) return !0;
  return !1;
}
function Dr(t, e) {
  return t.has(e);
}
fe.prototype.add = fe.prototype.push = function(t) {
  return this.__data__.set(t, "__lodash_hash_undefined__"), this;
}, fe.prototype.has = function(t) {
  return this.__data__.has(t);
};
function Ni(t, e, n, r, i, o) {
  var s = 1 & n, a = t.length, c = e.length;
  if (a != c && !(s && c > a)) return !1;
  var u = o.get(t), l = o.get(e);
  if (u && l) return u == e && l == t;
  var h = -1, f = !0, d = 2 & n ? new fe() : void 0;
  for (o.set(t, e), o.set(e, t); ++h < a; ) {
    var E = t[h], I = e[h];
    if (r) var S = s ? r(I, E, h, e, t, o) : r(E, I, h, t, e, o);
    if (S !== void 0) {
      if (S) continue;
      f = !1;
      break;
    }
    if (d) {
      if (!Zo(e, function(T, m) {
        if (!Dr(d, m) && (E === T || i(E, T, n, r, o))) return d.push(m);
      })) {
        f = !1;
        break;
      }
    } else if (E !== I && !i(E, I, n, r, o)) {
      f = !1;
      break;
    }
  }
  return o.delete(t), o.delete(e), f;
}
function Za(t) {
  var e = -1, n = Array(t.size);
  return t.forEach(function(r, i) {
    n[++e] = [i, r];
  }), n;
}
function jr(t) {
  var e = -1, n = Array(t.size);
  return t.forEach(function(r) {
    n[++e] = r;
  }), n;
}
var yi = gt ? gt.prototype : void 0, Wn = yi ? yi.valueOf : void 0, Qa = Object.prototype.hasOwnProperty, Ri = "[object Arguments]", Oi = "[object Array]", Xe = "[object Object]", Si = Object.prototype.hasOwnProperty;
function Ja(t, e, n, r, i, o) {
  var s = D(t), a = D(e), c = s ? Oi : mt(t), u = a ? Oi : mt(e), l = (c = c == Ri ? Xe : c) == Xe, h = (u = u == Ri ? Xe : u) == Xe, f = c == u;
  if (f && Me(t)) {
    if (!Me(e)) return !1;
    s = !0, l = !1;
  }
  if (f && !l) return o || (o = new xt()), s || Cr(t) ? Ni(t, e, n, r, i, o) : function(T, m, p, A, O, g, R) {
    switch (p) {
      case "[object DataView]":
        if (T.byteLength != m.byteLength || T.byteOffset != m.byteOffset) return !1;
        T = T.buffer, m = m.buffer;
      case "[object ArrayBuffer]":
        return !(T.byteLength != m.byteLength || !g(new hn(T), new hn(m)));
      case "[object Boolean]":
      case "[object Date]":
      case "[object Number]":
        return Be(+T, +m);
      case "[object Error]":
        return T.name == m.name && T.message == m.message;
      case "[object RegExp]":
      case "[object String]":
        return T == m + "";
      case "[object Map]":
        var N = Za;
      case "[object Set]":
        var v = 1 & A;
        if (N || (N = jr), T.size != m.size && !v) return !1;
        var y = R.get(T);
        if (y) return y == m;
        A |= 2, R.set(T, m);
        var M = Ni(N(T), N(m), A, O, g, R);
        return R.delete(T), M;
      case "[object Symbol]":
        if (Wn) return Wn.call(T) == Wn.call(m);
    }
    return !1;
  }(t, e, c, n, r, i, o);
  if (!(1 & n)) {
    var d = l && Si.call(t, "__wrapped__"), E = h && Si.call(e, "__wrapped__");
    if (d || E) {
      var I = d ? t.value() : t, S = E ? e.value() : e;
      return o || (o = new xt()), i(I, S, n, r, o);
    }
  }
  return !!f && (o || (o = new xt()), function(T, m, p, A, O, g) {
    var R = 1 & p, N = fr(T), v = N.length;
    if (v != fr(m).length && !R) return !1;
    for (var y = v; y--; ) {
      var M = N[y];
      if (!(R ? M in m : Qa.call(m, M))) return !1;
    }
    var w = g.get(T), F = g.get(m);
    if (w && F) return w == m && F == T;
    var $ = !0;
    g.set(T, m), g.set(m, T);
    for (var x = R; ++y < v; ) {
      var C = T[M = N[y]], j = m[M];
      if (A) var Y = R ? A(j, C, M, m, T, g) : A(C, j, M, T, m, g);
      if (!(Y === void 0 ? C === j || O(C, j, p, A, g) : Y)) {
        $ = !1;
        break;
      }
      x || (x = M == "constructor");
    }
    if ($ && !x) {
      var B = T.constructor, et = m.constructor;
      B == et || !("constructor" in T) || !("constructor" in m) || typeof B == "function" && B instanceof B && typeof et == "function" && et instanceof et || ($ = !1);
    }
    return g.delete(T), g.delete(m), $;
  }(t, e, n, r, i, o));
}
function Br(t, e, n, r, i) {
  return t === e || (t == null || e == null || !yt(t) && !yt(e) ? t != t && e != e : Ja(t, e, n, r, Br, i));
}
function Qo(t) {
  return t == t && !Tt(t);
}
function Jo(t, e) {
  return function(n) {
    return n != null && n[t] === e && (e !== void 0 || t in Object(n));
  };
}
function tc(t) {
  var e = function(n) {
    for (var r = At(n), i = r.length; i--; ) {
      var o = r[i], s = n[o];
      r[i] = [o, s, Qo(s)];
    }
    return r;
  }(t);
  return e.length == 1 && e[0][2] ? Jo(e[0][0], e[0][1]) : function(n) {
    return n === t || function(r, i, o, s) {
      var a = o.length, c = a;
      if (r == null) return !c;
      for (r = Object(r); a--; ) {
        var u = o[a];
        if (u[2] ? u[1] !== r[u[0]] : !(u[0] in r)) return !1;
      }
      for (; ++a < c; ) {
        var l = (u = o[a])[0], h = r[l], f = u[1];
        if (u[2]) {
          if (h === void 0 && !(l in r)) return !1;
        } else if (!Br(f, h, 3, s, new xt())) return !1;
      }
      return !0;
    }(n, 0, e);
  };
}
function ec(t, e) {
  return t != null && e in Object(t);
}
function ts(t, e, n) {
  for (var r = -1, i = (e = Ln(e, t)).length, o = !1; ++r < i; ) {
    var s = We(e[r]);
    if (!(o = t != null && n(t, s))) break;
    t = t[s];
  }
  return o || ++r != i ? o : !!(i = t == null ? 0 : t.length) && xr(i) && Rn(s, i) && (D(t) || Sn(t));
}
function nc(t, e) {
  return kr(t) && Qo(e) ? Jo(We(t), e) : function(n) {
    var r = function(i, o, s) {
      var a = i == null ? void 0 : Pr(i, o);
      return a === void 0 ? s : a;
    }(n, t);
    return r === void 0 && r === e ? function(i, o) {
      return i != null && ts(i, o, ec);
    }(n, t) : Br(e, r, 3);
  };
}
function rc(t) {
  return kr(t) ? (e = We(t), function(n) {
    return n?.[e];
  }) : /* @__PURE__ */ function(n) {
    return function(r) {
      return Pr(r, n);
    };
  }(t);
  var e;
}
function Ct(t) {
  return typeof t == "function" ? t : t == null ? de : typeof t == "object" ? D(t) ? nc(t[0], t[1]) : tc(t) : rc(t);
}
function ic(t, e, n, r) {
  for (var i = -1, o = t == null ? 0 : t.length; ++i < o; ) {
    var s = t[i];
    e(r, s, n(s), t);
  }
  return r;
}
var oc = function(t, e, n) {
  for (var r = -1, i = Object(t), o = n(t), s = o.length; s--; ) {
    var a = o[++r];
    if (e(i[a], a, i) === !1) break;
  }
  return t;
}, _i, se = (_i = function(t, e) {
  return t && oc(t, e, At);
}, function(t, e) {
  if (t == null) return t;
  if (!bt(t)) return _i(t, e);
  for (var n = t.length, r = -1, i = Object(t); ++r < n && e(i[r], r, i) !== !1; ) ;
  return t;
});
function sc(t, e, n, r) {
  return se(t, function(i, o, s) {
    e(r, i, n(i), s);
  }), r;
}
var es = Object.prototype, ac = es.hasOwnProperty, $r = Lr(function(t, e) {
  t = Object(t);
  var n = -1, r = e.length, i = r > 2 ? e[2] : void 0;
  for (i && Mo(e[0], e[1], i) && (r = 1); ++n < r; ) for (var o = e[n], s = Wo(o), a = -1, c = s.length; ++a < c; ) {
    var u = s[a], l = t[u];
    (l === void 0 || Be(l, es[u]) && !ac.call(t, u)) && (t[u] = o[u]);
  }
  return t;
});
function Li(t) {
  return yt(t) && bt(t);
}
var fn = Lr(function(t, e) {
  return Li(t) ? function(n, r, i, o) {
    var s = -1, a = wo, c = !0, u = n.length, l = [], h = r.length;
    if (!u) return l;
    r.length >= 200 && (a = Dr, c = !1, r = new fe(r));
    t: for (; ++s < u; ) {
      var f = n[s], d = f;
      if (f = f !== 0 ? f : 0, c && d == d) {
        for (var E = h; E--; ) if (r[E] === d) continue t;
        l.push(f);
      } else a(r, d, o) || l.push(f);
    }
    return l;
  }(t, Mr(e, 0, Li, !0)) : [];
});
function pe(t) {
  var e = t == null ? 0 : t.length;
  return e ? t[e - 1] : void 0;
}
function J(t, e, n) {
  var r = t == null ? 0 : t.length;
  return r ? zo(t, (e = e === void 0 ? 1 : yn(e)) < 0 ? 0 : e, r) : [];
}
function Fe(t, e, n) {
  var r = t == null ? 0 : t.length;
  return r ? zo(t, 0, (e = r - (e = e === void 0 ? 1 : yn(e))) < 0 ? 0 : e) : [];
}
function k(t, e) {
  var n;
  return (D(t) ? bo : se)(t, typeof (n = e) == "function" ? n : de);
}
function cc(t, e) {
  for (var n = -1, r = t == null ? 0 : t.length; ++n < r; ) if (!e(t[n], n, t)) return !1;
  return !0;
}
function uc(t, e) {
  var n = !0;
  return se(t, function(r, i, o) {
    return n = !!e(r, i, o);
  }), n;
}
function Nt(t, e, n) {
  return (D(t) ? cc : uc)(t, Ct(e));
}
function ns(t, e) {
  var n = [];
  return se(t, function(r, i, o) {
    e(r, i, o) && n.push(r);
  }), n;
}
function pt(t, e) {
  return (D(t) ? Ur : ns)(t, Ct(e));
}
var lc = Math.max, xi, me = (xi = function(t, e, n) {
  var r = t == null ? 0 : t.length;
  if (!r) return -1;
  var i = n == null ? 0 : yn(n);
  return i < 0 && (i = lc(r + i, 0)), Po(t, Ct(e), i);
}, function(t, e, n) {
  var r = Object(t);
  if (!bt(t)) {
    var i = Ct(e);
    t = At(t), e = function(s) {
      return i(r[s], s, r);
    };
  }
  var o = xi(t, e, n);
  return o > -1 ? r[i ? t[o] : o] : void 0;
});
function Rt(t) {
  return t && t.length ? t[0] : void 0;
}
function hc(t, e) {
  var n = -1, r = bt(t) ? Array(t.length) : [];
  return se(t, function(i, o, s) {
    r[++n] = e(i, o, s);
  }), r;
}
function _(t, e) {
  return (D(t) ? Nn : hc)(t, Ct(e));
}
function Et(t, e) {
  return Mr(_(t, e));
}
var Ci, ki, fc = Object.prototype.hasOwnProperty, dc = (Ci = function(t, e, n) {
  fc.call(t, n) ? t[n].push(e) : _r(t, n, [e]);
}, function(t, e) {
  var n = D(t) ? ic : sc, r = ki ? ki() : {};
  return n(t, Ci, Ct(e), r);
}), pc = Object.prototype.hasOwnProperty;
function mc(t, e) {
  return t != null && pc.call(t, e);
}
function L(t, e) {
  return t != null && ts(t, e, mc);
}
function at(t) {
  return typeof t == "string" || !D(t) && yt(t) && qt(t) == "[object String]";
}
function Z(t) {
  return t == null ? [] : function(e, n) {
    return Nn(n, function(r) {
      return e[r];
    });
  }(t, At(t));
}
var Ec = Math.max;
function it(t, e, n, r) {
  t = bt(t) ? t : Z(t), n = n ? yn(n) : 0;
  var i = t.length;
  return n < 0 && (n = Ec(i + n, 0)), at(t) ? n <= i && t.indexOf(e, n) > -1 : !!i && Sr(t, e, n) > -1;
}
function bi(t, e, n) {
  return t != null && t.length ? Sr(t, e, 0) : -1;
}
var gc = Object.prototype.hasOwnProperty;
function G(t) {
  if (t == null) return !0;
  if (bt(t) && (D(t) || typeof t == "string" || typeof t.splice == "function" || Me(t) || Cr(t) || Sn(t))) return !t.length;
  var e = mt(t);
  if (e == "[object Map]" || e == "[object Set]") return !t.size;
  if ($e(t)) return !$o(t).length;
  for (var n in t) if (gc.call(t, n)) return !1;
  return !0;
}
var Pi = Yt && Yt.isRegExp, Gt = Pi ? _n(Pi) : function(t) {
  return yt(t) && qt(t) == "[object RegExp]";
};
function zt(t) {
  return t === void 0;
}
function Tc(t, e, n, r) {
  if (!Tt(t)) return t;
  for (var i = -1, o = (e = Ln(e, t)).length, s = o - 1, a = t; a != null && ++i < o; ) {
    var c = We(e[i]), u = n;
    if (c === "__proto__" || c === "constructor" || c === "prototype") return t;
    if (i != s) {
      var l = a[c];
      (u = void 0) == void 0 && (u = Tt(l) ? l : Rn(e[i + 1]) ? [] : {});
    }
    On(a, c, u), a = a[c];
  }
  return t;
}
function Ot(t, e) {
  if (t == null) return {};
  var n = Nn(function(r) {
    return Ho(r, Wo, Ba);
  }(t), function(r) {
    return [r];
  });
  return e = Ct(e), function(r, i, o) {
    for (var s = -1, a = i.length, c = {}; ++s < a; ) {
      var u = i[s], l = Pr(r, u);
      o(l, u) && Tc(c, Ln(u, r), l);
    }
    return c;
  }(t, n, function(r, i) {
    return e(r, i[0]);
  });
}
function Ac(t, e, n, r, i) {
  return i(t, function(o, s, a) {
    n = r ? (r = !1, o) : e(n, o, s, a);
  }), n;
}
function ft(t, e, n) {
  var r = D(t) ? Da : Ac, i = arguments.length < 3;
  return r(t, Ct(e), n, i, se);
}
function xn(t, e) {
  return (D(t) ? Ur : ns)(t, function(n) {
    if (typeof n != "function") throw new TypeError("Expected a function");
    return function() {
      var r = arguments;
      switch (r.length) {
        case 0:
          return !n.call(this);
        case 1:
          return !n.call(this, r[0]);
        case 2:
          return !n.call(this, r[0], r[1]);
        case 3:
          return !n.call(this, r[0], r[1], r[2]);
      }
      return !n.apply(this, r);
    };
  }(Ct(e)));
}
function Ic(t, e) {
  var n;
  return se(t, function(r, i, o) {
    return !(n = e(r, i, o));
  }), !!n;
}
function rs(t, e, n) {
  return (D(t) ? Zo : Ic)(t, Ct(e));
}
var vc = he && 1 / jr(new he([, -0]))[1] == 1 / 0 ? function(t) {
  return new he(t);
} : q;
function mr(t) {
  return t && t.length ? function(e, n, r) {
    var i = -1, o = wo, s = e.length, a = !0, c = [], u = c;
    if (s >= 200) {
      var l = vc(e);
      if (l) return jr(l);
      a = !1, o = Dr, u = new fe();
    } else u = c;
    t: for (; ++i < s; ) {
      var h = e[i], f = h;
      if (h = h !== 0 ? h : 0, a && f == f) {
        for (var d = u.length; d--; ) if (u[d] === f) continue t;
        c.push(h);
      } else o(u, f, r) || (u !== c && u.push(f), c.push(h));
    }
    return c;
  }(t) : [];
}
function Er(t) {
  console && console.error && console.error(`Error: ${t}`);
}
function is(t) {
  console && console.warn && console.warn(`Warning: ${t}`);
}
function os(t) {
  const e = (/* @__PURE__ */ new Date()).getTime(), n = t();
  return { time: (/* @__PURE__ */ new Date()).getTime() - e, value: n };
}
function ss(t) {
  function e() {
  }
  e.prototype = t;
  const n = new e();
  function r() {
    return typeof n.bar;
  }
  return r(), r(), t;
}
function Nc(t) {
  return at((e = t).LABEL) && e.LABEL !== "" ? t.LABEL : t.name;
  var e;
}
class Pt {
  get definition() {
    return this._definition;
  }
  set definition(e) {
    this._definition = e;
  }
  constructor(e) {
    this._definition = e;
  }
  accept(e) {
    e.visit(this), k(this.definition, (n) => {
      n.accept(e);
    });
  }
}
class dt extends Pt {
  constructor(e) {
    super([]), this.idx = 1, ht(this, Ot(e, (n) => n !== void 0));
  }
  set definition(e) {
  }
  get definition() {
    return this.referencedRule !== void 0 ? this.referencedRule.definition : [];
  }
  accept(e) {
    e.visit(this);
  }
}
class Ee extends Pt {
  constructor(e) {
    super(e.definition), this.orgText = "", ht(this, Ot(e, (n) => n !== void 0));
  }
}
class ut extends Pt {
  constructor(e) {
    super(e.definition), this.ignoreAmbiguities = !1, ht(this, Ot(e, (n) => n !== void 0));
  }
}
class ct extends Pt {
  constructor(e) {
    super(e.definition), this.idx = 1, ht(this, Ot(e, (n) => n !== void 0));
  }
}
class wt extends Pt {
  constructor(e) {
    super(e.definition), this.idx = 1, ht(this, Ot(e, (n) => n !== void 0));
  }
}
class Mt extends Pt {
  constructor(e) {
    super(e.definition), this.idx = 1, ht(this, Ot(e, (n) => n !== void 0));
  }
}
class Q extends Pt {
  constructor(e) {
    super(e.definition), this.idx = 1, ht(this, Ot(e, (n) => n !== void 0));
  }
}
class St extends Pt {
  constructor(e) {
    super(e.definition), this.idx = 1, ht(this, Ot(e, (n) => n !== void 0));
  }
}
class _t extends Pt {
  get definition() {
    return this._definition;
  }
  set definition(e) {
    this._definition = e;
  }
  constructor(e) {
    super(e.definition), this.idx = 1, this.ignoreAmbiguities = !1, this.hasPredicates = !1, ht(this, Ot(e, (n) => n !== void 0));
  }
}
class K {
  constructor(e) {
    this.idx = 1, ht(this, Ot(e, (n) => n !== void 0));
  }
  accept(e) {
    e.visit(this);
  }
}
function rn(t) {
  function e(n) {
    return _(n, rn);
  }
  if (t instanceof dt) {
    const n = { type: "NonTerminal", name: t.nonTerminalName, idx: t.idx };
    return at(t.label) && (n.label = t.label), n;
  }
  if (t instanceof ut) return { type: "Alternative", definition: e(t.definition) };
  if (t instanceof ct) return { type: "Option", idx: t.idx, definition: e(t.definition) };
  if (t instanceof wt) return { type: "RepetitionMandatory", idx: t.idx, definition: e(t.definition) };
  if (t instanceof Mt) return { type: "RepetitionMandatoryWithSeparator", idx: t.idx, separator: rn(new K({ terminalType: t.separator })), definition: e(t.definition) };
  if (t instanceof St) return { type: "RepetitionWithSeparator", idx: t.idx, separator: rn(new K({ terminalType: t.separator })), definition: e(t.definition) };
  if (t instanceof Q) return { type: "Repetition", idx: t.idx, definition: e(t.definition) };
  if (t instanceof _t) return { type: "Alternation", idx: t.idx, definition: e(t.definition) };
  if (t instanceof K) {
    const n = { type: "Terminal", name: t.terminalType.name, label: Nc(t.terminalType), idx: t.idx };
    at(t.label) && (n.terminalLabel = t.label);
    const r = t.terminalType.PATTERN;
    return t.terminalType.PATTERN && (n.pattern = Gt(r) ? r.source : r), n;
  }
  if (t instanceof Ee) return { type: "Rule", name: t.name, orgText: t.orgText, definition: e(t.definition) };
  throw Error("non exhaustive match");
}
class ge {
  visit(e) {
    const n = e;
    switch (n.constructor) {
      case dt:
        return this.visitNonTerminal(n);
      case ut:
        return this.visitAlternative(n);
      case ct:
        return this.visitOption(n);
      case wt:
        return this.visitRepetitionMandatory(n);
      case Mt:
        return this.visitRepetitionMandatoryWithSeparator(n);
      case St:
        return this.visitRepetitionWithSeparator(n);
      case Q:
        return this.visitRepetition(n);
      case _t:
        return this.visitAlternation(n);
      case K:
        return this.visitTerminal(n);
      case Ee:
        return this.visitRule(n);
      default:
        throw Error("non exhaustive match");
    }
  }
  visitNonTerminal(e) {
  }
  visitAlternative(e) {
  }
  visitOption(e) {
  }
  visitRepetition(e) {
  }
  visitRepetitionMandatory(e) {
  }
  visitRepetitionMandatoryWithSeparator(e) {
  }
  visitRepetitionWithSeparator(e) {
  }
  visitAlternation(e) {
  }
  visitTerminal(e) {
  }
  visitRule(e) {
  }
}
function dn(t, e = []) {
  return t instanceof ct || t instanceof Q || t instanceof St || (t instanceof _t ? rs(t.definition, (n) => dn(n, e)) : !(t instanceof dt && it(e, t)) && t instanceof Pt && (t instanceof dt && e.push(t), Nt(t.definition, (n) => dn(n, e))));
}
function Lt(t) {
  if (t instanceof dt) return "SUBRULE";
  if (t instanceof ct) return "OPTION";
  if (t instanceof _t) return "OR";
  if (t instanceof wt) return "AT_LEAST_ONE";
  if (t instanceof Mt) return "AT_LEAST_ONE_SEP";
  if (t instanceof St) return "MANY_SEP";
  if (t instanceof Q) return "MANY";
  if (t instanceof K) return "CONSUME";
  throw Error("non exhaustive match");
}
class Cn {
  walk(e, n = []) {
    k(e.definition, (r, i) => {
      const o = J(e.definition, i + 1);
      if (r instanceof dt) this.walkProdRef(r, o, n);
      else if (r instanceof K) this.walkTerminal(r, o, n);
      else if (r instanceof ut) this.walkFlat(r, o, n);
      else if (r instanceof ct) this.walkOption(r, o, n);
      else if (r instanceof wt) this.walkAtLeastOne(r, o, n);
      else if (r instanceof Mt) this.walkAtLeastOneSep(r, o, n);
      else if (r instanceof St) this.walkManySep(r, o, n);
      else if (r instanceof Q) this.walkMany(r, o, n);
      else {
        if (!(r instanceof _t)) throw Error("non exhaustive match");
        this.walkOr(r, o, n);
      }
    });
  }
  walkTerminal(e, n, r) {
  }
  walkProdRef(e, n, r) {
  }
  walkFlat(e, n, r) {
    const i = n.concat(r);
    this.walk(e, i);
  }
  walkOption(e, n, r) {
    const i = n.concat(r);
    this.walk(e, i);
  }
  walkAtLeastOne(e, n, r) {
    const i = [new ct({ definition: e.definition })].concat(n, r);
    this.walk(e, i);
  }
  walkAtLeastOneSep(e, n, r) {
    const i = wi(e, n, r);
    this.walk(e, i);
  }
  walkMany(e, n, r) {
    const i = [new ct({ definition: e.definition })].concat(n, r);
    this.walk(e, i);
  }
  walkManySep(e, n, r) {
    const i = wi(e, n, r);
    this.walk(e, i);
  }
  walkOr(e, n, r) {
    const i = n.concat(r);
    k(e.definition, (o) => {
      const s = new ut({ definition: [o] });
      this.walk(s, i);
    });
  }
}
function wi(t, e, n) {
  return [new ct({ definition: [new K({ terminalType: t.separator })].concat(t.definition) })].concat(e, n);
}
function xe(t) {
  if (t instanceof dt) return xe(t.referencedRule);
  if (t instanceof K) return [t.terminalType];
  if (function(e) {
    return e instanceof ut || e instanceof ct || e instanceof Q || e instanceof wt || e instanceof Mt || e instanceof St || e instanceof K || e instanceof Ee;
  }(t)) return function(e) {
    let n = [];
    const r = e.definition;
    let i, o = 0, s = r.length > o, a = !0;
    for (; s && a; ) i = r[o], a = dn(i), n = n.concat(xe(i)), o += 1, s = r.length > o;
    return mr(n);
  }(t);
  if (function(e) {
    return e instanceof _t;
  }(t)) return function(e) {
    const n = _(e.definition, (r) => xe(r));
    return mr(vt(n));
  }(t);
  throw Error("non exhaustive match");
}
const as = "_~IN~_";
class yc extends Cn {
  constructor(e) {
    super(), this.topProd = e, this.follows = {};
  }
  startWalking() {
    return this.walk(this.topProd), this.follows;
  }
  walkTerminal(e, n, r) {
  }
  walkProdRef(e, n, r) {
    const i = (o = e.referencedRule, s = e.idx, o.name + s + as + this.topProd.name);
    var o, s;
    const a = n.concat(r), c = xe(new ut({ definition: a }));
    this.follows[i] = c;
  }
}
function b(t) {
  return t.charCodeAt(0);
}
function Gn(t, e) {
  Array.isArray(t) ? t.forEach(function(n) {
    e.push(n);
  }) : e.push(t);
}
function ve(t, e) {
  if (t[e] === !0) throw "duplicate flag " + e;
  t[e], t[e] = !0;
}
function ae(t) {
  if (t === void 0) throw Error("Internal Error - Should never get here!");
  return !0;
}
function Mi(t) {
  return t.type === "Character";
}
const pn = [];
for (let t = b("0"); t <= b("9"); t++) pn.push(t);
const mn = [b("_")].concat(pn);
for (let t = b("a"); t <= b("z"); t++) mn.push(t);
for (let t = b("A"); t <= b("Z"); t++) mn.push(t);
const Ui = [b(" "), b("\f"), b(`
`), b("\r"), b("	"), b("\v"), b("	"), b(" "), b(" "), b(" "), b(" "), b(" "), b(" "), b(" "), b(" "), b(" "), b(" "), b(" "), b(" "), b(" "), b("\u2028"), b("\u2029"), b(" "), b(" "), b(" "), b("\uFEFF")], Rc = /[0-9a-fA-F]/, qe = /[0-9]/, Oc = /[1-9]/;
class gr {
  visitChildren(e) {
    for (const n in e) {
      const r = e[n];
      e.hasOwnProperty(n) && (r.type !== void 0 ? this.visit(r) : Array.isArray(r) && r.forEach((i) => {
        this.visit(i);
      }, this));
    }
  }
  visit(e) {
    switch (e.type) {
      case "Pattern":
        this.visitPattern(e);
        break;
      case "Flags":
        this.visitFlags(e);
        break;
      case "Disjunction":
        this.visitDisjunction(e);
        break;
      case "Alternative":
        this.visitAlternative(e);
        break;
      case "StartAnchor":
        this.visitStartAnchor(e);
        break;
      case "EndAnchor":
        this.visitEndAnchor(e);
        break;
      case "WordBoundary":
        this.visitWordBoundary(e);
        break;
      case "NonWordBoundary":
        this.visitNonWordBoundary(e);
        break;
      case "Lookahead":
        this.visitLookahead(e);
        break;
      case "NegativeLookahead":
        this.visitNegativeLookahead(e);
        break;
      case "Character":
        this.visitCharacter(e);
        break;
      case "Set":
        this.visitSet(e);
        break;
      case "Group":
        this.visitGroup(e);
        break;
      case "GroupBackReference":
        this.visitGroupBackReference(e);
        break;
      case "Quantifier":
        this.visitQuantifier(e);
    }
    this.visitChildren(e);
  }
  visitPattern(e) {
  }
  visitFlags(e) {
  }
  visitDisjunction(e) {
  }
  visitAlternative(e) {
  }
  visitStartAnchor(e) {
  }
  visitEndAnchor(e) {
  }
  visitWordBoundary(e) {
  }
  visitNonWordBoundary(e) {
  }
  visitLookahead(e) {
  }
  visitNegativeLookahead(e) {
  }
  visitCharacter(e) {
  }
  visitSet(e) {
  }
  visitGroup(e) {
  }
  visitGroupBackReference(e) {
  }
  visitQuantifier(e) {
  }
}
let on = {};
const Sc = new class {
  constructor() {
    this.idx = 0, this.input = "", this.groupIdx = 0;
  }
  saveState() {
    return { idx: this.idx, input: this.input, groupIdx: this.groupIdx };
  }
  restoreState(t) {
    this.idx = t.idx, this.input = t.input, this.groupIdx = t.groupIdx;
  }
  pattern(t) {
    this.idx = 0, this.input = t, this.groupIdx = 0, this.consumeChar("/");
    const e = this.disjunction();
    this.consumeChar("/");
    const n = { type: "Flags", loc: { begin: this.idx, end: t.length }, global: !1, ignoreCase: !1, multiLine: !1, unicode: !1, sticky: !1 };
    for (; this.isRegExpFlag(); ) switch (this.popChar()) {
      case "g":
        ve(n, "global");
        break;
      case "i":
        ve(n, "ignoreCase");
        break;
      case "m":
        ve(n, "multiLine");
        break;
      case "u":
        ve(n, "unicode");
        break;
      case "y":
        ve(n, "sticky");
    }
    if (this.idx !== this.input.length) throw Error("Redundant input: " + this.input.substring(this.idx));
    return { type: "Pattern", flags: n, value: e, loc: this.loc(0) };
  }
  disjunction() {
    const t = [], e = this.idx;
    for (t.push(this.alternative()); this.peekChar() === "|"; ) this.consumeChar("|"), t.push(this.alternative());
    return { type: "Disjunction", value: t, loc: this.loc(e) };
  }
  alternative() {
    const t = [], e = this.idx;
    for (; this.isTerm(); ) t.push(this.term());
    return { type: "Alternative", value: t, loc: this.loc(e) };
  }
  term() {
    return this.isAssertion() ? this.assertion() : this.atom();
  }
  assertion() {
    const t = this.idx;
    switch (this.popChar()) {
      case "^":
        return { type: "StartAnchor", loc: this.loc(t) };
      case "$":
        return { type: "EndAnchor", loc: this.loc(t) };
      case "\\":
        switch (this.popChar()) {
          case "b":
            return { type: "WordBoundary", loc: this.loc(t) };
          case "B":
            return { type: "NonWordBoundary", loc: this.loc(t) };
        }
        throw Error("Invalid Assertion Escape");
      case "(":
        let e;
        switch (this.consumeChar("?"), this.popChar()) {
          case "=":
            e = "Lookahead";
            break;
          case "!":
            e = "NegativeLookahead";
        }
        ae(e);
        const n = this.disjunction();
        return this.consumeChar(")"), { type: e, value: n, loc: this.loc(t) };
    }
    return function() {
      throw Error("Internal Error - Should never get here!");
    }();
  }
  quantifier(t = !1) {
    let e;
    const n = this.idx;
    switch (this.popChar()) {
      case "*":
        e = { atLeast: 0, atMost: 1 / 0 };
        break;
      case "+":
        e = { atLeast: 1, atMost: 1 / 0 };
        break;
      case "?":
        e = { atLeast: 0, atMost: 1 };
        break;
      case "{":
        const r = this.integerIncludingZero();
        switch (this.popChar()) {
          case "}":
            e = { atLeast: r, atMost: r };
            break;
          case ",":
            let i;
            this.isDigit() ? (i = this.integerIncludingZero(), e = { atLeast: r, atMost: i }) : e = { atLeast: r, atMost: 1 / 0 }, this.consumeChar("}");
        }
        if (t === !0 && e === void 0) return;
        ae(e);
    }
    if (t !== !0 || e !== void 0) return ae(e) ? (this.peekChar(0) === "?" ? (this.consumeChar("?"), e.greedy = !1) : e.greedy = !0, e.type = "Quantifier", e.loc = this.loc(n), e) : void 0;
  }
  atom() {
    let t;
    const e = this.idx;
    switch (this.peekChar()) {
      case ".":
        t = this.dotAll();
        break;
      case "\\":
        t = this.atomEscape();
        break;
      case "[":
        t = this.characterClass();
        break;
      case "(":
        t = this.group();
    }
    if (t === void 0 && this.isPatternCharacter() && (t = this.patternCharacter()), ae(t)) return t.loc = this.loc(e), this.isQuantifier() && (t.quantifier = this.quantifier()), t;
  }
  dotAll() {
    return this.consumeChar("."), { type: "Set", complement: !0, value: [b(`
`), b("\r"), b("\u2028"), b("\u2029")] };
  }
  atomEscape() {
    switch (this.consumeChar("\\"), this.peekChar()) {
      case "1":
      case "2":
      case "3":
      case "4":
      case "5":
      case "6":
      case "7":
      case "8":
      case "9":
        return this.decimalEscapeAtom();
      case "d":
      case "D":
      case "s":
      case "S":
      case "w":
      case "W":
        return this.characterClassEscape();
      case "f":
      case "n":
      case "r":
      case "t":
      case "v":
        return this.controlEscapeAtom();
      case "c":
        return this.controlLetterEscapeAtom();
      case "0":
        return this.nulCharacterAtom();
      case "x":
        return this.hexEscapeSequenceAtom();
      case "u":
        return this.regExpUnicodeEscapeSequenceAtom();
      default:
        return this.identityEscapeAtom();
    }
  }
  decimalEscapeAtom() {
    return { type: "GroupBackReference", value: this.positiveInteger() };
  }
  characterClassEscape() {
    let t, e = !1;
    switch (this.popChar()) {
      case "d":
        t = pn;
        break;
      case "D":
        t = pn, e = !0;
        break;
      case "s":
        t = Ui;
        break;
      case "S":
        t = Ui, e = !0;
        break;
      case "w":
        t = mn;
        break;
      case "W":
        t = mn, e = !0;
    }
    if (ae(t)) return { type: "Set", value: t, complement: e };
  }
  controlEscapeAtom() {
    let t;
    switch (this.popChar()) {
      case "f":
        t = b("\f");
        break;
      case "n":
        t = b(`
`);
        break;
      case "r":
        t = b("\r");
        break;
      case "t":
        t = b("	");
        break;
      case "v":
        t = b("\v");
    }
    if (ae(t)) return { type: "Character", value: t };
  }
  controlLetterEscapeAtom() {
    this.consumeChar("c");
    const t = this.popChar();
    if (/[a-zA-Z]/.test(t) === !1) throw Error("Invalid ");
    return { type: "Character", value: t.toUpperCase().charCodeAt(0) - 64 };
  }
  nulCharacterAtom() {
    return this.consumeChar("0"), { type: "Character", value: b("\0") };
  }
  hexEscapeSequenceAtom() {
    return this.consumeChar("x"), this.parseHexDigits(2);
  }
  regExpUnicodeEscapeSequenceAtom() {
    return this.consumeChar("u"), this.parseHexDigits(4);
  }
  identityEscapeAtom() {
    return { type: "Character", value: b(this.popChar()) };
  }
  classPatternCharacterAtom() {
    switch (this.peekChar()) {
      case `
`:
      case "\r":
      case "\u2028":
      case "\u2029":
      case "\\":
      case "]":
        throw Error("TBD");
      default:
        return { type: "Character", value: b(this.popChar()) };
    }
  }
  characterClass() {
    const t = [];
    let e = !1;
    for (this.consumeChar("["), this.peekChar(0) === "^" && (this.consumeChar("^"), e = !0); this.isClassAtom(); ) {
      const n = this.classAtom();
      if (n.type, Mi(n) && this.isRangeDash()) {
        this.consumeChar("-");
        const r = this.classAtom();
        if (r.type, Mi(r)) {
          if (r.value < n.value) throw Error("Range out of order in character class");
          t.push({ from: n.value, to: r.value });
        } else Gn(n.value, t), t.push(b("-")), Gn(r.value, t);
      } else Gn(n.value, t);
    }
    return this.consumeChar("]"), { type: "Set", complement: e, value: t };
  }
  classAtom() {
    switch (this.peekChar()) {
      case "]":
      case `
`:
      case "\r":
      case "\u2028":
      case "\u2029":
        throw Error("TBD");
      case "\\":
        return this.classEscape();
      default:
        return this.classPatternCharacterAtom();
    }
  }
  classEscape() {
    switch (this.consumeChar("\\"), this.peekChar()) {
      case "b":
        return this.consumeChar("b"), { type: "Character", value: b("\b") };
      case "d":
      case "D":
      case "s":
      case "S":
      case "w":
      case "W":
        return this.characterClassEscape();
      case "f":
      case "n":
      case "r":
      case "t":
      case "v":
        return this.controlEscapeAtom();
      case "c":
        return this.controlLetterEscapeAtom();
      case "0":
        return this.nulCharacterAtom();
      case "x":
        return this.hexEscapeSequenceAtom();
      case "u":
        return this.regExpUnicodeEscapeSequenceAtom();
      default:
        return this.identityEscapeAtom();
    }
  }
  group() {
    let t = !0;
    this.consumeChar("("), this.peekChar(0) === "?" ? (this.consumeChar("?"), this.consumeChar(":"), t = !1) : this.groupIdx++;
    const e = this.disjunction();
    this.consumeChar(")");
    const n = { type: "Group", capturing: t, value: e };
    return t && (n.idx = this.groupIdx), n;
  }
  positiveInteger() {
    let t = this.popChar();
    if (Oc.test(t) === !1) throw Error("Expecting a positive integer");
    for (; qe.test(this.peekChar(0)); ) t += this.popChar();
    return parseInt(t, 10);
  }
  integerIncludingZero() {
    let t = this.popChar();
    if (qe.test(t) === !1) throw Error("Expecting an integer");
    for (; qe.test(this.peekChar(0)); ) t += this.popChar();
    return parseInt(t, 10);
  }
  patternCharacter() {
    const t = this.popChar();
    switch (t) {
      case `
`:
      case "\r":
      case "\u2028":
      case "\u2029":
      case "^":
      case "$":
      case "\\":
      case ".":
      case "*":
      case "+":
      case "?":
      case "(":
      case ")":
      case "[":
      case "|":
        throw Error("TBD");
      default:
        return { type: "Character", value: b(t) };
    }
  }
  isRegExpFlag() {
    switch (this.peekChar(0)) {
      case "g":
      case "i":
      case "m":
      case "u":
      case "y":
        return !0;
      default:
        return !1;
    }
  }
  isRangeDash() {
    return this.peekChar() === "-" && this.isClassAtom(1);
  }
  isDigit() {
    return qe.test(this.peekChar(0));
  }
  isClassAtom(t = 0) {
    switch (this.peekChar(t)) {
      case "]":
      case `
`:
      case "\r":
      case "\u2028":
      case "\u2029":
        return !1;
      default:
        return !0;
    }
  }
  isTerm() {
    return this.isAtom() || this.isAssertion();
  }
  isAtom() {
    if (this.isPatternCharacter()) return !0;
    switch (this.peekChar(0)) {
      case ".":
      case "\\":
      case "[":
      case "(":
        return !0;
      default:
        return !1;
    }
  }
  isAssertion() {
    switch (this.peekChar(0)) {
      case "^":
      case "$":
        return !0;
      case "\\":
        switch (this.peekChar(1)) {
          case "b":
          case "B":
            return !0;
          default:
            return !1;
        }
      case "(":
        return this.peekChar(1) === "?" && (this.peekChar(2) === "=" || this.peekChar(2) === "!");
      default:
        return !1;
    }
  }
  isQuantifier() {
    const t = this.saveState();
    try {
      return this.quantifier(!0) !== void 0;
    } catch {
      return !1;
    } finally {
      this.restoreState(t);
    }
  }
  isPatternCharacter() {
    switch (this.peekChar()) {
      case "^":
      case "$":
      case "\\":
      case ".":
      case "*":
      case "+":
      case "?":
      case "(":
      case ")":
      case "[":
      case "|":
      case "/":
      case `
`:
      case "\r":
      case "\u2028":
      case "\u2029":
        return !1;
      default:
        return !0;
    }
  }
  parseHexDigits(t) {
    let e = "";
    for (let n = 0; n < t; n++) {
      const r = this.popChar();
      if (Rc.test(r) === !1) throw Error("Expecting a HexDecimal digits");
      e += r;
    }
    return { type: "Character", value: parseInt(e, 16) };
  }
  peekChar(t = 0) {
    return this.input[this.idx + t];
  }
  popChar() {
    const t = this.peekChar(0);
    return this.consumeChar(void 0), t;
  }
  consumeChar(t) {
    if (t !== void 0 && this.input[this.idx] !== t) throw Error("Expected: '" + t + "' but found: '" + this.input[this.idx] + "' at offset: " + this.idx);
    if (this.idx >= this.input.length) throw Error("Unexpected end of input");
    this.idx++;
  }
  loc(t) {
    return { begin: t, end: this.idx };
  }
}();
function En(t) {
  const e = t.toString();
  if (on.hasOwnProperty(e)) return on[e];
  {
    const n = Sc.pattern(e);
    return on[e] = n, n;
  }
}
const cs = "Complement Sets are not supported for first char optimization", gn = `Unable to use "first char" lexer optimizations:
`;
function _c(t, e = !1) {
  try {
    const n = En(t);
    return Tr(n.value, {}, n.flags.ignoreCase);
  } catch (n) {
    if (n.message === cs) e && is(`${gn}	Unable to optimize: < ${t.toString()} >
	Complement Sets cannot be automatically optimized.
	This will disable the lexer's first char optimizations.
	See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.`);
    else {
      let r = "";
      e && (r = `
	This will disable the lexer's first char optimizations.
	See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details.`), Er(`${gn}
	Failed parsing: < ${t.toString()} >
	Using the @chevrotain/regexp-to-ast library
	Please open an issue at: https://github.com/chevrotain/chevrotain/issues` + r);
    }
  }
  return [];
}
function Tr(t, e, n) {
  switch (t.type) {
    case "Disjunction":
      for (let i = 0; i < t.value.length; i++) Tr(t.value[i], e, n);
      break;
    case "Alternative":
      const r = t.value;
      for (let i = 0; i < r.length; i++) {
        const o = r[i];
        switch (o.type) {
          case "EndAnchor":
          case "GroupBackReference":
          case "Lookahead":
          case "NegativeLookahead":
          case "StartAnchor":
          case "WordBoundary":
          case "NonWordBoundary":
            continue;
        }
        const s = o;
        switch (s.type) {
          case "Character":
            Ze(s.value, e, n);
            break;
          case "Set":
            if (s.complement === !0) throw Error(cs);
            k(s.value, (c) => {
              if (typeof c == "number") Ze(c, e, n);
              else {
                const u = c;
                if (n === !0) for (let l = u.from; l <= u.to; l++) Ze(l, e, n);
                else {
                  for (let l = u.from; l <= u.to && l < Oe; l++) Ze(l, e, n);
                  if (u.to >= Oe) {
                    const l = u.from >= Oe ? u.from : Oe, h = u.to, f = Ht(l), d = Ht(h);
                    for (let E = f; E <= d; E++) e[E] = E;
                  }
                }
              }
            });
            break;
          case "Group":
            Tr(s.value, e, n);
            break;
          default:
            throw Error("Non Exhaustive Match");
        }
        const a = s.quantifier !== void 0 && s.quantifier.atLeast === 0;
        if (s.type === "Group" && Ar(s) === !1 || s.type !== "Group" && a === !1) break;
      }
      break;
    default:
      throw Error("non exhaustive match!");
  }
  return Z(e);
}
function Ze(t, e, n) {
  const r = Ht(t);
  e[r] = r, n === !0 && function(i, o) {
    const s = String.fromCharCode(i), a = s.toUpperCase();
    if (a !== s) {
      const c = Ht(a.charCodeAt(0));
      o[c] = c;
    } else {
      const c = s.toLowerCase();
      if (c !== s) {
        const u = Ht(c.charCodeAt(0));
        o[u] = u;
      }
    }
  }(t, e);
}
function Fi(t, e) {
  return me(t.value, (n) => {
    if (typeof n == "number") return it(e, n);
    {
      const r = n;
      return me(e, (i) => r.from <= i && i <= r.to) !== void 0;
    }
  });
}
function Ar(t) {
  const e = t.quantifier;
  return !(!e || e.atLeast !== 0) || !!t.value && (D(t.value) ? Nt(t.value, Ar) : Ar(t.value));
}
class Lc extends gr {
  constructor(e) {
    super(), this.targetCharCodes = e, this.found = !1;
  }
  visitChildren(e) {
    if (this.found !== !0) {
      switch (e.type) {
        case "Lookahead":
          return void this.visitLookahead(e);
        case "NegativeLookahead":
          return void this.visitNegativeLookahead(e);
      }
      super.visitChildren(e);
    }
  }
  visitCharacter(e) {
    it(this.targetCharCodes, e.value) && (this.found = !0);
  }
  visitSet(e) {
    e.complement ? Fi(e, this.targetCharCodes) === void 0 && (this.found = !0) : Fi(e, this.targetCharCodes) !== void 0 && (this.found = !0);
  }
}
function Wr(t, e) {
  if (e instanceof RegExp) {
    const n = En(e), r = new Lc(t);
    return r.visit(n), r.found;
  }
  return me(e, (n) => it(t, n.charCodeAt(0))) !== void 0;
}
const te = "PATTERN", Ne = "defaultMode", zn = "modes";
let us = typeof new RegExp("(?:)").sticky == "boolean";
function xc(t, e) {
  const n = (e = $r(e, { useSticky: us, debug: !1, safeMode: !1, positionTracking: "full", lineTerminatorCharacters: ["\r", `
`], tracer: (m, p) => p() })).tracer;
  let r;
  n("initCharCodeToOptimizedIndexMap", () => {
    (function() {
      if (G(sn)) {
        sn = new Array(65536);
        for (let m = 0; m < 65536; m++) sn[m] = m > 255 ? 255 + ~~(m / 255) : m;
      }
    })();
  }), n("Reject Lexer.NA", () => {
    r = xn(t, (m) => m[te] === st.NA);
  });
  let i, o, s, a, c, u, l, h, f, d, E, I = !1;
  n("Transform Patterns", () => {
    I = !1, i = _(r, (m) => {
      const p = m[te];
      if (Gt(p)) {
        const A = p.source;
        return A.length !== 1 || A === "^" || A === "$" || A === "." || p.ignoreCase ? A.length !== 2 || A[0] !== "\\" || it(["d", "D", "s", "S", "t", "r", "n", "t", "0", "c", "b", "B", "f", "v", "w", "W"], A[1]) ? e.useSticky ? ji(p) : Di(p) : A[1] : A;
      }
      if (Kt(p)) return I = !0, { exec: p };
      if (typeof p == "object") return I = !0, p;
      if (typeof p == "string") {
        if (p.length === 1) return p;
        {
          const A = p.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&"), O = new RegExp(A);
          return e.useSticky ? ji(O) : Di(O);
        }
      }
      throw Error("non exhaustive match");
    });
  }), n("misc mapping", () => {
    o = _(r, (m) => m.tokenTypeIdx), s = _(r, (m) => {
      const p = m.GROUP;
      if (p !== st.SKIPPED) {
        if (at(p)) return p;
        if (zt(p)) return !1;
        throw Error("non exhaustive match");
      }
    }), a = _(r, (m) => {
      const p = m.LONGER_ALT;
      if (p)
        return D(p) ? _(p, (A) => bi(r, A)) : [bi(r, p)];
    }), c = _(r, (m) => m.PUSH_MODE), u = _(r, (m) => L(m, "POP_MODE"));
  }), n("Line Terminator Handling", () => {
    const m = fs(e.lineTerminatorCharacters);
    l = _(r, (p) => !1), e.positionTracking !== "onlyOffset" && (l = _(r, (p) => L(p, "LINE_BREAKS") ? !!p.LINE_BREAKS : hs(p, m) === !1 && Wr(m, p.PATTERN)));
  }), n("Misc Mapping #2", () => {
    h = _(r, ls), f = _(i, wc), d = ft(r, (m, p) => {
      const A = p.GROUP;
      return at(A) && A !== st.SKIPPED && (m[A] = []), m;
    }, {}), E = _(i, (m, p) => ({ pattern: i[p], longerAlt: a[p], canLineTerminator: l[p], isCustom: h[p], short: f[p], group: s[p], push: c[p], pop: u[p], tokenTypeIdx: o[p], tokenType: r[p] }));
  });
  let S = !0, T = [];
  return e.safeMode || n("First Char Optimization", () => {
    T = ft(r, (m, p, A) => {
      if (typeof p.PATTERN == "string") {
        const O = Ht(p.PATTERN.charCodeAt(0));
        Kn(m, O, E[A]);
      } else if (D(p.START_CHARS_HINT)) {
        let O;
        k(p.START_CHARS_HINT, (g) => {
          const R = Ht(typeof g == "string" ? g.charCodeAt(0) : g);
          O !== R && (O = R, Kn(m, R, E[A]));
        });
      } else if (Gt(p.PATTERN)) if (p.PATTERN.unicode) S = !1, e.ensureOptimizations && Er(`${gn}	Unable to analyze < ${p.PATTERN.toString()} > pattern.
	The regexp unicode flag is not currently supported by the regexp-to-ast library.
	This will disable the lexer's first char optimizations.
	For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE`);
      else {
        const O = _c(p.PATTERN, e.ensureOptimizations);
        G(O) && (S = !1), k(O, (g) => {
          Kn(m, g, E[A]);
        });
      }
      else e.ensureOptimizations && Er(`${gn}	TokenType: <${p.name}> is using a custom token pattern without providing <start_chars_hint> parameter.
	This will disable the lexer's first char optimizations.
	For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE`), S = !1;
      return m;
    }, []);
  }), { emptyGroups: d, patternIdxToConfig: E, charCodeToPatternIdxToConfig: T, hasCustom: I, canBeOptimized: S };
}
function Cc(t, e) {
  let n = [];
  const r = function(s) {
    const a = pt(s, (l) => !L(l, te)), c = _(a, (l) => ({ message: "Token Type: ->" + l.name + "<- missing static 'PATTERN' property", type: V.MISSING_PATTERN, tokenTypes: [l] })), u = fn(s, a);
    return { errors: c, valid: u };
  }(t);
  n = n.concat(r.errors);
  const i = function(s) {
    const a = pt(s, (l) => {
      const h = l[te];
      return !(Gt(h) || Kt(h) || L(h, "exec") || at(h));
    }), c = _(a, (l) => ({ message: "Token Type: ->" + l.name + "<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.", type: V.INVALID_PATTERN, tokenTypes: [l] })), u = fn(s, a);
    return { errors: c, valid: u };
  }(r.valid), o = i.valid;
  return n = n.concat(i.errors), n = n.concat(function(s) {
    let a = [];
    const c = pt(s, (u) => Gt(u[te]));
    return a = a.concat(function(u) {
      class l extends gr {
        constructor() {
          super(...arguments), this.found = !1;
        }
        visitEndAnchor(E) {
          this.found = !0;
        }
      }
      const h = pt(u, (d) => {
        const E = d.PATTERN;
        try {
          const I = En(E), S = new l();
          return S.visit(I), S.found;
        } catch {
          return kc.test(E.source);
        }
      });
      return _(h, (d) => ({ message: `Unexpected RegExp Anchor Error:
	Token Type: ->` + d.name + `<- static 'PATTERN' cannot contain end of input anchor '$'
	See chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS	for details.`, type: V.EOI_ANCHOR_FOUND, tokenTypes: [d] }));
    }(c)), a = a.concat(function(u) {
      class l extends gr {
        constructor() {
          super(...arguments), this.found = !1;
        }
        visitStartAnchor(E) {
          this.found = !0;
        }
      }
      const h = pt(u, (d) => {
        const E = d.PATTERN;
        try {
          const I = En(E), S = new l();
          return S.visit(I), S.found;
        } catch {
          return bc.test(E.source);
        }
      });
      return _(h, (d) => ({ message: `Unexpected RegExp Anchor Error:
	Token Type: ->` + d.name + `<- static 'PATTERN' cannot contain start of input anchor '^'
	See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS	for details.`, type: V.SOI_ANCHOR_FOUND, tokenTypes: [d] }));
    }(c)), a = a.concat(function(u) {
      const l = pt(u, (f) => {
        const d = f[te];
        return d instanceof RegExp && (d.multiline || d.global);
      });
      return _(l, (f) => ({ message: "Token Type: ->" + f.name + "<- static 'PATTERN' may NOT contain global('g') or multiline('m')", type: V.UNSUPPORTED_FLAGS_FOUND, tokenTypes: [f] }));
    }(c)), a = a.concat(function(u) {
      const l = [];
      let h = _(u, (d) => ft(u, (E, I) => (d.PATTERN.source !== I.PATTERN.source || it(l, I) || I.PATTERN === st.NA || (l.push(I), E.push(I)), E), []));
      return h = Ge(h), _(pt(h, (d) => d.length > 1), (d) => {
        const E = _(d, (I) => I.name);
        return { message: `The same RegExp pattern ->${Rt(d).PATTERN}<-has been used in all of the following Token Types: ${E.join(", ")} <-`, type: V.DUPLICATE_PATTERNS_FOUND, tokenTypes: d };
      });
    }(c)), a = a.concat(function(u) {
      const l = pt(u, (f) => f.PATTERN.test(""));
      return _(l, (f) => ({ message: "Token Type: ->" + f.name + "<- static 'PATTERN' must not match an empty string", type: V.EMPTY_MATCH_PATTERN, tokenTypes: [f] }));
    }(c)), a;
  }(o)), n = n.concat(function(s) {
    const a = pt(s, (u) => {
      if (!L(u, "GROUP")) return !1;
      const l = u.GROUP;
      return l !== st.SKIPPED && l !== st.NA && !at(l);
    });
    return _(a, (u) => ({ message: "Token Type: ->" + u.name + "<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String", type: V.INVALID_GROUP_TYPE_FOUND, tokenTypes: [u] }));
  }(o)), n = n.concat(function(s, a) {
    const c = pt(s, (l) => l.PUSH_MODE !== void 0 && !it(a, l.PUSH_MODE));
    return _(c, (l) => ({ message: `Token Type: ->${l.name}<- static 'PUSH_MODE' value cannot refer to a Lexer Mode ->${l.PUSH_MODE}<-which does not exist`, type: V.PUSH_MODE_DOES_NOT_EXIST, tokenTypes: [l] }));
  }(o, e)), n = n.concat(function(s) {
    const a = [], c = ft(s, (u, l, h) => {
      const f = l.PATTERN;
      return f === st.NA || (at(f) ? u.push({ str: f, idx: h, tokenType: l }) : Gt(f) && (d = f, me([".", "\\", "[", "]", "|", "^", "$", "(", ")", "?", "*", "+", "{"], (E) => d.source.indexOf(E) !== -1) === void 0) && u.push({ str: f.source, idx: h, tokenType: l })), u;
      var d;
    }, []);
    return k(s, (u, l) => {
      k(c, ({ str: h, idx: f, tokenType: d }) => {
        if (l < f && function(E, I) {
          if (Gt(I)) {
            const S = I.exec(E);
            return S !== null && S.index === 0;
          }
          if (Kt(I)) return I(E, 0, [], {});
          if (L(I, "exec")) return I.exec(E, 0, [], {});
          if (typeof I == "string") return I === E;
          throw Error("non exhaustive match");
        }(h, u.PATTERN)) {
          const E = `Token: ->${d.name}<- can never be matched.
Because it appears AFTER the Token Type ->${u.name}<-in the lexer's definition.
See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE`;
          a.push({ message: E, type: V.UNREACHABLE_PATTERN, tokenTypes: [u, d] });
        }
      });
    }), a;
  }(o)), n;
}
const kc = /[^\\][$]/, bc = /[^\\[][\^]|^\^/;
function Di(t) {
  const e = t.ignoreCase ? "i" : "";
  return new RegExp(`^(?:${t.source})`, e);
}
function ji(t) {
  const e = t.ignoreCase ? "iy" : "y";
  return new RegExp(`${t.source}`, e);
}
function Pc(t, e, n) {
  const r = [];
  let i = !1;
  const o = xn(Ge(vt(Z(t.modes))), (a) => a[te] === st.NA), s = fs(n);
  return e && k(o, (a) => {
    const c = hs(a, s);
    if (c !== !1) {
      const u = function(h, f) {
        if (f.issue === V.IDENTIFY_TERMINATOR) return `Warning: unable to identify line terminator usage in pattern.
	The problem is in the <${h.name}> Token Type
	 Root cause: ${f.errMsg}.
	For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR`;
        if (f.issue === V.CUSTOM_LINE_BREAK) return `Warning: A Custom Token Pattern should specify the <line_breaks> option.
	The problem is in the <${h.name}> Token Type
	For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK`;
        throw Error("non exhaustive match");
      }(a, c), l = { message: u, type: c.issue, tokenType: a };
      r.push(l);
    } else L(a, "LINE_BREAKS") ? a.LINE_BREAKS === !0 && (i = !0) : Wr(s, a.PATTERN) && (i = !0);
  }), e && !i && r.push({ message: `Warning: No LINE_BREAKS Found.
	This Lexer has been defined to track line and column information,
	But none of the Token Types can be identified as matching a line terminator.
	See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS 
	for details.`, type: V.NO_LINE_BREAKS_FLAGS }), r;
}
function ls(t) {
  const e = t.PATTERN;
  if (Gt(e)) return !1;
  if (Kt(e) || L(e, "exec")) return !0;
  if (at(e)) return !1;
  throw Error("non exhaustive match");
}
function wc(t) {
  return !(!at(t) || t.length !== 1) && t.charCodeAt(0);
}
const Mc = { test: function(t) {
  const e = t.length;
  for (let n = this.lastIndex; n < e; n++) {
    const r = t.charCodeAt(n);
    if (r === 10) return this.lastIndex = n + 1, !0;
    if (r === 13) return t.charCodeAt(n + 1) === 10 ? this.lastIndex = n + 2 : this.lastIndex = n + 1, !0;
  }
  return !1;
}, lastIndex: 0 };
function hs(t, e) {
  if (L(t, "LINE_BREAKS")) return !1;
  if (Gt(t.PATTERN)) {
    try {
      Wr(e, t.PATTERN);
    } catch (n) {
      return { issue: V.IDENTIFY_TERMINATOR, errMsg: n.message };
    }
    return !1;
  }
  if (at(t.PATTERN)) return !1;
  if (ls(t)) return { issue: V.CUSTOM_LINE_BREAK };
  throw Error("non exhaustive match");
}
function fs(t) {
  return _(t, (e) => at(e) ? e.charCodeAt(0) : e);
}
function Kn(t, e, n) {
  t[e] === void 0 ? t[e] = [n] : t[e].push(n);
}
const Oe = 256;
let sn = [];
function Ht(t) {
  return t < Oe ? t : sn[t];
}
function Ce(t, e) {
  const n = t.tokenTypeIdx;
  return n === e.tokenTypeIdx || e.isParent === !0 && e.categoryMatchesMap[n] === !0;
}
function Tn(t, e) {
  return t.tokenTypeIdx === e.tokenTypeIdx;
}
let Bi = 1;
const $i = {};
function ze(t) {
  const e = function(n) {
    let r = tt(n), i = n, o = !0;
    for (; o; ) {
      i = Ge(vt(_(i, (a) => a.CATEGORIES)));
      const s = fn(i, r);
      r = r.concat(s), G(s) ? o = !1 : i = s;
    }
    return r;
  }(t);
  (function(n) {
    k(n, (r) => {
      ps(r) || ($i[Bi] = r, r.tokenTypeIdx = Bi++), Wi(r) && !D(r.CATEGORIES) && (r.CATEGORIES = [r.CATEGORIES]), Wi(r) || (r.CATEGORIES = []), L(r, "categoryMatches") || (r.categoryMatches = []), function(i) {
        return L(i, "categoryMatchesMap");
      }(r) || (r.categoryMatchesMap = {});
    });
  })(e), function(n) {
    k(n, (r) => {
      ds([], r);
    });
  }(e), function(n) {
    k(n, (r) => {
      r.categoryMatches = [], k(r.categoryMatchesMap, (i, o) => {
        r.categoryMatches.push($i[o].tokenTypeIdx);
      });
    });
  }(e), k(e, (n) => {
    n.isParent = n.categoryMatches.length > 0;
  });
}
function ds(t, e) {
  k(t, (n) => {
    e.categoryMatchesMap[n.tokenTypeIdx] = !0;
  }), k(e.CATEGORIES, (n) => {
    const r = t.concat(e);
    it(r, n) || ds(r, n);
  });
}
function ps(t) {
  return L(t, "tokenTypeIdx");
}
function Wi(t) {
  return L(t, "CATEGORIES");
}
function Uc(t) {
  return L(t, "tokenTypeIdx");
}
const Fc = { buildUnableToPopLexerModeMessage: (t) => `Unable to pop Lexer Mode after encountering Token ->${t.image}<- The Mode Stack is empty`, buildUnexpectedCharactersMessage: (t, e, n, r, i) => `unexpected character: ->${t.charAt(e)}<- at offset: ${e}, skipped ${n} characters.` };
var V;
(function(t) {
  t[t.MISSING_PATTERN = 0] = "MISSING_PATTERN", t[t.INVALID_PATTERN = 1] = "INVALID_PATTERN", t[t.EOI_ANCHOR_FOUND = 2] = "EOI_ANCHOR_FOUND", t[t.UNSUPPORTED_FLAGS_FOUND = 3] = "UNSUPPORTED_FLAGS_FOUND", t[t.DUPLICATE_PATTERNS_FOUND = 4] = "DUPLICATE_PATTERNS_FOUND", t[t.INVALID_GROUP_TYPE_FOUND = 5] = "INVALID_GROUP_TYPE_FOUND", t[t.PUSH_MODE_DOES_NOT_EXIST = 6] = "PUSH_MODE_DOES_NOT_EXIST", t[t.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE = 7] = "MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE", t[t.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY = 8] = "MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY", t[t.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST = 9] = "MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST", t[t.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED = 10] = "LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED", t[t.SOI_ANCHOR_FOUND = 11] = "SOI_ANCHOR_FOUND", t[t.EMPTY_MATCH_PATTERN = 12] = "EMPTY_MATCH_PATTERN", t[t.NO_LINE_BREAKS_FLAGS = 13] = "NO_LINE_BREAKS_FLAGS", t[t.UNREACHABLE_PATTERN = 14] = "UNREACHABLE_PATTERN", t[t.IDENTIFY_TERMINATOR = 15] = "IDENTIFY_TERMINATOR", t[t.CUSTOM_LINE_BREAK = 16] = "CUSTOM_LINE_BREAK", t[t.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE = 17] = "MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE";
})(V || (V = {}));
const Se = { deferDefinitionErrorsHandling: !1, positionTracking: "full", lineTerminatorsPattern: /\n|\r\n?/g, lineTerminatorCharacters: [`
`, "\r"], ensureOptimizations: !1, safeMode: !1, errorMessageProvider: Fc, traceInitPerf: !1, skipValidations: !1, recoveryEnabled: !0 };
Object.freeze(Se);
class st {
  constructor(e, n = Se) {
    if (this.lexerDefinition = e, this.lexerDefinitionErrors = [], this.lexerDefinitionWarning = [], this.patternIdxToConfig = {}, this.charCodeToPatternIdxToConfig = {}, this.modes = [], this.emptyGroups = {}, this.trackStartLines = !0, this.trackEndLines = !0, this.hasCustom = !1, this.canModeBeOptimized = {}, this.TRACE_INIT = (i, o) => {
      if (this.traceInitPerf === !0) {
        this.traceInitIndent++;
        const s = new Array(this.traceInitIndent + 1).join("	");
        this.traceInitIndent < this.traceInitMaxIdent && console.log(`${s}--> <${i}>`);
        const { time: a, value: c } = os(o), u = a > 10 ? console.warn : console.log;
        return this.traceInitIndent < this.traceInitMaxIdent && u(`${s}<-- <${i}> time: ${a}ms`), this.traceInitIndent--, c;
      }
      return o();
    }, typeof n == "boolean") throw Error(`The second argument to the Lexer constructor is now an ILexerConfig Object.
a boolean 2nd argument is no longer supported`);
    this.config = ht({}, Se, n);
    const r = this.config.traceInitPerf;
    r === !0 ? (this.traceInitMaxIdent = 1 / 0, this.traceInitPerf = !0) : typeof r == "number" && (this.traceInitMaxIdent = r, this.traceInitPerf = !0), this.traceInitIndent = -1, this.TRACE_INIT("Lexer Constructor", () => {
      let i, o = !0;
      this.TRACE_INIT("Lexer Config handling", () => {
        if (this.config.lineTerminatorsPattern === Se.lineTerminatorsPattern) this.config.lineTerminatorsPattern = Mc;
        else if (this.config.lineTerminatorCharacters === Se.lineTerminatorCharacters) throw Error(`Error: Missing <lineTerminatorCharacters> property on the Lexer config.
	For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS`);
        if (n.safeMode && n.ensureOptimizations) throw Error('"safeMode" and "ensureOptimizations" flags are mutually exclusive.');
        this.trackStartLines = /full|onlyStart/i.test(this.config.positionTracking), this.trackEndLines = /full/i.test(this.config.positionTracking), D(e) ? i = { modes: { defaultMode: tt(e) }, defaultMode: Ne } : (o = !1, i = tt(e));
      }), this.config.skipValidations === !1 && (this.TRACE_INIT("performRuntimeChecks", () => {
        this.lexerDefinitionErrors = this.lexerDefinitionErrors.concat(function(a) {
          const c = [];
          return L(a, Ne) || c.push({ message: "A MultiMode Lexer cannot be initialized without a <" + Ne + `> property in its definition
`, type: V.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE }), L(a, zn) || c.push({ message: `A MultiMode Lexer cannot be initialized without a <modes> property in its definition
`, type: V.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY }), L(a, zn) && L(a, Ne) && !L(a.modes, a.defaultMode) && c.push({ message: `A MultiMode Lexer cannot be initialized with a ${Ne}: <${a.defaultMode}>which does not exist
`, type: V.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST }), L(a, zn) && k(a.modes, (u, l) => {
            k(u, (h, f) => {
              zt(h) ? c.push({ message: `A Lexer cannot be initialized using an undefined Token Type. Mode:<${l}> at index: <${f}>
`, type: V.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED }) : L(h, "LONGER_ALT") && k(D(h.LONGER_ALT) ? h.LONGER_ALT : [h.LONGER_ALT], (d) => {
                zt(d) || it(u, d) || c.push({ message: `A MultiMode Lexer cannot be initialized with a longer_alt <${d.name}> on token <${h.name}> outside of mode <${l}>
`, type: V.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE });
              });
            });
          }), c;
        }(i, this.trackStartLines, this.config.lineTerminatorCharacters));
      }), this.TRACE_INIT("performWarningRuntimeChecks", () => {
        this.lexerDefinitionWarning = this.lexerDefinitionWarning.concat(Pc(i, this.trackStartLines, this.config.lineTerminatorCharacters));
      })), i.modes = i.modes ? i.modes : {}, k(i.modes, (a, c) => {
        i.modes[c] = xn(a, (u) => zt(u));
      });
      const s = At(i.modes);
      if (k(i.modes, (a, c) => {
        this.TRACE_INIT(`Mode: <${c}> processing`, () => {
          if (this.modes.push(c), this.config.skipValidations === !1 && this.TRACE_INIT("validatePatterns", () => {
            this.lexerDefinitionErrors = this.lexerDefinitionErrors.concat(Cc(a, s));
          }), G(this.lexerDefinitionErrors)) {
            let u;
            ze(a), this.TRACE_INIT("analyzeTokenTypes", () => {
              u = xc(a, { lineTerminatorCharacters: this.config.lineTerminatorCharacters, positionTracking: n.positionTracking, ensureOptimizations: n.ensureOptimizations, safeMode: n.safeMode, tracer: this.TRACE_INIT });
            }), this.patternIdxToConfig[c] = u.patternIdxToConfig, this.charCodeToPatternIdxToConfig[c] = u.charCodeToPatternIdxToConfig, this.emptyGroups = ht({}, this.emptyGroups, u.emptyGroups), this.hasCustom = u.hasCustom || this.hasCustom, this.canModeBeOptimized[c] = u.canBeOptimized;
          }
        });
      }), this.defaultMode = i.defaultMode, !G(this.lexerDefinitionErrors) && !this.config.deferDefinitionErrorsHandling) {
        const a = _(this.lexerDefinitionErrors, (c) => c.message).join(`-----------------------
`);
        throw new Error(`Errors detected in definition of Lexer:
` + a);
      }
      k(this.lexerDefinitionWarning, (a) => {
        is(a.message);
      }), this.TRACE_INIT("Choosing sub-methods implementations", () => {
        if (us ? (this.chopInput = de, this.match = this.matchWithTest) : (this.updateLastIndex = q, this.match = this.matchWithExec), o && (this.handleModes = q), this.trackStartLines === !1 && (this.computeNewColumn = de), this.trackEndLines === !1 && (this.updateTokenEndLineColumnLocation = q), /full/i.test(this.config.positionTracking)) this.createTokenInstance = this.createFullToken;
        else if (/onlyStart/i.test(this.config.positionTracking)) this.createTokenInstance = this.createStartOnlyToken;
        else {
          if (!/onlyOffset/i.test(this.config.positionTracking)) throw Error(`Invalid <positionTracking> config option: "${this.config.positionTracking}"`);
          this.createTokenInstance = this.createOffsetOnlyToken;
        }
        this.hasCustom ? (this.addToken = this.addTokenUsingPush, this.handlePayload = this.handlePayloadWithCustom) : (this.addToken = this.addTokenUsingMemberAccess, this.handlePayload = this.handlePayloadNoCustom);
      }), this.TRACE_INIT("Failed Optimization Warnings", () => {
        const a = ft(this.canModeBeOptimized, (c, u, l) => (u === !1 && c.push(l), c), []);
        if (n.ensureOptimizations && !G(a)) throw Error(`Lexer Modes: < ${a.join(", ")} > cannot be optimized.
	 Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode.
	 Or inspect the console log for details on how to resolve these issues.`);
      }), this.TRACE_INIT("clearRegExpParserCache", () => {
        on = {};
      }), this.TRACE_INIT("toFastProperties", () => {
        ss(this);
      });
    });
  }
  tokenize(e, n = this.defaultMode) {
    if (!G(this.lexerDefinitionErrors)) {
      const r = _(this.lexerDefinitionErrors, (i) => i.message).join(`-----------------------
`);
      throw new Error(`Unable to Tokenize because Errors detected in definition of Lexer:
` + r);
    }
    return this.tokenizeInternal(e, n);
  }
  tokenizeInternal(e, n) {
    let r, i, o, s, a, c, u, l, h, f, d, E, I, S, T;
    const m = e, p = m.length;
    let A = 0, O = 0;
    const g = this.hasCustom ? 0 : Math.floor(e.length / 10), R = new Array(g), N = [];
    let v = this.trackStartLines ? 1 : void 0, y = this.trackStartLines ? 1 : void 0;
    const M = function(X) {
      const nt = {};
      return k(At(X), (Ut) => {
        const ot = X[Ut];
        if (!D(ot)) throw Error("non exhaustive match");
        nt[Ut] = [];
      }), nt;
    }(this.emptyGroups), w = this.trackStartLines, F = this.config.lineTerminatorsPattern;
    let $ = 0, x = [], C = [];
    const j = [], Y = [];
    let B;
    function et() {
      return x;
    }
    function Zt(X) {
      const nt = Ht(X), Ut = C[nt];
      return Ut === void 0 ? Y : Ut;
    }
    Object.freeze(Y);
    const Te = (X) => {
      if (j.length === 1 && X.tokenType.PUSH_MODE === void 0) {
        const nt = this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(X);
        N.push({ offset: X.startOffset, line: X.startLine, column: X.startColumn, length: X.image.length, message: nt });
      } else {
        j.pop();
        const nt = pe(j);
        x = this.patternIdxToConfig[nt], C = this.charCodeToPatternIdxToConfig[nt], $ = x.length;
        const Ut = this.canModeBeOptimized[nt] && this.config.safeMode === !1;
        B = C && Ut ? Zt : et;
      }
    };
    function Hr(X) {
      j.push(X), C = this.charCodeToPatternIdxToConfig[X], x = this.patternIdxToConfig[X], $ = x.length, $ = x.length;
      const nt = this.canModeBeOptimized[X] && this.config.safeMode === !1;
      B = C && nt ? Zt : et;
    }
    let It;
    Hr.call(this, n);
    const Yr = this.config.recoveryEnabled;
    for (; A < p; ) {
      c = null;
      const X = m.charCodeAt(A), nt = B(X), Ut = nt.length;
      for (r = 0; r < Ut; r++) {
        It = nt[r];
        const ot = It.pattern;
        u = null;
        const Ft = It.short;
        if (Ft !== !1 ? X === Ft && (c = ot) : It.isCustom === !0 ? (T = ot.exec(m, A, R, M), T !== null ? (c = T[0], T.payload !== void 0 && (u = T.payload)) : c = null) : (this.updateLastIndex(ot, A), c = this.match(ot, e, A)), c !== null) {
          if (a = It.longerAlt, a !== void 0) {
            const Dt = a.length;
            for (o = 0; o < Dt; o++) {
              const jt = x[a[o]], Qt = jt.pattern;
              if (l = null, jt.isCustom === !0 ? (T = Qt.exec(m, A, R, M), T !== null ? (s = T[0], T.payload !== void 0 && (l = T.payload)) : s = null) : (this.updateLastIndex(Qt, A), s = this.match(Qt, e, A)), s && s.length > c.length) {
                c = s, u = l, It = jt;
                break;
              }
            }
          }
          break;
        }
      }
      if (c !== null) {
        if (h = c.length, f = It.group, f !== void 0 && (d = It.tokenTypeIdx, E = this.createTokenInstance(c, A, d, It.tokenType, v, y, h), this.handlePayload(E, u), f === !1 ? O = this.addToken(R, O, E) : M[f].push(E)), e = this.chopInput(e, h), A += h, y = this.computeNewColumn(y, h), w === !0 && It.canLineTerminator === !0) {
          let ot, Ft, Dt = 0;
          F.lastIndex = 0;
          do
            ot = F.test(c), ot === !0 && (Ft = F.lastIndex - 1, Dt++);
          while (ot === !0);
          Dt !== 0 && (v += Dt, y = h - Ft, this.updateTokenEndLineColumnLocation(E, f, Ft, Dt, v, y, h));
        }
        this.handleModes(It, Te, Hr, E);
      } else {
        const ot = A, Ft = v, Dt = y;
        let jt = Yr === !1;
        for (; jt === !1 && A < p; ) for (e = this.chopInput(e, 1), A++, i = 0; i < $; i++) {
          const Qt = x[i], Mn = Qt.pattern, Xr = Qt.short;
          if (Xr !== !1 ? m.charCodeAt(A) === Xr && (jt = !0) : Qt.isCustom === !0 ? jt = Mn.exec(m, A, R, M) !== null : (this.updateLastIndex(Mn, A), jt = Mn.exec(e) !== null), jt === !0) break;
        }
        if (I = A - ot, y = this.computeNewColumn(y, I), S = this.config.errorMessageProvider.buildUnexpectedCharactersMessage(m, ot, I, Ft, Dt), N.push({ offset: ot, line: Ft, column: Dt, length: I, message: S }), Yr === !1) break;
      }
    }
    return this.hasCustom || (R.length = O), { tokens: R, groups: M, errors: N };
  }
  handleModes(e, n, r, i) {
    if (e.pop === !0) {
      const o = e.push;
      n(i), o !== void 0 && r.call(this, o);
    } else e.push !== void 0 && r.call(this, e.push);
  }
  chopInput(e, n) {
    return e.substring(n);
  }
  updateLastIndex(e, n) {
    e.lastIndex = n;
  }
  updateTokenEndLineColumnLocation(e, n, r, i, o, s, a) {
    let c, u;
    n !== void 0 && (c = r === a - 1, u = c ? -1 : 0, i === 1 && c === !0 || (e.endLine = o + u, e.endColumn = s - 1 - u));
  }
  computeNewColumn(e, n) {
    return e + n;
  }
  createOffsetOnlyToken(e, n, r, i) {
    return { image: e, startOffset: n, tokenTypeIdx: r, tokenType: i };
  }
  createStartOnlyToken(e, n, r, i, o, s) {
    return { image: e, startOffset: n, startLine: o, startColumn: s, tokenTypeIdx: r, tokenType: i };
  }
  createFullToken(e, n, r, i, o, s, a) {
    return { image: e, startOffset: n, endOffset: n + a - 1, startLine: o, endLine: o, startColumn: s, endColumn: s + a - 1, tokenTypeIdx: r, tokenType: i };
  }
  addTokenUsingPush(e, n, r) {
    return e.push(r), n;
  }
  addTokenUsingMemberAccess(e, n, r) {
    return e[n] = r, ++n;
  }
  handlePayloadNoCustom(e, n) {
  }
  handlePayloadWithCustom(e, n) {
    n !== null && (e.payload = n);
  }
  matchWithTest(e, n, r) {
    return e.test(n) === !0 ? n.substring(r, e.lastIndex) : null;
  }
  matchWithExec(e, n) {
    const r = e.exec(n);
    return r !== null ? r[0] : null;
  }
}
function ke(t) {
  return ms(t) ? t.LABEL : t.name;
}
function ms(t) {
  return at(t.LABEL) && t.LABEL !== "";
}
st.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.", st.NA = /NOT_APPLICABLE/;
const Dc = "parent", Gi = "categories", zi = "label", Ki = "group", Vi = "push_mode", Hi = "pop_mode", Yi = "longer_alt", Xi = "line_breaks", qi = "start_chars_hint";
function P(t) {
  return function(e) {
    const n = e.pattern, r = {};
    if (r.name = e.name, zt(n) || (r.PATTERN = n), L(e, Dc)) throw `The parent property is no longer supported.
See: https://github.com/chevrotain/chevrotain/issues/564#issuecomment-349062346 for details.`;
    return L(e, Gi) && (r.CATEGORIES = e[Gi]), ze([r]), L(e, zi) && (r.LABEL = e[zi]), L(e, Ki) && (r.GROUP = e[Ki]), L(e, Hi) && (r.POP_MODE = e[Hi]), L(e, Vi) && (r.PUSH_MODE = e[Vi]), L(e, Yi) && (r.LONGER_ALT = e[Yi]), L(e, Xi) && (r.LINE_BREAKS = e[Xi]), L(e, qi) && (r.START_CHARS_HINT = e[qi]), r;
  }(t);
}
const ee = P({ name: "EOF", pattern: st.NA });
function Gr(t, e, n, r, i, o, s, a) {
  return { image: e, startOffset: n, endOffset: r, startLine: i, endLine: o, startColumn: s, endColumn: a, tokenTypeIdx: t.tokenTypeIdx, tokenType: t };
}
ze([ee]);
const Es = { buildMismatchTokenMessage: ({ expected: t, actual: e, previous: n, ruleName: r }) => `Expecting ${ms(t) ? `--> ${ke(t)} <--` : `token of type --> ${t.name} <--`} but found --> '${e.image}' <--`, buildNotAllInputParsedMessage: ({ firstRedundant: t, ruleName: e }) => "Redundant input, expecting EOF but found: " + t.image, buildNoViableAltMessage({ expectedPathsPerAlt: t, actual: e, previous: n, customUserDescription: r, ruleName: i }) {
  const o = "Expecting: ", s = `
but found: '` + Rt(e).image + "'";
  if (r) return o + r + s;
  {
    const a = _(ft(t, (c, u) => c.concat(u), []), (c) => `[${_(c, (u) => ke(u)).join(", ")}]`);
    return o + `one of these possible Token sequences:
${_(a, (c, u) => `  ${u + 1}. ${c}`).join(`
`)}` + s;
  }
}, buildEarlyExitMessage({ expectedIterationPaths: t, actual: e, customUserDescription: n, ruleName: r }) {
  const i = "Expecting: ", o = `
but found: '` + Rt(e).image + "'";
  return n ? i + n + o : i + `expecting at least one iteration which starts with one of these possible Token sequences::
  <${_(t, (s) => `[${_(s, (a) => ke(a)).join(",")}]`).join(" ,")}>` + o;
} };
Object.freeze(Es);
const jc = { buildRuleNotFoundError: (t, e) => "Invalid grammar, reference to a rule which is not defined: ->" + e.nonTerminalName + `<-
inside top level rule: ->` + t.name + "<-" }, ne = { buildDuplicateFoundError(t, e) {
  const n = t.name, r = Rt(e), i = r.idx, o = Lt(r), s = (a = r) instanceof K ? a.terminalType.name : a instanceof dt ? a.nonTerminalName : "";
  var a;
  let c = `->${o}${i > 0 ? i : ""}<- ${s ? `with argument: ->${s}<-` : ""}
                  appears more than once (${e.length} times) in the top level rule: ->${n}<-.                  
                  For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES 
                  `;
  return c = c.replace(/[ \t]+/g, " "), c = c.replace(/\s\s+/g, `
`), c;
}, buildNamespaceConflictError: (t) => `Namespace conflict found in grammar.
The grammar has both a Terminal(Token) and a Non-Terminal(Rule) named: <${t.name}>.
To resolve this make sure each Terminal and Non-Terminal names are unique
This is easy to accomplish by using the convention that Terminal names start with an uppercase letter
and Non-Terminal names start with a lower case letter.`, buildAlternationPrefixAmbiguityError(t) {
  const e = _(t.prefixPath, (r) => ke(r)).join(", "), n = t.alternation.idx === 0 ? "" : t.alternation.idx;
  return `Ambiguous alternatives: <${t.ambiguityIndices.join(" ,")}> due to common lookahead prefix
in <OR${n}> inside <${t.topLevelRule.name}> Rule,
<${e}> may appears as a prefix path in all these alternatives.
See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#COMMON_PREFIX
For Further details.`;
}, buildAlternationAmbiguityError(t) {
  const e = _(t.prefixPath, (i) => ke(i)).join(", "), n = t.alternation.idx === 0 ? "" : t.alternation.idx;
  let r = `Ambiguous Alternatives Detected: <${t.ambiguityIndices.join(" ,")}> in <OR${n}> inside <${t.topLevelRule.name}> Rule,
<${e}> may appears as a prefix path in all these alternatives.
`;
  return r += `See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES
For Further details.`, r;
}, buildEmptyRepetitionError(t) {
  let e = Lt(t.repetition);
  return t.repetition.idx !== 0 && (e += t.repetition.idx), `The repetition <${e}> within Rule <${t.topLevelRule.name}> can never consume any tokens.
This could lead to an infinite loop.`;
}, buildTokenNameError: (t) => "deprecated", buildEmptyAlternationError: (t) => `Ambiguous empty alternative: <${t.emptyChoiceIdx + 1}> in <OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
Only the last alternative may be an empty alternative.`, buildTooManyAlternativesError: (t) => `An Alternation cannot have more than 256 alternatives:
<OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
 has ${t.alternation.definition.length + 1} alternatives.`, buildLeftRecursionError(t) {
  const e = t.topLevelRule.name;
  return `Left Recursion found in grammar.
rule: <${e}> can be invoked from itself (directly or indirectly)
without consuming any Tokens. The grammar path that causes this is: 
 ${`${e} --> ${_(t.leftRecursionPath, (n) => n.name).concat([e]).join(" --> ")}`}
 To fix this refactor your grammar to remove the left recursion.
see: https://en.wikipedia.org/wiki/LL_parser#Left_factoring.`;
}, buildInvalidRuleNameError: (t) => "deprecated", buildDuplicateRuleNameError(t) {
  let e;
  return e = t.topLevelRule instanceof Ee ? t.topLevelRule.name : t.topLevelRule, `Duplicate definition, rule: ->${e}<- is already defined in the grammar: ->${t.grammarName}<-`;
} };
class Bc extends ge {
  constructor(e, n) {
    super(), this.nameToTopRule = e, this.errMsgProvider = n, this.errors = [];
  }
  resolveRefs() {
    k(Z(this.nameToTopRule), (e) => {
      this.currTopLevel = e, e.accept(this);
    });
  }
  visitNonTerminal(e) {
    const n = this.nameToTopRule[e.nonTerminalName];
    if (n) e.referencedRule = n;
    else {
      const r = this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel, e);
      this.errors.push({ message: r, type: rt.UNRESOLVED_SUBRULE_REF, ruleName: this.currTopLevel.name, unresolvedRefName: e.nonTerminalName });
    }
  }
}
class $c extends Cn {
  constructor(e, n) {
    super(), this.topProd = e, this.path = n, this.possibleTokTypes = [], this.nextProductionName = "", this.nextProductionOccurrence = 0, this.found = !1, this.isAtEndOfPath = !1;
  }
  startWalking() {
    if (this.found = !1, this.path.ruleStack[0] !== this.topProd.name) throw Error("The path does not start with the walker's top Rule!");
    return this.ruleStack = tt(this.path.ruleStack).reverse(), this.occurrenceStack = tt(this.path.occurrenceStack).reverse(), this.ruleStack.pop(), this.occurrenceStack.pop(), this.updateExpectedNext(), this.walk(this.topProd), this.possibleTokTypes;
  }
  walk(e, n = []) {
    this.found || super.walk(e, n);
  }
  walkProdRef(e, n, r) {
    if (e.referencedRule.name === this.nextProductionName && e.idx === this.nextProductionOccurrence) {
      const i = n.concat(r);
      this.updateExpectedNext(), this.walk(e.referencedRule, i);
    }
  }
  updateExpectedNext() {
    G(this.ruleStack) ? (this.nextProductionName = "", this.nextProductionOccurrence = 0, this.isAtEndOfPath = !0) : (this.nextProductionName = this.ruleStack.pop(), this.nextProductionOccurrence = this.occurrenceStack.pop());
  }
}
class Wc extends $c {
  constructor(e, n) {
    super(e, n), this.path = n, this.nextTerminalName = "", this.nextTerminalOccurrence = 0, this.nextTerminalName = this.path.lastTok.name, this.nextTerminalOccurrence = this.path.lastTokOccurrence;
  }
  walkTerminal(e, n, r) {
    if (this.isAtEndOfPath && e.terminalType.name === this.nextTerminalName && e.idx === this.nextTerminalOccurrence && !this.found) {
      const i = n.concat(r), o = new ut({ definition: i });
      this.possibleTokTypes = xe(o), this.found = !0;
    }
  }
}
class kn extends Cn {
  constructor(e, n) {
    super(), this.topRule = e, this.occurrence = n, this.result = { token: void 0, occurrence: void 0, isEndOfRule: void 0 };
  }
  startWalking() {
    return this.walk(this.topRule), this.result;
  }
}
class Gc extends kn {
  walkMany(e, n, r) {
    if (e.idx === this.occurrence) {
      const i = Rt(n.concat(r));
      this.result.isEndOfRule = i === void 0, i instanceof K && (this.result.token = i.terminalType, this.result.occurrence = i.idx);
    } else super.walkMany(e, n, r);
  }
}
class Zi extends kn {
  walkManySep(e, n, r) {
    if (e.idx === this.occurrence) {
      const i = Rt(n.concat(r));
      this.result.isEndOfRule = i === void 0, i instanceof K && (this.result.token = i.terminalType, this.result.occurrence = i.idx);
    } else super.walkManySep(e, n, r);
  }
}
class zc extends kn {
  walkAtLeastOne(e, n, r) {
    if (e.idx === this.occurrence) {
      const i = Rt(n.concat(r));
      this.result.isEndOfRule = i === void 0, i instanceof K && (this.result.token = i.terminalType, this.result.occurrence = i.idx);
    } else super.walkAtLeastOne(e, n, r);
  }
}
class Qi extends kn {
  walkAtLeastOneSep(e, n, r) {
    if (e.idx === this.occurrence) {
      const i = Rt(n.concat(r));
      this.result.isEndOfRule = i === void 0, i instanceof K && (this.result.token = i.terminalType, this.result.occurrence = i.idx);
    } else super.walkAtLeastOneSep(e, n, r);
  }
}
function Ir(t, e, n = []) {
  n = tt(n);
  let r = [], i = 0;
  function o(s) {
    const a = Ir(s.concat(J(t, i + 1)), e, n);
    return r.concat(a);
  }
  for (; n.length < e && i < t.length; ) {
    const s = t[i];
    if (s instanceof ut || s instanceof dt) return o(s.definition);
    if (s instanceof ct) r = o(s.definition);
    else {
      if (s instanceof wt)
        return o(s.definition.concat([new Q({ definition: s.definition })]));
      if (s instanceof Mt)
        return o([new ut({ definition: s.definition }), new Q({ definition: [new K({ terminalType: s.separator })].concat(s.definition) })]);
      if (s instanceof St) {
        const a = s.definition.concat([new Q({ definition: [new K({ terminalType: s.separator })].concat(s.definition) })]);
        r = o(a);
      } else if (s instanceof Q) {
        const a = s.definition.concat([new Q({ definition: s.definition })]);
        r = o(a);
      } else {
        if (s instanceof _t) return k(s.definition, (a) => {
          G(a.definition) === !1 && (r = o(a.definition));
        }), r;
        if (!(s instanceof K)) throw Error("non exhaustive match");
        n.push(s.terminalType);
      }
    }
    i++;
  }
  return r.push({ partialPath: n, suffixDef: J(t, i) }), r;
}
function gs(t, e, n, r) {
  const i = "EXIT_NONE_TERMINAL", o = [i], s = "EXIT_ALTERNATIVE";
  let a = !1;
  const c = e.length, u = c - r - 1, l = [], h = [];
  for (h.push({ idx: -1, def: t, ruleStack: [], occurrenceStack: [] }); !G(h); ) {
    const f = h.pop();
    if (f === s) {
      a && pe(h).idx <= u && h.pop();
      continue;
    }
    const d = f.def, E = f.idx, I = f.ruleStack, S = f.occurrenceStack;
    if (G(d)) continue;
    const T = d[0];
    if (T === i) {
      const m = { idx: E, def: J(d), ruleStack: Fe(I), occurrenceStack: Fe(S) };
      h.push(m);
    } else if (T instanceof K) if (E < c - 1) {
      const m = E + 1;
      if (n(e[m], T.terminalType)) {
        const p = { idx: m, def: J(d), ruleStack: I, occurrenceStack: S };
        h.push(p);
      }
    } else {
      if (E !== c - 1) throw Error("non exhaustive match");
      l.push({ nextTokenType: T.terminalType, nextTokenOccurrence: T.idx, ruleStack: I, occurrenceStack: S }), a = !0;
    }
    else if (T instanceof dt) {
      const m = tt(I);
      m.push(T.nonTerminalName);
      const p = tt(S);
      p.push(T.idx);
      const A = { idx: E, def: T.definition.concat(o, J(d)), ruleStack: m, occurrenceStack: p };
      h.push(A);
    } else if (T instanceof ct) {
      const m = { idx: E, def: J(d), ruleStack: I, occurrenceStack: S };
      h.push(m), h.push(s);
      const p = { idx: E, def: T.definition.concat(J(d)), ruleStack: I, occurrenceStack: S };
      h.push(p);
    } else if (T instanceof wt) {
      const m = new Q({ definition: T.definition, idx: T.idx }), p = { idx: E, def: T.definition.concat([m], J(d)), ruleStack: I, occurrenceStack: S };
      h.push(p);
    } else if (T instanceof Mt) {
      const m = new K({ terminalType: T.separator }), p = new Q({ definition: [m].concat(T.definition), idx: T.idx }), A = { idx: E, def: T.definition.concat([p], J(d)), ruleStack: I, occurrenceStack: S };
      h.push(A);
    } else if (T instanceof St) {
      const m = { idx: E, def: J(d), ruleStack: I, occurrenceStack: S };
      h.push(m), h.push(s);
      const p = new K({ terminalType: T.separator }), A = new Q({ definition: [p].concat(T.definition), idx: T.idx }), O = { idx: E, def: T.definition.concat([A], J(d)), ruleStack: I, occurrenceStack: S };
      h.push(O);
    } else if (T instanceof Q) {
      const m = { idx: E, def: J(d), ruleStack: I, occurrenceStack: S };
      h.push(m), h.push(s);
      const p = new Q({ definition: T.definition, idx: T.idx }), A = { idx: E, def: T.definition.concat([p], J(d)), ruleStack: I, occurrenceStack: S };
      h.push(A);
    } else if (T instanceof _t) for (let m = T.definition.length - 1; m >= 0; m--) {
      const p = { idx: E, def: T.definition[m].definition.concat(J(d)), ruleStack: I, occurrenceStack: S };
      h.push(p), h.push(s);
    }
    else if (T instanceof ut) h.push({ idx: E, def: T.definition.concat(J(d)), ruleStack: I, occurrenceStack: S });
    else {
      if (!(T instanceof Ee)) throw Error("non exhaustive match");
      h.push(Kc(T, E, I, S));
    }
  }
  return l;
}
function Kc(t, e, n, r) {
  const i = tt(n);
  i.push(t.name);
  const o = tt(r);
  return o.push(1), { idx: e, def: t.definition, ruleStack: i, occurrenceStack: o };
}
var H;
function Ji(t) {
  if (t instanceof ct || t === "Option") return H.OPTION;
  if (t instanceof Q || t === "Repetition") return H.REPETITION;
  if (t instanceof wt || t === "RepetitionMandatory") return H.REPETITION_MANDATORY;
  if (t instanceof Mt || t === "RepetitionMandatoryWithSeparator") return H.REPETITION_MANDATORY_WITH_SEPARATOR;
  if (t instanceof St || t === "RepetitionWithSeparator") return H.REPETITION_WITH_SEPARATOR;
  if (t instanceof _t || t === "Alternation") return H.ALTERNATION;
  throw Error("non exhaustive match");
}
function Vc(t, e, n, r) {
  const i = t.length, o = Nt(t, (s) => Nt(s, (a) => a.length === 1));
  if (e) return function(s) {
    const a = _(s, (c) => c.GATE);
    for (let c = 0; c < i; c++) {
      const u = t[c], l = u.length, h = a[c];
      if (h === void 0 || h.call(this) !== !1) t: for (let f = 0; f < l; f++) {
        const d = u[f], E = d.length;
        for (let I = 0; I < E; I++) {
          const S = this.LA(I + 1);
          if (n(S, d[I]) === !1) continue t;
        }
        return c;
      }
    }
  };
  if (o && !r) {
    const s = ft(_(t, (a) => vt(a)), (a, c, u) => (k(c, (l) => {
      L(a, l.tokenTypeIdx) || (a[l.tokenTypeIdx] = u), k(l.categoryMatches, (h) => {
        L(a, h) || (a[h] = u);
      });
    }), a), {});
    return function() {
      const a = this.LA(1);
      return s[a.tokenTypeIdx];
    };
  }
  return function() {
    for (let s = 0; s < i; s++) {
      const a = t[s], c = a.length;
      t: for (let u = 0; u < c; u++) {
        const l = a[u], h = l.length;
        for (let f = 0; f < h; f++) {
          const d = this.LA(f + 1);
          if (n(d, l[f]) === !1) continue t;
        }
        return s;
      }
    }
  };
}
function Hc(t, e, n) {
  const r = Nt(t, (o) => o.length === 1), i = t.length;
  if (r && !n) {
    const o = vt(t);
    if (o.length === 1 && G(o[0].categoryMatches)) {
      const s = o[0].tokenTypeIdx;
      return function() {
        return this.LA(1).tokenTypeIdx === s;
      };
    }
    {
      const s = ft(o, (a, c, u) => (a[c.tokenTypeIdx] = !0, k(c.categoryMatches, (l) => {
        a[l] = !0;
      }), a), []);
      return function() {
        const a = this.LA(1);
        return s[a.tokenTypeIdx] === !0;
      };
    }
  }
  return function() {
    t: for (let o = 0; o < i; o++) {
      const s = t[o], a = s.length;
      for (let c = 0; c < a; c++) {
        const u = this.LA(c + 1);
        if (e(u, s[c]) === !1) continue t;
      }
      return !0;
    }
    return !1;
  };
}
(function(t) {
  t[t.OPTION = 0] = "OPTION", t[t.REPETITION = 1] = "REPETITION", t[t.REPETITION_MANDATORY = 2] = "REPETITION_MANDATORY", t[t.REPETITION_MANDATORY_WITH_SEPARATOR = 3] = "REPETITION_MANDATORY_WITH_SEPARATOR", t[t.REPETITION_WITH_SEPARATOR = 4] = "REPETITION_WITH_SEPARATOR", t[t.ALTERNATION = 5] = "ALTERNATION";
})(H || (H = {}));
class Yc extends Cn {
  constructor(e, n, r) {
    super(), this.topProd = e, this.targetOccurrence = n, this.targetProdType = r;
  }
  startWalking() {
    return this.walk(this.topProd), this.restDef;
  }
  checkIsTarget(e, n, r, i) {
    return e.idx === this.targetOccurrence && this.targetProdType === n && (this.restDef = r.concat(i), !0);
  }
  walkOption(e, n, r) {
    this.checkIsTarget(e, H.OPTION, n, r) || super.walkOption(e, n, r);
  }
  walkAtLeastOne(e, n, r) {
    this.checkIsTarget(e, H.REPETITION_MANDATORY, n, r) || super.walkOption(e, n, r);
  }
  walkAtLeastOneSep(e, n, r) {
    this.checkIsTarget(e, H.REPETITION_MANDATORY_WITH_SEPARATOR, n, r) || super.walkOption(e, n, r);
  }
  walkMany(e, n, r) {
    this.checkIsTarget(e, H.REPETITION, n, r) || super.walkOption(e, n, r);
  }
  walkManySep(e, n, r) {
    this.checkIsTarget(e, H.REPETITION_WITH_SEPARATOR, n, r) || super.walkOption(e, n, r);
  }
}
class Ts extends ge {
  constructor(e, n, r) {
    super(), this.targetOccurrence = e, this.targetProdType = n, this.targetRef = r, this.result = [];
  }
  checkIsTarget(e, n) {
    e.idx !== this.targetOccurrence || this.targetProdType !== n || this.targetRef !== void 0 && e !== this.targetRef || (this.result = e.definition);
  }
  visitOption(e) {
    this.checkIsTarget(e, H.OPTION);
  }
  visitRepetition(e) {
    this.checkIsTarget(e, H.REPETITION);
  }
  visitRepetitionMandatory(e) {
    this.checkIsTarget(e, H.REPETITION_MANDATORY);
  }
  visitRepetitionMandatoryWithSeparator(e) {
    this.checkIsTarget(e, H.REPETITION_MANDATORY_WITH_SEPARATOR);
  }
  visitRepetitionWithSeparator(e) {
    this.checkIsTarget(e, H.REPETITION_WITH_SEPARATOR);
  }
  visitAlternation(e) {
    this.checkIsTarget(e, H.ALTERNATION);
  }
}
function to(t) {
  const e = new Array(t);
  for (let n = 0; n < t; n++) e[n] = [];
  return e;
}
function Vn(t) {
  let e = [""];
  for (let n = 0; n < t.length; n++) {
    const r = t[n], i = [];
    for (let o = 0; o < e.length; o++) {
      const s = e[o];
      i.push(s + "_" + r.tokenTypeIdx);
      for (let a = 0; a < r.categoryMatches.length; a++) {
        const c = "_" + r.categoryMatches[a];
        i.push(s + c);
      }
    }
    e = i;
  }
  return e;
}
function Xc(t, e, n) {
  for (let r = 0; r < t.length; r++) {
    if (r === n) continue;
    const i = t[r];
    for (let o = 0; o < e.length; o++)
      if (i[e[o]] === !0) return !1;
  }
  return !0;
}
function As(t, e) {
  const n = _(t, (s) => Ir([s], 1)), r = to(n.length), i = _(n, (s) => {
    const a = {};
    return k(s, (c) => {
      k(Vn(c.partialPath), (u) => {
        a[u] = !0;
      });
    }), a;
  });
  let o = n;
  for (let s = 1; s <= e; s++) {
    const a = o;
    o = to(a.length);
    for (let c = 0; c < a.length; c++) {
      const u = a[c];
      for (let l = 0; l < u.length; l++) {
        const h = u[l].partialPath, f = u[l].suffixDef, d = Vn(h);
        if (Xc(i, d, c) || G(f) || h.length === e) {
          const E = r[c];
          if (Nr(E, h) === !1) {
            E.push(h);
            for (let I = 0; I < d.length; I++) {
              const S = d[I];
              i[c][S] = !0;
            }
          }
        } else {
          const E = Ir(f, s + 1, h);
          o[c] = o[c].concat(E), k(E, (I) => {
            k(Vn(I.partialPath), (S) => {
              i[c][S] = !0;
            });
          });
        }
      }
    }
  }
  return r;
}
function zr(t, e, n, r) {
  const i = new Ts(t, H.ALTERNATION, r);
  return e.accept(i), As(i.result, n);
}
function vr(t, e, n, r) {
  const i = new Ts(t, n);
  e.accept(i);
  const o = i.result, s = new Yc(e, t, n).startWalking();
  return As([new ut({ definition: o }), new ut({ definition: s })], r);
}
function Nr(t, e) {
  t: for (let n = 0; n < t.length; n++) {
    const r = t[n];
    if (r.length === e.length) {
      for (let i = 0; i < r.length; i++) {
        const o = e[i], s = r[i];
        if (!(o === s || s.categoryMatchesMap[o.tokenTypeIdx] !== void 0)) continue t;
      }
      return !0;
    }
  }
  return !1;
}
function eo(t) {
  return Nt(t, (e) => Nt(e, (n) => Nt(n, (r) => G(r.categoryMatches))));
}
function qc(t, e, n, r) {
  const i = Et(t, (c) => function(u, l) {
    const h = new Qc();
    u.accept(h);
    const f = h.allProductions, d = dc(f, Zc);
    return _(Z(Ot(d, (I) => I.length > 1)), (I) => {
      const S = Rt(I), T = l.buildDuplicateFoundError(u, I), m = Lt(S), p = { message: T, type: rt.DUPLICATE_PRODUCTIONS, ruleName: u.name, dslName: m, occurrence: S.idx }, A = Is(S);
      return A && (p.parameter = A), p;
    });
  }(c, n)), o = function(c, u, l) {
    const h = [], f = _(u, (d) => d.name);
    return k(c, (d) => {
      const E = d.name;
      if (it(f, E)) {
        const I = l.buildNamespaceConflictError(d);
        h.push({ message: I, type: rt.CONFLICT_TOKENS_RULES_NAMESPACE, ruleName: E });
      }
    }), h;
  }(t, e, n), s = Et(t, (c) => function(u, l) {
    const h = new Kr();
    return u.accept(h), Et(h.alternations, (d) => d.definition.length > 255 ? [{ message: l.buildTooManyAlternativesError({ topLevelRule: u, alternation: d }), type: rt.TOO_MANY_ALTS, ruleName: u.name, occurrence: d.idx }] : []);
  }(c, n)), a = Et(t, (c) => function(u, l, h, f) {
    const d = [];
    if (ft(l, (I, S) => S.name === u.name ? I + 1 : I, 0) > 1) {
      const I = f.buildDuplicateRuleNameError({ topLevelRule: u, grammarName: h });
      d.push({ message: I, type: rt.DUPLICATE_RULE_NAME, ruleName: u.name });
    }
    return d;
  }(c, t, r, n));
  return i.concat(o, s, a);
}
function Zc(t) {
  return `${Lt(t)}_#_${t.idx}_#_${Is(t)}`;
}
function Is(t) {
  return t instanceof K ? t.terminalType.name : t instanceof dt ? t.nonTerminalName : "";
}
class Qc extends ge {
  constructor() {
    super(...arguments), this.allProductions = [];
  }
  visitNonTerminal(e) {
    this.allProductions.push(e);
  }
  visitOption(e) {
    this.allProductions.push(e);
  }
  visitRepetitionWithSeparator(e) {
    this.allProductions.push(e);
  }
  visitRepetitionMandatory(e) {
    this.allProductions.push(e);
  }
  visitRepetitionMandatoryWithSeparator(e) {
    this.allProductions.push(e);
  }
  visitRepetition(e) {
    this.allProductions.push(e);
  }
  visitAlternation(e) {
    this.allProductions.push(e);
  }
  visitTerminal(e) {
    this.allProductions.push(e);
  }
}
function vs(t, e, n, r = []) {
  const i = [], o = an(e.definition);
  if (G(o)) return [];
  {
    const s = t.name;
    it(o, t) && i.push({ message: n.buildLeftRecursionError({ topLevelRule: t, leftRecursionPath: r }), type: rt.LEFT_RECURSION, ruleName: s });
    const a = Et(fn(o, r.concat([t])), (c) => {
      const u = tt(r);
      return u.push(c), vs(t, c, n, u);
    });
    return i.concat(a);
  }
}
function an(t) {
  let e = [];
  if (G(t)) return e;
  const n = Rt(t);
  if (n instanceof dt) e.push(n.referencedRule);
  else if (n instanceof ut || n instanceof ct || n instanceof wt || n instanceof Mt || n instanceof St || n instanceof Q) e = e.concat(an(n.definition));
  else if (n instanceof _t) e = vt(_(n.definition, (o) => an(o.definition)));
  else if (!(n instanceof K)) throw Error("non exhaustive match");
  const r = dn(n), i = t.length > 1;
  if (r && i) {
    const o = J(t);
    return e.concat(an(o));
  }
  return e;
}
class Kr extends ge {
  constructor() {
    super(...arguments), this.alternations = [];
  }
  visitAlternation(e) {
    this.alternations.push(e);
  }
}
function Jc(t, e, n) {
  const r = new Kr();
  t.accept(r);
  let i = r.alternations;
  return i = xn(i, (s) => s.ignoreAmbiguities === !0), Et(i, (s) => {
    const a = s.idx, c = s.maxLookahead || e, u = zr(a, t, c, s), l = function(f, d, E, I) {
      const S = [], T = ft(f, (p, A, O) => (d.definition[O].ignoreAmbiguities === !0 || k(A, (g) => {
        const R = [O];
        k(f, (N, v) => {
          O !== v && Nr(N, g) && d.definition[v].ignoreAmbiguities !== !0 && R.push(v);
        }), R.length > 1 && !Nr(S, g) && (S.push(g), p.push({ alts: R, path: g }));
      }), p), []);
      return _(T, (p) => {
        const A = _(p.alts, (O) => O + 1);
        return { message: I.buildAlternationAmbiguityError({ topLevelRule: E, alternation: d, ambiguityIndices: A, prefixPath: p.path }), type: rt.AMBIGUOUS_ALTS, ruleName: E.name, occurrence: d.idx, alternatives: p.alts };
      });
    }(u, s, t, n), h = function(f, d, E, I) {
      const S = ft(f, (m, p, A) => {
        const O = _(p, (g) => ({ idx: A, path: g }));
        return m.concat(O);
      }, []);
      return Ge(Et(S, (m) => {
        if (d.definition[m.idx].ignoreAmbiguities === !0) return [];
        const p = m.idx, A = m.path;
        return _(pt(S, (O) => {
          return d.definition[O.idx].ignoreAmbiguities !== !0 && O.idx < p && (g = O.path, R = A, g.length < R.length && Nt(g, (N, v) => {
            const y = R[v];
            return N === y || y.categoryMatchesMap[N.tokenTypeIdx];
          }));
          var g, R;
        }), (O) => {
          const g = [O.idx + 1, p + 1], R = d.idx === 0 ? "" : d.idx;
          return { message: I.buildAlternationPrefixAmbiguityError({ topLevelRule: E, alternation: d, ambiguityIndices: g, prefixPath: O.path }), type: rt.AMBIGUOUS_PREFIX_ALTS, ruleName: E.name, occurrence: R, alternatives: g };
        });
      }));
    }(u, s, t, n);
    return l.concat(h);
  });
}
class tu extends ge {
  constructor() {
    super(...arguments), this.allProductions = [];
  }
  visitRepetitionWithSeparator(e) {
    this.allProductions.push(e);
  }
  visitRepetitionMandatory(e) {
    this.allProductions.push(e);
  }
  visitRepetitionMandatoryWithSeparator(e) {
    this.allProductions.push(e);
  }
  visitRepetition(e) {
    this.allProductions.push(e);
  }
}
function eu(t) {
  const e = $r(t, { errMsgProvider: jc }), n = {};
  return k(t.rules, (r) => {
    n[r.name] = r;
  }), function(r, i) {
    const o = new Bc(r, i);
    return o.resolveRefs(), o.errors;
  }(n, e.errMsgProvider);
}
const Ns = "MismatchedTokenException", ys = "NoViableAltException", Rs = "EarlyExitException", Os = "NotAllInputParsedException", Ss = [Ns, ys, Rs, Os];
function Qe(t) {
  return it(Ss, t.name);
}
Object.freeze(Ss);
class bn extends Error {
  constructor(e, n) {
    super(e), this.token = n, this.resyncedTokens = [], Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
  }
}
class no extends bn {
  constructor(e, n, r) {
    super(e, n), this.previousToken = r, this.name = Ns;
  }
}
class nu extends bn {
  constructor(e, n, r) {
    super(e, n), this.previousToken = r, this.name = ys;
  }
}
class ru extends bn {
  constructor(e, n) {
    super(e, n), this.name = Os;
  }
}
class iu extends bn {
  constructor(e, n, r) {
    super(e, n), this.previousToken = r, this.name = Rs;
  }
}
const Hn = {}, _s = "InRuleRecoveryException";
class ou extends Error {
  constructor(e) {
    super(e), this.name = _s;
  }
}
function su(t, e, n, r, i, o, s) {
  const a = this.getKeyForAutomaticLookahead(r, i);
  let c = this.firstAfterRepMap[a];
  if (c === void 0) {
    const f = this.getCurrRuleFullName();
    c = new o(this.getGAstProductions()[f], i).startWalking(), this.firstAfterRepMap[a] = c;
  }
  let u = c.token, l = c.occurrence;
  const h = c.isEndOfRule;
  this.RULE_STACK.length === 1 && h && u === void 0 && (u = ee, l = 1), u !== void 0 && l !== void 0 && this.shouldInRepetitionRecoveryBeTried(u, l, s) && this.tryInRepetitionRecovery(t, e, n, u);
}
const Yn = 1024, Xn = 1280, Je = 1536;
function qn(t, e, n) {
  return n | e | t;
}
class au {
  constructor(e) {
    var n;
    this.maxLookahead = (n = e?.maxLookahead) !== null && n !== void 0 ? n : Bt.maxLookahead;
  }
  validate(e) {
    const n = this.validateNoLeftRecursion(e.rules);
    if (G(n)) {
      const r = this.validateEmptyOrAlternatives(e.rules), i = this.validateAmbiguousAlternationAlternatives(e.rules, this.maxLookahead), o = this.validateSomeNonEmptyLookaheadPath(e.rules, this.maxLookahead);
      return [...n, ...r, ...i, ...o];
    }
    return n;
  }
  validateNoLeftRecursion(e) {
    return Et(e, (n) => vs(n, n, ne));
  }
  validateEmptyOrAlternatives(e) {
    return Et(e, (n) => function(r, i) {
      const o = new Kr();
      return r.accept(o), Et(o.alternations, (s) => Et(Fe(s.definition), (a, c) => G(gs([a], [], Ce, 1)) ? [{ message: i.buildEmptyAlternationError({ topLevelRule: r, alternation: s, emptyChoiceIdx: c }), type: rt.NONE_LAST_EMPTY_ALT, ruleName: r.name, occurrence: s.idx, alternative: c + 1 }] : []));
    }(n, ne));
  }
  validateAmbiguousAlternationAlternatives(e, n) {
    return Et(e, (r) => Jc(r, n, ne));
  }
  validateSomeNonEmptyLookaheadPath(e, n) {
    return function(r, i, o) {
      const s = [];
      return k(r, (a) => {
        const c = new tu();
        a.accept(c), k(c.allProductions, (u) => {
          const l = Ji(u), h = u.maxLookahead || i;
          if (G(vt(vr(u.idx, a, l, h)[0]))) {
            const f = o.buildEmptyRepetitionError({ topLevelRule: a, repetition: u });
            s.push({ message: f, type: rt.NO_NON_EMPTY_LOOKAHEAD, ruleName: a.name });
          }
        });
      }), s;
    }(e, n, ne);
  }
  buildLookaheadForAlternation(e) {
    return function(n, r, i, o, s, a) {
      const c = zr(n, r, i);
      return a(c, o, eo(c) ? Tn : Ce, s);
    }(e.prodOccurrence, e.rule, e.maxLookahead, e.hasPredicates, e.dynamicTokensEnabled, Vc);
  }
  buildLookaheadForOptional(e) {
    return function(n, r, i, o, s, a) {
      const c = vr(n, r, s, i), u = eo(c) ? Tn : Ce;
      return a(c[0], u, o);
    }(e.prodOccurrence, e.rule, e.maxLookahead, e.dynamicTokensEnabled, Ji(e.prodType), Hc);
  }
}
const tn = new class extends ge {
  constructor() {
    super(...arguments), this.dslMethods = { option: [], alternation: [], repetition: [], repetitionWithSeparator: [], repetitionMandatory: [], repetitionMandatoryWithSeparator: [] };
  }
  reset() {
    this.dslMethods = { option: [], alternation: [], repetition: [], repetitionWithSeparator: [], repetitionMandatory: [], repetitionMandatoryWithSeparator: [] };
  }
  visitOption(t) {
    this.dslMethods.option.push(t);
  }
  visitRepetitionWithSeparator(t) {
    this.dslMethods.repetitionWithSeparator.push(t);
  }
  visitRepetitionMandatory(t) {
    this.dslMethods.repetitionMandatory.push(t);
  }
  visitRepetitionMandatoryWithSeparator(t) {
    this.dslMethods.repetitionMandatoryWithSeparator.push(t);
  }
  visitRepetition(t) {
    this.dslMethods.repetition.push(t);
  }
  visitAlternation(t) {
    this.dslMethods.alternation.push(t);
  }
}();
function ro(t, e) {
  isNaN(t.startOffset) === !0 ? (t.startOffset = e.startOffset, t.endOffset = e.endOffset) : t.endOffset < e.endOffset && (t.endOffset = e.endOffset);
}
function io(t, e) {
  isNaN(t.startOffset) === !0 ? (t.startOffset = e.startOffset, t.startColumn = e.startColumn, t.startLine = e.startLine, t.endOffset = e.endOffset, t.endColumn = e.endColumn, t.endLine = e.endLine) : t.endOffset < e.endOffset && (t.endOffset = e.endOffset, t.endColumn = e.endColumn, t.endLine = e.endLine);
}
function Ls(t, e) {
  Object.defineProperty(t, "name", { enumerable: !1, configurable: !0, writable: !1, value: e });
}
function cu(t, e) {
  const n = At(t), r = n.length;
  for (let i = 0; i < r; i++) {
    const o = t[n[i]], s = o.length;
    for (let a = 0; a < s; a++) {
      const c = o[a];
      c.tokenTypeIdx === void 0 && this[c.name](c.children, e);
    }
  }
}
function uu(t, e) {
  const n = function() {
  };
  Ls(n, t + "BaseSemantics");
  const r = { visit: function(i, o) {
    if (D(i) && (i = i[0]), !zt(i)) return this[i.name](i.children, o);
  }, validateVisitor: function() {
    const i = function(o, s) {
      return function(c, u) {
        const l = pt(u, (f) => Kt(c[f]) === !1), h = _(l, (f) => ({ msg: `Missing visitor method: <${f}> on ${c.constructor.name} CST Visitor.`, type: yr.MISSING_METHOD, methodName: f }));
        return Ge(h);
      }(o, s);
    }(this, e);
    if (!G(i)) {
      const o = _(i, (s) => s.msg);
      throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>:
	${o.join(`

`).replace(/\n/g, `
	`)}`);
    }
  } };
  return (n.prototype = r).constructor = n, n._RULE_NAMES = e, n;
}
var yr;
(function(t) {
  t[t.REDUNDANT_METHOD = 0] = "REDUNDANT_METHOD", t[t.MISSING_METHOD = 1] = "MISSING_METHOD";
})(yr || (yr = {}));
const Pn = { description: "This Object indicates the Parser is during Recording Phase" };
Object.freeze(Pn);
const oo = !0, so = Math.pow(2, 8) - 1, xs = P({ name: "RECORDING_PHASE_TOKEN", pattern: st.NA });
ze([xs]);
const Cs = Gr(xs, `This IToken indicates the Parser is in Recording Phase
	See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`, -1, -1, -1, -1, -1, -1);
Object.freeze(Cs);
const lu = { name: `This CSTNode indicates the Parser is in Recording Phase
	See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`, children: {} };
function ye(t, e, n, r = !1) {
  An(n);
  const i = pe(this.recordingProdStack), o = Kt(e) ? e : e.DEF, s = new t({ definition: [], idx: n });
  return r && (s.separator = e.SEP), L(e, "MAX_LOOKAHEAD") && (s.maxLookahead = e.MAX_LOOKAHEAD), this.recordingProdStack.push(s), o.call(this), i.definition.push(s), this.recordingProdStack.pop(), Pn;
}
function hu(t, e) {
  An(e);
  const n = pe(this.recordingProdStack), r = D(t) === !1, i = r === !1 ? t : t.DEF, o = new _t({ definition: [], idx: e, ignoreAmbiguities: r && t.IGNORE_AMBIGUITIES === !0 });
  L(t, "MAX_LOOKAHEAD") && (o.maxLookahead = t.MAX_LOOKAHEAD);
  const s = rs(i, (a) => Kt(a.GATE));
  return o.hasPredicates = s, n.definition.push(o), k(i, (a) => {
    const c = new ut({ definition: [] });
    o.definition.push(c), L(a, "IGNORE_AMBIGUITIES") ? c.ignoreAmbiguities = a.IGNORE_AMBIGUITIES : L(a, "GATE") && (c.ignoreAmbiguities = !0), this.recordingProdStack.push(c), a.ALT.call(this), this.recordingProdStack.pop();
  }), Pn;
}
function ao(t) {
  return t === 0 ? "" : `${t}`;
}
function An(t) {
  if (t < 0 || t > so) {
    const e = new Error(`Invalid DSL Method idx value: <${t}>
	Idx value must be a none negative value smaller than ${so + 1}`);
    throw e.KNOWN_RECORDER_ERROR = !0, e;
  }
}
const cn = Gr(ee, "", NaN, NaN, NaN, NaN, NaN, NaN);
Object.freeze(cn);
const Bt = Object.freeze({ recoveryEnabled: !1, maxLookahead: 3, dynamicTokensEnabled: !1, outputCst: !0, errorMessageProvider: Es, nodeLocationTracking: "none", traceInitPerf: !1, skipValidations: !1 }), en = Object.freeze({ recoveryValueFunc: () => {
}, resyncEnabled: !0 });
var rt, Zn;
(function(t) {
  t[t.INVALID_RULE_NAME = 0] = "INVALID_RULE_NAME", t[t.DUPLICATE_RULE_NAME = 1] = "DUPLICATE_RULE_NAME", t[t.INVALID_RULE_OVERRIDE = 2] = "INVALID_RULE_OVERRIDE", t[t.DUPLICATE_PRODUCTIONS = 3] = "DUPLICATE_PRODUCTIONS", t[t.UNRESOLVED_SUBRULE_REF = 4] = "UNRESOLVED_SUBRULE_REF", t[t.LEFT_RECURSION = 5] = "LEFT_RECURSION", t[t.NONE_LAST_EMPTY_ALT = 6] = "NONE_LAST_EMPTY_ALT", t[t.AMBIGUOUS_ALTS = 7] = "AMBIGUOUS_ALTS", t[t.CONFLICT_TOKENS_RULES_NAMESPACE = 8] = "CONFLICT_TOKENS_RULES_NAMESPACE", t[t.INVALID_TOKEN_NAME = 9] = "INVALID_TOKEN_NAME", t[t.NO_NON_EMPTY_LOOKAHEAD = 10] = "NO_NON_EMPTY_LOOKAHEAD", t[t.AMBIGUOUS_PREFIX_ALTS = 11] = "AMBIGUOUS_PREFIX_ALTS", t[t.TOO_MANY_ALTS = 12] = "TOO_MANY_ALTS", t[t.CUSTOM_LOOKAHEAD_VALIDATION = 13] = "CUSTOM_LOOKAHEAD_VALIDATION";
})(rt || (rt = {}));
class De {
  static performSelfAnalysis(e) {
    throw Error("The **static** `performSelfAnalysis` method has been deprecated.	\nUse the **instance** method with the same name instead.");
  }
  performSelfAnalysis() {
    this.TRACE_INIT("performSelfAnalysis", () => {
      let e;
      this.selfAnalysisDone = !0;
      const n = this.className;
      this.TRACE_INIT("toFastProps", () => {
        ss(this);
      }), this.TRACE_INIT("Grammar Recording", () => {
        try {
          this.enableRecording(), k(this.definedRulesNames, (i) => {
            const o = this[i].originalGrammarAction;
            let s;
            this.TRACE_INIT(`${i} Rule`, () => {
              s = this.topLevelRuleRecord(i, o);
            }), this.gastProductionsCache[i] = s;
          });
        } finally {
          this.disableRecording();
        }
      });
      let r = [];
      if (this.TRACE_INIT("Grammar Resolving", () => {
        r = eu({ rules: Z(this.gastProductionsCache) }), this.definitionErrors = this.definitionErrors.concat(r);
      }), this.TRACE_INIT("Grammar Validations", () => {
        if (G(r) && this.skipValidations === !1) {
          const o = (i = { rules: Z(this.gastProductionsCache), tokenTypes: Z(this.tokensMap), errMsgProvider: ne, grammarName: n }, qc((i = $r(i, { errMsgProvider: ne })).rules, i.tokenTypes, i.errMsgProvider, i.grammarName)), s = function(a) {
            return _(a.lookaheadStrategy.validate({ rules: a.rules, tokenTypes: a.tokenTypes, grammarName: a.grammarName }), (c) => Object.assign({ type: rt.CUSTOM_LOOKAHEAD_VALIDATION }, c));
          }({ lookaheadStrategy: this.lookaheadStrategy, rules: Z(this.gastProductionsCache), tokenTypes: Z(this.tokensMap), grammarName: n });
          this.definitionErrors = this.definitionErrors.concat(o, s);
        }
        var i;
      }), G(this.definitionErrors) && (this.recoveryEnabled && this.TRACE_INIT("computeAllProdsFollows", () => {
        const i = function(o) {
          const s = {};
          return k(o, (a) => {
            const c = new yc(a).startWalking();
            ht(s, c);
          }), s;
        }(Z(this.gastProductionsCache));
        this.resyncFollows = i;
      }), this.TRACE_INIT("ComputeLookaheadFunctions", () => {
        var i, o;
        (o = (i = this.lookaheadStrategy).initialize) === null || o === void 0 || o.call(i, { rules: Z(this.gastProductionsCache) }), this.preComputeLookaheadFunctions(Z(this.gastProductionsCache));
      })), !De.DEFER_DEFINITION_ERRORS_HANDLING && !G(this.definitionErrors)) throw e = _(this.definitionErrors, (i) => i.message), new Error(`Parser Definition Errors detected:
 ${e.join(`
-------------------------------
`)}`);
    });
  }
  constructor(e, n) {
    this.definitionErrors = [], this.selfAnalysisDone = !1;
    const r = this;
    if (r.initErrorHandler(n), r.initLexerAdapter(), r.initLooksAhead(n), r.initRecognizerEngine(e, n), r.initRecoverable(n), r.initTreeBuilder(n), r.initContentAssist(), r.initGastRecorder(n), r.initPerformanceTracer(n), L(n, "ignoredIssues")) throw new Error(`The <ignoredIssues> IParserConfig property has been deprecated.
	Please use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.
	See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES
	For further details.`);
    this.skipValidations = L(n, "skipValidations") ? n.skipValidations : Bt.skipValidations;
  }
}
De.DEFER_DEFINITION_ERRORS_HANDLING = !1, Zn = De, [class {
  initRecoverable(t) {
    this.firstAfterRepMap = {}, this.resyncFollows = {}, this.recoveryEnabled = L(t, "recoveryEnabled") ? t.recoveryEnabled : Bt.recoveryEnabled, this.recoveryEnabled && (this.attemptInRepetitionRecovery = su);
  }
  getTokenToInsert(t) {
    const e = Gr(t, "", NaN, NaN, NaN, NaN, NaN, NaN);
    return e.isInsertedInRecovery = !0, e;
  }
  canTokenTypeBeInsertedInRecovery(t) {
    return !0;
  }
  canTokenTypeBeDeletedInRecovery(t) {
    return !0;
  }
  tryInRepetitionRecovery(t, e, n, r) {
    const i = this.findReSyncTokenType(), o = this.exportLexerState(), s = [];
    let a = !1;
    const c = this.LA(1);
    let u = this.LA(1);
    const l = () => {
      const h = this.LA(0), f = this.errorMessageProvider.buildMismatchTokenMessage({ expected: r, actual: c, previous: h, ruleName: this.getCurrRuleFullName() }), d = new no(f, c, this.LA(0));
      d.resyncedTokens = Fe(s), this.SAVE_ERROR(d);
    };
    for (; !a; ) {
      if (this.tokenMatcher(u, r)) return void l();
      if (n.call(this)) return l(), void t.apply(this, e);
      this.tokenMatcher(u, i) ? a = !0 : (u = this.SKIP_TOKEN(), this.addToResyncTokens(u, s));
    }
    this.importLexerState(o);
  }
  shouldInRepetitionRecoveryBeTried(t, e, n) {
    return n !== !1 && !this.tokenMatcher(this.LA(1), t) && !this.isBackTracking() && !this.canPerformInRuleRecovery(t, this.getFollowsForInRuleRecovery(t, e));
  }
  getFollowsForInRuleRecovery(t, e) {
    const n = this.getCurrentGrammarPath(t, e);
    return this.getNextPossibleTokenTypes(n);
  }
  tryInRuleRecovery(t, e) {
    if (this.canRecoverWithSingleTokenInsertion(t, e)) return this.getTokenToInsert(t);
    if (this.canRecoverWithSingleTokenDeletion(t)) {
      const n = this.SKIP_TOKEN();
      return this.consumeToken(), n;
    }
    throw new ou("sad sad panda");
  }
  canPerformInRuleRecovery(t, e) {
    return this.canRecoverWithSingleTokenInsertion(t, e) || this.canRecoverWithSingleTokenDeletion(t);
  }
  canRecoverWithSingleTokenInsertion(t, e) {
    if (!this.canTokenTypeBeInsertedInRecovery(t) || G(e)) return !1;
    const n = this.LA(1);
    return me(e, (r) => this.tokenMatcher(n, r)) !== void 0;
  }
  canRecoverWithSingleTokenDeletion(t) {
    return !!this.canTokenTypeBeDeletedInRecovery(t) && this.tokenMatcher(this.LA(2), t);
  }
  isInCurrentRuleReSyncSet(t) {
    const e = this.getCurrFollowKey();
    return it(this.getFollowSetFromFollowKey(e), t);
  }
  findReSyncTokenType() {
    const t = this.flattenFollowSet();
    let e = this.LA(1), n = 2;
    for (; ; ) {
      const r = me(t, (i) => Ce(e, i));
      if (r !== void 0) return r;
      e = this.LA(n), n++;
    }
  }
  getCurrFollowKey() {
    if (this.RULE_STACK.length === 1) return Hn;
    const t = this.getLastExplicitRuleShortName(), e = this.getLastExplicitRuleOccurrenceIndex(), n = this.getPreviousExplicitRuleShortName();
    return { ruleName: this.shortRuleNameToFullName(t), idxInCallingRule: e, inRule: this.shortRuleNameToFullName(n) };
  }
  buildFullFollowKeyStack() {
    const t = this.RULE_STACK, e = this.RULE_OCCURRENCE_STACK;
    return _(t, (n, r) => r === 0 ? Hn : { ruleName: this.shortRuleNameToFullName(n), idxInCallingRule: e[r], inRule: this.shortRuleNameToFullName(t[r - 1]) });
  }
  flattenFollowSet() {
    return vt(_(this.buildFullFollowKeyStack(), (t) => this.getFollowSetFromFollowKey(t)));
  }
  getFollowSetFromFollowKey(t) {
    if (t === Hn) return [ee];
    const e = t.ruleName + t.idxInCallingRule + as + t.inRule;
    return this.resyncFollows[e];
  }
  addToResyncTokens(t, e) {
    return this.tokenMatcher(t, ee) || e.push(t), e;
  }
  reSyncTo(t) {
    const e = [];
    let n = this.LA(1);
    for (; this.tokenMatcher(n, t) === !1; ) n = this.SKIP_TOKEN(), this.addToResyncTokens(n, e);
    return Fe(e);
  }
  attemptInRepetitionRecovery(t, e, n, r, i, o, s) {
  }
  getCurrentGrammarPath(t, e) {
    return { ruleStack: this.getHumanReadableRuleStack(), occurrenceStack: tt(this.RULE_OCCURRENCE_STACK), lastTok: t, lastTokOccurrence: e };
  }
  getHumanReadableRuleStack() {
    return _(this.RULE_STACK, (t) => this.shortRuleNameToFullName(t));
  }
}, class {
  initLooksAhead(t) {
    this.dynamicTokensEnabled = L(t, "dynamicTokensEnabled") ? t.dynamicTokensEnabled : Bt.dynamicTokensEnabled, this.maxLookahead = L(t, "maxLookahead") ? t.maxLookahead : Bt.maxLookahead, this.lookaheadStrategy = L(t, "lookaheadStrategy") ? t.lookaheadStrategy : new au({ maxLookahead: this.maxLookahead }), this.lookAheadFuncsCache = /* @__PURE__ */ new Map();
  }
  preComputeLookaheadFunctions(t) {
    k(t, (e) => {
      this.TRACE_INIT(`${e.name} Rule Lookahead`, () => {
        const { alternation: n, repetition: r, option: i, repetitionMandatory: o, repetitionMandatoryWithSeparator: s, repetitionWithSeparator: a } = function(c) {
          tn.reset(), c.accept(tn);
          const u = tn.dslMethods;
          return tn.reset(), u;
        }(e);
        k(n, (c) => {
          const u = c.idx === 0 ? "" : c.idx;
          this.TRACE_INIT(`${Lt(c)}${u}`, () => {
            const l = this.lookaheadStrategy.buildLookaheadForAlternation({ prodOccurrence: c.idx, rule: e, maxLookahead: c.maxLookahead || this.maxLookahead, hasPredicates: c.hasPredicates, dynamicTokensEnabled: this.dynamicTokensEnabled }), h = qn(this.fullRuleNameToShort[e.name], 256, c.idx);
            this.setLaFuncCache(h, l);
          });
        }), k(r, (c) => {
          this.computeLookaheadFunc(e, c.idx, 768, "Repetition", c.maxLookahead, Lt(c));
        }), k(i, (c) => {
          this.computeLookaheadFunc(e, c.idx, 512, "Option", c.maxLookahead, Lt(c));
        }), k(o, (c) => {
          this.computeLookaheadFunc(e, c.idx, Yn, "RepetitionMandatory", c.maxLookahead, Lt(c));
        }), k(s, (c) => {
          this.computeLookaheadFunc(e, c.idx, Je, "RepetitionMandatoryWithSeparator", c.maxLookahead, Lt(c));
        }), k(a, (c) => {
          this.computeLookaheadFunc(e, c.idx, Xn, "RepetitionWithSeparator", c.maxLookahead, Lt(c));
        });
      });
    });
  }
  computeLookaheadFunc(t, e, n, r, i, o) {
    this.TRACE_INIT(`${o}${e === 0 ? "" : e}`, () => {
      const s = this.lookaheadStrategy.buildLookaheadForOptional({ prodOccurrence: e, rule: t, maxLookahead: i || this.maxLookahead, dynamicTokensEnabled: this.dynamicTokensEnabled, prodType: r }), a = qn(this.fullRuleNameToShort[t.name], n, e);
      this.setLaFuncCache(a, s);
    });
  }
  getKeyForAutomaticLookahead(t, e) {
    return qn(this.getLastExplicitRuleShortName(), t, e);
  }
  getLaFuncFromCache(t) {
    return this.lookAheadFuncsCache.get(t);
  }
  setLaFuncCache(t, e) {
    this.lookAheadFuncsCache.set(t, e);
  }
}, class {
  initTreeBuilder(t) {
    if (this.CST_STACK = [], this.outputCst = t.outputCst, this.nodeLocationTracking = L(t, "nodeLocationTracking") ? t.nodeLocationTracking : Bt.nodeLocationTracking, this.outputCst) if (/full/i.test(this.nodeLocationTracking)) this.recoveryEnabled ? (this.setNodeLocationFromToken = io, this.setNodeLocationFromNode = io, this.cstPostRule = q, this.setInitialNodeLocation = this.setInitialNodeLocationFullRecovery) : (this.setNodeLocationFromToken = q, this.setNodeLocationFromNode = q, this.cstPostRule = this.cstPostRuleFull, this.setInitialNodeLocation = this.setInitialNodeLocationFullRegular);
    else if (/onlyOffset/i.test(this.nodeLocationTracking)) this.recoveryEnabled ? (this.setNodeLocationFromToken = ro, this.setNodeLocationFromNode = ro, this.cstPostRule = q, this.setInitialNodeLocation = this.setInitialNodeLocationOnlyOffsetRecovery) : (this.setNodeLocationFromToken = q, this.setNodeLocationFromNode = q, this.cstPostRule = this.cstPostRuleOnlyOffset, this.setInitialNodeLocation = this.setInitialNodeLocationOnlyOffsetRegular);
    else {
      if (!/none/i.test(this.nodeLocationTracking)) throw Error(`Invalid <nodeLocationTracking> config option: "${t.nodeLocationTracking}"`);
      this.setNodeLocationFromToken = q, this.setNodeLocationFromNode = q, this.cstPostRule = q, this.setInitialNodeLocation = q;
    }
    else this.cstInvocationStateUpdate = q, this.cstFinallyStateUpdate = q, this.cstPostTerminal = q, this.cstPostNonTerminal = q, this.cstPostRule = q;
  }
  setInitialNodeLocationOnlyOffsetRecovery(t) {
    t.location = { startOffset: NaN, endOffset: NaN };
  }
  setInitialNodeLocationOnlyOffsetRegular(t) {
    t.location = { startOffset: this.LA(1).startOffset, endOffset: NaN };
  }
  setInitialNodeLocationFullRecovery(t) {
    t.location = { startOffset: NaN, startLine: NaN, startColumn: NaN, endOffset: NaN, endLine: NaN, endColumn: NaN };
  }
  setInitialNodeLocationFullRegular(t) {
    const e = this.LA(1);
    t.location = { startOffset: e.startOffset, startLine: e.startLine, startColumn: e.startColumn, endOffset: NaN, endLine: NaN, endColumn: NaN };
  }
  cstInvocationStateUpdate(t) {
    const e = { name: t, children: /* @__PURE__ */ Object.create(null) };
    this.setInitialNodeLocation(e), this.CST_STACK.push(e);
  }
  cstFinallyStateUpdate() {
    this.CST_STACK.pop();
  }
  cstPostRuleFull(t) {
    const e = this.LA(0), n = t.location;
    n.startOffset <= e.startOffset == 1 ? (n.endOffset = e.endOffset, n.endLine = e.endLine, n.endColumn = e.endColumn) : (n.startOffset = NaN, n.startLine = NaN, n.startColumn = NaN);
  }
  cstPostRuleOnlyOffset(t) {
    const e = this.LA(0), n = t.location;
    n.startOffset <= e.startOffset == 1 ? n.endOffset = e.endOffset : n.startOffset = NaN;
  }
  cstPostTerminal(t, e) {
    const n = this.CST_STACK[this.CST_STACK.length - 1];
    var r, i, o;
    i = e, o = t, (r = n).children[o] === void 0 ? r.children[o] = [i] : r.children[o].push(i), this.setNodeLocationFromToken(n.location, e);
  }
  cstPostNonTerminal(t, e) {
    const n = this.CST_STACK[this.CST_STACK.length - 1];
    (function(r, i, o) {
      r.children[i] === void 0 ? r.children[i] = [o] : r.children[i].push(o);
    })(n, e, t), this.setNodeLocationFromNode(n.location, t.location);
  }
  getBaseCstVisitorConstructor() {
    if (zt(this.baseCstVisitorConstructor)) {
      const t = uu(this.className, At(this.gastProductionsCache));
      return this.baseCstVisitorConstructor = t, t;
    }
    return this.baseCstVisitorConstructor;
  }
  getBaseCstVisitorConstructorWithDefaults() {
    if (zt(this.baseCstVisitorWithDefaultsConstructor)) {
      const t = function(e, n, r) {
        const i = function() {
        };
        Ls(i, e + "BaseSemanticsWithDefaults");
        const o = Object.create(r.prototype);
        return k(n, (s) => {
          o[s] = cu;
        }), (i.prototype = o).constructor = i, i;
      }(this.className, At(this.gastProductionsCache), this.getBaseCstVisitorConstructor());
      return this.baseCstVisitorWithDefaultsConstructor = t, t;
    }
    return this.baseCstVisitorWithDefaultsConstructor;
  }
  getLastExplicitRuleShortName() {
    const t = this.RULE_STACK;
    return t[t.length - 1];
  }
  getPreviousExplicitRuleShortName() {
    const t = this.RULE_STACK;
    return t[t.length - 2];
  }
  getLastExplicitRuleOccurrenceIndex() {
    const t = this.RULE_OCCURRENCE_STACK;
    return t[t.length - 1];
  }
}, class {
  initLexerAdapter() {
    this.tokVector = [], this.tokVectorLength = 0, this.currIdx = -1;
  }
  set input(t) {
    if (this.selfAnalysisDone !== !0) throw Error("Missing <performSelfAnalysis> invocation at the end of the Parser's constructor.");
    this.reset(), this.tokVector = t, this.tokVectorLength = t.length;
  }
  get input() {
    return this.tokVector;
  }
  SKIP_TOKEN() {
    return this.currIdx <= this.tokVector.length - 2 ? (this.consumeToken(), this.LA(1)) : cn;
  }
  LA(t) {
    const e = this.currIdx + t;
    return e < 0 || this.tokVectorLength <= e ? cn : this.tokVector[e];
  }
  consumeToken() {
    this.currIdx++;
  }
  exportLexerState() {
    return this.currIdx;
  }
  importLexerState(t) {
    this.currIdx = t;
  }
  resetLexerState() {
    this.currIdx = -1;
  }
  moveToTerminatedState() {
    this.currIdx = this.tokVector.length - 1;
  }
  getLexerPosition() {
    return this.exportLexerState();
  }
}, class {
  initRecognizerEngine(t, e) {
    if (this.className = this.constructor.name, this.shortRuleNameToFull = {}, this.fullRuleNameToShort = {}, this.ruleShortNameIdx = 256, this.tokenMatcher = Tn, this.subruleIdx = 0, this.definedRulesNames = [], this.tokensMap = {}, this.isBackTrackingStack = [], this.RULE_STACK = [], this.RULE_OCCURRENCE_STACK = [], this.gastProductionsCache = {}, L(e, "serializedGrammar")) throw Error(`The Parser's configuration can no longer contain a <serializedGrammar> property.
	See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0
	For Further details.`);
    if (D(t)) {
      if (G(t)) throw Error(`A Token Vocabulary cannot be empty.
	Note that the first argument for the parser constructor
	is no longer a Token vector (since v4.0).`);
      if (typeof t[0].startOffset == "number") throw Error(`The Parser constructor no longer accepts a token vector as the first argument.
	See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0
	For Further details.`);
    }
    if (D(t)) this.tokensMap = ft(t, (r, i) => (r[i.name] = i, r), {});
    else if (L(t, "modes") && Nt(vt(Z(t.modes)), Uc)) {
      const r = mr(vt(Z(t.modes)));
      this.tokensMap = ft(r, (i, o) => (i[o.name] = o, i), {});
    } else {
      if (!Tt(t)) throw new Error("<tokensDictionary> argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");
      this.tokensMap = tt(t);
    }
    this.tokensMap.EOF = ee;
    const n = Nt(L(t, "modes") ? vt(Z(t.modes)) : Z(t), (r) => G(r.categoryMatches));
    this.tokenMatcher = n ? Tn : Ce, ze(Z(this.tokensMap));
  }
  defineRule(t, e, n) {
    if (this.selfAnalysisDone) throw Error(`Grammar rule <${t}> may not be defined after the 'performSelfAnalysis' method has been called'
Make sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.`);
    const r = L(n, "resyncEnabled") ? n.resyncEnabled : en.resyncEnabled, i = L(n, "recoveryValueFunc") ? n.recoveryValueFunc : en.recoveryValueFunc, o = this.ruleShortNameIdx << 12;
    let s;
    return this.ruleShortNameIdx++, this.shortRuleNameToFull[o] = t, this.fullRuleNameToShort[t] = o, s = this.outputCst === !0 ? function(...a) {
      try {
        this.ruleInvocationStateUpdate(o, t, this.subruleIdx), e.apply(this, a);
        const c = this.CST_STACK[this.CST_STACK.length - 1];
        return this.cstPostRule(c), c;
      } catch (c) {
        return this.invokeRuleCatch(c, r, i);
      } finally {
        this.ruleFinallyStateUpdate();
      }
    } : function(...a) {
      try {
        return this.ruleInvocationStateUpdate(o, t, this.subruleIdx), e.apply(this, a);
      } catch (c) {
        return this.invokeRuleCatch(c, r, i);
      } finally {
        this.ruleFinallyStateUpdate();
      }
    }, Object.assign(s, { ruleName: t, originalGrammarAction: e });
  }
  invokeRuleCatch(t, e, n) {
    const r = this.RULE_STACK.length === 1, i = e && !this.isBackTracking() && this.recoveryEnabled;
    if (Qe(t)) {
      const o = t;
      if (i) {
        const s = this.findReSyncTokenType();
        if (this.isInCurrentRuleReSyncSet(s)) {
          if (o.resyncedTokens = this.reSyncTo(s), this.outputCst) {
            const a = this.CST_STACK[this.CST_STACK.length - 1];
            return a.recoveredNode = !0, a;
          }
          return n(t);
        }
        if (this.outputCst) {
          const a = this.CST_STACK[this.CST_STACK.length - 1];
          a.recoveredNode = !0, o.partialCstResult = a;
        }
        throw o;
      }
      if (r) return this.moveToTerminatedState(), n(t);
      throw o;
    }
    throw t;
  }
  optionInternal(t, e) {
    const n = this.getKeyForAutomaticLookahead(512, e);
    return this.optionInternalLogic(t, e, n);
  }
  optionInternalLogic(t, e, n) {
    let r, i = this.getLaFuncFromCache(n);
    if (typeof t != "function") {
      r = t.DEF;
      const o = t.GATE;
      if (o !== void 0) {
        const s = i;
        i = () => o.call(this) && s.call(this);
      }
    } else r = t;
    if (i.call(this) === !0) return r.call(this);
  }
  atLeastOneInternal(t, e) {
    const n = this.getKeyForAutomaticLookahead(Yn, t);
    return this.atLeastOneInternalLogic(t, e, n);
  }
  atLeastOneInternalLogic(t, e, n) {
    let r, i = this.getLaFuncFromCache(n);
    if (typeof e != "function") {
      r = e.DEF;
      const o = e.GATE;
      if (o !== void 0) {
        const s = i;
        i = () => o.call(this) && s.call(this);
      }
    } else r = e;
    if (i.call(this) !== !0) throw this.raiseEarlyExitException(t, H.REPETITION_MANDATORY, e.ERR_MSG);
    {
      let o = this.doSingleRepetition(r);
      for (; i.call(this) === !0 && o === !0; ) o = this.doSingleRepetition(r);
    }
    this.attemptInRepetitionRecovery(this.atLeastOneInternal, [t, e], i, Yn, t, zc);
  }
  atLeastOneSepFirstInternal(t, e) {
    const n = this.getKeyForAutomaticLookahead(Je, t);
    this.atLeastOneSepFirstInternalLogic(t, e, n);
  }
  atLeastOneSepFirstInternalLogic(t, e, n) {
    const r = e.DEF, i = e.SEP;
    if (this.getLaFuncFromCache(n).call(this) !== !0) throw this.raiseEarlyExitException(t, H.REPETITION_MANDATORY_WITH_SEPARATOR, e.ERR_MSG);
    {
      r.call(this);
      const o = () => this.tokenMatcher(this.LA(1), i);
      for (; this.tokenMatcher(this.LA(1), i) === !0; ) this.CONSUME(i), r.call(this);
      this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal, [t, i, o, r, Qi], o, Je, t, Qi);
    }
  }
  manyInternal(t, e) {
    const n = this.getKeyForAutomaticLookahead(768, t);
    return this.manyInternalLogic(t, e, n);
  }
  manyInternalLogic(t, e, n) {
    let r, i = this.getLaFuncFromCache(n);
    if (typeof e != "function") {
      r = e.DEF;
      const s = e.GATE;
      if (s !== void 0) {
        const a = i;
        i = () => s.call(this) && a.call(this);
      }
    } else r = e;
    let o = !0;
    for (; i.call(this) === !0 && o === !0; ) o = this.doSingleRepetition(r);
    this.attemptInRepetitionRecovery(this.manyInternal, [t, e], i, 768, t, Gc, o);
  }
  manySepFirstInternal(t, e) {
    const n = this.getKeyForAutomaticLookahead(Xn, t);
    this.manySepFirstInternalLogic(t, e, n);
  }
  manySepFirstInternalLogic(t, e, n) {
    const r = e.DEF, i = e.SEP;
    if (this.getLaFuncFromCache(n).call(this) === !0) {
      r.call(this);
      const o = () => this.tokenMatcher(this.LA(1), i);
      for (; this.tokenMatcher(this.LA(1), i) === !0; ) this.CONSUME(i), r.call(this);
      this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal, [t, i, o, r, Zi], o, Xn, t, Zi);
    }
  }
  repetitionSepSecondInternal(t, e, n, r, i) {
    for (; n(); ) this.CONSUME(e), r.call(this);
    this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal, [t, e, n, r, i], n, Je, t, i);
  }
  doSingleRepetition(t) {
    const e = this.getLexerPosition();
    return t.call(this), this.getLexerPosition() > e;
  }
  orInternal(t, e) {
    const n = this.getKeyForAutomaticLookahead(256, e), r = D(t) ? t : t.DEF, i = this.getLaFuncFromCache(n).call(this, r);
    if (i !== void 0) return r[i].ALT.call(this);
    this.raiseNoAltException(e, t.ERR_MSG);
  }
  ruleFinallyStateUpdate() {
    if (this.RULE_STACK.pop(), this.RULE_OCCURRENCE_STACK.pop(), this.cstFinallyStateUpdate(), this.RULE_STACK.length === 0 && this.isAtEndOfInput() === !1) {
      const t = this.LA(1), e = this.errorMessageProvider.buildNotAllInputParsedMessage({ firstRedundant: t, ruleName: this.getCurrRuleFullName() });
      this.SAVE_ERROR(new ru(e, t));
    }
  }
  subruleInternal(t, e, n) {
    let r;
    try {
      const i = n !== void 0 ? n.ARGS : void 0;
      return this.subruleIdx = e, r = t.apply(this, i), this.cstPostNonTerminal(r, n !== void 0 && n.LABEL !== void 0 ? n.LABEL : t.ruleName), r;
    } catch (i) {
      throw this.subruleInternalError(i, n, t.ruleName);
    }
  }
  subruleInternalError(t, e, n) {
    throw Qe(t) && t.partialCstResult !== void 0 && (this.cstPostNonTerminal(t.partialCstResult, e !== void 0 && e.LABEL !== void 0 ? e.LABEL : n), delete t.partialCstResult), t;
  }
  consumeInternal(t, e, n) {
    let r;
    try {
      const i = this.LA(1);
      this.tokenMatcher(i, t) === !0 ? (this.consumeToken(), r = i) : this.consumeInternalError(t, i, n);
    } catch (i) {
      r = this.consumeInternalRecovery(t, e, i);
    }
    return this.cstPostTerminal(n !== void 0 && n.LABEL !== void 0 ? n.LABEL : t.name, r), r;
  }
  consumeInternalError(t, e, n) {
    let r;
    const i = this.LA(0);
    throw r = n !== void 0 && n.ERR_MSG ? n.ERR_MSG : this.errorMessageProvider.buildMismatchTokenMessage({ expected: t, actual: e, previous: i, ruleName: this.getCurrRuleFullName() }), this.SAVE_ERROR(new no(r, e, i));
  }
  consumeInternalRecovery(t, e, n) {
    if (!this.recoveryEnabled || n.name !== "MismatchedTokenException" || this.isBackTracking()) throw n;
    {
      const r = this.getFollowsForInRuleRecovery(t, e);
      try {
        return this.tryInRuleRecovery(t, r);
      } catch (i) {
        throw i.name === _s ? n : i;
      }
    }
  }
  saveRecogState() {
    const t = this.errors, e = tt(this.RULE_STACK);
    return { errors: t, lexerState: this.exportLexerState(), RULE_STACK: e, CST_STACK: this.CST_STACK };
  }
  reloadRecogState(t) {
    this.errors = t.errors, this.importLexerState(t.lexerState), this.RULE_STACK = t.RULE_STACK;
  }
  ruleInvocationStateUpdate(t, e, n) {
    this.RULE_OCCURRENCE_STACK.push(n), this.RULE_STACK.push(t), this.cstInvocationStateUpdate(e);
  }
  isBackTracking() {
    return this.isBackTrackingStack.length !== 0;
  }
  getCurrRuleFullName() {
    const t = this.getLastExplicitRuleShortName();
    return this.shortRuleNameToFull[t];
  }
  shortRuleNameToFullName(t) {
    return this.shortRuleNameToFull[t];
  }
  isAtEndOfInput() {
    return this.tokenMatcher(this.LA(1), ee);
  }
  reset() {
    this.resetLexerState(), this.subruleIdx = 0, this.isBackTrackingStack = [], this.errors = [], this.RULE_STACK = [], this.CST_STACK = [], this.RULE_OCCURRENCE_STACK = [];
  }
}, class {
  ACTION(t) {
    return t.call(this);
  }
  consume(t, e, n) {
    return this.consumeInternal(e, t, n);
  }
  subrule(t, e, n) {
    return this.subruleInternal(e, t, n);
  }
  option(t, e) {
    return this.optionInternal(e, t);
  }
  or(t, e) {
    return this.orInternal(e, t);
  }
  many(t, e) {
    return this.manyInternal(t, e);
  }
  atLeastOne(t, e) {
    return this.atLeastOneInternal(t, e);
  }
  CONSUME(t, e) {
    return this.consumeInternal(t, 0, e);
  }
  CONSUME1(t, e) {
    return this.consumeInternal(t, 1, e);
  }
  CONSUME2(t, e) {
    return this.consumeInternal(t, 2, e);
  }
  CONSUME3(t, e) {
    return this.consumeInternal(t, 3, e);
  }
  CONSUME4(t, e) {
    return this.consumeInternal(t, 4, e);
  }
  CONSUME5(t, e) {
    return this.consumeInternal(t, 5, e);
  }
  CONSUME6(t, e) {
    return this.consumeInternal(t, 6, e);
  }
  CONSUME7(t, e) {
    return this.consumeInternal(t, 7, e);
  }
  CONSUME8(t, e) {
    return this.consumeInternal(t, 8, e);
  }
  CONSUME9(t, e) {
    return this.consumeInternal(t, 9, e);
  }
  SUBRULE(t, e) {
    return this.subruleInternal(t, 0, e);
  }
  SUBRULE1(t, e) {
    return this.subruleInternal(t, 1, e);
  }
  SUBRULE2(t, e) {
    return this.subruleInternal(t, 2, e);
  }
  SUBRULE3(t, e) {
    return this.subruleInternal(t, 3, e);
  }
  SUBRULE4(t, e) {
    return this.subruleInternal(t, 4, e);
  }
  SUBRULE5(t, e) {
    return this.subruleInternal(t, 5, e);
  }
  SUBRULE6(t, e) {
    return this.subruleInternal(t, 6, e);
  }
  SUBRULE7(t, e) {
    return this.subruleInternal(t, 7, e);
  }
  SUBRULE8(t, e) {
    return this.subruleInternal(t, 8, e);
  }
  SUBRULE9(t, e) {
    return this.subruleInternal(t, 9, e);
  }
  OPTION(t) {
    return this.optionInternal(t, 0);
  }
  OPTION1(t) {
    return this.optionInternal(t, 1);
  }
  OPTION2(t) {
    return this.optionInternal(t, 2);
  }
  OPTION3(t) {
    return this.optionInternal(t, 3);
  }
  OPTION4(t) {
    return this.optionInternal(t, 4);
  }
  OPTION5(t) {
    return this.optionInternal(t, 5);
  }
  OPTION6(t) {
    return this.optionInternal(t, 6);
  }
  OPTION7(t) {
    return this.optionInternal(t, 7);
  }
  OPTION8(t) {
    return this.optionInternal(t, 8);
  }
  OPTION9(t) {
    return this.optionInternal(t, 9);
  }
  OR(t) {
    return this.orInternal(t, 0);
  }
  OR1(t) {
    return this.orInternal(t, 1);
  }
  OR2(t) {
    return this.orInternal(t, 2);
  }
  OR3(t) {
    return this.orInternal(t, 3);
  }
  OR4(t) {
    return this.orInternal(t, 4);
  }
  OR5(t) {
    return this.orInternal(t, 5);
  }
  OR6(t) {
    return this.orInternal(t, 6);
  }
  OR7(t) {
    return this.orInternal(t, 7);
  }
  OR8(t) {
    return this.orInternal(t, 8);
  }
  OR9(t) {
    return this.orInternal(t, 9);
  }
  MANY(t) {
    this.manyInternal(0, t);
  }
  MANY1(t) {
    this.manyInternal(1, t);
  }
  MANY2(t) {
    this.manyInternal(2, t);
  }
  MANY3(t) {
    this.manyInternal(3, t);
  }
  MANY4(t) {
    this.manyInternal(4, t);
  }
  MANY5(t) {
    this.manyInternal(5, t);
  }
  MANY6(t) {
    this.manyInternal(6, t);
  }
  MANY7(t) {
    this.manyInternal(7, t);
  }
  MANY8(t) {
    this.manyInternal(8, t);
  }
  MANY9(t) {
    this.manyInternal(9, t);
  }
  MANY_SEP(t) {
    this.manySepFirstInternal(0, t);
  }
  MANY_SEP1(t) {
    this.manySepFirstInternal(1, t);
  }
  MANY_SEP2(t) {
    this.manySepFirstInternal(2, t);
  }
  MANY_SEP3(t) {
    this.manySepFirstInternal(3, t);
  }
  MANY_SEP4(t) {
    this.manySepFirstInternal(4, t);
  }
  MANY_SEP5(t) {
    this.manySepFirstInternal(5, t);
  }
  MANY_SEP6(t) {
    this.manySepFirstInternal(6, t);
  }
  MANY_SEP7(t) {
    this.manySepFirstInternal(7, t);
  }
  MANY_SEP8(t) {
    this.manySepFirstInternal(8, t);
  }
  MANY_SEP9(t) {
    this.manySepFirstInternal(9, t);
  }
  AT_LEAST_ONE(t) {
    this.atLeastOneInternal(0, t);
  }
  AT_LEAST_ONE1(t) {
    return this.atLeastOneInternal(1, t);
  }
  AT_LEAST_ONE2(t) {
    this.atLeastOneInternal(2, t);
  }
  AT_LEAST_ONE3(t) {
    this.atLeastOneInternal(3, t);
  }
  AT_LEAST_ONE4(t) {
    this.atLeastOneInternal(4, t);
  }
  AT_LEAST_ONE5(t) {
    this.atLeastOneInternal(5, t);
  }
  AT_LEAST_ONE6(t) {
    this.atLeastOneInternal(6, t);
  }
  AT_LEAST_ONE7(t) {
    this.atLeastOneInternal(7, t);
  }
  AT_LEAST_ONE8(t) {
    this.atLeastOneInternal(8, t);
  }
  AT_LEAST_ONE9(t) {
    this.atLeastOneInternal(9, t);
  }
  AT_LEAST_ONE_SEP(t) {
    this.atLeastOneSepFirstInternal(0, t);
  }
  AT_LEAST_ONE_SEP1(t) {
    this.atLeastOneSepFirstInternal(1, t);
  }
  AT_LEAST_ONE_SEP2(t) {
    this.atLeastOneSepFirstInternal(2, t);
  }
  AT_LEAST_ONE_SEP3(t) {
    this.atLeastOneSepFirstInternal(3, t);
  }
  AT_LEAST_ONE_SEP4(t) {
    this.atLeastOneSepFirstInternal(4, t);
  }
  AT_LEAST_ONE_SEP5(t) {
    this.atLeastOneSepFirstInternal(5, t);
  }
  AT_LEAST_ONE_SEP6(t) {
    this.atLeastOneSepFirstInternal(6, t);
  }
  AT_LEAST_ONE_SEP7(t) {
    this.atLeastOneSepFirstInternal(7, t);
  }
  AT_LEAST_ONE_SEP8(t) {
    this.atLeastOneSepFirstInternal(8, t);
  }
  AT_LEAST_ONE_SEP9(t) {
    this.atLeastOneSepFirstInternal(9, t);
  }
  RULE(t, e, n = en) {
    if (it(this.definedRulesNames, t)) {
      const i = { message: ne.buildDuplicateRuleNameError({ topLevelRule: t, grammarName: this.className }), type: rt.DUPLICATE_RULE_NAME, ruleName: t };
      this.definitionErrors.push(i);
    }
    this.definedRulesNames.push(t);
    const r = this.defineRule(t, e, n);
    return this[t] = r, r;
  }
  OVERRIDE_RULE(t, e, n = en) {
    const r = function(o, s, a) {
      const c = [];
      let u;
      return it(s, o) || (u = `Invalid rule override, rule: ->${o}<- cannot be overridden in the grammar: ->${a}<-as it is not defined in any of the super grammars `, c.push({ message: u, type: rt.INVALID_RULE_OVERRIDE, ruleName: o })), c;
    }(t, this.definedRulesNames, this.className);
    this.definitionErrors = this.definitionErrors.concat(r);
    const i = this.defineRule(t, e, n);
    return this[t] = i, i;
  }
  BACKTRACK(t, e) {
    return function() {
      this.isBackTrackingStack.push(1);
      const n = this.saveRecogState();
      try {
        return t.apply(this, e), !0;
      } catch (r) {
        if (Qe(r)) return !1;
        throw r;
      } finally {
        this.reloadRecogState(n), this.isBackTrackingStack.pop();
      }
    };
  }
  getGAstProductions() {
    return this.gastProductionsCache;
  }
  getSerializedGastProductions() {
    return _(Z(this.gastProductionsCache), rn);
  }
}, class {
  initErrorHandler(t) {
    this._errors = [], this.errorMessageProvider = L(t, "errorMessageProvider") ? t.errorMessageProvider : Bt.errorMessageProvider;
  }
  SAVE_ERROR(t) {
    if (Qe(t)) return t.context = { ruleStack: this.getHumanReadableRuleStack(), ruleOccurrenceStack: tt(this.RULE_OCCURRENCE_STACK) }, this._errors.push(t), t;
    throw Error("Trying to save an Error which is not a RecognitionException");
  }
  get errors() {
    return tt(this._errors);
  }
  set errors(t) {
    this._errors = t;
  }
  raiseEarlyExitException(t, e, n) {
    const r = this.getCurrRuleFullName(), i = vr(t, this.getGAstProductions()[r], e, this.maxLookahead)[0], o = [];
    for (let a = 1; a <= this.maxLookahead; a++) o.push(this.LA(a));
    const s = this.errorMessageProvider.buildEarlyExitMessage({ expectedIterationPaths: i, actual: o, previous: this.LA(0), customUserDescription: n, ruleName: r });
    throw this.SAVE_ERROR(new iu(s, this.LA(1), this.LA(0)));
  }
  raiseNoAltException(t, e) {
    const n = this.getCurrRuleFullName(), r = zr(t, this.getGAstProductions()[n], this.maxLookahead), i = [];
    for (let a = 1; a <= this.maxLookahead; a++) i.push(this.LA(a));
    const o = this.LA(0), s = this.errorMessageProvider.buildNoViableAltMessage({ expectedPathsPerAlt: r, actual: i, previous: o, customUserDescription: e, ruleName: this.getCurrRuleFullName() });
    throw this.SAVE_ERROR(new nu(s, this.LA(1), o));
  }
}, class {
  initContentAssist() {
  }
  computeContentAssist(t, e) {
    const n = this.gastProductionsCache[t];
    if (zt(n)) throw Error(`Rule ->${t}<- does not exist in this grammar.`);
    return gs([n], e, this.tokenMatcher, this.maxLookahead);
  }
  getNextPossibleTokenTypes(t) {
    const e = Rt(t.ruleStack), n = this.getGAstProductions()[e];
    return new Wc(n, t).startWalking();
  }
}, class {
  initGastRecorder(t) {
    this.recordingProdStack = [], this.RECORDING_PHASE = !1;
  }
  enableRecording() {
    this.RECORDING_PHASE = !0, this.TRACE_INIT("Enable Recording", () => {
      for (let t = 0; t < 10; t++) {
        const e = t > 0 ? t : "";
        this[`CONSUME${e}`] = function(n, r) {
          return this.consumeInternalRecord(n, t, r);
        }, this[`SUBRULE${e}`] = function(n, r) {
          return this.subruleInternalRecord(n, t, r);
        }, this[`OPTION${e}`] = function(n) {
          return this.optionInternalRecord(n, t);
        }, this[`OR${e}`] = function(n) {
          return this.orInternalRecord(n, t);
        }, this[`MANY${e}`] = function(n) {
          this.manyInternalRecord(t, n);
        }, this[`MANY_SEP${e}`] = function(n) {
          this.manySepFirstInternalRecord(t, n);
        }, this[`AT_LEAST_ONE${e}`] = function(n) {
          this.atLeastOneInternalRecord(t, n);
        }, this[`AT_LEAST_ONE_SEP${e}`] = function(n) {
          this.atLeastOneSepFirstInternalRecord(t, n);
        };
      }
      this.consume = function(t, e, n) {
        return this.consumeInternalRecord(e, t, n);
      }, this.subrule = function(t, e, n) {
        return this.subruleInternalRecord(e, t, n);
      }, this.option = function(t, e) {
        return this.optionInternalRecord(e, t);
      }, this.or = function(t, e) {
        return this.orInternalRecord(e, t);
      }, this.many = function(t, e) {
        this.manyInternalRecord(t, e);
      }, this.atLeastOne = function(t, e) {
        this.atLeastOneInternalRecord(t, e);
      }, this.ACTION = this.ACTION_RECORD, this.BACKTRACK = this.BACKTRACK_RECORD, this.LA = this.LA_RECORD;
    });
  }
  disableRecording() {
    this.RECORDING_PHASE = !1, this.TRACE_INIT("Deleting Recording methods", () => {
      const t = this;
      for (let e = 0; e < 10; e++) {
        const n = e > 0 ? e : "";
        delete t[`CONSUME${n}`], delete t[`SUBRULE${n}`], delete t[`OPTION${n}`], delete t[`OR${n}`], delete t[`MANY${n}`], delete t[`MANY_SEP${n}`], delete t[`AT_LEAST_ONE${n}`], delete t[`AT_LEAST_ONE_SEP${n}`];
      }
      delete t.consume, delete t.subrule, delete t.option, delete t.or, delete t.many, delete t.atLeastOne, delete t.ACTION, delete t.BACKTRACK, delete t.LA;
    });
  }
  ACTION_RECORD(t) {
  }
  BACKTRACK_RECORD(t, e) {
    return () => !0;
  }
  LA_RECORD(t) {
    return cn;
  }
  topLevelRuleRecord(t, e) {
    try {
      const n = new Ee({ definition: [], name: t });
      return n.name = t, this.recordingProdStack.push(n), e.call(this), this.recordingProdStack.pop(), n;
    } catch (n) {
      if (n.KNOWN_RECORDER_ERROR !== !0) try {
        n.message = n.message + `
	 This error was thrown during the "grammar recording phase" For more info see:
	https://chevrotain.io/docs/guide/internals.html#grammar-recording`;
      } catch {
        throw n;
      }
      throw n;
    }
  }
  optionInternalRecord(t, e) {
    return ye.call(this, ct, t, e);
  }
  atLeastOneInternalRecord(t, e) {
    ye.call(this, wt, e, t);
  }
  atLeastOneSepFirstInternalRecord(t, e) {
    ye.call(this, Mt, e, t, oo);
  }
  manyInternalRecord(t, e) {
    ye.call(this, Q, e, t);
  }
  manySepFirstInternalRecord(t, e) {
    ye.call(this, St, e, t, oo);
  }
  orInternalRecord(t, e) {
    return hu.call(this, t, e);
  }
  subruleInternalRecord(t, e, n) {
    if (An(e), !t || L(t, "ruleName") === !1) {
      const s = new Error(`<SUBRULE${ao(e)}> argument is invalid expecting a Parser method reference but got: <${JSON.stringify(t)}>
 inside top level rule: <${this.recordingProdStack[0].name}>`);
      throw s.KNOWN_RECORDER_ERROR = !0, s;
    }
    const r = pe(this.recordingProdStack), i = t.ruleName, o = new dt({ idx: e, nonTerminalName: i, label: n?.LABEL, referencedRule: void 0 });
    return r.definition.push(o), this.outputCst ? lu : Pn;
  }
  consumeInternalRecord(t, e, n) {
    if (An(e), !ps(t)) {
      const o = new Error(`<CONSUME${ao(e)}> argument is invalid expecting a TokenType reference but got: <${JSON.stringify(t)}>
 inside top level rule: <${this.recordingProdStack[0].name}>`);
      throw o.KNOWN_RECORDER_ERROR = !0, o;
    }
    const r = pe(this.recordingProdStack), i = new K({ idx: e, terminalType: t, label: n?.LABEL });
    return r.definition.push(i), Cs;
  }
}, class {
  initPerformanceTracer(t) {
    if (L(t, "traceInitPerf")) {
      const e = t.traceInitPerf, n = typeof e == "number";
      this.traceInitMaxIdent = n ? e : 1 / 0, this.traceInitPerf = n ? e > 0 : e;
    } else this.traceInitMaxIdent = 0, this.traceInitPerf = Bt.traceInitPerf;
    this.traceInitIndent = -1;
  }
  TRACE_INIT(t, e) {
    if (this.traceInitPerf === !0) {
      this.traceInitIndent++;
      const n = new Array(this.traceInitIndent + 1).join("	");
      this.traceInitIndent < this.traceInitMaxIdent && console.log(`${n}--> <${t}>`);
      const { time: r, value: i } = os(e), o = r > 10 ? console.warn : console.log;
      return this.traceInitIndent < this.traceInitMaxIdent && o(`${n}<-- <${t}> time: ${r}ms`), this.traceInitIndent--, i;
    }
    return e();
  }
}].forEach((t) => {
  const e = t.prototype;
  Object.getOwnPropertyNames(e).forEach((n) => {
    if (n === "constructor") return;
    const r = Object.getOwnPropertyDescriptor(e, n);
    r && (r.get || r.set) ? Object.defineProperty(Zn.prototype, n, r) : Zn.prototype[n] = t.prototype[n];
  });
});
class fu extends De {
  constructor(e, n = Bt) {
    const r = tt(n);
    r.outputCst = !1, super(e, r);
  }
}
const du = P({ name: "WhiteSpace", pattern: /\s+/, group: st.SKIPPED }), ks = P({ name: "String", pattern: /"(""|[^"])*"/ }), pu = P({ name: "SingleQuotedString", pattern: /'(''|[^'])*'/ }), mu = P({ name: "SheetQuoted", pattern: /'((?![\\/[\]*?:]).)+?'!/ }), Eu = P({ name: "FunctionToken", pattern: /[A-Za-z_]+[A-Za-z_0-9.]*\(/ }), bs = P({ name: "NamedTableReference", pattern: /[A-Za-z_]+[A-Za-z_0-9.]*\[/ }), gu = P({ name: "BracketedString", pattern: /\[([^[\]]*)\]/, longer_alt: [bs, ks] }), Ps = P({ name: "LiteralError", pattern: /#PARSE!|#NULL!|#DIV\/0!|#VALUE!|#NUM!|#FIELD!|#N\/A|#GETTING_DATA|#SPILL!|#CONNECT!|#BLOCKED!|#UNKNOWN!|#FIELD!|#CALC!|#BUSY!|#PYTHON!|#TIMEOUT!/ }), ws = P({ name: "RefError", pattern: /#REF!|#NAME\?/ }), Tu = P({ name: "Sheet", pattern: /[A-Za-z_.\d\u007F-\uFFFF]+!/ }), Au = /^[a-zA-Z_][a-zA-Z0-9_.?]*:?/, wn = P({ name: "Name", pattern: { exec: (t, e) => {
  try {
    const n = Au.exec(t.substring(e));
    if (n) {
      const r = n[0];
      if (r.endsWith(":")) {
        const i = r.length;
        return r[i - 2] === "." ? [r.substring(0, i - 2)] : [r.substring(0, i - 1)];
      }
      return [r];
    }
  } catch (n) {
    console.warn("Error parsing name", n);
  }
  return null;
} }, line_breaks: !1, start_chars_hint: (() => {
  const t = [];
  for (let e = 65; e <= 90; e++) t.push(e);
  for (let e = 97; e <= 122; e++) t.push(e);
  for (let e = 48; e <= 57; e++) t.push(e);
  return t;
})() }), Iu = P({ name: "Cell", pattern: /[$]?[A-Za-z]{1,3}[$]?[1-9][0-9]*/, longer_alt: wn }), vu = P({ name: "Column", pattern: /[$]?[A-Za-z]{1,3}/, longer_alt: wn }), Nu = P({ name: "AbsRow", pattern: /[$][0-9]+/, longer_alt: wn }), yu = P({ name: "NumberToken", pattern: /[0-9]+[.]?[0-9]*([eE][+-][0-9]+)?/ }), Ru = P({ name: "Boolean", pattern: /TRUE|FALSE/i }), Ou = P({ name: "Comma", pattern: /,/ }), Su = P({ name: "RangeUnion", pattern: /:/ }), _u = P({ name: "RangeTrimFull", pattern: /\.:\./ }), Lu = P({ name: "RangeTrimLeading", pattern: /\.:/ }), xu = P({ name: "RangeTrimTrailing", pattern: /:\./ }), Cu = P({ name: "Semicolon", pattern: /;/ }), ku = P({ name: "OpenParen", pattern: /\(/ }), bu = P({ name: "CloseParen", pattern: /\)/ }), Pu = P({ name: "OpenSquareParen", pattern: /\[/ }), wu = P({ name: "CloseSquareParen", pattern: /]/ });
P({ name: "exclamationMark", pattern: /!/ });
const Mu = P({ name: "OpenCurlyParen", pattern: /{/ }), Uu = P({ name: "CloseCurlyParen", pattern: /}/ }), Fu = P({ name: "QuoteS", pattern: /'/ }), co = P({ name: "MulOp", pattern: /\*/ }), Du = P({ name: "PlusOp", pattern: /\+/ }), ju = P({ name: "DivOp", pattern: /\// }), Bu = P({ name: "MinOp", pattern: /-/ }), $u = P({ name: "ImplicitIntersectOp", pattern: /@/ }), Wu = P({ name: "ConcatOp", pattern: /&/ }), Gu = P({ name: "ExOp", pattern: /\^/ }), zu = P({ name: "PercentOp", pattern: /%/ }), Ms = P({ name: "TableSpecifier", pattern: /#(All|Data|Headers|Totals|This Row)/i }), Ku = P({ name: "ArrayAnchorOp", pattern: /#/, longer_alt: [Ms, Ps, ws] }), Vu = P({ name: "GtOp", pattern: />/ }), Hu = P({ name: "EqOp", pattern: /=/ }), Yu = P({ name: "LtOp", pattern: /</ }), Us = [du, ks, mu, pu, Eu, bs, gu, Ps, ws, Tu, Iu, Ru, vu, Nu, Ms, Ku, $u, wn, yu, Ou, _u, Lu, xu, Su, Cu, ku, bu, Pu, wu, Mu, Uu, Fu, co, Du, ju, Bu, Wu, Gu, co, zu, P({ name: "NeqOp", pattern: /<>/ }), P({ name: "GteOp", pattern: />=/ }), P({ name: "LteOp", pattern: /<=/ }), Vu, Hu, Yu], Xu = new st(Us, { ensureOptimizations: !0 }), Vr = {};
Us.forEach((t) => {
  Vr[t.name] = t;
});
const Xt = { boolean: 3, string: 2, number: 1 }, qu = (t, e) => {
  let n = t + e;
  return n = Math.abs(n) < 99e-14 ? 0 : n, isFinite(n) ? n : Number.NaN;
}, Zu = (t, e) => {
  let n = t - e;
  return n = Math.abs(n) < 99e-14 ? 0 : n, isFinite(n) ? n : Number.NaN;
}, Fs = (t, e) => {
  let n = t * e;
  return n = Math.abs(n) < 99e-14 ? 0 : n, isFinite(n) ? n : Number.NaN;
}, Ds = (t, e) => {
  if (e === 0) return 1 / 0;
  let n = t / e;
  return n = Math.abs(n) < 99e-14 ? 0 : n, isFinite(n) ? n : Number.NaN;
}, Qu = (t, e) => {
  const n = t ** e;
  return isFinite(n) ? n : Number.NaN;
}, Ju = (t = "", e = "") => (t === null && (t = ""), e === null && (e = ""), typeof t == "boolean" && (t = t ? "TRUE" : "FALSE"), typeof e == "boolean" && (e = e ? "TRUE" : "FALSE"), "" + t + e), tl = (t = null, e = null) => typeof t == typeof e && t === e, el = (t = null, e = null) => typeof t != typeof e || t !== e, nl = (t = null, e = null) => {
  const n = typeof t, r = typeof e;
  return n === r ? t > e : Xt[n] > Xt[r];
}, rl = (t = null, e = null) => {
  const n = typeof t, r = typeof e;
  return n === r ? t >= e : Xt[n] >= Xt[r];
}, il = (t = null, e = null) => {
  const n = typeof t, r = typeof e;
  return n === r ? t < e : Xt[n] < Xt[r];
}, ol = (t = null, e = null) => {
  const n = typeof t, r = typeof e;
  return n === r ? t <= e : Xt[n] <= Xt[r];
}, sl = { type: re.Number, coerce: !0, includeBoolean: !0, includeMistyped: !0, mismatchFill: U.BuiltIn.NA }, al = { type: re.String, coerce: !0, includeMistyped: !0, mismatchFill: U.BuiltIn.NA }, js = { type: null, coerce: !0, includeMistyped: !0, mismatchFill: U.BuiltIn.NA }, le = (t, e, n, r) => {
  if (e !== null && e.colStart !== void 0 && (e = t.getValueAt(e.rowStart, e.colStart)), n !== null && n.colStart !== void 0 && (n = t.getValueAt(n.rowStart, n.colStart)), typeof e == "number" && typeof n == "number") return r(e, n);
  let i, o;
  return e?.isIRange ? i = e : n?.isIRange && (o = n), !i && !o ? (e = Pe(e, we(e, !0), re.Number, !0, !1), n = Pe(n, we(n, !0), re.Number, !0, !1), e instanceof U.Value ? e : n instanceof U.Value ? n : r(e, n)) : (i || (i = t.getRange(e)), i.broadcast(n, r, sl).fillEmpty(0));
}, ce = (t, e, n, r) => {
  let i, o;
  return e !== null && e.colStart !== void 0 && (e = t.getValueAt(e.rowStart, e.colStart)), n !== null && n.colStart !== void 0 && (n = t.getValueAt(n.rowStart, n.colStart)), e?.isIRange ? (i = e, o = n) : n?.isIRange && (i = n, o = e), i ? i.broadcast(o, r, js) : r(e, n);
}, uo = (t, e) => {
  e == null && (e = 0);
  let n, r = 1;
  if (t === "+") return e;
  if (t !== "-") throw new U.Value(`Unrecognized prefix: ${t}`);
  return r = -r, e?.isIRange && (n = e), n ? n.broadcast(r, Fs, js) : typeof (e = Pe(e, we(e, !0), re.Number)) != "number" || isNaN(e) ? U.BuiltIn.Value : e * r;
}, Re = (t, e, n, r) => {
  if (!e) return U.BuiltIn.Ref;
  if (e.isIReferenceRange && (e = e.getCoords()), e.colStart === void 0) return U.BuiltIn.Ref;
  if (n.isIReferenceRange && (n = n.getCoords()), n.colStart === void 0) return U.BuiltIn.Ref;
  const i = r(e, n);
  return i ? t.getReference(i) : U.BuiltIn.Null;
}, cl = { "+": (t, e, n) => le(t, e, n, qu), "-": (t, e, n) => le(t, e, n, Zu), "*": (t, e, n) => le(t, e, n, Fs), "/": (t, e, n) => le(t, e, n, Ds), "^": (t, e, n) => le(t, e, n, Qu), " ": (t, e, n, r) => Re(t, e, n, Vt.intersectRanges), ":": (t, e, n, r) => Re(t, e, n, Vt.unionRanges), ".:.": (t, e, n, r) => {
  const i = Re(t, e, n, Vt.unionRanges);
  return t.getFunction("TRIMRANGE").execute(i, 3, 3);
}, ".:": (t, e, n, r) => {
  const i = Re(t, e, n, Vt.unionRanges);
  return t.getFunction("TRIMRANGE").execute(i, 1, 1);
}, ":.": (t, e, n, r) => {
  const i = Re(t, e, n, Vt.unionRanges);
  return t.getFunction("TRIMRANGE").execute(i, 2, 2);
}, "&": (t, e, n) => ((r, i, o, s) => {
  if (i !== null && i.colStart !== void 0 && (i = r.getValueAt(i.rowStart, i.colStart)), o !== null && o.colStart !== void 0 && (o = r.getValueAt(o.rowStart, o.colStart)), typeof i == "string" && typeof o == "string") return s(i, o);
  let a, c;
  return i?.isIRange ? a = i : o?.isIRange && (c = o), a || c ? (a || (a = r.getRange(i)), a.broadcast(o, s, al)) : s(i = Pe(i, we(i, !0), re.String), o = Pe(o, we(o, !0), re.String));
})(t, e, n, Ju), "=": (t, e, n) => ce(t, e, n, tl), "<>": (t, e, n) => ce(t, e, n, el), ">": (t, e, n) => ce(t, e, n, nl), "<": (t, e, n) => ce(t, e, n, il), ">=": (t, e, n) => ce(t, e, n, rl), "<=": (t, e, n) => ce(t, e, n, ol) }, ul = { "-": (t, e) => uo("-", e), "+": (t, e) => uo("+", e), "@": (t, e) => {
  if (!e || !e.isIReferenceRange) return e;
  const n = e.getCoords(), r = e, i = t.getPosition(), o = r.getHeight(), s = r.getWidth();
  if (s > 1 && o > 1) return U.BuiltIn.Value;
  if (o > 1) {
    const a = i.rowIndex - n.rowStart;
    if (a >= 0 && a < o) return r.getValueAt(a, 0);
  } else {
    if (!(s > 1)) return r.getValueAt(0, 0);
    {
      const a = i.colIndex - n.colStart;
      if (a >= 0 && a < s) return r.getValueAt(0, a);
    }
  }
  return U.BuiltIn.Value;
} }, ll = { "%": (t, e) => le(t, e, 100, Ds), "#": (t, e) => t.getSpillAt(e.rowStart, e.colStart) || U.BuiltIn.Ref };
function lo(t) {
  const e = (t = t.toUpperCase()).length;
  let n = 0;
  for (let r = 0; r < e; r++) {
    const i = t.charCodeAt(r);
    isNaN(i) || (n += (i - 64) * 26 ** (e - r - 1));
  }
  return n;
}
function Qn(t) {
  return { type: "cell", value: Object.freeze({ colIndex: t.colIndex, rowIndex: t.rowIndex, $colIndex: t.$colIndex || !1, $rowIndex: t.$rowIndex || !1 }), inputs: null, isReference: !0 };
}
function ho(t, e) {
  const n = t.startsWith("$");
  n && (t = t.substring(1));
  let r = parseInt(t) - 1;
  return n || r === Number.MIN_SAFE_INTEGER || (r -= e.colIndex), { type: "cell", value: Object.freeze({ colIndex: Number.MIN_SAFE_INTEGER, $colIndex: !1, rowIndex: r, $rowIndex: n }), inputs: null, isReference: !0 };
}
function fo(t, e) {
  return { type: "function", value: t = t.toUpperCase(), inputs: e };
}
function Jn(t, e) {
  return { type: "tableReference", value: t, inputs: e };
}
function tr(t) {
  return { type: "tableSpecifier", value: t, inputs: null, isReference: !0 };
}
function Rr(t, e, n, r = !1) {
  const i = { type: "infix", value: t, inputs: [e, n] };
  return r && (i.isReference = !0), i;
}
function er(t, e, n = !1) {
  const r = { type: "postfix", value: t, inputs: [e] };
  return n && (r.isReference = !0), r;
}
function _e(t, e, n = !1) {
  const r = { type: "prefix", value: t, inputs: [e] };
  return n && (r.isReference = !0), r;
}
function nr(t) {
  return { type: "named", value: t, inputs: null, isReference: !0 };
}
function po(t) {
  return { type: "number", value: Number(t), isLiteral: !0 };
}
function rr(t) {
  let e = t;
  const n = t && t.length > 1 && t[0] === '"' && t[t.length - 1] === '"';
  return n && (e = t.substring(1, t.length - 1)), { type: n ? "quotedString" : "string", value: e, isLiteral: !0 };
}
function mo(t) {
  return { type: "boolean", value: t === "TRUE" || t.toUpperCase() === "TRUE", isLiteral: !0 };
}
function Eo(t) {
  return { type: "error", value: U.getBuiltInByLabel(t.toUpperCase()), isLiteral: !0 };
}
function In(t) {
  return { type: "error", value: t ? U.getBuiltInByLabel(t.toUpperCase()) : U.BuiltIn.Ref, inputs: null, isReference: !0 };
}
function je(t, e) {
  return function r(i, o) {
    const s = i.inputs;
    let a;
    if (s) {
      const l = s.length;
      for (let h = 0; h < l; h++) {
        const f = s[h], d = r(f, i);
        d !== f && (a || (a = [...s]), a[h] = d);
      }
    }
    const c = a ? { ...i, inputs: a } : i, u = e(c, o);
    return u === void 0 ? c : u;
  }(t, void 0) || this;
}
function un(t, e) {
  let n = 0, r = je(t, (p) => {
    const A = { ...p };
    return A.evalIndex = n++, A;
  });
  const i = new Array(n), o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map();
  let a;
  const c = /* @__PURE__ */ new Map(), u = [], l = [];
  r = je(r, (p, A) => {
    const O = p.type, g = p.evalIndex;
    if (i[g] = null, p.isReference) {
      const R = p, N = { node: p, index: c.size, op: null, value: null, inputs: null };
      if (c.set(R, N), O === "cell") {
        const v = R.value;
        return v.$colIndex && (N.hasHorizontalAbs = !0), v.$rowIndex && (N.hasVerticalAbs = !0), N.value = s.size, s.set(R, s.size), o.add(N), p.refIndex = l.length, void l.push(N.index);
      }
      if (O === "infix" || O === "prefix" || O === "postfix" || O === "spill") {
        const v = R.inputs, y = v.length, M = p.value;
        N.op = M;
        const w = new Array(y);
        N.inputs = w;
        for (let F = 0; F < y; F++) {
          const $ = v[F], x = c.get($);
          x && (x.hasHorizontalAbs && (N.hasHorizontalAbs = !0), x.hasVerticalAbs && (N.hasVerticalAbs = !0)), w[F] = x ? x.index : -1, o.delete(x);
        }
        if (o.add(N), Bs.includes(M)) {
          const F = v[0], $ = !!F && F.type === "cell", x = v[1], C = !!x && x.type === "cell";
          $ && C && (l.splice(x.refIndex, 1), x.refIndex = F.refIndex, p.refIndex = F.refIndex, l[F.refIndex] = N.index);
        } else M === "#" && (p.refIndex = v[0].refIndex);
        return void u.push(p);
      }
      if (O === "error" || O === "named") {
        a || (a = /* @__PURE__ */ new Map());
        const v = R.value;
        let y = a.get(v);
        return N.op = O, y === void 0 && (y = a.size, a.set(v, y)), N.value = y, o.add(N), p.refIndex = l.length, void l.push(N.index);
      }
      O === "tableReference" && (N.op = O), O === "tableSpecifier" && (N.op = O), O === "structuredArg" && (N.op = O);
    } else if (A && A.isReference) {
      const R = p, N = { node: p, index: c.size, op: "function", value: p.value, inputs: null };
      c.set(R, N);
    }
    if (p.isLiteral) if (O !== "array") i[g] = p.value;
    else {
      const R = p.value, N = R.length, v = new Array(N);
      for (let y = 0; y < N; y++) {
        const M = R[y].value, w = M.length, F = new Array(w);
        for (let $ = 0; $ < w; $++) {
          const x = M[$];
          let C = x.value;
          if (x.type === "prefix") {
            const j = x.value;
            C = x.inputs[0].value, j === "-" && (C = -C);
          }
          F[$] = C;
        }
        v[y] = F;
      }
      i[g] = $s(v);
    }
    else {
      if (O !== "empty") return u.push(p), p;
      i[g] = void 0;
    }
  });
  const h = new Array(s.size);
  s.forEach((p, A) => {
    const O = A.value, g = O.colIndex, R = O.rowIndex, N = O.$colIndex, v = O.$rowIndex, y = { colStart: g, rowStart: R, colEnd: g, rowEnd: R, $colStart: N, $rowStart: v, $colEnd: N, $rowEnd: v };
    g === Number.MIN_SAFE_INTEGER && (y.colEnd = Number.MAX_SAFE_INTEGER), R === Number.MIN_SAFE_INTEGER && (y.rowEnd = Number.MAX_SAFE_INTEGER), O.sheetName && (y.sheetName = O.sheetName), h[p] = y;
  });
  const f = h.length, d = new Array(f);
  for (let p = 0; p < f; p++) d[p] = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0, sheetName: null };
  const E = new Array(c.size);
  let I;
  c.forEach((p) => {
    E[p.index] = p;
  }), a && (I = [], a.forEach((p, A) => {
    I.push(A);
  }));
  const S = [];
  o.forEach((p) => {
    S.push(p.index);
  });
  const T = u.length;
  for (let p = 0; p < T; p++) {
    const A = u[p], O = A.type;
    if (O === "infix") {
      const g = A.value;
      A.fn = cl[g];
    } else if (O === "prefix") {
      const g = A.value;
      A.fn = ul[g];
    } else if (O === "postfix") {
      const g = A.value;
      A.fn = ll[g];
    }
  }
  const m = function(p) {
    const A = [], O = (N, v) => {
      const y = { type: N.type, value: N.value };
      N.evalIndex !== void 0 && (y.evalIndex = N.evalIndex), N.refIndex !== void 0 && (y.refIndex = N.refIndex), v && (y.ctx = v), A.push(y);
    }, g = (N, v, y, M) => {
      if (v == null || A.length > 1 && N === "whitespace" && A[A.length - 1].type === "whitespace") return;
      const w = { type: N, value: v };
      y && (w.ctx = y), M !== void 0 && (w.evalIndex = M), A.push(w);
    };
    (function N(v, y, M) {
      const w = v.evalIndex ?? M ?? 0, F = v.type, $ = (x, C, j) => {
        if (!x) return;
        const Y = x.length;
        for (let B = 0; B < Y; B++) N(x[B], C, j), B < Y - 1 && g("comma", ",", C);
      };
      if (v.isLiteral) {
        if (g("whitespace", v.wsBefore, y), F === "array") {
          g("type", "{", y);
          const x = v.value, C = x.length;
          for (let j = 0; j < C; j++) {
            const Y = x[j], B = Y.value, et = B.length;
            for (let Zt = 0; Zt < et; Zt++) {
              const Te = B[Zt];
              g("whitespace", Te.wsBefore, y), N(Te, y, w), g("whitespace", Te.wsAfter, y), Zt < et - 1 && g("comma", ",", y);
            }
            j < C - 1 && (g("whitespace", Y.wsBefore, y), g("comma", ";", y), g("whitespace", Y.wsAfter, y));
          }
          v.error || g("type", "}", y);
        } else F === "quotedString" && (v = { type: F, value: '"' + v.value + '"' }), O(v, y);
        g("whitespace", v.wsAfter, y);
      } else if (F === "infix") N(v.inputs[0], y, w), g("whitespace", v.wsBefore, y), O(v, y), g("whitespace", v.wsAfter, y), N(v.inputs[1], y, w);
      else if (F === "prefix") g("whitespace", v.wsBefore, y), O(v, y), g("whitespace", v.wsAfter, y), N(v.inputs[0], y, w);
      else if (F === "postfix") N(v.inputs[0], y, w), g("whitespace", v.wsBefore, y), O(v, y), g("whitespace", v.wsAfter, y);
      else {
        g("whitespace", v.wsBefore, y);
        const x = v.inputs;
        switch (F) {
          case "function":
            O(v, y);
            const C = { name: String(v.value), argIndex: -1 };
            if (g("paren", "(", C, v.evalIndex), x) {
              const Y = x.length;
              for (let B = 0; B < Y; B++) {
                const et = { ...C, argIndex: B };
                N(x[B], et, w), B < Y - 1 && g("comma", ",", et);
              }
            }
            v.error || g("paren", ")", C, v.evalIndex);
            break;
          case "cell":
            O(v, y);
            break;
          case "paren":
            g(F, "(", y, w), $(x, y, w), v.error || g(F, ")", y, w);
            break;
          case "squareParen":
            g(F, "[", y, w), $(x, y, w), v.error || g(F, "]", y, w);
            break;
          case "tableReference":
            O(v, y);
            const j = { name: String(v.value), argIndex: -1 };
            if (g("paren", "[", j), x) {
              const Y = x.length;
              for (let B = 0; B < Y; B++) {
                const et = { ...j, argIndex: B };
                N(x[B], et, w), B < Y - 1 && g("comma", ",", et);
              }
            }
            v.error || g("paren", "]", j);
            break;
          default:
            v.value !== void 0 && O(v, y), x && x.forEach((Y) => N(Y, y, w));
        }
        g("whitespace", v.wsAfter, y);
      }
    })(p);
    const R = A.length;
    for (let N = 0; N < R; N++) {
      const v = A[N];
      if (v.type === "whitespace" && v.evalIndex === void 0) {
        const y = A[N + 1];
        y && y.evalIndex !== void 0 && (v.evalIndex = y.evalIndex);
      }
    }
    return A;
  }(r);
  return { ast: r, evaluations: i, executions: u, precedentsAbsolute: d, precedentsExecute: E, precedentsNamed: I, precedentsRelative: h, precedentsRoot: S, references: l, tokens: m, error: e };
}
function go(t, e) {
  let n, r = -1, i = "";
  Number.isSafeInteger(t.previousToken?.startLine) ? (r = t.previousToken.startLine, n = t.previousToken.endColumn + 1) : Number.isSafeInteger(t.token?.startLine) && (r = t.token.startLine, n = t.token.startColumn), r !== -1 ? (i += `
` + e.split(`
`)[r - 1] + `
`, i += Array(n - 1).fill(" ").join("") + `^
`, i += `Error at position ${r}:${n}
` + t.message, t.errorLocation = { line: r, column: n }) : i = e + `
` + t.message;
  const o = new U.Parse(i);
  return o.details = t, o;
}
const ir = function(t, e) {
  return e.wsBefore && (t.wsBefore = e.wsBefore), e.wsAfter && (t.wsAfter = e.wsAfter), e.image && (t.image = e.image), t;
}, hl = "_XLFN.", To = Object.freeze([[":", ".:.", ".:", , ":."], ["^"], ["*", "/"], ["+", "-"], ["&"], ["<", ">", "=", "<>", "<=", ">="]]), Bs = Object.freeze([":", ".:.", ".:", , ":."]), fl = Object.freeze([":", " ", ".:.", ".:", , ":."]), dl = Object.freeze(["@"]), pl = Object.freeze(["#"]), or = Object.freeze(fl.concat(dl).concat(pl)), { String: Ao, SheetQuoted: ml, SingleQuotedString: El, FunctionToken: gl, NamedTableReference: Tl, LiteralError: Io, RefError: vo, Cell: Al, Sheet: Il, Name: No, NumberToken: yo, Boolean: Ro, Column: vl, AbsRow: Nl, ImplicitIntersectOp: sr, Comma: ue, RangeUnion: yl, RangeTrimFull: Rl, RangeTrimLeading: Ol, RangeTrimTrailing: Sl, Semicolon: _l, OpenParen: Ll, CloseParen: ar, OpenSquareParen: Oo, CloseSquareParen: So, OpenCurlyParen: xl, CloseCurlyParen: Cl, MulOp: kl, PlusOp: cr, DivOp: bl, MinOp: ur, ConcatOp: Pl, ExOp: wl, PercentOp: Ml, ArrayAnchorOp: _o, TableSpecifier: Ul, BracketedString: Lo, NeqOp: Fl, GteOp: Dl, LteOp: jl, GtOp: Bl, EqOp: $l, LtOp: Wl } = Vr;
class Gl extends fu {
  constructor() {
    super(Vr, { nodeLocationTracking: "full", maxLookahead: 1, skipValidations: !0, recoveryEnabled: !0 }), this.position = { colIndex: 0, rowIndex: 0 }, this.astErrors = [];
    const e = this, n = (r, i, o) => {
      let s;
      e.CONSUME(i);
      const a = e.getLexerPosition();
      s = e.ACTION(() => (s = { type: r, value: null, inputs: null }, this._ensureWhitespace(s, a, !0)));
      const c = [], u = e.SUBRULE(e.intersectOp);
      u && c.push(u);
      const l = e.SUBRULE(e.group), h = e.OPTION(() => this.CONSUME(o));
      return s = e.ACTION(() => {
        if (l) for (let f = 0; f < l.length; f++) c.push(l[f]);
        return s && (h || this._reportError(s, "Missing closing parenthesis", a), s.inputs = c), this._ensureWhitespace(s, e.getLexerPosition(), !1, !0);
      }), s;
    };
    e.RULE("infixOp", () => {
      const r = [], i = [e.SUBRULE(e.postfixOp)];
      return e.MANY(() => {
        const o = e.OR(e.c1 || (e.c1 = [{ ALT: () => e.CONSUME(yl).image }, { ALT: () => e.CONSUME(cr).image }, { ALT: () => e.CONSUME(ur).image }, { ALT: () => e.CONSUME(kl).image }, { ALT: () => e.CONSUME(bl).image }, { ALT: () => e.CONSUME(wl).image }, { ALT: () => e.CONSUME(Pl).image }, { ALT: () => e.CONSUME(Bl).image }, { ALT: () => e.CONSUME($l).image }, { ALT: () => e.CONSUME(Wl).image }, { ALT: () => e.CONSUME(Fl).image }, { ALT: () => e.CONSUME(Dl).image }, { ALT: () => e.CONSUME(jl).image }, { ALT: () => e.CONSUME(Rl).image }, { ALT: () => e.CONSUME(Ol).image }, { ALT: () => e.CONSUME(Sl).image }]));
        r.push([o, e.getLexerPosition(), or.includes(o)]), i.push(e.SUBRULE2(e.postfixOp));
      }), e.ACTION(() => {
        let o = r.length;
        const s = To.length;
        for (let a = 0; o > 0 && a < s; a++) {
          const c = To[a];
          let u = r.length;
          for (let l = 0; l < u; l++) {
            const h = r[l], f = h[0];
            if (!c.includes(f)) continue;
            let d = Rr(f, i[l], i[l + 1], h[2]);
            d = this._ensureWhitespace(d, h[1]), r.splice(l, 1), i.splice(l, 2, d), l--, u--, o--;
          }
        }
      }), i[0];
    }), e.RULE("plusMinusOp", () => e.OR([{ ALT: () => e.CONSUME(cr).image }, { ALT: () => e.CONSUME(ur).image }])), e.RULE("postfixOp", () => {
      let r = e.SUBRULE(e.prefixOp);
      const i = [];
      return e.MANY(() => {
        const o = e.OR([{ ALT: () => e.CONSUME(Ml).image }, { ALT: () => e.CONSUME(_o).image }]);
        e.ACTION(() => {
          i.push([o, e.getLexerPosition()]);
        });
      }), e.ACTION(() => {
        const o = i.length;
        if (o !== 0) for (let s = 0; s < o; s++) {
          const a = i[s], c = a[0], u = a[1], l = or.includes(c);
          r = er(c, r, l), r = this._ensureWhitespace(r, u);
        }
      }), r;
    }), e.RULE("prefixOp", () => {
      const r = [];
      e.MANY(() => {
        const o = e.OR([{ ALT: () => e.CONSUME(cr).image }, { ALT: () => e.CONSUME(ur).image }, { ALT: () => e.CONSUME(sr).image }]);
        e.ACTION(() => {
          r.push([o, e.getLexerPosition()]);
        });
      });
      let i = e.SUBRULE(e.formula);
      return e.ACTION(() => {
        const o = r.length;
        if (o !== 0) for (let s = o - 1; s >= 0; s--) {
          const a = r[s], c = a[0], u = a[1], l = or.includes(c);
          i = _e(c, i, l), i = this._ensureWhitespace(i, u);
        }
      }), i;
    }), e.RULE("intersectOp", () => {
      const r = [e.SUBRULE(e.infixOp)];
      return e.MANY(() => {
        e.OPTION({ GATE: () => {
          const i = e.LA(0);
          return e.LA(1).startOffset > i.endOffset + 1;
        }, DEF: () => {
          r.push(e.SUBRULE3(e.infixOp));
        } });
      }), e.ACTION(() => {
        for (; r.length > 1; ) {
          let i = r.length - 1;
          for (let o = 0; o < i; o++) {
            const s = r[o], a = r[o + 1], c = Rr(" ", s, a, !0);
            if (delete s.wsAfter, a.wsBefore) {
              const u = a.wsBefore.slice(0, -1), l = u.length;
              delete a.wsBefore, l > 0 && (c.wsBefore = u);
            }
            o + 1 < i && delete a.wsAfter, r.splice(o, 2, c), o--, i--;
          }
        }
      }), r[0];
    }), e.RULE("formula", () => e.OR9([{ ALT: () => e.SUBRULE(e.referenceWithoutInfix) }, { ALT: () => e.SUBRULE(e.function) }, { ALT: () => e.SUBRULE(e.paren) }, { ALT: () => e.SUBRULE(e.namedTableReference) }, { ALT: () => e.SUBRULE(e.bracketedString) }, { ALT: () => e.SUBRULE(e.squareParen) }, { ALT: () => e.SUBRULE(e.literal) }, { ALT: () => e.SUBRULE(e.literalArray) }])), e.RULE("group", () => {
      const r = [];
      return e.MANY(() => {
        e.CONSUME(ue);
        const i = e.SUBRULE2(e.intersectOp);
        e.ACTION(() => {
          r.push(i);
        });
      }), r;
    }), e.RULE("paren", () => n("paren", Ll, ar)), e.RULE("literalArray", () => {
      let r = { type: "row", value: [], isLiteral: !0 };
      e.CONSUME(xl);
      const i = e.getLexerPosition();
      let o = e.ACTION(() => this._ensureWhitespace({ type: "array", value: [r], isLiteral: !0 }, i, !0));
      const s = e.SUBRULE(e.literalForArray);
      e.ACTION(() => {
        r.value.push(s);
      }), e.MANY(() => {
        const c = e.OR([{ ALT: () => e.CONSUME(ue).image }, { ALT: () => e.CONSUME(_l).image }]), u = e.SUBRULE2(e.literalForArray);
        e.ACTION(() => {
          c === "," || (r = { type: "row", value: [], isLiteral: !0 }, o.value.push(r)), r.value.push(u);
        });
      });
      const a = e.OPTION(() => this.CONSUME(Cl));
      return o = e.ACTION(() => (a || this._reportError(o, "Missing closing parenthesis '}'", i), this._ensureWhitespace(o, e.getLexerPosition(), !1, !0))), o;
    }), e.RULE("literalForArray", () => e.OR([{ ALT: () => {
      const r = e.OPTION(() => e.SUBRULE(e.plusMinusOp)), i = e.CONSUME(yo), o = e.ACTION(() => this._ensureWhitespace(po(i.image), e.getLexerPosition()));
      return r ? e.ACTION(() => /* @__PURE__ */ function(s, a) {
        return { type: "prefix", value: s, inputs: [a] };
      }(r, o)) : o;
    } }, { ALT: () => {
      const r = e.CONSUME(Ao);
      return e.ACTION(() => this._ensureWhitespace(rr(r.image), e.getLexerPosition()));
    } }, { ALT: () => {
      const r = e.CONSUME(Ro);
      return e.ACTION(() => this._ensureWhitespace(mo(r.image), e.getLexerPosition()));
    } }, { ALT: () => {
      const r = e.CONSUME(Io);
      return e.ACTION(() => this._ensureWhitespace(Eo(r.image), e.getLexerPosition()));
    } }, { ALT: () => {
      const r = e.CONSUME(vo);
      return e.ACTION(() => this._ensureWhitespace(In(r.image), e.getLexerPosition()));
    } }])), e.RULE("literal", () => e.OR([{ ALT: () => {
      const r = e.CONSUME(yo);
      return e.ACTION(() => this._ensureWhitespace(po(r.image), e.getLexerPosition()));
    } }, { ALT: () => {
      const r = e.CONSUME(Ao);
      return e.ACTION(() => this._ensureWhitespace(rr(r.image), e.getLexerPosition()));
    } }, { ALT: () => {
      const r = e.CONSUME(Ro);
      return e.ACTION(() => this._ensureWhitespace(mo(r.image), e.getLexerPosition()));
    } }, { ALT: () => {
      const r = e.CONSUME(Io);
      return e.ACTION(() => this._ensureWhitespace(Eo(r.image), e.getLexerPosition()));
    } }])), e.RULE("function", () => {
      const r = e.CONSUME(gl).image.slice(0, -1), i = e.getLexerPosition(), o = e.SUBRULE(e.functionArguments);
      let s = e.ACTION(() => this._ensureWhitespace(fo(r, o), i, !0));
      const a = e.OPTION(() => this.CONSUME(ar));
      return s = e.ACTION(() => (a || this._reportError(s, "Missing closing parenthesis ')'", i), this._ensureWhitespace(s, e.getLexerPosition(), !1, !0))), s;
    }), e.RULE("functionArguments", () => {
      const r = [];
      return e.MANY2(() => {
        let i;
        e.CONSUME2(ue), i = e.ACTION(() => this._ensureWhitespace({ type: "empty", value: "" }, e.getLexerPosition(), !1, !0)), r.push(i);
      }), e.OPTION(() => {
        r.push(e.SUBRULE(e.intersectOp)), e.MANY(() => {
          let i;
          e.CONSUME1(ue), i = e.ACTION(() => this._ensureWhitespace({ type: "empty", value: "" }, e.getLexerPosition(), !1, !0)), r.push(i), e.OPTION3(() => {
            r.pop(), r.push(e.SUBRULE2(e.intersectOp));
          });
        });
      }), r;
    }), e.RULE("bracketedString", () => {
      const r = e.CONSUME(Lo), i = e.getLexerPosition();
      return e.ACTION(() => {
        const o = r.image;
        let s = Jn("", [tr(o.substring(1, o.length - 1))]);
        return s = this._ensureWhitespace(s, i, !0, !1), s = this._ensureWhitespace(s, e.getLexerPosition(), !1, !0), s;
      });
    }), e.RULE("squareParen", () => {
      e.CONSUME(Oo);
      const r = e.getLexerPosition();
      let i = Jn("", [e.SUBRULE(e.structuredArgument)]);
      const o = e.OPTION(() => this.CONSUME(So));
      return e.ACTION(() => {
        o || this._reportError(i, "Missing closing parenthesis ']'", r), i = this._ensureWhitespace(i, r, !0, !1), i = this._ensureWhitespace(i, e.getLexerPosition(), !1, !0);
      }), i;
    }), e.RULE("namedTableReference", () => {
      const r = e.CONSUME(Tl).image.slice(0, -1), i = e.getLexerPosition(), o = e.SUBRULE(e.structuredArguments);
      let s = e.ACTION(() => this._ensureWhitespace(Jn(r, o), i, !0));
      const a = e.OPTION(() => this.CONSUME(So));
      return s = e.ACTION(() => (a || this._reportError(s, "Missing closing parenthesis ']'", i), this._ensureWhitespace(s, e.getLexerPosition(), !1, !0))), s;
    }), e.RULE("structuredArguments", () => {
      const r = [];
      return e.MANY2(() => {
        e.CONSUME2(ue), e.ACTION(() => {
          r.push(this._ensureWhitespace({ type: "empty", value: "" }, e.getLexerPosition(), !1, !0));
        });
      }), e.OPTION(() => {
        const i = e.SUBRULE(e.structuredArgument);
        e.ACTION(() => {
          i && r.push(i);
        }), e.MANY(() => {
          e.CONSUME1(ue), e.OPTION3(() => {
            let o = e.SUBRULE2(e.structuredArgument);
            e.ACTION(() => {
              o || (o = this._ensureWhitespace({ type: "empty", value: "" }, e.getLexerPosition(), !1, !0)), r.push(o);
            });
          });
        });
      }), r;
    }), e.RULE("structuredArgument", () => {
      const r = e.OPTION(() => e.CONSUME(sr)), i = e.getLexerPosition(), o = e.OPTION2(() => this.CONSUME(Oo));
      let s = e.OR([{ ALT: () => {
        const a = e.CONSUME(Ul);
        return e.ACTION(() => this._ensureWhitespace(tr(a.image), e.getLexerPosition()));
      } }, { ALT: () => {
        const a = e.CONSUME(Lo);
        return e.ACTION(() => this._ensureWhitespace(tr(a.image), e.getLexerPosition()));
      } }, { ALT: () => {
        const a = e.CONSUME(No);
        return e.ACTION(() => this._ensureWhitespace(nr(a.image), e.getLexerPosition()));
      } }, { ALT: () => {
        const a = e.CONSUME(El);
        return e.ACTION(() => this._ensureWhitespace(rr(a.image), e.getLexerPosition()));
      } }]);
      if (o) {
        const a = e.OPTION3(() => this.CONSUME(ar));
        e.ACTION(() => (a || this._reportError(s, "Missing closing parenthesis ']'", i), this._ensureWhitespace(s, e.getLexerPosition(), !1, !0))), s = { type: "structuredArg", value: null, inputs: [s] };
      }
      return e.ACTION(() => {
        r && (s = _e(r.image, s, !0), s = this._ensureWhitespace(s, e.getLexerPosition()));
      }), s;
    }), e.RULE("referenceWithoutInfix", () => e.OR([{ ALT: () => e.SUBRULE(e.reference) }, { ALT: () => {
      const r = e.SUBRULE(e.prefixSheetName), i = e.SUBRULE2(e.formula);
      return e.ACTION(() => {
        if ((o = i) && o.isFormulaError) return i;
        var o;
        i.ref && (i.ref.sheet = r);
      }), i;
    } }])), e.RULE("reference", () => {
      const r = e.OPTION4(() => e.CONSUME(sr));
      let i = e.OR([{ ALT: () => {
        const o = e.CONSUME(Al), s = e.getLexerPosition(), a = e.OPTION(() => e.CONSUME(_o));
        return e.ACTION(() => {
          const c = this._ensureWhitespace(function(u, l) {
            const h = u.match(/([$]?)([A-Za-z]{1,3})([$]?)([1-9][0-9]*)/);
            let f = lo(h[2]) - 1;
            const d = h[1].length === 1;
            let E = +h[4] - 1;
            const I = h[3].length === 1;
            return d || f === Number.MIN_SAFE_INTEGER || (f -= l.colIndex), I || E === Number.MIN_SAFE_INTEGER || (E -= l.rowIndex), { type: "cell", value: Object.freeze({ colIndex: f, rowIndex: E, $colIndex: d, $rowIndex: I }), inputs: null, isReference: !0 };
          }(o.image, e.position), s);
          return a ? this._ensureWhitespace(er("#", c, !0), s) : c;
        });
      } }, { ALT: () => {
        const o = e.CONSUME(No);
        return e.ACTION(() => this._ensureWhitespace(nr(o.image), e.getLexerPosition()));
      } }, { ALT: () => {
        const o = e.CONSUME(vl);
        return e.ACTION(() => this._ensureWhitespace(function(s, a) {
          const c = s.startsWith("$");
          c && (s = s.substring(1));
          let u = lo(s) - 1;
          return c || u === Number.MIN_SAFE_INTEGER || (u -= a.colIndex), { type: "cell", value: Object.freeze({ colIndex: u, rowIndex: Number.MIN_SAFE_INTEGER, $colIndex: c, $rowIndex: !1 }), inputs: null, isReference: !0 };
        }(o.image, e.position), e.getLexerPosition()));
      } }, { ALT: () => {
        const o = e.CONSUME(Nl);
        return e.ACTION(() => this._ensureWhitespace(ho(o.image, e.position), e.getLexerPosition()));
      } }, { ALT: () => {
        const o = e.CONSUME(vo);
        return e.ACTION(() => this._ensureWhitespace(In(o.image), e.getLexerPosition()));
      } }]);
      return e.ACTION(() => {
        r && (i = _e(r, i, !0), i = this._ensureWhitespace(i, e.getLexerPosition()));
      }), i;
    }), e.RULE("prefixSheetName", () => e.OR([{ ALT: () => e.CONSUME(Il).image.slice(0, -1) }, { ALT: () => e.CONSUME(ml).image.slice(1, -2).replace(/''/g, "'") }])), e.performSelfAnalysis();
  }
  _reportError(e, n, r = void 0, i = "SyntaxError") {
    r === void 0 && (r = this.getLexerPosition()), e.error = !0, this.astErrors.push({ name: i, message: n, previousToken: this.input[r], ast: e });
  }
  _ensureWhitespace(e, n, r = !1, i = !1) {
    if (!e) return console.warn("node is null"), e;
    const o = this.input, s = o[n];
    if (e.image || (e.image = s.image), !i) {
      const a = s.startOffset, c = o[n - 1], u = c?.endOffset ?? -1;
      u + 1 < a && (e.wsBefore = " ".repeat(a - u - 1));
    }
    if (!r) {
      const a = s.endOffset, c = o[n + 1], u = c?.startOffset ?? this.inputTextLength;
      a + 1 < u && (e.wsAfter = " ".repeat(u - a - 1));
    }
    return e;
  }
  _createAST(e, n) {
    const r = function(a) {
      const c = Xu.tokenize(a);
      if (c.errors.length > 0) {
        const u = c.errors[0], l = u.line, h = u.column;
        let f = `
` + a.split(`
`)[l - 1] + `
`;
        throw f += Array(h - 1).fill(" ").join("") + `^
`, u.message = f + `Error at position ${l}:${h}
` + u.message, u.errorLocation = { line: l, column: h }, new U.Parse(u.message, { line: l, column: h, offset: u.offset, length: u.length });
      }
      return c;
    }(n);
    let i;
    if (!r) return i = { type: "text", value: n }, i;
    const o = r.tokens;
    this.input = o, this.inputTextLength = n.length;
    const s = e.getPosition();
    return this.position = s, this.astErrors = [], this.reset(), i = this.intersectOp(), i = je(i, (a, c) => {
      let u = a.type;
      if (u === "function" && a.value && a.value.toUpperCase().startsWith(hl)) {
        const h = a.value.substring(6);
        let f = a.image.substring(6), d = a;
        h === "ANCHORARRAY" ? (d = er("#", a.inputs[0], !0), f = "#") : h === "SINGLE" ? (d = _e("@", a.inputs[0], !0), f = "@") : d = fo(h, a.inputs), ir(d, a), d.image = f, u = (a = d).type;
      }
      if (c?.isReference) {
        const h = c.value;
        if ((h === ":" || h === ".:." || h === ".:" || h === ":.") && Number.isInteger(a.value)) {
          const f = c.inputs[0] === a ? c.inputs[1] : c.inputs[0];
          if (f && Number.isInteger(f.value)) {
            const d = ho(a.image, s);
            return ir(d, a), d;
          }
        }
      } else if (u === "cell") {
        const h = a.value;
        if (h.rowIndex === Number.MIN_SAFE_INTEGER || h.colIndex >= 16384) {
          const f = nr(a.image);
          return ir(f, a), f;
        }
      }
      return a;
    }), i;
  }
  build(e, n) {
    if (n.length === 0) throw Error("Input must not be empty.");
    let r, i, o;
    try {
      r = this._createAST(e, n);
    } catch (c) {
      o = c instanceof U.Parse ? c : new U.Parse(c.message, c);
    }
    const s = this.errors;
    s.length > 0 && (o = go(s[0], n));
    const a = this.astErrors;
    return a.length > 0 && (o = go(a[0], n)), i = r ? un(r, o) : { ast: null, evaluations: lt.EmptyArray, executions: lt.EmptyArray, precedentsAbsolute: lt.EmptyArray, precedentsExecute: lt.EmptyArray, precedentsNamed: null, precedentsRelative: lt.EmptyArray, precedentsRoot: lt.EmptyArray, references: lt.EmptyArray, tokens: lt.EmptyArray, error: o }, i;
  }
}
class be {
  constructor(e, n) {
    this._options = e, this._compiled = n;
  }
  getTextAt(e, n, r = !1) {
    return r ? Ke(this._compiled.tokens) : Ws(this._compiled.tokens, e, n);
  }
  getTokens() {
    return this._compiled.tokens;
  }
  getError() {
    return this._compiled.error ?? null;
  }
  isEquals(e) {
    if (!(e && e instanceof be)) return !1;
    if (this === e) return !0;
    const n = this._compiled.tokens, r = e._compiled.tokens;
    return n.length !== r.length ? !1 : Ke(n) === Ke(r);
  }
  getReferences() {
    const e = this._compiled, n = e.references, r = n.length;
    if (r === 0) return lt.EmptyArray;
    const i = e.precedentsExecute, o = e.precedentsRelative, s = new Array(r);
    for (let a = 0; a < r; a++) {
      const c = i[n[a]], u = c.inputs;
      if (u && u.length === 2) {
        const l = o[i[u[0]].value], h = o[i[u[1]].value];
        s[a] = { colStart: l.colStart, rowStart: l.rowStart, colEnd: h.colEnd, rowEnd: h.rowEnd, $colStart: l.$colStart, $rowStart: l.$rowStart, $colEnd: h.$colEnd, $rowEnd: h.$rowEnd, sheetName: l.sheetName };
      } else if (c.node.type === "cell") {
        const l = o[c.value];
        s[a] = { ...l };
      } else if (c.op === "named") {
        const l = e.precedentsNamed;
        s[a] = l[c.value];
      } else c.op === "error" && (s[a] = c.node.value);
    }
    return s;
  }
  setReferenceAt(e, n) {
    const r = this._compiled, i = r.references;
    if (i.length === 0) return lt.EmptyArray;
    const o = r.precedentsExecute, s = i[e];
    if (s === void 0) throw new Error(`Invalid reference index: ${e}`);
    const a = o[s], c = a.node, u = c.inputs ?? lt.EmptyArray;
    let l, h, f = !1;
    n && (l = { colIndex: n.colStart, rowIndex: n.rowStart, $colIndex: n.$colStart ?? !1, $rowIndex: n.$rowStart ?? !1 }, n.sheetName && (l.sheetName = n.sheetName), f = !Vt.isSingleCell(n), f && (h = { colIndex: n.colEnd, rowIndex: n.rowEnd, $colIndex: n.$colEnd ?? !1, $rowIndex: n.$rowEnd ?? !1 }, n.colEnd === Number.MAX_SAFE_INTEGER && (h.colIndex = Number.MIN_SAFE_INTEGER), n.rowEnd === Number.MAX_SAFE_INTEGER && (h.rowIndex = Number.MIN_SAFE_INTEGER)));
    const d = u.length === 2;
    let E = -1, I = -1;
    if (d) E = u[0].evalIndex, I = u[1].evalIndex;
    else {
      if (c.type !== "cell") throw a.op === "named" ? new Error("Cannot setReference for a named reference") : new Error(`Invalidate reference index: ${e}`);
      E = c.evalIndex;
    }
    const S = this._compiled.ast, T = je(S, (A) => {
      if (!A || !A.isReference) return;
      const O = A.type;
      if (!n && Bs.includes(A.value)) {
        const v = u[0], y = u[1];
        let M = v.evalIndex === E, w = y.evalIndex === I;
        if (M || w) {
          const F = In();
          return F.image = "#REF!", F;
        }
      }
      if (!(O === "cell" || O === "error")) return;
      const g = A.evalIndex;
      let R, N = g === E;
      if (N || g === I) {
        if (n) if (d === f) {
          let v = N ? l : h;
          R = { ...A }, R.value = v, R.image = null;
        } else R = f ? Rr(":", Qn(l), Qn(h), !0) : Qn(l);
        else R = In(), R.image = "#REF!";
        return R;
      }
    });
    if (T === S) return this;
    const m = un(T, this._compiled.error), p = this._options;
    return new be(p, m);
  }
  _resolveNamed(e, n, r, i) {
    const o = this._options?.getNamed;
    if (!o) return U.BuiltIn.Name;
    let s = o?.(e, this._options.getSheetName?.())?.[0];
    return s ? (s.isFormulaError || (s = Un(s, n, r, i)), s) : U.BuiltIn.Name;
  }
  getDirectPrecedentsAt(e, n, r = !1, i, o) {
    const s = this._compiled, a = s.precedentsRoot, c = a.length;
    if (c === 0) return lt.EmptyArray;
    const u = s.precedentsRelative, l = s.precedentsAbsolute, h = u.length;
    for (let T = 0; T < h; T++) {
      const m = u[T];
      let p = l[T], A = Un(m, e, n, p);
      l[T] = A;
    }
    let f = !1;
    const d = s.precedentsExecute, E = d.length, I = Or;
    for (let T = 0; T < E; T++) {
      const m = d[T], p = m.op;
      if (!p) {
        const N = l[m.value];
        I[m.index] = N;
        continue;
      }
      if (p === "named") {
        f = !0, I[m.index] = this._resolveNamed(m.node.value, e, n);
        continue;
      }
      if (p === "error") {
        I[m.index] = m.node.value;
        continue;
      }
      if (p === "@" || p === "#") {
        I[m.index] = I[m.inputs[0]];
        continue;
      }
      const A = m.inputs;
      if (!A) continue;
      let O = I[A[0]];
      if (O === void 0) {
        I[m.index] = U.BuiltIn.Value;
        continue;
      }
      if (O.isFormulaError) {
        I[m.index] = O;
        continue;
      }
      let g, R = I[A[1]];
      R !== void 0 ? R.isFormulaError ? I[m.index] = R : (p === " " ? g = Vt.intersectRanges(O, R) : p !== ":" && p !== ".:." && p !== ":." && p !== ".:" || (g = I[m.index] = Vt.unionRanges(O, R)), I[m.index] = g ?? U.BuiltIn.Null) : I[m.index] = U.BuiltIn.Value;
    }
    const S = new Array(c);
    for (let T = 0; T < c; T++) {
      const m = a[T], p = I[m];
      if (S[T] = p?.rowStart !== void 0 ? { ...p } : p, i || o) {
        const A = d[m];
        f && A.op === "named" ? (i && (i[T] = p.$colStart || p.$colEnd), o && (o[T] = p.$rowStart || p.$rowEnd)) : (i && (i[T] = A.hasVerticalAbs), o && (o[T] = A.hasHorizontalAbs));
      }
    }
    return S;
  }
  evaluate(e, n, r) {
    const i = e.getPosition(), o = i?.rowIndex ?? 0, s = i?.colIndex ?? 0;
    let a = this._compiled;
    if (n !== void 0) {
      let g;
      if (je(a.ast, (R) => {
        R.evalIndex === n && (g = R);
      }), !g) throw new Error(`Invalid evalIndex: ${n}`);
      a = un(g, a.error);
    }
    if (a.error) return a.error;
    const c = a.evaluations, u = a.executions;
    let l, h;
    r || (r = this._resolvePrecedents(e));
    const f = a.precedentsExecute, d = a.precedentsRelative, E = a.precedentsAbsolute, I = f.length;
    for (let g = 0; g < I; g++) {
      const R = f[g], N = R.op;
      if (N) {
        if (N === "named") {
          const v = R.node;
          let y = this._resolveNamed(R.node.value, o, s);
          y?.colStart !== void 0 && (y = e.getReference(y)), c[v.evalIndex] = y;
        } else if (N === "error") {
          const v = R.node;
          c[v.evalIndex] = R.node.value;
        }
      } else {
        const v = d[R.value];
        let y = E[g];
        const M = Un(v, o, s, y), w = R.node;
        c[w.evalIndex] = M;
      }
    }
    const S = a.precedentsRoot, T = S.length;
    if (T !== r.length) return U.BuiltIn.Parse;
    for (let g = 0; g < T; g++) {
      const R = f[S[g]].node;
      let N = r[g];
      N.isIRange && R.type === "cell" && N.size > 1 && (N = N.getValueAt(0, 0) ?? null), c[R.evalIndex] = N;
    }
    let m;
    const p = (g) => {
      const R = g.inputs, N = R ? R.length : 0;
      let v;
      switch (g.type) {
        case "infix":
          const y = g.value;
          let M = c[R[0].evalIndex], w = c[R[1].evalIndex];
          if (y === "+" && typeof M == "number" && typeof w == "number") {
            const C = M + w;
            return Math.abs(C) < 99e-14 ? 0 : C;
          }
          if (y === "-" && typeof M == "number" && typeof w == "number") {
            const C = M - w;
            return Math.abs(C) < 99e-14 ? 0 : C;
          }
          if (M && M.isFormulaError) return M;
          if (w && w.isFormulaError) return w;
          const F = g.fn;
          return v = F ? F(e, M, w) : U.BuiltIn.Value, v = Ve(v, null), v;
        case "function":
          m || (m = new Array(N)), m.length !== N && (m.length = N);
          for (let C = 0; C < N; C++) m[C] = c[R[C].evalIndex];
          return v = this._callFunction(e, g, m), v && typeof v.then == "function" ? v.then((C) => {
            C = Ve(C, e), v instanceof U.Known && (h = v), c[g.evalIndex] = C;
          }).catch((C) => {
            const j = C instanceof U.Known ? C : new U.Value("Uncaught error", { cause: C });
            c[g.evalIndex] = j;
          }) : v instanceof U.Known && (h = v), v;
        case "prefix":
        case "postfix":
          let $ = c[R[0].evalIndex];
          if ($ && $.isFormulaError) return $;
          const x = g.fn;
          return v = x ? x(e, $) : U.BuiltIn.Value, v;
        case "paren":
          if (N === 1) return c[R[0].evalIndex];
          {
            const C = new Array(N);
            for (let j = 0; j < N; j++) C[j] = c[R[j].evalIndex];
            return C;
          }
        case "named":
          return null;
        case "empty":
          return;
      }
    };
    let A = u.length;
    for (let g = 0; g < A; g++) {
      const R = u[g];
      if (h) return h;
      if (l) l = l.then(() => {
        const N = p(R);
        return c[R.evalIndex] = N, N;
      });
      else {
        const N = p(R);
        c[R.evalIndex] = N, N && typeof N.then == "function" && (l = N);
      }
    }
    if (l) return l.then(() => {
      const g = c[c.length - 1];
      return this._finalizeReturnValue(e, g);
    });
    const O = c[c.length - 1];
    return this._finalizeReturnValue(e, O);
  }
  _resolvePrecedents(e) {
    const n = e.getPosition(), r = n?.rowIndex ?? 0, i = n?.colIndex ?? 0, o = this.getDirectPrecedentsAt(r, i), s = o.length;
    let a;
    if (s > 0) {
      a = new Array(s);
      for (let c = 0; c < s; c++) {
        const u = o[c];
        if (u instanceof U.Known) a[c] = u;
        else if (Array.isArray(u)) {
          const l = new Array(u.length);
          for (let h = 0; h < u.length; h++) l[h] = e.getReference(u[h]);
          a[c] = l;
        } else a[c] = e.getReference(u);
      }
    } else a = lt.EmptyArray;
    return a;
  }
  wrapImplicit(e, n, r) {
    const i = this._compiled.ast;
    if (!i || !i.isReference) return this;
    if (i.type === "cell") return this;
    if (i.value === "@") return this;
    if (!r) return this;
    const o = Gs(n) + zs(e);
    if (r.has(o)) return this;
    const s = un(_e("@", i, !0), this._compiled.error);
    return new be(this._options, s);
  }
  _callFunction(e, n, r) {
    const i = n?.cacheFn ?? e.getFunction(n.value);
    if (!i) return new U.Parse();
    const o = i.isBuiltIn();
    let s;
    o ? n.cacheFn = i : this._context = e;
    try {
      s = i.execute(...r);
    } catch (a) {
      s = a instanceof U.Known ? a : new U.Value(a.message, { cause: a });
    }
    return o || (this._context = null), s === void 0 ? new U.Parse() : s;
  }
  _finalizeReturnValue(e, n) {
    if (n && n.colStart !== void 0 && (n = e.getValueAt(n.rowStart, n.colStart)), Array.isArray(n)) if (n.length === 1 && Array.isArray(n[0]) && n[0].length === 1) n = n[0][0], Array.isArray(n) && (n = U.BuiltIn.Value);
    else try {
      n = e.getRange(n);
    } catch {
      n = U.BuiltIn.Value;
    }
    return n?.isIRange ? n.size === 1 ? (n = n.getValueAt(0, 0, zl), (n = Ve(n, e)) === null && (n = 0)) : n = n.fillEmpty(0) : (n = Ve(n, e)) === null && (n = 0), n;
  }
  get [Symbol.toStringTag]() {
    return "[FormulaBlock]";
  }
  toString() {
    const e = this._compiled;
    if (e.error) return e.error.toString();
    const n = this._context;
    if (n) {
      const r = n.getPosition();
      return this.getTextAt(r.rowIndex, r.colIndex);
    }
    return Ke(e.tokens);
  }
}
const Or = new Array(20);
for (let t = 0; t < Or.length; t++) Or[t] = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0, sheetName: null };
const zl = { type: null };
class Yl {
  constructor(e) {
    this._options = { getEntireCoords: Ks, ...e }, this._astBuilder = new Gl();
  }
  parse(e, n) {
    e.getPosition().sheetName;
    const i = this._astBuilder.build(e, n);
    return new be(this._options, i);
  }
  eval(e, n) {
    return this.parse(e, n).evaluate(e);
  }
}
export {
  Yl as FormulaParser
};