import { getLookaheadPathsForOptionalProd as e, getLookaheadPathsForOr as t } from "../../grammar/lookahead.js";
import { EarlyExitException as n, NoViableAltException as r, isRecognitionException as i } from "../../exceptions_public.js";
import { DEFAULT_PARSER_CONFIG as a } from "../parser.js";
//#region ../../node_modules/chevrotain/lib/src/parse/parser/traits/error_handler.js
var o = class {
	initErrorHandler(e) {
		this._errors = [], this.errorMessageProvider = Object.hasOwn(e, "errorMessageProvider") ? e.errorMessageProvider : a.errorMessageProvider;
	}
	SAVE_ERROR(e) {
		if (i(e)) return e.context = {
			ruleStack: this.getHumanReadableRuleStack(),
			ruleOccurrenceStack: this.RULE_OCCURRENCE_STACK.slice(0, this.RULE_OCCURRENCE_STACK_IDX + 1)
		}, this._errors.push(e), e;
		throw Error("Trying to save an Error which is not a RecognitionException");
	}
	get errors() {
		return [...this._errors];
	}
	set errors(e) {
		this._errors = e;
	}
	raiseEarlyExitException(t, r, i) {
		let a = this.getCurrRuleFullName(), o = this.getGAstProductions()[a], s = e(t, o, r, this.maxLookahead)[0], c = [];
		for (let e = 1; e <= this.maxLookahead; e++) c.push(this.LA(e));
		let l = this.errorMessageProvider.buildEarlyExitMessage({
			expectedIterationPaths: s,
			actual: c,
			previous: this.LA(0),
			customUserDescription: i,
			ruleName: a
		});
		throw this.SAVE_ERROR(new n(l, this.LA(1), this.LA(0)));
	}
	raiseNoAltException(e, n) {
		let i = this.getCurrRuleFullName(), a = this.getGAstProductions()[i], o = t(e, a, this.maxLookahead), s = [];
		for (let e = 1; e <= this.maxLookahead; e++) s.push(this.LA(e));
		let c = this.LA(0), l = this.errorMessageProvider.buildNoViableAltMessage({
			expectedPathsPerAlt: o,
			actual: s,
			previous: c,
			customUserDescription: n,
			ruleName: this.getCurrRuleFullName()
		});
		throw this.SAVE_ERROR(new r(l, this.LA(1), c));
	}
};
//#endregion
export { o as ErrorHandler };
