import { defaultGrammarValidatorErrorProvider as e } from "../errors_public.js";
import { DEFAULT_PARSER_CONFIG as d } from "../parser/parser.js";
import { validateSomeNonEmptyLookaheadPath as n, validateNoLeftRecursion as u, validateEmptyOrAlternative as m, validateAmbiguousAlternationAlternatives as s } from "./checks.js";
import { buildLookaheadFuncForOr as h, buildLookaheadFuncForOptionalProd as v, getProdType as c, buildAlternativesLookAheadFunc as L, buildSingleAlternativeLookaheadFunction as k } from "./lookahead.js";
import A from "../../../../../../../lodash-es@4.17.21/node_modules/lodash-es/isEmpty.js";
import o from "../../../../../../../lodash-es@4.17.21/node_modules/lodash-es/flatMap.js";
class P {
  constructor(a) {
    var r;
    this.maxLookahead = (r = a == null ? void 0 : a.maxLookahead) !== null && r !== void 0 ? r : d.maxLookahead;
  }
  validate(a) {
    const r = this.validateNoLeftRecursion(a.rules);
    if (A(r)) {
      const t = this.validateEmptyOrAlternatives(a.rules), l = this.validateAmbiguousAlternationAlternatives(a.rules, this.maxLookahead), i = this.validateSomeNonEmptyLookaheadPath(a.rules, this.maxLookahead);
      return [
        ...r,
        ...t,
        ...l,
        ...i
      ];
    }
    return r;
  }
  validateNoLeftRecursion(a) {
    return o(a, (r) => u(r, r, e));
  }
  validateEmptyOrAlternatives(a) {
    return o(a, (r) => m(r, e));
  }
  validateAmbiguousAlternationAlternatives(a, r) {
    return o(a, (t) => s(t, r, e));
  }
  validateSomeNonEmptyLookaheadPath(a, r) {
    return n(a, r, e);
  }
  buildLookaheadForAlternation(a) {
    return h(a.prodOccurrence, a.rule, a.maxLookahead, a.hasPredicates, a.dynamicTokensEnabled, L);
  }
  buildLookaheadForOptional(a) {
    return v(a.prodOccurrence, a.rule, a.maxLookahead, a.dynamicTokensEnabled, c(a.prodType), k);
  }
}
export {
  P as LLkLookaheadStrategy
};
