var specialForm = /^(block|let*|return-from|catch|load-time-value|setq|eval-when|locally|symbol-macrolet|flet|macrolet|tagbody|function|multiple-value-call|the|go|multiple-value-prog1|throw|if|progn|unwind-protect|labels|progv|let|quote)$/, assumeBody = /^with|^def|^do|^prog|case$|^cond$|bind$|when$|unless$/, numLiteral = /^(?:[+\-]?(?:\d+|\d*\.\d+)(?:[efd][+\-]?\d+)?|[+\-]?\d+(?:\/[+\-]?\d+)?|#b[+\-]?[01]+|#o[+\-]?[0-7]+|#x[+\-]?[\da-f]+)/, symbol = /[^\s'`,@()\[\]";]/, type;
function readSym(e) {
  for (var a; a = e.next(); ) if (a == "\\") e.next();
  else if (!symbol.test(a)) {
    e.backUp(1);
    break;
  }
  return e.current();
}
function base(s, c) {
  if (s.eatSpace()) return type = "ws", null;
  if (s.match(numLiteral)) return "number";
  var l = s.next();
  if (l == "\\" && (l = s.next()), l == '"') return (c.tokenize = inString)(s, c);
  if (l == "(") return type = "open", "bracket";
  if (l == ")") return type = "close", "bracket";
  if (l == ";") return s.skipToEnd(), type = "ws", "comment";
  if (/['`,@]/.test(l)) return null;
  if (l == "|") return s.skipTo("|") ? (s.next(), "variableName") : (s.skipToEnd(), "error");
  if (l == "#") {
    var l = s.next();
    return l == "(" ? (type = "open", "bracket") : /[+\-=\.']/.test(l) || /\d/.test(l) && s.match(/^\d*#/) ? null : l == "|" ? (c.tokenize = inComment)(s, c) : l == ":" ? (readSym(s), "meta") : l == "\\" ? (s.next(), readSym(s), "string.special") : "error";
  } else {
    var u = readSym(s);
    return u == "." ? null : (type = "symbol", u == "nil" || u == "t" || u.charAt(0) == ":" ? "atom" : c.lastType == "open" && (specialForm.test(u) || assumeBody.test(u)) ? "keyword" : u.charAt(0) == "&" ? "variableName.special" : "variableName");
  }
}
function inString(e, a) {
  for (var o = false, s; s = e.next(); ) {
    if (s == '"' && !o) {
      a.tokenize = base;
      break;
    }
    o = !o && s == "\\";
  }
  return "string";
}
function inComment(e, a) {
  for (var o, s; o = e.next(); ) {
    if (o == "#" && s == "|") {
      a.tokenize = base;
      break;
    }
    s = o;
  }
  return type = "ws", "comment";
}
const commonLisp = {
  name: "commonlisp",
  startState: function() {
    return {
      ctx: {
        prev: null,
        start: 0,
        indentTo: 0
      },
      lastType: null,
      tokenize: base
    };
  },
  token: function(e, o) {
    e.sol() && typeof o.ctx.indentTo != "number" && (o.ctx.indentTo = o.ctx.start + 1), type = null;
    var s = o.tokenize(e, o);
    return type != "ws" && (o.ctx.indentTo == null ? type == "symbol" && assumeBody.test(e.current()) ? o.ctx.indentTo = o.ctx.start + e.indentUnit : o.ctx.indentTo = "next" : o.ctx.indentTo == "next" && (o.ctx.indentTo = e.column()), o.lastType = type), type == "open" ? o.ctx = {
      prev: o.ctx,
      start: e.column(),
      indentTo: null
    } : type == "close" && (o.ctx = o.ctx.prev || o.ctx), s;
  },
  indent: function(e) {
    var a = e.ctx.indentTo;
    return typeof a == "number" ? a : e.ctx.start + 1;
  },
  languageData: {
    commentTokens: {
      line: ";;",
      block: {
        open: "#|",
        close: "|#"
      }
    },
    closeBrackets: { brackets: [
      "(",
      "[",
      "{",
      '"'
    ] }
  }
};
export {
  commonLisp as t
};
