import { RegExpParser as e } from "../../../@chevrotain/regexp-to-ast/lib/src/regexp-parser.js";
import { BaseRegExpVisitor as t } from "../../../@chevrotain/regexp-to-ast/lib/src/base-regexp-visitor.js";
import "../../../@chevrotain/regexp-to-ast/lib/src/api.js";
//#region ../../node_modules/langium/lib/utils/regexp-utils.js
var n = /\r?\n/gm, r = new e(), i = new class extends t {
	constructor() {
		super(...arguments), this.isStarting = !0, this.endRegexpStack = [], this.multiline = !1;
	}
	get endRegex() {
		return this.endRegexpStack.join("");
	}
	reset(e) {
		this.multiline = !1, this.regex = e, this.startRegexp = "", this.isStarting = !0, this.endRegexpStack = [];
	}
	visitGroup(e) {
		e.quantifier && (this.isStarting = !1, this.endRegexpStack = []);
	}
	visitCharacter(e) {
		let t = String.fromCharCode(e.value);
		if (!this.multiline && t === "\n" && (this.multiline = !0), e.quantifier) this.isStarting = !1, this.endRegexpStack = [];
		else {
			let e = c(t);
			this.endRegexpStack.push(e), this.isStarting && (this.startRegexp += e);
		}
	}
	visitSet(e) {
		if (!this.multiline) {
			let t = this.regex.substring(e.loc.begin, e.loc.end), n = new RegExp(t);
			this.multiline = !!"\n".match(n);
		}
		if (e.quantifier) this.isStarting = !1, this.endRegexpStack = [];
		else {
			let t = this.regex.substring(e.loc.begin, e.loc.end);
			this.endRegexpStack.push(t), this.isStarting && (this.startRegexp += t);
		}
	}
	visitChildren(e) {
		e.type === "Group" && e.quantifier || super.visitChildren(e);
	}
}();
function a(e) {
	try {
		return typeof e == "string" && (e = new RegExp(e)), e = e.toString(), i.reset(e), i.visit(r.pattern(e)), i.multiline;
	} catch {
		return !1;
	}
}
var o = "\f\n\r	\v \xA0            \u2028\u2029  　﻿".split("");
function s(e) {
	let t = typeof e == "string" ? new RegExp(e) : e;
	return o.some((e) => t.test(e));
}
function c(e) {
	return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function l(e, t) {
	let n = u(e), r = t.match(n);
	return !!r && r[0].length > 0;
}
function u(e) {
	typeof e == "string" && (e = new RegExp(e));
	let t = e, n = e.source, r = 0;
	function i() {
		let e = "", a;
		function o(t) {
			e += n.substr(r, t), r += t;
		}
		function s(t) {
			e += "(?:" + n.substr(r, t) + "|$)", r += t;
		}
		for (; r < n.length;) switch (n[r]) {
			case "\\":
				switch (n[r + 1]) {
					case "c":
						s(3);
						break;
					case "x":
						s(4);
						break;
					case "u":
						t.unicode ? n[r + 2] === "{" ? s(n.indexOf("}", r) - r + 1) : s(6) : s(2);
						break;
					case "p":
					case "P":
						t.unicode ? s(n.indexOf("}", r) - r + 1) : s(2);
						break;
					case "k":
						s(n.indexOf(">", r) - r + 1);
						break;
					default:
						s(2);
						break;
				}
				break;
			case "[":
				a = /\[(?:\\.|.)*?\]/g, a.lastIndex = r, a = a.exec(n) || [], s(a[0].length);
				break;
			case "|":
			case "^":
			case "$":
			case "*":
			case "+":
			case "?":
				o(1);
				break;
			case "{":
				a = /\{\d+,?\d*\}/g, a.lastIndex = r, a = a.exec(n), a ? o(a[0].length) : s(1);
				break;
			case "(":
				if (n[r + 1] === "?") switch (n[r + 2]) {
					case ":":
						e += "(?:", r += 3, e += i() + "|$)";
						break;
					case "=":
						e += "(?=", r += 3, e += i() + ")";
						break;
					case "!":
						a = r, r += 3, i(), e += n.substr(a, r - a);
						break;
					case "<":
						switch (n[r + 3]) {
							case "=":
							case "!":
								a = r, r += 4, i(), e += n.substr(a, r - a);
								break;
							default:
								o(n.indexOf(">", r) - r + 1), e += i() + "|$)";
								break;
						}
						break;
				}
				else o(1), e += i() + "|$)";
				break;
			case ")": return ++r, e;
			default:
				s(1);
				break;
		}
		return e;
	}
	return new RegExp(i(), e.flags);
}
//#endregion
export { n as NEWLINE_REGEXP, c as escapeRegExp, a as isMultilineComment, s as isWhitespace, l as partialMatches };
