var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", SYMBOL = "symbol", ATOM = "atom", NUMBER = "number", BRACKET = "bracket", INDENT_WORD_SKIP = 2;
function makeKeywords(e) {
  for (var m = {}, h = e.split(" "), g = 0; g < h.length; ++g) m[h[g]] = true;
  return m;
}
var keywords = makeKeywords("\u03BB case-lambda call/cc class cond-expand define-class define-values exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax define-macro defmacro delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?"), indentKeys = makeKeywords("define let letrec let* lambda define-macro defmacro let-syntax letrec-syntax let-values let*-values define-syntax syntax-rules define-values when unless");
function stateStack(e, m, h) {
  this.indent = e, this.type = m, this.prev = h;
}
function pushStack(e, m, h) {
  e.indentStack = new stateStack(m, h, e.indentStack);
}
function popStack(e) {
  e.indentStack = e.indentStack.prev;
}
var binaryMatcher = /* @__PURE__ */ new RegExp(/^(?:[-+]i|[-+][01]+#*(?:\/[01]+#*)?i|[-+]?[01]+#*(?:\/[01]+#*)?@[-+]?[01]+#*(?:\/[01]+#*)?|[-+]?[01]+#*(?:\/[01]+#*)?[-+](?:[01]+#*(?:\/[01]+#*)?)?i|[-+]?[01]+#*(?:\/[01]+#*)?)(?=[()\s;"]|$)/i), octalMatcher = /* @__PURE__ */ new RegExp(/^(?:[-+]i|[-+][0-7]+#*(?:\/[0-7]+#*)?i|[-+]?[0-7]+#*(?:\/[0-7]+#*)?@[-+]?[0-7]+#*(?:\/[0-7]+#*)?|[-+]?[0-7]+#*(?:\/[0-7]+#*)?[-+](?:[0-7]+#*(?:\/[0-7]+#*)?)?i|[-+]?[0-7]+#*(?:\/[0-7]+#*)?)(?=[()\s;"]|$)/i), hexMatcher = /* @__PURE__ */ new RegExp(/^(?:[-+]i|[-+][\da-f]+#*(?:\/[\da-f]+#*)?i|[-+]?[\da-f]+#*(?:\/[\da-f]+#*)?@[-+]?[\da-f]+#*(?:\/[\da-f]+#*)?|[-+]?[\da-f]+#*(?:\/[\da-f]+#*)?[-+](?:[\da-f]+#*(?:\/[\da-f]+#*)?)?i|[-+]?[\da-f]+#*(?:\/[\da-f]+#*)?)(?=[()\s;"]|$)/i), decimalMatcher = /* @__PURE__ */ new RegExp(/^(?:[-+]i|[-+](?:(?:(?:\d+#+\.?#*|\d+\.\d*#*|\.\d+#*|\d+)(?:[esfdl][-+]?\d+)?)|\d+#*\/\d+#*)i|[-+]?(?:(?:(?:\d+#+\.?#*|\d+\.\d*#*|\.\d+#*|\d+)(?:[esfdl][-+]?\d+)?)|\d+#*\/\d+#*)@[-+]?(?:(?:(?:\d+#+\.?#*|\d+\.\d*#*|\.\d+#*|\d+)(?:[esfdl][-+]?\d+)?)|\d+#*\/\d+#*)|[-+]?(?:(?:(?:\d+#+\.?#*|\d+\.\d*#*|\.\d+#*|\d+)(?:[esfdl][-+]?\d+)?)|\d+#*\/\d+#*)[-+](?:(?:(?:\d+#+\.?#*|\d+\.\d*#*|\.\d+#*|\d+)(?:[esfdl][-+]?\d+)?)|\d+#*\/\d+#*)?i|(?:(?:(?:\d+#+\.?#*|\d+\.\d*#*|\.\d+#*|\d+)(?:[esfdl][-+]?\d+)?)|\d+#*\/\d+#*))(?=[()\s;"]|$)/i);
function isBinaryNumber(e) {
  return e.match(binaryMatcher);
}
function isOctalNumber(e) {
  return e.match(octalMatcher);
}
function isDecimalNumber(e, m) {
  return m === true && e.backUp(1), e.match(decimalMatcher);
}
function isHexNumber(e) {
  return e.match(hexMatcher);
}
function processEscapedSequence(e, m) {
  for (var h, g = false; (h = e.next()) != null; ) {
    if (h == m.token && !g) {
      m.state.mode = false;
      break;
    }
    g = !g && h == "\\";
  }
}
const scheme = {
  name: "scheme",
  startState: function() {
    return {
      indentStack: null,
      indentation: 0,
      mode: false,
      sExprComment: false,
      sExprQuote: false
    };
  },
  token: function(_, v) {
    if (v.indentStack == null && _.sol() && (v.indentation = _.indentation()), _.eatSpace()) return null;
    var y = null;
    switch (v.mode) {
      case "string":
        processEscapedSequence(_, {
          token: '"',
          state: v
        }), y = STRING;
        break;
      case "symbol":
        processEscapedSequence(_, {
          token: "|",
          state: v
        }), y = SYMBOL;
        break;
      case "comment":
        for (var b, x = false; (b = _.next()) != null; ) {
          if (b == "#" && x) {
            v.mode = false;
            break;
          }
          x = b == "|";
        }
        y = COMMENT;
        break;
      case "s-expr-comment":
        if (v.mode = false, _.peek() == "(" || _.peek() == "[") v.sExprComment = 0;
        else {
          _.eatWhile(/[^\s\(\)\[\]]/), y = COMMENT;
          break;
        }
      default:
        var S = _.next();
        if (S == '"') v.mode = "string", y = STRING;
        else if (S == "'") _.peek() == "(" || _.peek() == "[" ? (typeof v.sExprQuote != "number" && (v.sExprQuote = 0), y = ATOM) : (_.eatWhile(/[\w_\-!$%&*+\.\/:<=>?@\^~]/), y = ATOM);
        else if (S == "|") v.mode = "symbol", y = SYMBOL;
        else if (S == "#") if (_.eat("|")) v.mode = "comment", y = COMMENT;
        else if (_.eat(/[tf]/i)) y = ATOM;
        else if (_.eat(";")) v.mode = "s-expr-comment", y = COMMENT;
        else {
          var C = null, w = false, T = true;
          _.eat(/[ei]/i) ? w = true : _.backUp(1), _.match(/^#b/i) ? C = isBinaryNumber : _.match(/^#o/i) ? C = isOctalNumber : _.match(/^#x/i) ? C = isHexNumber : _.match(/^#d/i) ? C = isDecimalNumber : _.match(/^[-+0-9.]/, false) ? (T = false, C = isDecimalNumber) : w || _.eat("#"), C != null && (T && !w && _.match(/^#[ei]/i), C(_) && (y = NUMBER));
        }
        else if (/^[-+0-9.]/.test(S) && isDecimalNumber(_, true)) y = NUMBER;
        else if (S == ";") _.skipToEnd(), y = COMMENT;
        else if (S == "(" || S == "[") {
          for (var E = "", D = _.column(), O; (O = _.eat(/[^\s\(\[\;\)\]]/)) != null; ) E += O;
          E.length > 0 && indentKeys.propertyIsEnumerable(E) ? pushStack(v, D + INDENT_WORD_SKIP, S) : (_.eatSpace(), _.eol() || _.peek() == ";" ? pushStack(v, D + 1, S) : pushStack(v, D + _.current().length, S)), _.backUp(_.current().length - 1), typeof v.sExprComment == "number" && v.sExprComment++, typeof v.sExprQuote == "number" && v.sExprQuote++, y = BRACKET;
        } else S == ")" || S == "]" ? (y = BRACKET, v.indentStack != null && v.indentStack.type == (S == ")" ? "(" : "[") && (popStack(v), typeof v.sExprComment == "number" && --v.sExprComment == 0 && (y = COMMENT, v.sExprComment = false), typeof v.sExprQuote == "number" && --v.sExprQuote == 0 && (y = ATOM, v.sExprQuote = false))) : (_.eatWhile(/[\w_\-!$%&*+\.\/:<=>?@\^~]/), y = keywords && keywords.propertyIsEnumerable(_.current()) ? BUILTIN : "variable");
    }
    return typeof v.sExprComment == "number" ? COMMENT : typeof v.sExprQuote == "number" ? ATOM : y;
  },
  indent: function(e) {
    return e.indentStack == null ? e.indentation : e.indentStack.indent;
  },
  languageData: {
    closeBrackets: { brackets: [
      "(",
      "[",
      "{",
      '"'
    ] },
    commentTokens: { line: ";;" }
  }
};
export {
  scheme as t
};
