function prefixRE(e) {
  return RegExp("^(?:" + e.join("|") + ")", "i");
}
function wordRE(e) {
  return RegExp("^(?:" + e.join("|") + ")$", "i");
}
var builtins = wordRE(/* @__PURE__ */ "_G,_VERSION,assert,collectgarbage,dofile,error,getfenv,getmetatable,ipairs,load,loadfile,loadstring,module,next,pairs,pcall,print,rawequal,rawget,rawset,require,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,coroutine.create,coroutine.resume,coroutine.running,coroutine.status,coroutine.wrap,coroutine.yield,debug.debug,debug.getfenv,debug.gethook,debug.getinfo,debug.getlocal,debug.getmetatable,debug.getregistry,debug.getupvalue,debug.setfenv,debug.sethook,debug.setlocal,debug.setmetatable,debug.setupvalue,debug.traceback,close,flush,lines,read,seek,setvbuf,write,io.close,io.flush,io.input,io.lines,io.open,io.output,io.popen,io.read,io.stderr,io.stdin,io.stdout,io.tmpfile,io.type,io.write,math.abs,math.acos,math.asin,math.atan,math.atan2,math.ceil,math.cos,math.cosh,math.deg,math.exp,math.floor,math.fmod,math.frexp,math.huge,math.ldexp,math.log,math.log10,math.max,math.min,math.modf,math.pi,math.pow,math.rad,math.random,math.randomseed,math.sin,math.sinh,math.sqrt,math.tan,math.tanh,os.clock,os.date,os.difftime,os.execute,os.exit,os.getenv,os.remove,os.rename,os.setlocale,os.time,os.tmpname,package.cpath,package.loaded,package.loaders,package.loadlib,package.path,package.preload,package.seeall,string.byte,string.char,string.dump,string.find,string.format,string.gmatch,string.gsub,string.len,string.lower,string.match,string.rep,string.reverse,string.sub,string.upper,table.concat,table.insert,table.maxn,table.remove,table.sort".split(",")), keywords = wordRE([
  "and",
  "break",
  "elseif",
  "false",
  "nil",
  "not",
  "or",
  "return",
  "true",
  "function",
  "end",
  "if",
  "then",
  "else",
  "do",
  "while",
  "repeat",
  "until",
  "for",
  "in",
  "local"
]), indentTokens = wordRE([
  "function",
  "if",
  "repeat",
  "do",
  "\\(",
  "{"
]), dedentTokens = wordRE([
  "end",
  "until",
  "\\)",
  "}"
]), dedentPartial = prefixRE([
  "end",
  "until",
  "\\)",
  "}",
  "else",
  "elseif"
]);
function readBracket(e) {
  for (var a = 0; e.eat("="); ) ++a;
  return e.eat("["), a;
}
function normal(e, a) {
  var o = e.next();
  return o == "-" && e.eat("-") ? e.eat("[") && e.eat("[") ? (a.cur = bracketed(readBracket(e), "comment"))(e, a) : (e.skipToEnd(), "comment") : o == '"' || o == "'" ? (a.cur = string(o))(e, a) : o == "[" && /[\[=]/.test(e.peek()) ? (a.cur = bracketed(readBracket(e), "string"))(e, a) : /\d/.test(o) ? (e.eatWhile(/[\w.%]/), "number") : /[\w_]/.test(o) ? (e.eatWhile(/[\w\\\-_.]/), "variable") : null;
}
function bracketed(e, a) {
  return function(o, s) {
    for (var c = null, l; (l = o.next()) != null; ) if (c == null) l == "]" && (c = 0);
    else if (l == "=") ++c;
    else if (l == "]" && c == e) {
      s.cur = normal;
      break;
    } else c = null;
    return a;
  };
}
function string(e) {
  return function(a, o) {
    for (var s = false, c; (c = a.next()) != null && !(c == e && !s); ) s = !s && c == "\\";
    return s || (o.cur = normal), "string";
  };
}
const lua = {
  name: "lua",
  startState: function() {
    return {
      basecol: 0,
      indentDepth: 0,
      cur: normal
    };
  },
  token: function(e, a) {
    if (e.eatSpace()) return null;
    var u = a.cur(e, a), d = e.current();
    return u == "variable" && (keywords.test(d) ? u = "keyword" : builtins.test(d) && (u = "builtin")), u != "comment" && u != "string" && (indentTokens.test(d) ? ++a.indentDepth : dedentTokens.test(d) && --a.indentDepth), u;
  },
  indent: function(e, a, o) {
    var s = dedentPartial.test(a);
    return e.basecol + o.unit * (e.indentDepth - (s ? 1 : 0));
  },
  languageData: {
    indentOnInput: /^\s*(?:end|until|else|\)|\})$/,
    commentTokens: {
      line: "--",
      block: {
        open: "--[[",
        close: "]]--"
      }
    }
  }
};
export {
  lua as t
};
