import { defaultLexerErrorProvider } from "../../../chevrotain/lib/src/scan/lexer_errors_public.js";
import { Lexer } from "../../../chevrotain/lib/src/scan/lexer_public.js";
import "../../../chevrotain/lib/src/api.js";
var DefaultLexerErrorMessageProvider = class {
	buildUnexpectedCharactersMessage(r, i, a, o, s) {
		return defaultLexerErrorProvider.buildUnexpectedCharactersMessage(r, i, a, o, s);
	}
	buildUnableToPopLexerModeMessage(r) {
		return defaultLexerErrorProvider.buildUnableToPopLexerModeMessage(r);
	}
};
const DEFAULT_TOKENIZE_OPTIONS = { mode: "full" };
var DefaultLexer = class {
	constructor(e) {
		this.errorMessageProvider = e.parser.LexerErrorMessageProvider, this.tokenBuilder = e.parser.TokenBuilder;
		let i = this.tokenBuilder.buildTokens(e.Grammar, { caseInsensitive: e.LanguageMetaData.caseInsensitive });
		this.tokenTypes = this.toTokenTypeDictionary(i), this.chevrotainLexer = new Lexer(isTokenTypeDictionary(i) ? Object.values(i) : i, {
			positionTracking: "full",
			skipValidations: e.LanguageMetaData.mode === "production",
			errorMessageProvider: this.errorMessageProvider
		});
	}
	get definition() {
		return this.tokenTypes;
	}
	tokenize(e, r = DEFAULT_TOKENIZE_OPTIONS) {
		let i = this.chevrotainLexer.tokenize(e);
		return {
			tokens: i.tokens,
			errors: i.errors,
			hidden: i.groups.hidden ?? [],
			report: this.tokenBuilder.flushLexingReport?.(e)
		};
	}
	toTokenTypeDictionary(e) {
		if (isTokenTypeDictionary(e)) return e;
		let r = isIMultiModeLexerDefinition(e) ? Object.values(e.modes).flat() : e, i = {};
		return r.forEach((e) => i[e.name] = e), i;
	}
};
function isTokenTypeArray(e) {
	return Array.isArray(e) && (e.length === 0 || "name" in e[0]);
}
function isIMultiModeLexerDefinition(e) {
	return e && "modes" in e && "defaultMode" in e;
}
function isTokenTypeDictionary(e) {
	return !isTokenTypeArray(e) && !isIMultiModeLexerDefinition(e);
}
export { DEFAULT_TOKENIZE_OPTIONS, DefaultLexer, DefaultLexerErrorMessageProvider, isIMultiModeLexerDefinition, isTokenTypeArray, isTokenTypeDictionary };
