import { Option as l, Terminal as w, NonTerminal as r, Alternative as s, RepetitionMandatory as p, RepetitionMandatoryWithSeparator as h, RepetitionWithSeparator as R, Repetition as O, Alternation as m } from "../../../../../../../@chevrotain_gast@11.0.3/node_modules/@chevrotain/gast/lib/src/model.js";
import f from "../../../../../../../lodash-es@4.17.21/node_modules/lodash-es/forEach.js";
import S from "../../../../../../../lodash-es@4.17.21/node_modules/lodash-es/drop.js";
class T {
  walk(n, e = []) {
    f(n.definition, (t, i) => {
      const a = S(n.definition, i + 1);
      if (t instanceof r)
        this.walkProdRef(t, a, e);
      else if (t instanceof w)
        this.walkTerminal(t, a, e);
      else if (t instanceof s)
        this.walkFlat(t, a, e);
      else if (t instanceof l)
        this.walkOption(t, a, e);
      else if (t instanceof p)
        this.walkAtLeastOne(t, a, e);
      else if (t instanceof h)
        this.walkAtLeastOneSep(t, a, e);
      else if (t instanceof R)
        this.walkManySep(t, a, e);
      else if (t instanceof O)
        this.walkMany(t, a, e);
      else if (t instanceof m)
        this.walkOr(t, a, e);
      else
        throw Error("non exhaustive match");
    });
  }
  walkTerminal(n, e, t) {
  }
  walkProdRef(n, e, t) {
  }
  walkFlat(n, e, t) {
    const i = e.concat(t);
    this.walk(n, i);
  }
  walkOption(n, e, t) {
    const i = e.concat(t);
    this.walk(n, i);
  }
  walkAtLeastOne(n, e, t) {
    const i = [
      new l({ definition: n.definition })
    ].concat(e, t);
    this.walk(n, i);
  }
  walkAtLeastOneSep(n, e, t) {
    const i = c(n, e, t);
    this.walk(n, i);
  }
  walkMany(n, e, t) {
    const i = [
      new l({ definition: n.definition })
    ].concat(e, t);
    this.walk(n, i);
  }
  walkManySep(n, e, t) {
    const i = c(n, e, t);
    this.walk(n, i);
  }
  walkOr(n, e, t) {
    const i = e.concat(t);
    f(n.definition, (a) => {
      const k = new s({ definition: [a] });
      this.walk(k, i);
    });
  }
}
function c(o, n, e) {
  return [
    new l({
      definition: [
        new w({ terminalType: o.separator })
      ].concat(o.definition)
    })
  ].concat(n, e);
}
export {
  T as RestWalker
};
