import { addNoneTerminalToCst as e, addTerminalToCst as t, setNodeLocationFull as n, setNodeLocationOnlyOffset as r } from "../../cst/cst.js";
import { createBaseSemanticVisitorConstructor as i, createBaseVisitorConstructorWithDefaults as a } from "../../cst/cst_visitor.js";
import { DEFAULT_PARSER_CONFIG as o } from "../parser.js";
//#region ../../node_modules/chevrotain/lib/src/parse/parser/traits/tree_builder.js
var s = class {
	initTreeBuilder(e) {
		if (this.CST_STACK = [], this.outputCst = e.outputCst, this.nodeLocationTracking = Object.hasOwn(e, "nodeLocationTracking") ? e.nodeLocationTracking : o.nodeLocationTracking, !this.outputCst) this.cstInvocationStateUpdate = () => {}, this.cstFinallyStateUpdate = () => {}, this.cstPostTerminal = () => {}, this.cstPostNonTerminal = () => {}, this.cstPostRule = () => {};
		else if (/full/i.test(this.nodeLocationTracking)) this.recoveryEnabled ? (this.setNodeLocationFromToken = n, this.setNodeLocationFromNode = n, this.cstPostRule = () => {}, this.setInitialNodeLocation = this.setInitialNodeLocationFullRecovery) : (this.setNodeLocationFromToken = () => {}, this.setNodeLocationFromNode = () => {}, this.cstPostRule = this.cstPostRuleFull, this.setInitialNodeLocation = this.setInitialNodeLocationFullRegular);
		else if (/onlyOffset/i.test(this.nodeLocationTracking)) this.recoveryEnabled ? (this.setNodeLocationFromToken = r, this.setNodeLocationFromNode = r, this.cstPostRule = () => {}, this.setInitialNodeLocation = this.setInitialNodeLocationOnlyOffsetRecovery) : (this.setNodeLocationFromToken = () => {}, this.setNodeLocationFromNode = () => {}, this.cstPostRule = this.cstPostRuleOnlyOffset, this.setInitialNodeLocation = this.setInitialNodeLocationOnlyOffsetRegular);
		else if (/none/i.test(this.nodeLocationTracking)) this.setNodeLocationFromToken = () => {}, this.setNodeLocationFromNode = () => {}, this.cstPostRule = () => {}, this.setInitialNodeLocation = () => {};
		else throw Error(`Invalid <nodeLocationTracking> config option: "${e.nodeLocationTracking}"`);
	}
	setInitialNodeLocationOnlyOffsetRecovery(e) {
		e.location = {
			startOffset: NaN,
			endOffset: NaN
		};
	}
	setInitialNodeLocationOnlyOffsetRegular(e) {
		e.location = {
			startOffset: this.LA_FAST(1).startOffset,
			endOffset: NaN
		};
	}
	setInitialNodeLocationFullRecovery(e) {
		e.location = {
			startOffset: NaN,
			startLine: NaN,
			startColumn: NaN,
			endOffset: NaN,
			endLine: NaN,
			endColumn: NaN
		};
	}
	setInitialNodeLocationFullRegular(e) {
		let t = this.LA_FAST(1);
		e.location = {
			startOffset: t.startOffset,
			startLine: t.startLine,
			startColumn: t.startColumn,
			endOffset: NaN,
			endLine: NaN,
			endColumn: NaN
		};
	}
	cstInvocationStateUpdate(e) {
		let t = {
			name: e,
			children: Object.create(null)
		};
		this.setInitialNodeLocation(t), this.CST_STACK.push(t);
	}
	cstFinallyStateUpdate() {
		this.CST_STACK.pop();
	}
	cstPostRuleFull(e) {
		let t = this.LA(0), n = e.location;
		n.startOffset <= t.startOffset ? (n.endOffset = t.endOffset, n.endLine = t.endLine, n.endColumn = t.endColumn) : (n.startOffset = NaN, n.startLine = NaN, n.startColumn = NaN);
	}
	cstPostRuleOnlyOffset(e) {
		let t = this.LA(0), n = e.location;
		n.startOffset <= t.startOffset ? n.endOffset = t.endOffset : n.startOffset = NaN;
	}
	cstPostTerminal(e, n) {
		let r = this.CST_STACK[this.CST_STACK.length - 1];
		t(r, n, e), this.setNodeLocationFromToken(r.location, n);
	}
	cstPostNonTerminal(t, n) {
		let r = this.CST_STACK[this.CST_STACK.length - 1];
		e(r, n, t), this.setNodeLocationFromNode(r.location, t.location);
	}
	getBaseCstVisitorConstructor() {
		if (this.baseCstVisitorConstructor === void 0) {
			let e = i(this.className, Object.keys(this.gastProductionsCache));
			return this.baseCstVisitorConstructor = e, e;
		}
		return this.baseCstVisitorConstructor;
	}
	getBaseCstVisitorConstructorWithDefaults() {
		if (this.baseCstVisitorWithDefaultsConstructor === void 0) {
			let e = a(this.className, Object.keys(this.gastProductionsCache), this.getBaseCstVisitorConstructor());
			return this.baseCstVisitorWithDefaultsConstructor = e, e;
		}
		return this.baseCstVisitorWithDefaultsConstructor;
	}
	getPreviousExplicitRuleShortName() {
		return this.RULE_STACK[this.RULE_STACK_IDX - 1];
	}
	getLastExplicitRuleOccurrenceIndex() {
		return this.RULE_OCCURRENCE_STACK[this.RULE_OCCURRENCE_STACK_IDX];
	}
};
//#endregion
export { s as TreeBuilder };
