"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const errors_public = require("./lib-src-parse-errors_public.cjs");
const parser = require("./lib-src-parse-parser-parser.cjs");
const checks = require("./lib-src-parse-grammar-checks.cjs");
const lookahead = require("./lib-src-parse-grammar-lookahead.cjs");
const isEmpty = require("../lodash-es/isEmpty.cjs");
const flatMap = require("../lodash-es/flatMap.cjs");
class LLkLookaheadStrategy {
  constructor(options) {
    var _a;
    this.maxLookahead = (_a = options === null || options === void 0 ? void 0 : options.maxLookahead) !== null && _a !== void 0 ? _a : parser.DEFAULT_PARSER_CONFIG.maxLookahead;
  }
  validate(options) {
    const leftRecursionErrors = this.validateNoLeftRecursion(options.rules);
    if (isEmpty.default(leftRecursionErrors)) {
      const emptyAltErrors = this.validateEmptyOrAlternatives(options.rules);
      const ambiguousAltsErrors = this.validateAmbiguousAlternationAlternatives(options.rules, this.maxLookahead);
      const emptyRepetitionErrors = this.validateSomeNonEmptyLookaheadPath(options.rules, this.maxLookahead);
      const allErrors = [
        ...leftRecursionErrors,
        ...emptyAltErrors,
        ...ambiguousAltsErrors,
        ...emptyRepetitionErrors
      ];
      return allErrors;
    }
    return leftRecursionErrors;
  }
  validateNoLeftRecursion(rules) {
    return flatMap.default(rules, (currTopRule) => checks.validateNoLeftRecursion(currTopRule, currTopRule, errors_public.defaultGrammarValidatorErrorProvider));
  }
  validateEmptyOrAlternatives(rules) {
    return flatMap.default(rules, (currTopRule) => checks.validateEmptyOrAlternative(currTopRule, errors_public.defaultGrammarValidatorErrorProvider));
  }
  validateAmbiguousAlternationAlternatives(rules, maxLookahead) {
    return flatMap.default(rules, (currTopRule) => checks.validateAmbiguousAlternationAlternatives(currTopRule, maxLookahead, errors_public.defaultGrammarValidatorErrorProvider));
  }
  validateSomeNonEmptyLookaheadPath(rules, maxLookahead) {
    return checks.validateSomeNonEmptyLookaheadPath(rules, maxLookahead, errors_public.defaultGrammarValidatorErrorProvider);
  }
  buildLookaheadForAlternation(options) {
    return lookahead.buildLookaheadFuncForOr(options.prodOccurrence, options.rule, options.maxLookahead, options.hasPredicates, options.dynamicTokensEnabled, lookahead.buildAlternativesLookAheadFunc);
  }
  buildLookaheadForOptional(options) {
    return lookahead.buildLookaheadFuncForOptionalProd(options.prodOccurrence, options.rule, options.maxLookahead, options.dynamicTokensEnabled, lookahead.getProdType(options.prodType), lookahead.buildSingleAlternativeLookaheadFunction);
  }
}
exports.LLkLookaheadStrategy = LLkLookaheadStrategy;
//# sourceMappingURL=lib-src-parse-grammar-llk_lookahead.cjs.map
