import { ParserDefinitionErrorType as t } from "../parser/parser.js";
import { GAstVisitor as i } from "../../../../../../../@chevrotain_gast@11.0.3/node_modules/@chevrotain/gast/lib/src/visitor.js";
import m from "../../../../../../../lodash-es@4.17.21/node_modules/lodash-es/forEach.js";
import n from "../../../../../../../lodash-es@4.17.21/node_modules/lodash-es/values.js";
function c(s, e) {
  const r = new l(s, e);
  return r.resolveRefs(), r.errors;
}
class l extends i {
  constructor(e, r) {
    super(), this.nameToTopRule = e, this.errMsgProvider = r, this.errors = [];
  }
  resolveRefs() {
    m(n(this.nameToTopRule), (e) => {
      this.currTopLevel = e, e.accept(this);
    });
  }
  visitNonTerminal(e) {
    const r = this.nameToTopRule[e.nonTerminalName];
    if (r)
      e.referencedRule = r;
    else {
      const o = this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel, e);
      this.errors.push({
        message: o,
        type: t.UNRESOLVED_SUBRULE_REF,
        ruleName: this.currTopLevel.name,
        unresolvedRefName: e.nonTerminalName
      });
    }
  }
}
export {
  l as GastRefResolverVisitor,
  c as resolveGrammar
};
