import assign_default from "../../../../../lodash-es/assign.js";
import forEach_default from "../../../../../lodash-es/forEach.js";
import { Alternative } from "../../../../../@chevrotain/gast/lib/src/model.js";
import { RestWalker } from "./rest.js";
import { first } from "./first.js";
import { IN } from "../constants.js";
var ResyncFollowsWalker = class extends RestWalker {
	constructor(e) {
		super(), this.topProd = e, this.follows = {};
	}
	startWalking() {
		return this.walk(this.topProd), this.follows;
	}
	walkTerminal(e, i, a) {}
	walkProdRef(e, i, o) {
		let s = buildBetweenProdsFollowPrefix(e.referencedRule, e.idx) + this.topProd.name, c = first(new Alternative({ definition: i.concat(o) }));
		this.follows[s] = c;
	}
};
function computeAllProdsFollows(a) {
	let o = {};
	return forEach_default(a, (i) => {
		assign_default(o, new ResyncFollowsWalker(i).startWalking());
	}), o;
}
function buildBetweenProdsFollowPrefix(e, i) {
	return e.name + i + IN;
}
export { computeAllProdsFollows };
