//#region ../../node_modules/@chevrotain/gast/lib/src/model.js
function e(e) {
	return t(e) ? e.LABEL : e.name;
}
function t(e) {
	return typeof e.LABEL == "string" && e.LABEL !== "";
}
var n = class {
	get definition() {
		return this._definition;
	}
	set definition(e) {
		this._definition = e;
	}
	constructor(e) {
		this._definition = e;
	}
	accept(e) {
		e.visit(this), this.definition.forEach((t) => {
			t.accept(e);
		});
	}
}, r = class extends n {
	constructor(e) {
		super([]), this.idx = 1, Object.assign(this, h(e));
	}
	set definition(e) {}
	get definition() {
		return this.referencedRule === void 0 ? [] : this.referencedRule.definition;
	}
	accept(e) {
		e.visit(this);
	}
}, i = class extends n {
	constructor(e) {
		super(e.definition), this.orgText = "", Object.assign(this, h(e));
	}
}, a = class extends n {
	constructor(e) {
		super(e.definition), this.ignoreAmbiguities = !1, Object.assign(this, h(e));
	}
}, o = class extends n {
	constructor(e) {
		super(e.definition), this.idx = 1, Object.assign(this, h(e));
	}
}, s = class extends n {
	constructor(e) {
		super(e.definition), this.idx = 1, Object.assign(this, h(e));
	}
}, c = class extends n {
	constructor(e) {
		super(e.definition), this.idx = 1, Object.assign(this, h(e));
	}
}, l = class extends n {
	constructor(e) {
		super(e.definition), this.idx = 1, Object.assign(this, h(e));
	}
}, u = class extends n {
	constructor(e) {
		super(e.definition), this.idx = 1, Object.assign(this, h(e));
	}
}, d = class extends n {
	get definition() {
		return this._definition;
	}
	set definition(e) {
		this._definition = e;
	}
	constructor(e) {
		super(e.definition), this.idx = 1, this.ignoreAmbiguities = !1, this.hasPredicates = !1, Object.assign(this, h(e));
	}
}, f = class {
	constructor(e) {
		this.idx = 1, Object.assign(this, h(e));
	}
	accept(e) {
		e.visit(this);
	}
};
function p(e) {
	return e.map(m);
}
function m(t) {
	function n(e) {
		return e.map(m);
	}
	/* istanbul ignore else */
	if (t instanceof r) {
		let e = {
			type: "NonTerminal",
			name: t.nonTerminalName,
			idx: t.idx
		};
		return typeof t.label == "string" && (e.label = t.label), e;
	} else if (t instanceof a) return {
		type: "Alternative",
		definition: n(t.definition)
	};
	else if (t instanceof o) return {
		type: "Option",
		idx: t.idx,
		definition: n(t.definition)
	};
	else if (t instanceof s) return {
		type: "RepetitionMandatory",
		idx: t.idx,
		definition: n(t.definition)
	};
	else if (t instanceof c) return {
		type: "RepetitionMandatoryWithSeparator",
		idx: t.idx,
		separator: m(new f({ terminalType: t.separator })),
		definition: n(t.definition)
	};
	else if (t instanceof u) return {
		type: "RepetitionWithSeparator",
		idx: t.idx,
		separator: m(new f({ terminalType: t.separator })),
		definition: n(t.definition)
	};
	else if (t instanceof l) return {
		type: "Repetition",
		idx: t.idx,
		definition: n(t.definition)
	};
	else if (t instanceof d) return {
		type: "Alternation",
		idx: t.idx,
		definition: n(t.definition)
	};
	else if (t instanceof f) {
		let n = {
			type: "Terminal",
			name: t.terminalType.name,
			label: e(t.terminalType),
			idx: t.idx
		};
		typeof t.label == "string" && (n.terminalLabel = t.label);
		let r = t.terminalType.PATTERN;
		return t.terminalType.PATTERN && (n.pattern = r instanceof RegExp ? r.source : r), n;
	} else if (t instanceof i) return {
		type: "Rule",
		name: t.name,
		orgText: t.orgText,
		definition: n(t.definition)
	};
	else throw Error("non exhaustive match");
}
function h(e) {
	return Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
}
//#endregion
export { n as AbstractProduction, d as Alternation, a as Alternative, r as NonTerminal, o as Option, l as Repetition, s as RepetitionMandatory, c as RepetitionMandatoryWithSeparator, u as RepetitionWithSeparator, i as Rule, f as Terminal, p as serializeGrammar, m as serializeProduction };
