function wordRegexp(t, T, E) {
  return E === void 0 && (E = ""), T === void 0 && (T = "\\b"), /* @__PURE__ */ RegExp("^" + E + "((" + t.join(")|(") + "))" + T);
}
var octChar = "\\\\[0-7]{1,3}", hexChar = "\\\\x[A-Fa-f0-9]{1,2}", sChar = `\\\\[abefnrtv0%?'"\\\\]`, uChar = "([^\\u0027\\u005C\\uD800-\\uDFFF]|[\\uD800-\\uDFFF][\\uDC00-\\uDFFF])", asciiOperatorsList = [
  "[<>]:",
  "[<>=]=",
  "<<=?",
  ">>>?=?",
  "=>",
  "--?>",
  "<--[->]?",
  "\\/\\/",
  "\\.{2,3}",
  "[\\.\\\\%*+\\-<>!\\/^|&]=?",
  "\\?",
  "\\$",
  "~",
  ":"
], operators = wordRegexp(/* @__PURE__ */ "[<>]:,[<>=]=,[!=]==,<<=?,>>>?=?,=>?,--?>,<--[->]?,\\/\\/,[\\\\%*+\\-<>!\\/^|&\\u00F7\\u22BB]=?,\\?,\\$,~,:,\\u00D7,\\u2208,\\u2209,\\u220B,\\u220C,\\u2218,\\u221A,\\u221B,\\u2229,\\u222A,\\u2260,\\u2264,\\u2265,\\u2286,\\u2288,\\u228A,\\u22C5,\\b(in|isa)\\b(?!.?\\()".split(","), ""), delimiters = /^[;,()[\]{}]/, identifiers = /^[_A-Za-z\u00A1-\u2217\u2219-\uFFFF][\w\u00A1-\u2217\u2219-\uFFFF]*!*/, chars = wordRegexp([
  octChar,
  hexChar,
  sChar,
  uChar
], "'"), openersList = [
  "begin",
  "function",
  "type",
  "struct",
  "immutable",
  "let",
  "macro",
  "for",
  "while",
  "quote",
  "if",
  "else",
  "elseif",
  "try",
  "finally",
  "catch",
  "do"
], closersList = [
  "end",
  "else",
  "elseif",
  "catch",
  "finally"
], keywordsList = /* @__PURE__ */ "if.else.elseif.while.for.begin.let.end.do.try.catch.finally.return.break.continue.global.local.const.export.import.importall.using.function.where.macro.module.baremodule.struct.type.mutable.immutable.quote.typealias.abstract.primitive.bitstype".split("."), builtinsList = [
  "true",
  "false",
  "nothing",
  "NaN",
  "Inf"
], openers = wordRegexp(openersList), closers = wordRegexp(closersList), keywords = wordRegexp(keywordsList), builtins = wordRegexp(builtinsList), macro = /^@[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/, symbol = /^:[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/, stringPrefixes = /^(`|([_A-Za-z\u00A1-\uFFFF]*"("")?))/, macroOperators = wordRegexp(asciiOperatorsList, "", "@"), symbolOperators = wordRegexp(asciiOperatorsList, "", ":");
function inArray(t) {
  return t.nestedArrays > 0;
}
function inGenerator(t) {
  return t.nestedGenerators > 0;
}
function currentScope(t, T) {
  return T === void 0 && (T = 0), t.scopes.length <= T ? null : t.scopes[t.scopes.length - (T + 1)];
}
function tokenBase(t, T) {
  if (t.match("#=", false)) return T.tokenize = tokenComment, T.tokenize(t, T);
  var E = T.leavingExpr;
  if (t.sol() && (E = false), T.leavingExpr = false, E && t.match(/^'+/)) return "operator";
  if (t.match(/\.{4,}/)) return "error";
  if (t.match(/\.{1,3}/)) return "operator";
  if (t.eatSpace()) return null;
  var D = t.peek();
  if (D === "#") return t.skipToEnd(), "comment";
  if (D === "[" && (T.scopes.push("["), T.nestedArrays++), D === "(" && (T.scopes.push("("), T.nestedGenerators++), inArray(T) && D === "]") {
    for (; T.scopes.length && currentScope(T) !== "["; ) T.scopes.pop();
    T.scopes.pop(), T.nestedArrays--, T.leavingExpr = true;
  }
  if (inGenerator(T) && D === ")") {
    for (; T.scopes.length && currentScope(T) !== "("; ) T.scopes.pop();
    T.scopes.pop(), T.nestedGenerators--, T.leavingExpr = true;
  }
  if (inArray(T)) {
    if (T.lastToken == "end" && t.match(":")) return "operator";
    if (t.match("end")) return "number";
  }
  var O;
  if ((O = t.match(openers, false)) && T.scopes.push(O[0]), t.match(closers, false) && T.scopes.pop(), t.match(/^::(?![:\$])/)) return T.tokenize = tokenAnnotation, T.tokenize(t, T);
  if (!E && (t.match(symbol) || t.match(symbolOperators))) return "builtin";
  if (t.match(operators)) return "operator";
  if (t.match(/^\.?\d/, false)) {
    var k = RegExp(/^im\b/), A = false;
    if (t.match(/^0x\.[0-9a-f_]+p[\+\-]?[_\d]+/i) && (A = true), t.match(/^0x[0-9a-f_]+/i) && (A = true), t.match(/^0b[01_]+/i) && (A = true), t.match(/^0o[0-7_]+/i) && (A = true), t.match(/^(?:(?:\d[_\d]*)?\.(?!\.)(?:\d[_\d]*)?|\d[_\d]*\.(?!\.)(?:\d[_\d]*))?([Eef][\+\-]?[_\d]+)?/i) && (A = true), t.match(/^\d[_\d]*(e[\+\-]?\d+)?/i) && (A = true), A) return t.match(k), T.leavingExpr = true, "number";
  }
  if (t.match("'")) return T.tokenize = tokenChar, T.tokenize(t, T);
  if (t.match(stringPrefixes)) return T.tokenize = tokenStringFactory(t.current()), T.tokenize(t, T);
  if (t.match(macro) || t.match(macroOperators)) return "meta";
  if (t.match(delimiters)) return null;
  if (t.match(keywords)) return "keyword";
  if (t.match(builtins)) return "builtin";
  var j = T.isDefinition || T.lastToken == "function" || T.lastToken == "macro" || T.lastToken == "type" || T.lastToken == "struct" || T.lastToken == "immutable";
  return t.match(identifiers) ? j ? t.peek() === "." ? (T.isDefinition = true, "variable") : (T.isDefinition = false, "def") : (T.leavingExpr = true, "variable") : (t.next(), "error");
}
function tokenAnnotation(t, T) {
  return t.match(/.*?(?=[,;{}()=\s]|$)/), t.match("{") ? T.nestedParameters++ : t.match("}") && T.nestedParameters > 0 && T.nestedParameters--, T.nestedParameters > 0 ? t.match(/.*?(?={|})/) || t.next() : T.nestedParameters == 0 && (T.tokenize = tokenBase), "builtin";
}
function tokenComment(t, T) {
  return t.match("#=") && T.nestedComments++, t.match(/.*?(?=(#=|=#))/) || t.skipToEnd(), t.match("=#") && (T.nestedComments--, T.nestedComments == 0 && (T.tokenize = tokenBase)), "comment";
}
function tokenChar(t, T) {
  var E = false, D;
  if (t.match(chars)) E = true;
  else if (D = t.match(/\\u([a-f0-9]{1,4})(?=')/i)) {
    var O = parseInt(D[1], 16);
    (O <= 55295 || O >= 57344) && (E = true, t.next());
  } else if (D = t.match(/\\U([A-Fa-f0-9]{5,8})(?=')/)) {
    var O = parseInt(D[1], 16);
    O <= 1114111 && (E = true, t.next());
  }
  return E ? (T.leavingExpr = true, T.tokenize = tokenBase, "string") : (t.match(/^[^']+(?=')/) || t.skipToEnd(), t.match("'") && (T.tokenize = tokenBase), "error");
}
function tokenStringFactory(t) {
  t.substr(-3) === '"""' ? t = '"""' : t.substr(-1) === '"' && (t = '"');
  function T(T2, E) {
    if (T2.eat("\\")) T2.next();
    else if (T2.match(t)) return E.tokenize = tokenBase, E.leavingExpr = true, "string";
    else T2.eat(/[`"]/);
    return T2.eatWhile(/[^\\`"]/), "string";
  }
  return T;
}
const julia = {
  name: "julia",
  startState: function() {
    return {
      tokenize: tokenBase,
      scopes: [],
      lastToken: null,
      leavingExpr: false,
      isDefinition: false,
      nestedArrays: 0,
      nestedComments: 0,
      nestedGenerators: 0,
      nestedParameters: 0,
      firstParenPos: -1
    };
  },
  token: function(t, T) {
    var E = T.tokenize(t, T), D = t.current();
    return D && E && (T.lastToken = D), E;
  },
  indent: function(t, T, E) {
    var D = 0;
    return (T === "]" || T === ")" || /^end\b/.test(T) || /^else/.test(T) || /^catch\b/.test(T) || /^elseif\b/.test(T) || /^finally/.test(T)) && (D = -1), (t.scopes.length + D) * E.unit;
  },
  languageData: {
    indentOnInput: /^\s*(end|else|catch|finally)\b$/,
    commentTokens: {
      line: "#",
      block: {
        open: "#=",
        close: "=#"
      }
    },
    closeBrackets: { brackets: [
      "(",
      "[",
      "{",
      '"'
    ] },
    autocomplete: keywordsList.concat(builtinsList)
  }
};
export {
  julia as t
};
