var curPunc, keywords = buildRE(/* @__PURE__ */ "abs.acos.aj.aj0.all.and.any.asc.asin.asof.atan.attr.avg.avgs.bin.by.ceiling.cols.cor.cos.count.cov.cross.csv.cut.delete.deltas.desc.dev.differ.distinct.div.do.each.ej.enlist.eval.except.exec.exit.exp.fby.fills.first.fkeys.flip.floor.from.get.getenv.group.gtime.hclose.hcount.hdel.hopen.hsym.iasc.idesc.if.ij.in.insert.inter.inv.key.keys.last.like.list.lj.load.log.lower.lsq.ltime.ltrim.mavg.max.maxs.mcount.md5.mdev.med.meta.min.mins.mmax.mmin.mmu.mod.msum.neg.next.not.null.or.over.parse.peach.pj.plist.prd.prds.prev.prior.rand.rank.ratios.raze.read0.read1.reciprocal.reverse.rload.rotate.rsave.rtrim.save.scan.select.set.setenv.show.signum.sin.sqrt.ss.ssr.string.sublist.sum.sums.sv.system.tables.tan.til.trim.txf.type.uj.ungroup.union.update.upper.upsert.value.var.view.views.vs.wavg.where.where.while.within.wj.wj1.wsum.xasc.xbar.xcol.xcols.xdesc.xexp.xgroup.xkey.xlog.xprev.xrank".split(".")), E = /[|/&^!+:\\\-*%$=~#;@><,?_\'\"\[\(\]\)\s{}]/;
function buildRE(e) {
  return /* @__PURE__ */ RegExp("^(" + e.join("|") + ")$");
}
function tokenBase(a, c) {
  var l = a.sol(), u = a.next();
  if (curPunc = null, l) {
    if (u == "/") return (c.tokenize = tokenLineComment)(a, c);
    if (u == "\\") return a.eol() || /\s/.test(a.peek()) ? (a.skipToEnd(), /^\\\s*$/.test(a.current()) ? (c.tokenize = tokenCommentToEOF)(a) : c.tokenize = tokenBase, "comment") : (c.tokenize = tokenBase, "builtin");
  }
  if (/\s/.test(u)) return a.peek() == "/" ? (a.skipToEnd(), "comment") : "null";
  if (u == '"') return (c.tokenize = tokenString)(a, c);
  if (u == "`") return a.eatWhile(/[A-Za-z\d_:\/.]/), "macroName";
  if (u == "." && /\d/.test(a.peek()) || /\d/.test(u)) {
    var d = null;
    return a.backUp(1), a.match(/^\d{4}\.\d{2}(m|\.\d{2}([DT](\d{2}(:\d{2}(:\d{2}(\.\d{1,9})?)?)?)?)?)/) || a.match(/^\d+D(\d{2}(:\d{2}(:\d{2}(\.\d{1,9})?)?)?)/) || a.match(/^\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?/) || a.match(/^\d+[ptuv]{1}/) ? d = "temporal" : (a.match(/^0[NwW]{1}/) || a.match(/^0x[\da-fA-F]*/) || a.match(/^[01]+[b]{1}/) || a.match(/^\d+[chijn]{1}/) || a.match(/-?\d*(\.\d*)?(e[+\-]?\d+)?(e|f)?/)) && (d = "number"), d && (!(u = a.peek()) || E.test(u)) ? d : (a.next(), "error");
  }
  return /[A-Za-z]|\./.test(u) ? (a.eatWhile(/[A-Za-z._\d]/), keywords.test(a.current()) ? "keyword" : "variable") : /[|/&^!+:\\\-*%$=~#;@><\.,?_\']/.test(u) || /[{}\(\[\]\)]/.test(u) ? null : "error";
}
function tokenLineComment(e, r) {
  return e.skipToEnd(), /^\/\s*$/.test(e.current()) ? (r.tokenize = tokenBlockComment)(e, r) : r.tokenize = tokenBase, "comment";
}
function tokenBlockComment(e, r) {
  var i = e.sol() && e.peek() == "\\";
  return e.skipToEnd(), i && /^\\\s*$/.test(e.current()) && (r.tokenize = tokenBase), "comment";
}
function tokenCommentToEOF(e) {
  return e.skipToEnd(), "comment";
}
function tokenString(e, r) {
  for (var i = false, a, s = false; a = e.next(); ) {
    if (a == '"' && !i) {
      s = true;
      break;
    }
    i = !i && a == "\\";
  }
  return s && (r.tokenize = tokenBase), "string";
}
function pushContext(e, r, i) {
  e.context = {
    prev: e.context,
    indent: e.indent,
    col: i,
    type: r
  };
}
function popContext(e) {
  e.indent = e.context.indent, e.context = e.context.prev;
}
const q = {
  name: "q",
  startState: function() {
    return {
      tokenize: tokenBase,
      context: null,
      indent: 0,
      col: 0
    };
  },
  token: function(r, i) {
    r.sol() && (i.context && i.context.align == null && (i.context.align = false), i.indent = r.indentation());
    var a = i.tokenize(r, i);
    if (a != "comment" && i.context && i.context.align == null && i.context.type != "pattern" && (i.context.align = true), curPunc == "(") pushContext(i, ")", r.column());
    else if (curPunc == "[") pushContext(i, "]", r.column());
    else if (curPunc == "{") pushContext(i, "}", r.column());
    else if (/[\]\}\)]/.test(curPunc)) {
      for (; i.context && i.context.type == "pattern"; ) popContext(i);
      i.context && curPunc == i.context.type && popContext(i);
    } else curPunc == "." && i.context && i.context.type == "pattern" ? popContext(i) : /atom|string|variable/.test(a) && i.context && (/[\}\]]/.test(i.context.type) ? pushContext(i, "pattern", r.column()) : i.context.type == "pattern" && !i.context.align && (i.context.align = true, i.context.col = r.column()));
    return a;
  },
  indent: function(e, r, i) {
    var a = r && r.charAt(0), o = e.context;
    if (/[\]\}]/.test(a)) for (; o && o.type == "pattern"; ) o = o.prev;
    var s = o && a == o.type;
    return o ? o.type == "pattern" ? o.col : o.align ? o.col + (s ? 0 : 1) : o.indent + (s ? 0 : i.unit) : 0;
  },
  languageData: { commentTokens: { line: "/" } }
};
export {
  q as t
};
