import values_default from "../../../../../../lodash-es/values.js";
import includes_default from "../../../../../../lodash-es/includes.js";
import { serializeGrammar } from "../../../../../../@chevrotain/gast/lib/src/model.js";
import { defaultGrammarValidatorErrorProvider } from "../../errors_public.js";
import { validateRuleIsOverridden } from "../../grammar/checks.js";
import { isRecognitionException } from "../../exceptions_public.js";
import { DEFAULT_RULE_CONFIG, ParserDefinitionErrorType } from "../parser.js";
var RecognizerApi = class {
	ACTION(e) {
		return e.call(this);
	}
	consume(e, i, a) {
		return this.consumeInternal(i, e, a);
	}
	subrule(e, i, a) {
		return this.subruleInternal(i, e, a);
	}
	option(e, i) {
		return this.optionInternal(i, e);
	}
	or(e, i) {
		return this.orInternal(i, e);
	}
	many(e, i) {
		return this.manyInternal(e, i);
	}
	atLeastOne(e, i) {
		return this.atLeastOneInternal(e, i);
	}
	CONSUME(e, i) {
		return this.consumeInternal(e, 0, i);
	}
	CONSUME1(e, i) {
		return this.consumeInternal(e, 1, i);
	}
	CONSUME2(e, i) {
		return this.consumeInternal(e, 2, i);
	}
	CONSUME3(e, i) {
		return this.consumeInternal(e, 3, i);
	}
	CONSUME4(e, i) {
		return this.consumeInternal(e, 4, i);
	}
	CONSUME5(e, i) {
		return this.consumeInternal(e, 5, i);
	}
	CONSUME6(e, i) {
		return this.consumeInternal(e, 6, i);
	}
	CONSUME7(e, i) {
		return this.consumeInternal(e, 7, i);
	}
	CONSUME8(e, i) {
		return this.consumeInternal(e, 8, i);
	}
	CONSUME9(e, i) {
		return this.consumeInternal(e, 9, i);
	}
	SUBRULE(e, i) {
		return this.subruleInternal(e, 0, i);
	}
	SUBRULE1(e, i) {
		return this.subruleInternal(e, 1, i);
	}
	SUBRULE2(e, i) {
		return this.subruleInternal(e, 2, i);
	}
	SUBRULE3(e, i) {
		return this.subruleInternal(e, 3, i);
	}
	SUBRULE4(e, i) {
		return this.subruleInternal(e, 4, i);
	}
	SUBRULE5(e, i) {
		return this.subruleInternal(e, 5, i);
	}
	SUBRULE6(e, i) {
		return this.subruleInternal(e, 6, i);
	}
	SUBRULE7(e, i) {
		return this.subruleInternal(e, 7, i);
	}
	SUBRULE8(e, i) {
		return this.subruleInternal(e, 8, i);
	}
	SUBRULE9(e, i) {
		return this.subruleInternal(e, 9, i);
	}
	OPTION(e) {
		return this.optionInternal(e, 0);
	}
	OPTION1(e) {
		return this.optionInternal(e, 1);
	}
	OPTION2(e) {
		return this.optionInternal(e, 2);
	}
	OPTION3(e) {
		return this.optionInternal(e, 3);
	}
	OPTION4(e) {
		return this.optionInternal(e, 4);
	}
	OPTION5(e) {
		return this.optionInternal(e, 5);
	}
	OPTION6(e) {
		return this.optionInternal(e, 6);
	}
	OPTION7(e) {
		return this.optionInternal(e, 7);
	}
	OPTION8(e) {
		return this.optionInternal(e, 8);
	}
	OPTION9(e) {
		return this.optionInternal(e, 9);
	}
	OR(e) {
		return this.orInternal(e, 0);
	}
	OR1(e) {
		return this.orInternal(e, 1);
	}
	OR2(e) {
		return this.orInternal(e, 2);
	}
	OR3(e) {
		return this.orInternal(e, 3);
	}
	OR4(e) {
		return this.orInternal(e, 4);
	}
	OR5(e) {
		return this.orInternal(e, 5);
	}
	OR6(e) {
		return this.orInternal(e, 6);
	}
	OR7(e) {
		return this.orInternal(e, 7);
	}
	OR8(e) {
		return this.orInternal(e, 8);
	}
	OR9(e) {
		return this.orInternal(e, 9);
	}
	MANY(e) {
		this.manyInternal(0, e);
	}
	MANY1(e) {
		this.manyInternal(1, e);
	}
	MANY2(e) {
		this.manyInternal(2, e);
	}
	MANY3(e) {
		this.manyInternal(3, e);
	}
	MANY4(e) {
		this.manyInternal(4, e);
	}
	MANY5(e) {
		this.manyInternal(5, e);
	}
	MANY6(e) {
		this.manyInternal(6, e);
	}
	MANY7(e) {
		this.manyInternal(7, e);
	}
	MANY8(e) {
		this.manyInternal(8, e);
	}
	MANY9(e) {
		this.manyInternal(9, e);
	}
	MANY_SEP(e) {
		this.manySepFirstInternal(0, e);
	}
	MANY_SEP1(e) {
		this.manySepFirstInternal(1, e);
	}
	MANY_SEP2(e) {
		this.manySepFirstInternal(2, e);
	}
	MANY_SEP3(e) {
		this.manySepFirstInternal(3, e);
	}
	MANY_SEP4(e) {
		this.manySepFirstInternal(4, e);
	}
	MANY_SEP5(e) {
		this.manySepFirstInternal(5, e);
	}
	MANY_SEP6(e) {
		this.manySepFirstInternal(6, e);
	}
	MANY_SEP7(e) {
		this.manySepFirstInternal(7, e);
	}
	MANY_SEP8(e) {
		this.manySepFirstInternal(8, e);
	}
	MANY_SEP9(e) {
		this.manySepFirstInternal(9, e);
	}
	AT_LEAST_ONE(e) {
		this.atLeastOneInternal(0, e);
	}
	AT_LEAST_ONE1(e) {
		return this.atLeastOneInternal(1, e);
	}
	AT_LEAST_ONE2(e) {
		this.atLeastOneInternal(2, e);
	}
	AT_LEAST_ONE3(e) {
		this.atLeastOneInternal(3, e);
	}
	AT_LEAST_ONE4(e) {
		this.atLeastOneInternal(4, e);
	}
	AT_LEAST_ONE5(e) {
		this.atLeastOneInternal(5, e);
	}
	AT_LEAST_ONE6(e) {
		this.atLeastOneInternal(6, e);
	}
	AT_LEAST_ONE7(e) {
		this.atLeastOneInternal(7, e);
	}
	AT_LEAST_ONE8(e) {
		this.atLeastOneInternal(8, e);
	}
	AT_LEAST_ONE9(e) {
		this.atLeastOneInternal(9, e);
	}
	AT_LEAST_ONE_SEP(e) {
		this.atLeastOneSepFirstInternal(0, e);
	}
	AT_LEAST_ONE_SEP1(e) {
		this.atLeastOneSepFirstInternal(1, e);
	}
	AT_LEAST_ONE_SEP2(e) {
		this.atLeastOneSepFirstInternal(2, e);
	}
	AT_LEAST_ONE_SEP3(e) {
		this.atLeastOneSepFirstInternal(3, e);
	}
	AT_LEAST_ONE_SEP4(e) {
		this.atLeastOneSepFirstInternal(4, e);
	}
	AT_LEAST_ONE_SEP5(e) {
		this.atLeastOneSepFirstInternal(5, e);
	}
	AT_LEAST_ONE_SEP6(e) {
		this.atLeastOneSepFirstInternal(6, e);
	}
	AT_LEAST_ONE_SEP7(e) {
		this.atLeastOneSepFirstInternal(7, e);
	}
	AT_LEAST_ONE_SEP8(e) {
		this.atLeastOneSepFirstInternal(8, e);
	}
	AT_LEAST_ONE_SEP9(e) {
		this.atLeastOneSepFirstInternal(9, e);
	}
	RULE(e, a, s = DEFAULT_RULE_CONFIG) {
		if (includes_default(this.definedRulesNames, e)) {
			let i = {
				message: defaultGrammarValidatorErrorProvider.buildDuplicateRuleNameError({
					topLevelRule: e,
					grammarName: this.className
				}),
				type: ParserDefinitionErrorType.DUPLICATE_RULE_NAME,
				ruleName: e
			};
			this.definitionErrors.push(i);
		}
		this.definedRulesNames.push(e);
		let c = this.defineRule(e, a, s);
		return this[e] = c, c;
	}
	OVERRIDE_RULE(e, i, a = DEFAULT_RULE_CONFIG) {
		let o = validateRuleIsOverridden(e, this.definedRulesNames, this.className);
		this.definitionErrors = this.definitionErrors.concat(o);
		let c = this.defineRule(e, i, a);
		return this[e] = c, c;
	}
	BACKTRACK(e, i) {
		return function() {
			this.isBackTrackingStack.push(1);
			let a = this.saveRecogState();
			try {
				return e.apply(this, i), !0;
			} catch (e) {
				if (isRecognitionException(e)) return !1;
				throw e;
			} finally {
				this.reloadRecogState(a), this.isBackTrackingStack.pop();
			}
		};
	}
	getGAstProductions() {
		return this.gastProductionsCache;
	}
	getSerializedGastProductions() {
		return serializeGrammar(values_default(this.gastProductionsCache));
	}
};
export { RecognizerApi };
