import { COMMENT as q, DECLARATION as B, RULESET as F } from "./Enum.js";
import { strlen as E, append as L, replace as z, indexof as G, sizeof as H, substr as N, abs as J, trim as K, from as U } from "./Utility.js";
import { dealloc as P, alloc as Q, next as O, peek as R, delimit as x, identifier as V, commenter as W, escaping as X, whitespace as Y, node as D, char as Z, prev as _, caret as y } from "./Tokenizer.js";
function ra(e) {
  return P(M("", null, null, null, [""], e = Q(e), 0, [0], e));
}
function M(e, o, n, i, m, p, C, v, A) {
  for (var w = 0, d = 0, r = C, l = 0, u = 0, b = 0, f = 1, T = 1, s = 1, c = 0, k = "", g = m, h = p, t = i, a = k; T; )
    switch (b = c, c = O()) {
      case 40:
        if (b != 108 && a.charCodeAt(r - 1) == 58) {
          G(a += z(x(c), "&", "&\f"), "&\f") != -1 && (s = -1);
          break;
        }
      case 34:
      case 39:
      case 91:
        a += x(c);
        break;
      case 9:
      case 10:
      case 13:
      case 32:
        a += Y(b);
        break;
      case 92:
        a += X(y() - 1, 7);
        continue;
      case 47:
        switch (R()) {
          case 42:
          case 47:
            L($(W(O(), y()), o, n), A);
            break;
          default:
            a += "/";
        }
        break;
      case 123 * f:
        v[w++] = E(a) * s;
      case 125 * f:
      case 59:
      case 0:
        switch (c) {
          case 0:
          case 125:
            T = 0;
          case 59 + d:
            u > 0 && E(a) - r && L(u > 32 ? S(a + ";", i, n, r - 1) : S(z(a, " ", "") + ";", i, n, r - 2), A);
            break;
          case 59:
            a += ";";
          default:
            if (L(t = I(a, o, n, w, d, m, v, k, g = [], h = [], r), p), c === 123)
              if (d === 0)
                M(a, o, t, t, g, p, r, v, h);
              else
                switch (l) {
                  case 100:
                  case 109:
                  case 115:
                    M(e, t, t, i && L(I(e, t, t, 0, 0, m, v, k, m, g = [], r), h), m, h, r, v, i ? g : h);
                    break;
                  default:
                    M(a, t, t, t, [""], h, 0, v, h);
                }
        }
        w = d = u = 0, f = s = 1, k = a = "", r = C;
        break;
      case 58:
        r = 1 + E(a), u = b;
      default:
        if (f < 1) {
          if (c == 123)
            --f;
          else if (c == 125 && f++ == 0 && _() == 125)
            continue;
        }
        switch (a += U(c), c * f) {
          case 38:
            s = d > 0 ? 1 : (a += "\f", -1);
            break;
          case 44:
            v[w++] = (E(a) - 1) * s, s = 1;
            break;
          case 64:
            R() === 45 && (a += x(O())), l = R(), d = r = E(k = a += V(y())), c++;
            break;
          case 45:
            b === 45 && E(a) == 2 && (f = 0);
        }
    }
  return p;
}
function I(e, o, n, i, m, p, C, v, A, w, d) {
  for (var r = m - 1, l = m === 0 ? p : [""], u = H(l), b = 0, f = 0, T = 0; b < i; ++b)
    for (var s = 0, c = N(e, r + 1, r = J(f = C[b])), k = e; s < u; ++s)
      (k = K(f > 0 ? l[s] + " " + c : z(c, /&\f/g, l[s]))) && (A[T++] = k);
  return D(e, o, n, m === 0 ? F : v, A, w, d);
}
function $(e, o, n) {
  return D(e, o, n, q, U(Z()), N(e, 2, -2), 0);
}
function S(e, o, n, i) {
  return D(e, o, n, B, N(e, 0, i), N(e, i + 1, -1), i);
}
export {
  $ as comment,
  ra as compile,
  S as declaration,
  M as parse,
  I as ruleset
};
//# sourceMappingURL=Parser.js.map
