import isEmpty_default from "../../../../../lodash-es/isEmpty.js";
import flatMap_default from "../../../../../lodash-es/flatMap.js";
import { defaultGrammarValidatorErrorProvider } from "../errors_public.js";
import { buildAlternativesLookAheadFunc, buildLookaheadFuncForOptionalProd, buildLookaheadFuncForOr, buildSingleAlternativeLookaheadFunction, getProdType } from "./lookahead.js";
import { validateAmbiguousAlternationAlternatives, validateEmptyOrAlternative, validateNoLeftRecursion, validateSomeNonEmptyLookaheadPath } from "./checks.js";
import { DEFAULT_PARSER_CONFIG } from "../parser/parser.js";
var LLkLookaheadStrategy = class {
	constructor(e) {
		this.maxLookahead = e?.maxLookahead ?? DEFAULT_PARSER_CONFIG.maxLookahead;
	}
	validate(u) {
		let d = this.validateNoLeftRecursion(u.rules);
		if (isEmpty_default(d)) {
			let e = this.validateEmptyOrAlternatives(u.rules), f = this.validateAmbiguousAlternationAlternatives(u.rules, this.maxLookahead), p = this.validateSomeNonEmptyLookaheadPath(u.rules, this.maxLookahead);
			return [
				...d,
				...e,
				...f,
				...p
			];
		}
		return d;
	}
	validateNoLeftRecursion(e) {
		return flatMap_default(e, (e) => validateNoLeftRecursion(e, e, defaultGrammarValidatorErrorProvider));
	}
	validateEmptyOrAlternatives(e) {
		return flatMap_default(e, (e) => validateEmptyOrAlternative(e, defaultGrammarValidatorErrorProvider));
	}
	validateAmbiguousAlternationAlternatives(e, f) {
		return flatMap_default(e, (e) => validateAmbiguousAlternationAlternatives(e, f, defaultGrammarValidatorErrorProvider));
	}
	validateSomeNonEmptyLookaheadPath(e, u) {
		return validateSomeNonEmptyLookaheadPath(e, u, defaultGrammarValidatorErrorProvider);
	}
	buildLookaheadForAlternation(e) {
		return buildLookaheadFuncForOr(e.prodOccurrence, e.rule, e.maxLookahead, e.hasPredicates, e.dynamicTokensEnabled, buildAlternativesLookAheadFunc);
	}
	buildLookaheadForOptional(e) {
		return buildLookaheadFuncForOptionalProd(e.prodOccurrence, e.rule, e.maxLookahead, e.dynamicTokensEnabled, getProdType(e.prodType), buildSingleAlternativeLookaheadFunction);
	}
};
export { LLkLookaheadStrategy };
