"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const rest = require("./lib-src-parse-grammar-rest.cjs");
const first = require("./lib-src-parse-grammar-first.cjs");
const constants = require("./lib-src-parse-constants.cjs");
const model = require("../@chevrotain/gast/lib-src-model.cjs");
const forEach = require("../lodash-es/forEach.cjs");
const assign = require("../lodash-es/assign.cjs");
class ResyncFollowsWalker extends rest.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 model.Alternative({ definition: fullRest });
    const t_in_topProd_follows = first.first(restProd);
    this.follows[followName] = t_in_topProd_follows;
  }
}
function computeAllProdsFollows(topProductions) {
  const reSyncFollows = {};
  forEach.default(topProductions, (topProd) => {
    const currRefsFollow = new ResyncFollowsWalker(topProd).startWalking();
    assign.default(reSyncFollows, currRefsFollow);
  });
  return reSyncFollows;
}
function buildBetweenProdsFollowPrefix(inner, occurenceInParent) {
  return inner.name + occurenceInParent + constants.IN;
}
exports.ResyncFollowsWalker = ResyncFollowsWalker;
exports.buildBetweenProdsFollowPrefix = buildBetweenProdsFollowPrefix;
exports.computeAllProdsFollows = computeAllProdsFollows;
//# sourceMappingURL=lib-src-parse-grammar-follow.cjs.map
