import { GAstVisitor as e } from "../../../../../@chevrotain/gast/lib/src/visitor.js";
import { ParserDefinitionErrorType as t } from "../parser/parser.js";
//#region ../../node_modules/chevrotain/lib/src/parse/grammar/resolver.js
function n(e, t) {
	let n = new r(e, t);
	return n.resolveRefs(), n.errors;
}
var r = class extends e {
	constructor(e, t) {
		super(), this.nameToTopRule = e, this.errMsgProvider = t, this.errors = [];
	}
	resolveRefs() {
		Object.values(this.nameToTopRule).forEach((e) => {
			this.currTopLevel = e, e.accept(this);
		});
	}
	visitNonTerminal(e) {
		let n = this.nameToTopRule[e.nonTerminalName];
		if (n) e.referencedRule = n;
		else {
			let n = this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel, e);
			this.errors.push({
				message: n,
				type: t.UNRESOLVED_SUBRULE_REF,
				ruleName: this.currTopLevel.name,
				unresolvedRefName: e.nonTerminalName
			});
		}
	}
};
//#endregion
export { n as resolveGrammar };
