import { Alternation as e, Alternative as t, NonTerminal as n, Option as r, Repetition as i, RepetitionMandatory as a, RepetitionMandatoryWithSeparator as o, RepetitionWithSeparator as s, Rule as c, Terminal as l } from "../../../../../../@chevrotain/gast/lib/src/model.js";
import { augmentTokenTypes as u, hasShortKeyProperty as d } from "../../../scan/tokens.js";
import { Lexer as f } from "../../../scan/lexer_public.js";
import { createToken as p, createTokenInstance as m } from "../../../scan/tokens_public.js";
import "../../grammar/keys.js";
import { END_OF_FILE as h } from "../parser.js";
//#region ../../node_modules/chevrotain/lib/src/parse/parser/traits/gast_recorder.js
var g = { description: "This Object indicates the Parser is during Recording Phase" };
Object.freeze(g);
var _ = !0, v = 2 ** 8 - 1, y = p({
	name: "RECORDING_PHASE_TOKEN",
	pattern: f.NA
});
u([y]);
var b = m(y, "This IToken indicates the Parser is in Recording Phase\n	See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details", -1, -1, -1, -1, -1, -1);
Object.freeze(b);
var x = {
	name: "This CSTNode indicates the Parser is in Recording Phase\n	See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details",
	children: {}
}, S = class {
	initGastRecorder(e) {
		this.recordingProdStack = [], this.RECORDING_PHASE = !1;
	}
	enableRecording() {
		this.RECORDING_PHASE = !0, this.TRACE_INIT("Enable Recording", () => {
			for (let e = 0; e < 10; e++) {
				let t = e > 0 ? e : "";
				this[`CONSUME${t}`] = function(t, n) {
					return this.consumeInternalRecord(t, e, n);
				}, this[`SUBRULE${t}`] = function(t, n) {
					return this.subruleInternalRecord(t, e, n);
				}, this[`OPTION${t}`] = function(t) {
					return this.optionInternalRecord(t, e);
				}, this[`OR${t}`] = function(t) {
					return this.orInternalRecord(t, e);
				}, this[`MANY${t}`] = function(t) {
					this.manyInternalRecord(e, t);
				}, this[`MANY_SEP${t}`] = function(t) {
					this.manySepFirstInternalRecord(e, t);
				}, this[`AT_LEAST_ONE${t}`] = function(t) {
					this.atLeastOneInternalRecord(e, t);
				}, this[`AT_LEAST_ONE_SEP${t}`] = function(t) {
					this.atLeastOneSepFirstInternalRecord(e, t);
				};
			}
			this.consume = function(e, t, n) {
				return this.consumeInternalRecord(t, e, n);
			}, this.subrule = function(e, t, n) {
				return this.subruleInternalRecord(t, e, n);
			}, this.option = function(e, t) {
				return this.optionInternalRecord(t, e);
			}, this.or = function(e, t) {
				return this.orInternalRecord(t, e);
			}, this.many = function(e, t) {
				this.manyInternalRecord(e, t);
			}, this.atLeastOne = function(e, t) {
				this.atLeastOneInternalRecord(e, t);
			}, this.ACTION = this.ACTION_RECORD, this.BACKTRACK = this.BACKTRACK_RECORD, this.LA = this.LA_RECORD;
		});
	}
	disableRecording() {
		this.RECORDING_PHASE = !1, this.TRACE_INIT("Deleting Recording methods", () => {
			let e = this;
			for (let t = 0; t < 10; t++) {
				let n = t > 0 ? t : "";
				delete e[`CONSUME${n}`], delete e[`SUBRULE${n}`], delete e[`OPTION${n}`], delete e[`OR${n}`], delete e[`MANY${n}`], delete e[`MANY_SEP${n}`], delete e[`AT_LEAST_ONE${n}`], delete e[`AT_LEAST_ONE_SEP${n}`];
			}
			delete e.consume, delete e.subrule, delete e.option, delete e.or, delete e.many, delete e.atLeastOne, delete e.ACTION, delete e.BACKTRACK, delete e.LA;
		});
	}
	ACTION_RECORD(e) {}
	BACKTRACK_RECORD(e, t) {
		return () => !0;
	}
	LA_RECORD(e) {
		return h;
	}
	topLevelRuleRecord(e, t) {
		try {
			let n = new c({
				definition: [],
				name: e
			});
			return n.name = e, this.recordingProdStack.push(n), t.call(this), this.recordingProdStack.pop(), n;
		} catch (e) {
			if (e.KNOWN_RECORDER_ERROR !== !0) try {
				e.message += "\n	 This error was thrown during the \"grammar recording phase\" For more info see:\n	https://chevrotain.io/docs/guide/internals.html#grammar-recording";
			} catch {
				throw e;
			}
			throw e;
		}
	}
	optionInternalRecord(e, t) {
		return C.call(this, r, e, t);
	}
	atLeastOneInternalRecord(e, t) {
		C.call(this, a, t, e);
	}
	atLeastOneSepFirstInternalRecord(e, t) {
		C.call(this, o, t, e, _);
	}
	manyInternalRecord(e, t) {
		C.call(this, i, t, e);
	}
	manySepFirstInternalRecord(e, t) {
		C.call(this, s, t, e, _);
	}
	orInternalRecord(e, t) {
		return w.call(this, e, t);
	}
	subruleInternalRecord(e, t, r) {
		if (E(t), !e || !Object.hasOwn(e, "ruleName")) {
			let n = /* @__PURE__ */ Error(`<SUBRULE${T(t)}> argument is invalid expecting a Parser method reference but got: <${JSON.stringify(e)}>\n inside top level rule: <${this.recordingProdStack[0].name}>`);
			throw n.KNOWN_RECORDER_ERROR = !0, n;
		}
		let i = this.recordingProdStack.at(-1), a = e.ruleName, o = new n({
			idx: t,
			nonTerminalName: a,
			label: r?.LABEL,
			referencedRule: void 0
		});
		return i.definition.push(o), this.outputCst ? x : g;
	}
	consumeInternalRecord(e, t, n) {
		if (E(t), !d(e)) {
			let n = /* @__PURE__ */ Error(`<CONSUME${T(t)}> argument is invalid expecting a TokenType reference but got: <${JSON.stringify(e)}>\n inside top level rule: <${this.recordingProdStack[0].name}>`);
			throw n.KNOWN_RECORDER_ERROR = !0, n;
		}
		let r = this.recordingProdStack.at(-1), i = new l({
			idx: t,
			terminalType: e,
			label: n?.LABEL
		});
		return r.definition.push(i), b;
	}
};
function C(e, t, n, r = !1) {
	E(n);
	let i = this.recordingProdStack.at(-1), a = typeof t == "function" ? t : t.DEF, o = new e({
		definition: [],
		idx: n
	});
	return r && (o.separator = t.SEP), Object.hasOwn(t, "MAX_LOOKAHEAD") && (o.maxLookahead = t.MAX_LOOKAHEAD), this.recordingProdStack.push(o), a.call(this), i.definition.push(o), this.recordingProdStack.pop(), g;
}
function w(n, r) {
	E(r);
	let i = this.recordingProdStack.at(-1), a = Array.isArray(n) === !1, o = a === !1 ? n : n.DEF, s = new e({
		definition: [],
		idx: r,
		ignoreAmbiguities: a && n.IGNORE_AMBIGUITIES === !0
	});
	return Object.hasOwn(n, "MAX_LOOKAHEAD") && (s.maxLookahead = n.MAX_LOOKAHEAD), s.hasPredicates = o.some((e) => typeof e.GATE == "function"), i.definition.push(s), o.forEach((e) => {
		let n = new t({ definition: [] });
		s.definition.push(n), Object.hasOwn(e, "IGNORE_AMBIGUITIES") ? n.ignoreAmbiguities = e.IGNORE_AMBIGUITIES : Object.hasOwn(e, "GATE") && (n.ignoreAmbiguities = !0), this.recordingProdStack.push(n), e.ALT.call(this), this.recordingProdStack.pop();
	}), g;
}
function T(e) {
	return e === 0 ? "" : `${e}`;
}
function E(e) {
	if (e < 0 || e > v) {
		let t = /* @__PURE__ */ Error(`Invalid DSL Method idx value: <${e}>\n\tIdx value must be a none negative value smaller than ${v + 1}`);
		throw t.KNOWN_RECORDER_ERROR = !0, t;
	}
}
//#endregion
export { S as GastRecorder };
