import { RestWalker } from "./lib-src-parse-grammar-rest.js";
import { first } from "./lib-src-parse-grammar-first.js";
import { IN } from "./lib-src-parse-constants.js";
import { Alternative } from "../@chevrotain/gast/lib-src-model.js";
import forEach from "../lodash-es/forEach2.js";
import assign from "../lodash-es/assign.js";
class ResyncFollowsWalker extends RestWalker {
  constructor(topProd) {
    super();
    this.topProd = topProd;
    this.follows = {};
  }
  startWalking() {
    this.walk(this.topProd);
    return this.follows;
  }
  walkTerminal(terminal, currRest, prevRest) {
  }
  walkProdRef(refProd, currRest, prevRest) {
    const followName = buildBetweenProdsFollowPrefix(refProd.referencedRule, refProd.idx) + this.topProd.name;
    const fullRest = currRest.concat(prevRest);
    const restProd = new Alternative({ definition: fullRest });
    const t_in_topProd_follows = first(restProd);
    this.follows[followName] = t_in_topProd_follows;
  }
}
function computeAllProdsFollows(topProductions) {
  const reSyncFollows = {};
  forEach(topProductions, (topProd) => {
    const currRefsFollow = new ResyncFollowsWalker(topProd).startWalking();
    assign(reSyncFollows, currRefsFollow);
  });
  return reSyncFollows;
}
function buildBetweenProdsFollowPrefix(inner, occurenceInParent) {
  return inner.name + occurenceInParent + IN;
}
export {
  ResyncFollowsWalker,
  buildBetweenProdsFollowPrefix,
  computeAllProdsFollows
};
//# sourceMappingURL=lib-src-parse-grammar-follow.js.map
