import n from "../../../../../../lodash-es@4.17.21/node_modules/lodash-es/assign.js";
import r from "../../../../../../lodash-es@4.17.21/node_modules/lodash-es/pickBy.js";
import l from "../../../../../../lodash-es@4.17.21/node_modules/lodash-es/forEach.js";
import d from "../../../../../../lodash-es@4.17.21/node_modules/lodash-es/map.js";
import c from "../../../../../../lodash-es@4.17.21/node_modules/lodash-es/isString.js";
import u from "../../../../../../lodash-es@4.17.21/node_modules/lodash-es/isRegExp.js";
function p(i) {
  return h(i) ? i.LABEL : i.name;
}
function h(i) {
  return c(i.LABEL) && i.LABEL !== "";
}
class s {
  get definition() {
    return this._definition;
  }
  set definition(e) {
    this._definition = e;
  }
  constructor(e) {
    this._definition = e;
  }
  accept(e) {
    e.visit(this), l(this.definition, (t) => {
      t.accept(e);
    });
  }
}
class m extends s {
  constructor(e) {
    super([]), this.idx = 1, n(this, r(e, (t) => t !== void 0));
  }
  set definition(e) {
  }
  get definition() {
    return this.referencedRule !== void 0 ? this.referencedRule.definition : [];
  }
  accept(e) {
    e.visit(this);
  }
}
class x extends s {
  constructor(e) {
    super(e.definition), this.orgText = "", n(this, r(e, (t) => t !== void 0));
  }
}
class y extends s {
  constructor(e) {
    super(e.definition), this.ignoreAmbiguities = !1, n(this, r(e, (t) => t !== void 0));
  }
}
class T extends s {
  constructor(e) {
    super(e.definition), this.idx = 1, n(this, r(e, (t) => t !== void 0));
  }
}
class R extends s {
  constructor(e) {
    super(e.definition), this.idx = 1, n(this, r(e, (t) => t !== void 0));
  }
}
class g extends s {
  constructor(e) {
    super(e.definition), this.idx = 1, n(this, r(e, (t) => t !== void 0));
  }
}
class A extends s {
  constructor(e) {
    super(e.definition), this.idx = 1, n(this, r(e, (t) => t !== void 0));
  }
}
class b extends s {
  constructor(e) {
    super(e.definition), this.idx = 1, n(this, r(e, (t) => t !== void 0));
  }
}
class L extends s {
  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, n(this, r(e, (t) => t !== void 0));
  }
}
class o {
  constructor(e) {
    this.idx = 1, n(this, r(e, (t) => t !== void 0));
  }
  accept(e) {
    e.visit(this);
  }
}
function z(i) {
  return d(i, a);
}
function a(i) {
  function e(t) {
    return d(t, a);
  }
  if (i instanceof m) {
    const t = {
      type: "NonTerminal",
      name: i.nonTerminalName,
      idx: i.idx
    };
    return c(i.label) && (t.label = i.label), t;
  } else {
    if (i instanceof y)
      return {
        type: "Alternative",
        definition: e(i.definition)
      };
    if (i instanceof T)
      return {
        type: "Option",
        idx: i.idx,
        definition: e(i.definition)
      };
    if (i instanceof R)
      return {
        type: "RepetitionMandatory",
        idx: i.idx,
        definition: e(i.definition)
      };
    if (i instanceof g)
      return {
        type: "RepetitionMandatoryWithSeparator",
        idx: i.idx,
        separator: a(new o({ terminalType: i.separator })),
        definition: e(i.definition)
      };
    if (i instanceof b)
      return {
        type: "RepetitionWithSeparator",
        idx: i.idx,
        separator: a(new o({ terminalType: i.separator })),
        definition: e(i.definition)
      };
    if (i instanceof A)
      return {
        type: "Repetition",
        idx: i.idx,
        definition: e(i.definition)
      };
    if (i instanceof L)
      return {
        type: "Alternation",
        idx: i.idx,
        definition: e(i.definition)
      };
    if (i instanceof o) {
      const t = {
        type: "Terminal",
        name: i.terminalType.name,
        label: p(i.terminalType),
        idx: i.idx
      };
      c(i.label) && (t.terminalLabel = i.label);
      const f = i.terminalType.PATTERN;
      return i.terminalType.PATTERN && (t.pattern = u(f) ? f.source : f), t;
    } else {
      if (i instanceof x)
        return {
          type: "Rule",
          name: i.name,
          orgText: i.orgText,
          definition: e(i.definition)
        };
      throw Error("non exhaustive match");
    }
  }
}
export {
  s as AbstractProduction,
  L as Alternation,
  y as Alternative,
  m as NonTerminal,
  T as Option,
  A as Repetition,
  R as RepetitionMandatory,
  g as RepetitionMandatoryWithSeparator,
  b as RepetitionWithSeparator,
  x as Rule,
  o as Terminal,
  z as serializeGrammar,
  a as serializeProduction
};
