var keywords = (function() {
  function e(e2) {
    return {
      type: e2,
      style: "keyword"
    };
  }
  for (var o = e("operator"), s = {
    type: "atom",
    style: "atom"
  }, c = {
    type: "punctuation",
    style: null
  }, l = {
    type: "axis_specifier",
    style: "qualifier"
  }, u = { ",": c }, d = /* @__PURE__ */ "after.all.allowing.ancestor.ancestor-or-self.any.array.as.ascending.at.attribute.base-uri.before.boundary-space.by.case.cast.castable.catch.child.collation.comment.construction.contains.content.context.copy.copy-namespaces.count.decimal-format.declare.default.delete.descendant.descendant-or-self.descending.diacritics.different.distance.document.document-node.element.else.empty.empty-sequence.encoding.end.entire.every.exactly.except.external.first.following.following-sibling.for.from.ftand.ftnot.ft-option.ftor.function.fuzzy.greatest.group.if.import.in.inherit.insensitive.insert.instance.intersect.into.invoke.is.item.language.last.lax.least.let.levels.lowercase.map.modify.module.most.namespace.next.no.node.nodes.no-inherit.no-preserve.not.occurs.of.only.option.order.ordered.ordering.paragraph.paragraphs.parent.phrase.preceding.preceding-sibling.preserve.previous.processing-instruction.relationship.rename.replace.return.revalidation.same.satisfies.schema.schema-attribute.schema-element.score.self.sensitive.sentence.sentences.sequence.skip.sliding.some.stable.start.stemming.stop.strict.strip.switch.text.then.thesaurus.times.to.transform.treat.try.tumbling.type.typeswitch.union.unordered.update.updating.uppercase.using.validate.value.variable.version.weight.when.where.wildcards.window.with.without.word.words.xquery".split("."), f = 0, p = d.length; f < p; f++) u[d[f]] = e(d[f]);
  for (var m = /* @__PURE__ */ "xs:anyAtomicType.xs:anySimpleType.xs:anyType.xs:anyURI.xs:base64Binary.xs:boolean.xs:byte.xs:date.xs:dateTime.xs:dateTimeStamp.xs:dayTimeDuration.xs:decimal.xs:double.xs:duration.xs:ENTITIES.xs:ENTITY.xs:float.xs:gDay.xs:gMonth.xs:gMonthDay.xs:gYear.xs:gYearMonth.xs:hexBinary.xs:ID.xs:IDREF.xs:IDREFS.xs:int.xs:integer.xs:item.xs:java.xs:language.xs:long.xs:Name.xs:NCName.xs:negativeInteger.xs:NMTOKEN.xs:NMTOKENS.xs:nonNegativeInteger.xs:nonPositiveInteger.xs:normalizedString.xs:NOTATION.xs:numeric.xs:positiveInteger.xs:precisionDecimal.xs:QName.xs:short.xs:string.xs:time.xs:token.xs:unsignedByte.xs:unsignedInt.xs:unsignedLong.xs:unsignedShort.xs:untyped.xs:untypedAtomic.xs:yearMonthDuration".split("."), f = 0, p = m.length; f < p; f++) u[m[f]] = s;
  for (var h = [
    "eq",
    "ne",
    "lt",
    "le",
    "gt",
    "ge",
    ":=",
    "=",
    ">",
    ">=",
    "<",
    "<=",
    ".",
    "|",
    "?",
    "and",
    "or",
    "div",
    "idiv",
    "mod",
    "*",
    "/",
    "+",
    "-"
  ], f = 0, p = h.length; f < p; f++) u[h[f]] = o;
  for (var g = [
    "self::",
    "attribute::",
    "child::",
    "descendant::",
    "descendant-or-self::",
    "parent::",
    "ancestor::",
    "ancestor-or-self::",
    "following::",
    "preceding::",
    "following-sibling::",
    "preceding-sibling::"
  ], f = 0, p = g.length; f < p; f++) u[g[f]] = l;
  return u;
})();
function chain(e, o, s) {
  return o.tokenize = s, s(e, o);
}
function tokenBase(s, l) {
  var p = s.next(), _ = false, v = isEQNameAhead(s);
  if (p == "<") {
    if (s.match("!--", true)) return chain(s, l, tokenXMLComment);
    if (s.match("![CDATA", false)) return l.tokenize = tokenCDATA, "tag";
    if (s.match("?", false)) return chain(s, l, tokenPreProcessing);
    var y = s.eat("/");
    s.eatSpace();
    for (var b = "", x; x = s.eat(/[^\s\u00a0=<>\"\'\/?]/); ) b += x;
    return chain(s, l, tokenTag(b, y));
  } else if (p == "{") return pushStateStack(l, { type: "codeblock" }), null;
  else if (p == "}") return popStateStack(l), null;
  else if (isInXmlBlock(l)) return p == ">" ? "tag" : p == "/" && s.eat(">") ? (popStateStack(l), "tag") : "variable";
  else if (/\d/.test(p)) return s.match(/^\d*(?:\.\d*)?(?:E[+\-]?\d+)?/), "atom";
  else if (p === "(" && s.eat(":")) return pushStateStack(l, { type: "comment" }), chain(s, l, tokenComment);
  else if (!v && (p === '"' || p === "'")) return startString(s, l, p);
  else if (p === "$") return chain(s, l, tokenVariable);
  else if (p === ":" && s.eat("=")) return "keyword";
  else if (p === "(") return pushStateStack(l, { type: "paren" }), null;
  else if (p === ")") return popStateStack(l), null;
  else if (p === "[") return pushStateStack(l, { type: "bracket" }), null;
  else if (p === "]") return popStateStack(l), null;
  else {
    var S = keywords.propertyIsEnumerable(p) && keywords[p];
    if (v && p === '"') for (; s.next() !== '"'; ) ;
    if (v && p === "'") for (; s.next() !== "'"; ) ;
    S || s.eatWhile(/[\w\$_-]/);
    var C = s.eat(":");
    !s.eat(":") && C && s.eatWhile(/[\w\$_-]/), s.match(/^[ \t]*\(/, false) && (_ = true);
    var w = s.current();
    return S = keywords.propertyIsEnumerable(w) && keywords[w], _ && !S && (S = {
      type: "function_call",
      style: "def"
    }), isInXmlConstructor(l) ? (popStateStack(l), "variable") : ((w == "element" || w == "attribute" || S.type == "axis_specifier") && pushStateStack(l, { type: "xmlconstructor" }), S ? S.style : "variable");
  }
}
function tokenComment(e, o) {
  for (var s = false, c = false, l = 0, u; u = e.next(); ) {
    if (u == ")" && s) if (l > 0) l--;
    else {
      popStateStack(o);
      break;
    }
    else u == ":" && c && l++;
    s = u == ":", c = u == "(";
  }
  return "comment";
}
function tokenString(e, o) {
  return function(c, l) {
    for (var u; u = c.next(); ) if (u == e) {
      popStateStack(l), o && (l.tokenize = o);
      break;
    } else if (c.match("{", false) && isInXmlAttributeBlock(l)) return pushStateStack(l, { type: "codeblock" }), l.tokenize = tokenBase, "string";
    return "string";
  };
}
function startString(e, s, c, u) {
  let d = tokenString(c, u);
  return pushStateStack(s, {
    type: "string",
    name: c,
    tokenize: d
  }), chain(e, s, d);
}
function tokenVariable(e, o) {
  var c = /[\w\$_-]/;
  if (e.eat('"')) {
    for (; e.next() !== '"'; ) ;
    e.eat(":");
  } else e.eatWhile(c), e.match(":=", false) || e.eat(":");
  return e.eatWhile(c), o.tokenize = tokenBase, "variable";
}
function tokenTag(e, o) {
  return function(c, l) {
    if (c.eatSpace(), o && c.eat(">")) return popStateStack(l), l.tokenize = tokenBase, "tag";
    if (c.eat("/") || pushStateStack(l, {
      type: "tag",
      name: e,
      tokenize: tokenBase
    }), c.eat(">")) l.tokenize = tokenBase;
    else return l.tokenize = tokenAttribute, "tag";
    return "tag";
  };
}
function tokenAttribute(e, o) {
  var c = e.next();
  return c == "/" && e.eat(">") ? (isInXmlAttributeBlock(o) && popStateStack(o), isInXmlBlock(o) && popStateStack(o), "tag") : c == ">" ? (isInXmlAttributeBlock(o) && popStateStack(o), "tag") : c == "=" ? null : c == '"' || c == "'" ? startString(e, o, c, tokenAttribute) : (isInXmlAttributeBlock(o) || pushStateStack(o, {
    type: "attribute",
    tokenize: tokenAttribute
  }), e.eat(/[a-zA-Z_:]/), e.eatWhile(/[-a-zA-Z0-9_:.]/), e.eatSpace(), (e.match(">", false) || e.match("/", false)) && (popStateStack(o), o.tokenize = tokenBase), "attribute");
}
function tokenXMLComment(e, o) {
  for (var c; c = e.next(); ) if (c == "-" && e.match("->", true)) return o.tokenize = tokenBase, "comment";
}
function tokenCDATA(e, o) {
  for (var c; c = e.next(); ) if (c == "]" && e.match("]", true)) return o.tokenize = tokenBase, "comment";
}
function tokenPreProcessing(e, o) {
  for (var c; c = e.next(); ) if (c == "?" && e.match(">", true)) return o.tokenize = tokenBase, "processingInstruction";
}
function isInXmlBlock(e) {
  return isIn(e, "tag");
}
function isInXmlAttributeBlock(e) {
  return isIn(e, "attribute");
}
function isInXmlConstructor(e) {
  return isIn(e, "xmlconstructor");
}
function isEQNameAhead(e) {
  return e.current() === '"' ? e.match(/^[^\"]+\"\:/, false) : e.current() === "'" ? e.match(/^[^\"]+\'\:/, false) : false;
}
function isIn(e, o) {
  return e.stack.length && e.stack[e.stack.length - 1].type == o;
}
function pushStateStack(e, o) {
  e.stack.push(o);
}
function popStateStack(e) {
  e.stack.pop(), e.tokenize = e.stack.length && e.stack[e.stack.length - 1].tokenize || tokenBase;
}
const xQuery = {
  name: "xquery",
  startState: function() {
    return {
      tokenize: tokenBase,
      cc: [],
      stack: []
    };
  },
  token: function(e, o) {
    return e.eatSpace() ? null : o.tokenize(e, o);
  },
  languageData: { commentTokens: { block: {
    open: "(:",
    close: ":)"
  } } }
};
export {
  xQuery as t
};
