import { GAstVisitor as e } from "../../../../../../@chevrotain/gast/lib/src/visitor.js";
import { getProductionDslName as t } from "../../../../../../@chevrotain/gast/lib/src/helpers.js";
import { AT_LEAST_ONE_IDX as n, AT_LEAST_ONE_SEP_IDX as r, MANY_SEP_IDX as i, getKeyForAutomaticLookahead as a } from "../../grammar/keys.js";
import { LLkLookaheadStrategy as o } from "../../grammar/llk_lookahead.js";
import { DEFAULT_PARSER_CONFIG as s } from "../parser.js";
//#region ../../node_modules/chevrotain/lib/src/parse/parser/traits/looksahead.js
var c = class {
	initLooksAhead(e) {
		this.dynamicTokensEnabled = Object.hasOwn(e, "dynamicTokensEnabled") ? e.dynamicTokensEnabled : s.dynamicTokensEnabled, this.maxLookahead = Object.hasOwn(e, "maxLookahead") ? e.maxLookahead : s.maxLookahead, this.lookaheadStrategy = Object.hasOwn(e, "lookaheadStrategy") ? e.lookaheadStrategy : new o({ maxLookahead: this.maxLookahead }), this.lookAheadFuncsCache = /* @__PURE__ */ new Map();
	}
	preComputeLookaheadFunctions(e) {
		e.forEach((e) => {
			this.TRACE_INIT(`${e.name} Rule Lookahead`, () => {
				let { alternation: o, repetition: s, option: c, repetitionMandatory: l, repetitionMandatoryWithSeparator: d, repetitionWithSeparator: f } = u(e);
				o.forEach((n) => {
					let r = n.idx === 0 ? "" : n.idx;
					this.TRACE_INIT(`${t(n)}${r}`, () => {
						let t = this.lookaheadStrategy.buildLookaheadForAlternation({
							prodOccurrence: n.idx,
							rule: e,
							maxLookahead: n.maxLookahead || this.maxLookahead,
							hasPredicates: n.hasPredicates,
							dynamicTokensEnabled: this.dynamicTokensEnabled
						}), r = a(this.fullRuleNameToShort[e.name], 256, n.idx);
						this.setLaFuncCache(r, t);
					});
				}), s.forEach((n) => {
					this.computeLookaheadFunc(e, n.idx, 768, "Repetition", n.maxLookahead, t(n));
				}), c.forEach((n) => {
					this.computeLookaheadFunc(e, n.idx, 512, "Option", n.maxLookahead, t(n));
				}), l.forEach((r) => {
					this.computeLookaheadFunc(e, r.idx, n, "RepetitionMandatory", r.maxLookahead, t(r));
				}), d.forEach((n) => {
					this.computeLookaheadFunc(e, n.idx, r, "RepetitionMandatoryWithSeparator", n.maxLookahead, t(n));
				}), f.forEach((n) => {
					this.computeLookaheadFunc(e, n.idx, i, "RepetitionWithSeparator", n.maxLookahead, t(n));
				});
			});
		});
	}
	computeLookaheadFunc(e, t, n, r, i, o) {
		this.TRACE_INIT(`${o}${t === 0 ? "" : t}`, () => {
			let o = this.lookaheadStrategy.buildLookaheadForOptional({
				prodOccurrence: t,
				rule: e,
				maxLookahead: i || this.maxLookahead,
				dynamicTokensEnabled: this.dynamicTokensEnabled,
				prodType: r
			}), s = a(this.fullRuleNameToShort[e.name], n, t);
			this.setLaFuncCache(s, o);
		});
	}
	getKeyForAutomaticLookahead(e, t) {
		return a(this.currRuleShortName, e, t);
	}
	getLaFuncFromCache(e) {
		return this.lookAheadFuncsCache.get(e);
	}
	/* istanbul ignore next */
	setLaFuncCache(e, t) {
		this.lookAheadFuncsCache.set(e, t);
	}
}, l = new class extends e {
	constructor() {
		super(...arguments), this.dslMethods = {
			option: [],
			alternation: [],
			repetition: [],
			repetitionWithSeparator: [],
			repetitionMandatory: [],
			repetitionMandatoryWithSeparator: []
		};
	}
	reset() {
		this.dslMethods = {
			option: [],
			alternation: [],
			repetition: [],
			repetitionWithSeparator: [],
			repetitionMandatory: [],
			repetitionMandatoryWithSeparator: []
		};
	}
	visitOption(e) {
		this.dslMethods.option.push(e);
	}
	visitRepetitionWithSeparator(e) {
		this.dslMethods.repetitionWithSeparator.push(e);
	}
	visitRepetitionMandatory(e) {
		this.dslMethods.repetitionMandatory.push(e);
	}
	visitRepetitionMandatoryWithSeparator(e) {
		this.dslMethods.repetitionMandatoryWithSeparator.push(e);
	}
	visitRepetition(e) {
		this.dslMethods.repetition.push(e);
	}
	visitAlternation(e) {
		this.dslMethods.alternation.push(e);
	}
}();
function u(e) {
	l.reset(), e.accept(l);
	let t = l.dslMethods;
	return l.reset(), t;
}
//#endregion
export { c as LooksAhead };
