import _ from "../../../../lodash-es@4.17.22/node_modules/lodash-es/map.js";
import C from "../../../../lodash-es@4.17.22/node_modules/lodash-es/filter.js";
import "../../../../chevrotain@11.0.3/node_modules/chevrotain/lib/src/parse/parser/parser.js";
import "../../../../chevrotain@11.0.3/node_modules/chevrotain/lib/src/scan/lexer_public.js";
import "../../../../chevrotain@11.0.3/node_modules/chevrotain/lib/src/scan/tokens_public.js";
import "../../../../chevrotain@11.0.3/node_modules/chevrotain/lib/src/parse/grammar/lookahead.js";
import "../../../../chevrotain@11.0.3/node_modules/chevrotain/lib/src/parse/errors_public.js";
import { Terminal as K, NonTerminal as U, Alternation as m, Option as O, Repetition as N, RepetitionWithSeparator as M, RepetitionMandatory as L, RepetitionMandatoryWithSeparator as k } from "../../../../@chevrotain_gast@11.0.3/node_modules/@chevrotain/gast/lib/src/model.js";
import "../../../../chevrotain@11.0.3/node_modules/chevrotain/lib/src/parse/exceptions_public.js";
function T(t, e, n) {
  return `${t.name}_${e}_${n}`;
}
const h = 1, D = 2, E = 4, b = 5, $ = 7, v = 8, I = 9, j = 10, H = 11, w = 12;
class y {
  constructor(e) {
    this.target = e;
  }
  isEpsilon() {
    return !1;
  }
}
class Y extends y {
  constructor(e, n) {
    super(e), this.tokenType = n;
  }
}
class q extends y {
  constructor(e) {
    super(e);
  }
  isEpsilon() {
    return !0;
  }
}
class x extends y {
  constructor(e, n, s) {
    super(e), this.rule = n, this.followState = s;
  }
  isEpsilon() {
    return !0;
  }
}
function St(t) {
  const e = {
    decisionMap: {},
    decisionStates: [],
    ruleToStartState: /* @__PURE__ */ new Map(),
    ruleToStopState: /* @__PURE__ */ new Map(),
    states: []
  };
  z(e, t);
  const n = t.length;
  for (let s = 0; s < n; s++) {
    const o = t[s], i = S(e, o, o);
    i !== void 0 && st(e, o, i);
  }
  return e;
}
function z(t, e) {
  const n = e.length;
  for (let s = 0; s < n; s++) {
    const o = e[s], i = l(t, o, void 0, {
      type: D
    }), c = l(t, o, void 0, {
      type: $
    });
    i.stop = c, t.ruleToStartState.set(o, i), t.ruleToStopState.set(o, c);
  }
}
function B(t, e, n) {
  return n instanceof K ? A(t, e, n.terminalType, n) : n instanceof U ? nt(t, e, n) : n instanceof m ? V(t, e, n) : n instanceof O ? X(t, e, n) : n instanceof N ? F(t, e, n) : n instanceof M ? G(t, e, n) : n instanceof L ? J(t, e, n) : n instanceof k ? Q(t, e, n) : S(t, e, n);
}
function F(t, e, n) {
  const s = l(t, e, n, {
    type: b
  });
  u(t, s);
  const o = d(t, e, s, n, S(t, e, n));
  return W(t, e, n, o);
}
function G(t, e, n) {
  const s = l(t, e, n, {
    type: b
  });
  u(t, s);
  const o = d(t, e, s, n, S(t, e, n)), i = A(t, e, n.separator, n);
  return W(t, e, n, o, i);
}
function J(t, e, n) {
  const s = l(t, e, n, {
    type: E
  });
  u(t, s);
  const o = d(t, e, s, n, S(t, e, n));
  return P(t, e, n, o);
}
function Q(t, e, n) {
  const s = l(t, e, n, {
    type: E
  });
  u(t, s);
  const o = d(t, e, s, n, S(t, e, n)), i = A(t, e, n.separator, n);
  return P(t, e, n, o, i);
}
function V(t, e, n) {
  const s = l(t, e, n, {
    type: h
  });
  u(t, s);
  const o = _(n.definition, (c) => B(t, e, c));
  return d(t, e, s, n, ...o);
}
function X(t, e, n) {
  const s = l(t, e, n, {
    type: h
  });
  u(t, s);
  const o = d(t, e, s, n, S(t, e, n));
  return Z(t, e, n, o);
}
function S(t, e, n) {
  const s = C(_(n.definition, (o) => B(t, e, o)), (o) => o !== void 0);
  return s.length === 1 ? s[0] : s.length === 0 ? void 0 : et(t, s);
}
function P(t, e, n, s, o) {
  const i = s.left, c = s.right, r = l(t, e, n, {
    type: H
  });
  u(t, r);
  const a = l(t, e, n, {
    type: w
  });
  return i.loopback = r, a.loopback = r, t.decisionMap[T(e, o ? "RepetitionMandatoryWithSeparator" : "RepetitionMandatory", n.idx)] = r, f(c, r), o === void 0 ? (f(r, i), f(r, a)) : (f(r, a), f(r, o.left), f(o.right, i)), {
    left: i,
    right: a
  };
}
function W(t, e, n, s, o) {
  const i = s.left, c = s.right, r = l(t, e, n, {
    type: j
  });
  u(t, r);
  const a = l(t, e, n, {
    type: w
  }), p = l(t, e, n, {
    type: I
  });
  return r.loopback = p, a.loopback = p, f(r, i), f(r, a), f(c, p), o !== void 0 ? (f(p, a), f(p, o.left), f(o.right, i)) : f(p, r), t.decisionMap[T(e, o ? "RepetitionWithSeparator" : "Repetition", n.idx)] = r, {
    left: r,
    right: a
  };
}
function Z(t, e, n, s) {
  const o = s.left, i = s.right;
  return f(o, i), t.decisionMap[T(e, "Option", n.idx)] = o, s;
}
function u(t, e) {
  return t.decisionStates.push(e), e.decision = t.decisionStates.length - 1, e.decision;
}
function d(t, e, n, s, ...o) {
  const i = l(t, e, s, {
    type: v,
    start: n
  });
  n.end = i;
  for (const r of o)
    r !== void 0 ? (f(n, r.left), f(r.right, i)) : f(n, i);
  const c = {
    left: n,
    right: i
  };
  return t.decisionMap[T(e, tt(s), s.idx)] = n, c;
}
function tt(t) {
  if (t instanceof m)
    return "Alternation";
  if (t instanceof O)
    return "Option";
  if (t instanceof N)
    return "Repetition";
  if (t instanceof M)
    return "RepetitionWithSeparator";
  if (t instanceof L)
    return "RepetitionMandatory";
  if (t instanceof k)
    return "RepetitionMandatoryWithSeparator";
  throw new Error("Invalid production type encountered");
}
function et(t, e) {
  const n = e.length;
  for (let i = 0; i < n - 1; i++) {
    const c = e[i];
    let r;
    c.left.transitions.length === 1 && (r = c.left.transitions[0]);
    const a = r instanceof x, p = r, g = e[i + 1].left;
    c.left.type === h && c.right.type === h && r !== void 0 && (a && p.followState === c.right || r.target === c.right) ? (a ? p.followState = g : r.target = g, ot(t, c.right)) : f(c.right, g);
  }
  const s = e[0], o = e[n - 1];
  return {
    left: s.left,
    right: o.right
  };
}
function A(t, e, n, s) {
  const o = l(t, e, s, {
    type: h
  }), i = l(t, e, s, {
    type: h
  });
  return R(o, new Y(i, n)), {
    left: o,
    right: i
  };
}
function nt(t, e, n) {
  const s = n.referencedRule, o = t.ruleToStartState.get(s), i = l(t, e, n, {
    type: h
  }), c = l(t, e, n, {
    type: h
  }), r = new x(o, s, c);
  return R(i, r), {
    left: i,
    right: c
  };
}
function st(t, e, n) {
  const s = t.ruleToStartState.get(e);
  f(s, n.left);
  const o = t.ruleToStopState.get(e);
  return f(n.right, o), {
    left: s,
    right: o
  };
}
function f(t, e) {
  const n = new q(e);
  R(t, n);
}
function l(t, e, n, s) {
  const o = Object.assign({
    atn: t,
    production: n,
    epsilonOnlyTransitions: !1,
    rule: e,
    transitions: [],
    nextTokenWithinRule: [],
    stateNumber: t.states.length
  }, s);
  return t.states.push(o), o;
}
function R(t, e) {
  t.transitions.length === 0 && (t.epsilonOnlyTransitions = e.isEpsilon()), t.transitions.push(e);
}
function ot(t, e) {
  t.states.splice(t.states.indexOf(e), 1);
}
export {
  h as ATN_BASIC,
  v as ATN_BLOCK_END,
  w as ATN_LOOP_END,
  E as ATN_PLUS_BLOCK_START,
  H as ATN_PLUS_LOOP_BACK,
  D as ATN_RULE_START,
  $ as ATN_RULE_STOP,
  b as ATN_STAR_BLOCK_START,
  I as ATN_STAR_LOOP_BACK,
  j as ATN_STAR_LOOP_ENTRY,
  y as AbstractTransition,
  Y as AtomTransition,
  q as EpsilonTransition,
  x as RuleTransition,
  T as buildATNKey,
  St as createATN
};
