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